forked from yaso_meth/mih-project
update loading screen title & add notes list to patient view screen
This commit is contained in:
38
Frontend/patient_manager/lib/components/buildNotesList.dart
Normal file
38
Frontend/patient_manager/lib/components/buildNotesList.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/objects/notes.dart';
|
||||
|
||||
class BuildNotesList extends StatefulWidget {
|
||||
final List<Note> notes;
|
||||
const BuildNotesList({
|
||||
super.key,
|
||||
required this.notes,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BuildNotesList> createState() => _BuildNotesListState();
|
||||
}
|
||||
|
||||
int indexOn = 0;
|
||||
|
||||
class _BuildNotesListState extends State<BuildNotesList> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return const Divider();
|
||||
},
|
||||
itemCount: widget.notes.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
widget.notes[index].note_name,
|
||||
),
|
||||
subtitle: Text(widget.notes[index].note_text),
|
||||
trailing: const Icon(Icons.arrow_forward),
|
||||
onTap: () {},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,8 @@ class _BuildPatientsListState extends State<BuildPatientsList> {
|
||||
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
||||
return widget.patients[index].id_no.contains(widget.searchString)
|
||||
? ListTile(
|
||||
title: Text(widget.patients[index].first_name +
|
||||
" " +
|
||||
widget.patients[index].last_name),
|
||||
title: Text(
|
||||
"${widget.patients[index].first_name} ${widget.patients[index].last_name}"),
|
||||
subtitle: Text(widget.patients[index].id_no),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
|
||||
90
Frontend/patient_manager/lib/components/patientNotes.dart
Normal file
90
Frontend/patient_manager/lib/components/patientNotes.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/buildNotesList.dart';
|
||||
import 'package:patient_manager/objects/notes.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
Future<List<Note>> fetchNotes(String endpoint) async {
|
||||
final response = await http.get(Uri.parse(endpoint));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<Note> notes = List<Note>.from(l.map((model) => Note.fromJson(model)));
|
||||
return notes;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
|
||||
class PatientNotes extends StatefulWidget {
|
||||
final int patientIndex;
|
||||
const PatientNotes({super.key, required this.patientIndex});
|
||||
|
||||
@override
|
||||
State<PatientNotes> createState() => _PatientNotesState();
|
||||
}
|
||||
|
||||
class _PatientNotesState extends State<PatientNotes> {
|
||||
String endpoint = "http://localhost:80/notes/patients/";
|
||||
late Future<List<Note>> futueNotes;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
futueNotes = fetchNotes(endpoint + widget.patientIndex.toString());
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: futueNotes,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (snapshot.hasData) {
|
||||
final notesList = snapshot.data!;
|
||||
return Expanded(
|
||||
flex: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Card(
|
||||
elevation: 20.0,
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Color.fromARGB(255, 219, 218, 218),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Column(children: [
|
||||
const Text(
|
||||
"Notes",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Divider(),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BuildNotesList(notes: notesList),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: Text("Error Loading Notes"),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
35
Frontend/patient_manager/lib/objects/notes.dart
Normal file
35
Frontend/patient_manager/lib/objects/notes.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
class Note {
|
||||
final int idpatient_notes;
|
||||
final String note_name;
|
||||
final String note_text;
|
||||
final int patient_id;
|
||||
final String insert_date;
|
||||
|
||||
const Note({
|
||||
required this.idpatient_notes,
|
||||
required this.note_name,
|
||||
required this.note_text,
|
||||
required this.patient_id,
|
||||
required this.insert_date,
|
||||
});
|
||||
|
||||
factory Note.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
"idpatient_notes": int idpatient_notes,
|
||||
"note_name": String note_name,
|
||||
"note_text": String note_text,
|
||||
"patient_id": int patient_id,
|
||||
"insert_date": String insert_date,
|
||||
} =>
|
||||
Note(
|
||||
idpatient_notes: idpatient_notes,
|
||||
note_name: note_name,
|
||||
note_text: note_text,
|
||||
patient_id: patient_id,
|
||||
insert_date: insert_date,
|
||||
),
|
||||
_ => throw const FormatException('Failed to load album.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import 'package:patient_manager/components/buildPatientList.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/myAppDrawer.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mysql_client/mysql_client.dart';
|
||||
import 'package:patient_manager/components/mySearchInput.dart';
|
||||
import 'package:patient_manager/objects/patients.dart';
|
||||
|
||||
@@ -37,8 +36,6 @@ class PatientManager extends StatefulWidget {
|
||||
class _PatientManagerState extends State<PatientManager> {
|
||||
TextEditingController searchController = TextEditingController();
|
||||
String endpoint = "http://localhost:80/patients/user/";
|
||||
late MySQLConnection conn;
|
||||
String resultsofDB = "";
|
||||
late Future<List<Patient>> futurePatients;
|
||||
String searchString = "";
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/PatientDetails.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/patientNotes.dart';
|
||||
import 'package:patient_manager/objects/patients.dart';
|
||||
|
||||
class PatientView extends StatefulWidget {
|
||||
@@ -21,12 +22,22 @@ class _PatientViewState extends State<PatientView> {
|
||||
child: Column(
|
||||
children: [
|
||||
PatientDetails(selectedPatient: widget.selectedPatient),
|
||||
const SizedBox(
|
||||
height: 10.0,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
PatientNotes(
|
||||
patientIndex: widget.selectedPatient.idpatients,
|
||||
),
|
||||
PatientNotes(
|
||||
patientIndex: widget.selectedPatient.idpatients,
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
// Center(
|
||||
// child: Text(widget.selectedPatient.first_name),
|
||||
// ),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="patient_manager">
|
||||
<meta name="apple-mobile-web-app-title" content="Mzanzi Innovation Hub">
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>patient_manager</title>
|
||||
<title>Mzanzi Innovation Hub</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user