From 0fbede68b18d6652026f0f542a357353169b9c36 Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Mon, 29 Jul 2024 11:07:22 +0200 Subject: [PATCH] change to have personal notes view --- .../lib/components/patientNotes.dart | 71 ++++++++++++------- .../patient_manager/lib/objects/notes.dart | 8 +-- .../lib/pages/patientView.dart | 9 ++- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/Frontend/patient_manager/lib/components/patientNotes.dart b/Frontend/patient_manager/lib/components/patientNotes.dart index 28ab06a6..15350584 100644 --- a/Frontend/patient_manager/lib/components/patientNotes.dart +++ b/Frontend/patient_manager/lib/components/patientNotes.dart @@ -9,12 +9,15 @@ import 'package:patient_manager/components/myTextInput.dart'; import 'package:patient_manager/components/mybutton.dart'; import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/main.dart'; +import 'package:patient_manager/objects/appUser.dart'; import 'package:patient_manager/objects/notes.dart'; import 'package:supertokens_flutter/http.dart' as http; class PatientNotes extends StatefulWidget { - final int patientIndex; - const PatientNotes({super.key, required this.patientIndex}); + final String patientAppId; + final AppUser signedInUser; + const PatientNotes( + {super.key, required this.patientAppId, required this.signedInUser}); @override State createState() => _PatientNotesState(); @@ -28,7 +31,8 @@ class _PatientNotesState extends State { late Future> futueNotes; Future> fetchNotes(String endpoint) async { - final response = await http.get(Uri.parse(endpoint)); + final response = await http.get(Uri.parse( + "${AppEnviroment.baseApiUrl}/notes/patients/${widget.patientAppId}")); if (response.statusCode == 200) { Iterable l = jsonDecode(response.body); List notes = @@ -50,12 +54,12 @@ class _PatientNotesState extends State { body: jsonEncode({ "note_name": titleController.text, "note_text": noteTextController.text, - "patient_id": widget.patientIndex, + "patient_id": widget.patientAppId, }), ); if (response.statusCode == 201) { setState(() { - futueNotes = fetchNotes(endpoint + widget.patientIndex.toString()); + futueNotes = fetchNotes(endpoint + widget.patientAppId.toString()); }); // Navigator.of(context) // .pushNamed('/patient-manager', arguments: widget.userEmail); @@ -212,9 +216,42 @@ class _PatientNotesState extends State { } } + List setIcons() { + if (widget.signedInUser.type == "personal") { + return [ + Text( + "Notes", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.bold, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + ), + ]; + } else { + return [ + Text( + "Notes", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.bold, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + ), + IconButton( + onPressed: () { + addNotePopUp(); + }, + icon: Icon(Icons.add, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + ) + ]; + } + } + @override void initState() { - futueNotes = fetchNotes(endpoint + widget.patientIndex.toString()); + futueNotes = fetchNotes(endpoint + widget.patientAppId); super.initState(); } @@ -244,27 +281,7 @@ class _PatientNotesState extends State { child: Column(children: [ Row( mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Notes", - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 25, - fontWeight: FontWeight.bold, - color: MzanziInnovationHub.of(context)! - .theme - .secondaryColor()), - ), - IconButton( - onPressed: () { - addNotePopUp(); - }, - icon: Icon(Icons.add, - color: MzanziInnovationHub.of(context)! - .theme - .secondaryColor()), - ) - ], + children: setIcons(), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), diff --git a/Frontend/patient_manager/lib/objects/notes.dart b/Frontend/patient_manager/lib/objects/notes.dart index fac7ec19..190d08b1 100644 --- a/Frontend/patient_manager/lib/objects/notes.dart +++ b/Frontend/patient_manager/lib/objects/notes.dart @@ -2,14 +2,14 @@ class Note { final int idpatient_notes; final String note_name; final String note_text; - final int patient_id; final String insert_date; + final String app_id; const Note({ required this.idpatient_notes, required this.note_name, required this.note_text, - required this.patient_id, + required this.app_id, required this.insert_date, }); @@ -19,15 +19,15 @@ class Note { "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, + "app_id": String app_id, } => Note( idpatient_notes: idpatient_notes, note_name: note_name, note_text: note_text, - patient_id: patient_id, insert_date: insert_date, + app_id: app_id, ), _ => throw const FormatException('Failed to load album.'), }; diff --git a/Frontend/patient_manager/lib/pages/patientView.dart b/Frontend/patient_manager/lib/pages/patientView.dart index c36458da..3ab1f86c 100644 --- a/Frontend/patient_manager/lib/pages/patientView.dart +++ b/Frontend/patient_manager/lib/pages/patientView.dart @@ -26,8 +26,10 @@ class PatientView extends StatefulWidget { class _PatientViewState extends State { Future fetchPatient() async { //print("Patien manager page: $endpoint"); - final response = await http.get(Uri.parse( - "${AppEnviroment.baseApiUrl}/patients/${widget.signedInUser.app_id}")); + var patientAppId = widget.signedInUser.app_id; + + final response = await http + .get(Uri.parse("${AppEnviroment.baseApiUrl}/patients/$patientAppId")); // print("Here"); // print("Body: ${response.body}"); // print("Code: ${response.statusCode}"); @@ -91,7 +93,8 @@ class _PatientViewState extends State { SizedBox( width: 650, child: PatientNotes( - patientIndex: snapshot.data!.idpatients, + patientAppId: snapshot.data!.app_id, + signedInUser: widget.signedInUser, ), ), SizedBox(