diff --git a/Frontend/patient_manager/lib/components/patientFiles.dart b/Frontend/patient_manager/lib/components/patientFiles.dart index 35eddc19..24b85302 100644 --- a/Frontend/patient_manager/lib/components/patientFiles.dart +++ b/Frontend/patient_manager/lib/components/patientFiles.dart @@ -5,6 +5,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:patient_manager/components/buildFilesList.dart'; import 'package:patient_manager/components/medCertInput.dart'; +import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/myTextInput.dart'; import 'package:patient_manager/components/mybutton.dart'; import 'package:patient_manager/main.dart'; @@ -87,10 +88,10 @@ class _PatientFilesState extends State { String message = "Successfully added file"; messagePopUp(message); } else { - messagePopUp("error response 2"); + internetConnectionPopUp(); } } else { - messagePopUp("error respose 1"); + internetConnectionPopUp(); } } @@ -124,10 +125,10 @@ class _PatientFilesState extends State { String message = "Successfully added file"; messagePopUp(message); } else { - messagePopUp("error response 2"); + internetConnectionPopUp(); } } else { - messagePopUp("error respose 1"); + internetConnectionPopUp(); } } @@ -139,6 +140,7 @@ class _PatientFilesState extends State { appUser = AppUser.fromJson(jsonDecode(response.body) as Map); } else { + internetConnectionPopUp(); throw Exception('Failed to load user'); } } @@ -163,6 +165,7 @@ class _PatientFilesState extends State { List.from(l.map((model) => PFile.fromJson(model))); return files; } else { + internetConnectionPopUp(); throw Exception('failed to load patients'); } } @@ -181,39 +184,76 @@ class _PatientFilesState extends State { void medCertPopUp() { showDialog( context: context, - builder: (context) => AlertDialog( - title: const Row( - mainAxisAlignment: MainAxisAlignment.center, + builder: (context) => Dialog( + child: Stack( children: [ - Text("Create Medical Certificate"), + Container( + padding: const EdgeInsets.all(10.0), + width: 700.0, + //height: 475.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 5.0), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + "Create Medical Certificate", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.blueAccent, + fontSize: 35.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 25.0), + Medcertinput( + startDateController: startDateController, + endDateTextController: endDateTextController, + retDateTextController: retDateTextController, + ), + SizedBox( + width: 300, + height: 100, + child: MyButton( + onTap: () { + if (isMedCertFieldsFilled()) { + generateMedCert(); + Navigator.pop(context); + } else { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage( + errorType: "Input Error"); + }, + ); + } + }, + buttonText: "Add Note")) + ], + ), + ), + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: const Icon( + Icons.close, + color: Colors.red, + size: 35, + ), + ), + ), ], ), - content: Medcertinput( - startDateController: startDateController, - endDateTextController: endDateTextController, - retDateTextController: retDateTextController, - ), - actions: [ - TextButton( - onPressed: () { - generateMedCert(); - Navigator.pop(context); - }, - child: const Text( - "Generate", - style: TextStyle(fontWeight: FontWeight.bold), - ), - ), - TextButton( - onPressed: () { - startDateController.clear(); - endDateTextController.clear(); - retDateTextController.clear(); - Navigator.pop(context); - }, - child: const Text("Cancel"), - ) - ], ), ); } @@ -221,73 +261,126 @@ class _PatientFilesState extends State { void uploudFilePopUp() { showDialog( context: context, - builder: (context) => AlertDialog( - title: const Row( - mainAxisAlignment: MainAxisAlignment.center, + builder: (context) => Dialog( + child: Stack( children: [ - Text("Upload File"), + Container( + padding: const EdgeInsets.all(10.0), + width: 700.0, + //height: 475.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 5.0), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + "Upload File", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.blueAccent, + fontSize: 35.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 700, + child: MyButton( + onTap: () async { + FilePickerResult? result = + await FilePicker.platform.pickFiles(); + if (result == null) return; + final selectedFile = result.files.first; + setState(() { + selected = selectedFile; + }); + + setState(() { + selectedFileController.text = selectedFile.name; + }); + }, + buttonText: "Select File"), + ), + MyTextField( + controller: selectedFileController, + hintText: "Selected FIle", + editable: false, + required: true, + ), + SizedBox( + width: 300, + height: 100, + child: MyButton( + onTap: () { + if (isFileFieldsFilled()) { + uploadSelectedFile(selected); + Navigator.pop(context); + } else { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage( + errorType: "Input Error"); + }, + ); + } + }, + buttonText: "Add Note")) + ], + ), + ), + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: const Icon( + Icons.close, + color: Colors.red, + size: 35, + ), + ), + ), ], ), - content: SizedBox( - width: 700, - height: 250, - child: Column( - children: [ - SizedBox( - width: 700, - child: MyButton( - onTap: () async { - FilePickerResult? result = - await FilePicker.platform.pickFiles(); - if (result == null) return; - final selectedFile = result.files.first; - //selectedFile - // print("Name: ${selectedFile.name}"); - // print("Extension: ${selectedFile.extension}"); - // print("Content: ${selectedFile.bytes}"); - - setState(() { - selected = selectedFile; - }); - - setState(() { - selectedFileController.text = selectedFile.name; - }); - }, - buttonText: "Select File"), - ), - MyTextField( - controller: selectedFileController, - hintText: "Selected FIle", - editable: false, - required: true, - ) - ], - ), - ), - actions: [ - TextButton( - onPressed: () { - uploadSelectedFile(selected); - Navigator.pop(context); - }, - child: const Text( - "Upload", - style: TextStyle(fontWeight: FontWeight.bold), - ), - ), - TextButton( - onPressed: () { - selectedFileController.clear(); - Navigator.pop(context); - }, - child: const Text("Cancel"), - ) - ], ), ); } + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Internet Connection"); + }, + ); + } + + bool isMedCertFieldsFilled() { + if (startDateController.text.isEmpty || + endDateTextController.text.isEmpty || + retDateTextController.text.isEmpty) { + return false; + } else { + return true; + } + } + + bool isFileFieldsFilled() { + if (selectedFileController.text.isEmpty) { + return false; + } else { + return true; + } + } + @override void initState() { futueFiles = fetchFiles(endpointFiles + widget.patientIndex.toString()); diff --git a/Frontend/patient_manager/lib/components/patientNotes.dart b/Frontend/patient_manager/lib/components/patientNotes.dart index 9e749077..ebb6537c 100644 --- a/Frontend/patient_manager/lib/components/patientNotes.dart +++ b/Frontend/patient_manager/lib/components/patientNotes.dart @@ -2,23 +2,13 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:patient_manager/components/buildNotesList.dart'; +import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/myMLTextInput.dart'; import 'package:patient_manager/components/myTextInput.dart'; +import 'package:patient_manager/components/mybutton.dart'; import 'package:patient_manager/objects/notes.dart'; import 'package:http/http.dart' as http; -Future> fetchNotes(String endpoint) async { - final response = await http.get(Uri.parse(endpoint)); - if (response.statusCode == 200) { - Iterable l = jsonDecode(response.body); - List notes = List.from(l.map((model) => Note.fromJson(model))); - //print("Here notes"); - return notes; - } else { - throw Exception('failed to load patients'); - } -} - class PatientNotes extends StatefulWidget { final int patientIndex; const PatientNotes({super.key, required this.patientIndex}); @@ -34,6 +24,20 @@ class _PatientNotesState extends State { final noteTextController = TextEditingController(); late Future> futueNotes; + Future> fetchNotes(String endpoint) async { + final response = await http.get(Uri.parse(endpoint)); + if (response.statusCode == 200) { + Iterable l = jsonDecode(response.body); + List notes = + List.from(l.map((model) => Note.fromJson(model))); + //print("Here notes"); + return notes; + } else { + internetConnectionPopUp(); + throw Exception('failed to load patients'); + } + } + Future addPatientNoteAPICall() async { var response = await http.post( Uri.parse(apiUrlAddNote), @@ -55,10 +59,19 @@ class _PatientNotesState extends State { String message = "Successfully added Note"; messagePopUp(message); } else { - messagePopUp("error"); + internetConnectionPopUp(); } } + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Internet Connection"); + }, + ); + } + void messagePopUp(error) { showDialog( context: context, @@ -70,6 +83,106 @@ class _PatientNotesState extends State { ); } + void addNotePopUp() { + showDialog( + context: context, + builder: (context) => Dialog( + child: Stack( + children: [ + Container( + padding: const EdgeInsets.all(10.0), + width: 700.0, + //height: 475.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 5.0), + ), + child: Column( + //mainAxisSize: MainAxisSize.max, + children: [ + const Text( + "Add Note", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.blueAccent, + fontSize: 35.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 700, + child: MyTextField( + controller: titleController, + hintText: "Title of Note", + editable: true, + required: true, + ), + ), + const SizedBox(height: 25.0), + Expanded( + child: MyMLTextField( + controller: noteTextController, + hintText: "Note Details", + editable: true, + required: true, + ), + ), + SizedBox( + width: 300, + height: 100, + child: MyButton( + onTap: () { + if (isFieldsFilled()) { + addPatientNoteAPICall(); + Navigator.pop(context); + } else { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage( + errorType: "Input Error"); + }, + ); + } + }, + buttonText: "Add Note")) + ], + ), + ), + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + titleController.clear(); + noteTextController.clear(); + }, + icon: const Icon( + Icons.close, + color: Colors.red, + size: 35, + ), + ), + ), + ], + ), + ), + ); + } + + bool isFieldsFilled() { + if (titleController.text.isEmpty || noteTextController.text.isEmpty) { + return false; + } else { + return true; + } + } + @override void initState() { futueNotes = fetchNotes(endpoint + widget.patientIndex.toString()); @@ -115,61 +228,7 @@ class _PatientNotesState extends State { ), IconButton( onPressed: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Add Note"), - ], - ), - content: Column( - children: [ - SizedBox( - width: 700, - child: MyTextField( - controller: titleController, - hintText: "Title of Note", - editable: true, - required: true, - ), - ), - const SizedBox( - height: 25.0, - ), - Expanded( - child: MyMLTextField( - controller: noteTextController, - hintText: "Note Details", - editable: true, - required: true, - ), - ), - ], - ), - actions: [ - TextButton( - onPressed: () { - addPatientNoteAPICall(); - Navigator.pop(context); - //print(widget.patientIndex); - }, - child: const Text( - "Submit", - style: TextStyle( - fontWeight: FontWeight.bold), - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: const Text("Cancel"), - ) - ], - ), - ); + addNotePopUp(); }, icon: const Icon(Icons.add), ) diff --git a/Frontend/patient_manager/lib/components/profileUserUpdate.dart b/Frontend/patient_manager/lib/components/profileUserUpdate.dart index 5a5ac02a..237d0f16 100644 --- a/Frontend/patient_manager/lib/components/profileUserUpdate.dart +++ b/Frontend/patient_manager/lib/components/profileUserUpdate.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/components/myDropdownInput.dart'; +import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/myTextInput.dart'; import 'package:patient_manager/components/mybutton.dart'; import 'package:patient_manager/objects/appUser.dart'; @@ -21,6 +22,16 @@ class _ProfileUserUpdateState extends State { final lnameController = TextEditingController(); final titleController = TextEditingController(); + bool isFieldsFilled() { + if (fnameController.text.isEmpty || + lnameController.text.isEmpty || + titleController.text.isEmpty) { + return false; + } else { + return true; + } + } + @override void initState() { fnameController.text = widget.signedInUser.fname; @@ -70,24 +81,12 @@ class _ProfileUserUpdateState extends State { height: 100.0, child: MyButton( onTap: () { - if (fnameController.text == "") { - showDialog( + if (isFieldsFilled()) { + } else { + showDialog( context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Incomplete Field\\s'), - content: const Text( - 'Please conplete all fields', - ), - actions: [ - TextButton( - child: const Text('Disable'), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); + builder: (context) { + return const MyErrorMessage(errorType: "Input Error"); }, ); } diff --git a/Frontend/patient_manager/lib/pages/patientEdit.dart b/Frontend/patient_manager/lib/pages/patientEdit.dart index df5e8990..9fd0882a 100644 --- a/Frontend/patient_manager/lib/pages/patientEdit.dart +++ b/Frontend/patient_manager/lib/pages/patientEdit.dart @@ -149,102 +149,105 @@ class _EditPatientState extends State { ); } - Widget deletePatientPopUp() { - return Dialog( - child: Stack( - children: [ - Container( - padding: const EdgeInsets.all(10.0), - width: 500.0, - height: 475.0, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(25.0), - border: Border.all(color: Colors.blueAccent, width: 5.0), - ), - child: Column( - //mainAxisSize: MainAxisSize.max, - children: [ - const Icon( - Icons.warning_amber_rounded, - size: 100, - color: Colors.blueAccent, - ), - const SizedBox(height: 15), - const Text( - "Are you sure you want to delete this?", - textAlign: TextAlign.center, - style: TextStyle( + void deletePatientPopUp() { + showDialog( + context: context, + builder: (context) => Dialog( + child: Stack( + children: [ + Container( + padding: const EdgeInsets.all(10.0), + width: 500.0, + height: 475.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 5.0), + ), + child: Column( + //mainAxisSize: MainAxisSize.max, + children: [ + const Icon( + Icons.warning_amber_rounded, + size: 100, color: Colors.blueAccent, - fontSize: 25.0, - fontWeight: FontWeight.bold, ), - ), - const SizedBox(height: 10), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0), - child: Text( - "This action is permanent! Deleting ${fnameController.text} ${lnameController.text} will remove him\\her from your account. You won't be able to recover it once it's gone.", - style: const TextStyle( - color: Colors.black, - fontSize: 15.0, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 25.0), - child: Text( - "Here's what you'll be deleting:", + const SizedBox(height: 15), + const Text( + "Are you sure you want to delete this?", + textAlign: TextAlign.center, style: TextStyle( - color: Colors.black, - fontSize: 20.0, + color: Colors.blueAccent, + fontSize: 25.0, fontWeight: FontWeight.bold, ), ), - ), - const SizedBox(height: 10), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 25.0), - child: SizedBox( - width: 450, + const SizedBox(height: 10), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 25.0), child: Text( - "1) Patient Profile Information.\n2) Patient Notes\n3) Patient Files.", - textAlign: TextAlign.left, - style: TextStyle( + "This action is permanent! Deleting ${fnameController.text} ${lnameController.text} will remove him\\her from your account. You won't be able to recover it once it's gone.", + style: const TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.bold, ), ), ), - ), - SizedBox( - width: 300, - height: 100, - child: MyButton( - onTap: deletePatientApiCall, buttonText: "Delete")) - ], - ), - ), - Positioned( - top: 5, - right: 5, - width: 50, - height: 50, - child: IconButton( - onPressed: () { - Navigator.pop(context); - }, - icon: const Icon( - Icons.close, - color: Colors.red, - size: 35, + const SizedBox(height: 15), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 25.0), + child: Text( + "Here's what you'll be deleting:", + style: TextStyle( + color: Colors.black, + fontSize: 20.0, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox(height: 10), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 25.0), + child: SizedBox( + width: 450, + child: Text( + "1) Patient Profile Information.\n2) Patient Notes\n3) Patient Files.", + textAlign: TextAlign.left, + style: TextStyle( + color: Colors.black, + fontSize: 15.0, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + SizedBox( + width: 300, + height: 100, + child: MyButton( + onTap: deletePatientApiCall, buttonText: "Delete")) + ], ), ), - ), - ], + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: const Icon( + Icons.close, + color: Colors.red, + size: 35, + ), + ), + ), + ], + ), ), ); } @@ -315,10 +318,7 @@ class _EditPatientState extends State { icon: const Icon(Icons.delete), alignment: Alignment.topRight, onPressed: () { - showDialog( - context: context, - builder: (context) => deletePatientPopUp(), - ); + deletePatientPopUp(); }, ) ],