diff --git a/Frontend/patient_manager/lib/components/buildPatientList.dart b/Frontend/patient_manager/lib/components/buildPatientList.dart index b0085dde..bad6bfa0 100644 --- a/Frontend/patient_manager/lib/components/buildPatientList.dart +++ b/Frontend/patient_manager/lib/components/buildPatientList.dart @@ -4,6 +4,7 @@ import 'package:patient_manager/objects/patients.dart'; class BuildPatientsList extends StatefulWidget { final List patients; final searchString; + const BuildPatientsList({ super.key, required this.patients, diff --git a/Frontend/patient_manager/lib/components/myTextInput.dart b/Frontend/patient_manager/lib/components/myTextInput.dart index 446195ae..da1ab217 100644 --- a/Frontend/patient_manager/lib/components/myTextInput.dart +++ b/Frontend/patient_manager/lib/components/myTextInput.dart @@ -3,19 +3,30 @@ import 'package:flutter/material.dart'; class MyTextField extends StatelessWidget { final controller; final String hintText; + final bool editable; const MyTextField({ super.key, required this.controller, required this.hintText, + required this.editable, }); + bool makeEditable() { + if (editable) { + return false; + } else { + return true; + } + } + @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 25.0), child: TextField( controller: controller, + readOnly: makeEditable(), obscureText: false, decoration: InputDecoration( fillColor: Colors.white, diff --git a/Frontend/patient_manager/lib/components/patientDetails.dart b/Frontend/patient_manager/lib/components/patientDetails.dart index c33de7f4..8f4c2c71 100644 --- a/Frontend/patient_manager/lib/components/patientDetails.dart +++ b/Frontend/patient_manager/lib/components/patientDetails.dart @@ -30,13 +30,27 @@ class _PatientDetailsState extends State { child: SelectionArea( child: Column( children: [ - const Text( - "Patient Details", - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 35, - fontWeight: FontWeight.bold, - ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + "Patient Details", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 35, + fontWeight: FontWeight.bold, + ), + ), + IconButton( + icon: const Icon(Icons.edit), + alignment: Alignment.topRight, + onPressed: () { + Navigator.of(context).pushNamed( + '/patient-manager/patient/edit', + arguments: widget.selectedPatient); + }, + ) + ], ), const Divider(), const SizedBox(height: 10), diff --git a/Frontend/patient_manager/lib/objects/emailAndPatientScreenArgs.dart b/Frontend/patient_manager/lib/objects/emailAndPatientScreenArgs.dart new file mode 100644 index 00000000..a24e9d4a --- /dev/null +++ b/Frontend/patient_manager/lib/objects/emailAndPatientScreenArgs.dart @@ -0,0 +1,6 @@ +class EditScreenArguments { + final String useremail; + final String selectedPatient; + + EditScreenArguments({required this.useremail, required this.selectedPatient}); +} diff --git a/Frontend/patient_manager/lib/pages/patientAdd.dart b/Frontend/patient_manager/lib/pages/patientAdd.dart index 2c4a78f3..3d060e73 100644 --- a/Frontend/patient_manager/lib/pages/patientAdd.dart +++ b/Frontend/patient_manager/lib/pages/patientAdd.dart @@ -34,18 +34,11 @@ class _AddPatientState extends State { late int futureDocOfficeId; Future getOfficeIdByUser(String endpoint) async { - print("here1.1"); final response = await http.get(Uri.parse(endpoint)); - print("here1.2"); if (response.statusCode == 200) { - print("here1.3"); String body = response.body; - print(body); - print("here1.4"); var decodedData = jsonDecode(body); - print("here1.5"); AppUser u = AppUser.fromJson(decodedData as Map); - print("here1.6"); setState(() { futureDocOfficeId = u.docOffice_id; //print(futureDocOfficeId); @@ -56,10 +49,8 @@ class _AddPatientState extends State { } Future addPatientAPICall() async { - print("here1"); await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail); print(futureDocOfficeId.toString()); - print("here2"); var response = await http.post( Uri.parse(apiUrl), headers: { @@ -78,14 +69,12 @@ class _AddPatientState extends State { "doc_office_id": futureDocOfficeId, }), ); - print("here3"); if (response.statusCode == 201) { Navigator.of(context) .pushNamed('/patient-manager', arguments: widget.userEmail); - messagePopUp(fnameController.text + - " " + - lnameController.text + - " Successfully added"); + String message = + "${fnameController.text} ${lnameController.text} Successfully added"; + messagePopUp(message); } else { messagePopUp("error"); } @@ -124,8 +113,10 @@ class _AddPatientState extends State { children: [ Expanded( child: MyTextField( - controller: idController, - hintText: "13 digit ID Number or Passport"), + controller: idController, + hintText: "13 digit ID Number or Passport", + editable: true, + ), ), ], ), @@ -136,6 +127,7 @@ class _AddPatientState extends State { child: MyTextField( controller: fnameController, hintText: "First Name", + editable: true, ), ), ], @@ -147,6 +139,7 @@ class _AddPatientState extends State { child: MyTextField( controller: lnameController, hintText: "Last Name", + editable: true, ), ), ], @@ -158,6 +151,7 @@ class _AddPatientState extends State { child: MyTextField( controller: cellController, hintText: "Cell Number", + editable: true, ), ), ], @@ -169,6 +163,7 @@ class _AddPatientState extends State { child: MyTextField( controller: emailController, hintText: "Email", + editable: true, ), ), ], @@ -180,6 +175,7 @@ class _AddPatientState extends State { child: MyTextField( controller: addressController, hintText: "Address", + editable: true, ), ), ], @@ -201,6 +197,7 @@ class _AddPatientState extends State { child: MyTextField( controller: medNoController, hintText: "Medical Aid No.", + editable: true, ), ), ], @@ -212,6 +209,7 @@ class _AddPatientState extends State { child: MyTextField( controller: medNameController, hintText: "Medical Aid Name", + editable: true, ), ), ], @@ -223,6 +221,7 @@ class _AddPatientState extends State { child: MyTextField( controller: medSchemeController, hintText: "Medical Aid Scheme", + editable: true, ), ), ], diff --git a/Frontend/patient_manager/lib/pages/patientEdit.dart b/Frontend/patient_manager/lib/pages/patientEdit.dart new file mode 100644 index 00000000..575b3a97 --- /dev/null +++ b/Frontend/patient_manager/lib/pages/patientEdit.dart @@ -0,0 +1,305 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:patient_manager/components/myTextInput.dart'; +import 'package:patient_manager/components/mybutton.dart'; +import 'package:supabase_flutter/supabase_flutter.dart'; +import '../components/myAppBar.dart'; +import 'package:http/http.dart' as http; +import '../objects/AppUser.dart'; +import '../objects/patients.dart'; + +class EditPatient extends StatefulWidget { + final Patient selectedPatient; + + const EditPatient({ + super.key, + required this.selectedPatient, + }); + + @override + State createState() => _EditPatientState(); +} + +class _EditPatientState extends State { + var idController = TextEditingController(); + final fnameController = TextEditingController(); + final lnameController = TextEditingController(); + final cellController = TextEditingController(); + final emailController = TextEditingController(); + final medNoController = TextEditingController(); + final medNameController = TextEditingController(); + final medSchemeController = TextEditingController(); + final addressController = TextEditingController(); + final docOfficeIdApiUrl = "http://localhost:80/docOffices/user/"; + final apiUrl = "http://localhost:80/patients/update/"; + late int futureDocOfficeId; + late String userEmail; + + Future getOfficeIdByUser(String endpoint) async { + final response = await http.get(Uri.parse(endpoint)); + if (response.statusCode == 200) { + String body = response.body; + var decodedData = jsonDecode(body); + AppUser u = AppUser.fromJson(decodedData as Map); + setState(() { + futureDocOfficeId = u.docOffice_id; + //print(futureDocOfficeId); + }); + } else { + throw Exception('failed to load patients'); + } + } + + Future updatePatientApiCall() async { + print("Here1"); + //userEmail = getLoginUserEmail() as String; + print(userEmail); + print("Here2"); + await getOfficeIdByUser(docOfficeIdApiUrl + userEmail); + print(futureDocOfficeId.toString()); + print("Here3"); + var response = await http.put( + Uri.parse(apiUrl), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "id_no": idController.text, + "first_name": fnameController.text, + "last_name": lnameController.text, + "email": emailController.text, + "cell_no": cellController.text, + "medical_aid_name": medNameController.text, + "medical_aid_no": medNoController.text, + "medical_aid_scheme": medSchemeController.text, + "address": addressController.text, + "doc_office_id": futureDocOfficeId, + }), + ); + print("Here4"); + print(response.statusCode); + if (response.statusCode == 200) { + Navigator.of(context).pushNamed('/patient-manager', arguments: userEmail); + String message = + "${fnameController.text} ${lnameController.text} Successfully Updated"; + messagePopUp(message); + } else { + messagePopUp("error ${response.statusCode}"); + } + } + + Future getLoginUserEmail() async { + userEmail = + (await Supabase.instance.client.auth.currentUser?.email.toString())!; + //print(userEmail); + } + + void messagePopUp(error) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text(error), + ); + }, + ); + } + + @override + void initState() { + getLoginUserEmail(); + setState(() { + idController.value = TextEditingValue(text: widget.selectedPatient.id_no); + fnameController.value = + TextEditingValue(text: widget.selectedPatient.first_name); + lnameController.value = + TextEditingValue(text: widget.selectedPatient.last_name); + cellController.value = + TextEditingValue(text: widget.selectedPatient.cell_no); + emailController.value = + TextEditingValue(text: widget.selectedPatient.email); + medNameController.value = + TextEditingValue(text: widget.selectedPatient.medical_aid_name); + medNoController.value = + TextEditingValue(text: widget.selectedPatient.medical_aid_no); + medSchemeController.value = + TextEditingValue(text: widget.selectedPatient.medical_aid_scheme); + addressController.value = + TextEditingValue(text: widget.selectedPatient.address); + }); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const MyAppBar(barTitle: "Edit Patient"), + body: Padding( + padding: const EdgeInsets.all(15.0), + child: SingleChildScrollView( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + "Personal Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + //color: Colors.blueAccent, + ), + ), + IconButton( + icon: const Icon(Icons.delete), + alignment: Alignment.topRight, + onPressed: () { + // Navigator.of(context).pushNamed( + // '/patient-manager/patient/edit', + // arguments: widget.selectedPatient); + }, + ) + ], + ), + Row( + children: [ + Expanded( + child: MyTextField( + controller: idController, + hintText: "13 digit ID Number or Passport", + editable: false, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: fnameController, + hintText: "First Name", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: lnameController, + hintText: "Last Name", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: cellController, + hintText: "Cell Number", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: emailController, + hintText: "Email", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: addressController, + hintText: "Address", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 15.0), + const Text( + "Medical Aid Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + //color: Colors.blueAccent, + ), + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medNoController, + hintText: "Medical Aid No.", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medNameController, + hintText: "Medical Aid Name", + editable: true, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medSchemeController, + hintText: "Medical Aid Scheme", + editable: true, + ), + ), + ], + ), + //const SizedBox(height: 10.0), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: 500.0, + height: 100.0, + child: MyButton( + onTap: () { + updatePatientApiCall(); + }, + buttonText: "Update", + ), + ), + ], + ), + ], + ), + ), + ), + ); + } +} diff --git a/Frontend/patient_manager/lib/pages/register.dart b/Frontend/patient_manager/lib/pages/register.dart index e50ef938..610f5fd7 100644 --- a/Frontend/patient_manager/lib/pages/register.dart +++ b/Frontend/patient_manager/lib/pages/register.dart @@ -95,6 +95,7 @@ class _RegisterState extends State { child: MyTextField( controller: officeID, hintText: 'OfficeID', + editable: true, ), ), //spacer @@ -105,6 +106,7 @@ class _RegisterState extends State { child: MyTextField( controller: emailController, hintText: 'Email', + editable: true, ), ), //spacer diff --git a/Frontend/patient_manager/lib/pages/signin.dart b/Frontend/patient_manager/lib/pages/signin.dart index 289d7c51..2cd4e26d 100644 --- a/Frontend/patient_manager/lib/pages/signin.dart +++ b/Frontend/patient_manager/lib/pages/signin.dart @@ -82,6 +82,7 @@ class _SignInState extends State { child: MyTextField( controller: emailController, hintText: 'Email', + editable: true, ), ), //spacer diff --git a/Frontend/patient_manager/lib/router/routeGenerator.dart b/Frontend/patient_manager/lib/router/routeGenerator.dart index 3cafda8e..9240d0f1 100644 --- a/Frontend/patient_manager/lib/router/routeGenerator.dart +++ b/Frontend/patient_manager/lib/router/routeGenerator.dart @@ -8,6 +8,7 @@ import 'package:patient_manager/objects/patients.dart'; import 'package:patient_manager/pages/home.dart'; import 'package:patient_manager/pages/patientManager.dart'; import 'package:patient_manager/pages/patientView.dart'; +import '../pages/patientEdit.dart'; class RouteGenerator { static Route generateRoute(RouteSettings settings) { @@ -45,6 +46,15 @@ class RouteGenerator { ); } return _errorRoute(); + case '/patient-manager/patient/edit': + if (args is Patient) { + return MaterialPageRoute( + builder: (_) => EditPatient( + selectedPatient: args, + ), + ); + } + return _errorRoute(); case '/signin': return MaterialPageRoute(builder: (_) => const SignInOrRegister()); // //case '/signIn': diff --git a/backend/routers/__pycache__/patients.cpython-310.pyc b/backend/routers/__pycache__/patients.cpython-310.pyc index 3ee63dc9..cd0a9bc8 100644 Binary files a/backend/routers/__pycache__/patients.cpython-310.pyc and b/backend/routers/__pycache__/patients.cpython-310.pyc differ diff --git a/backend/routers/patients.py b/backend/routers/patients.py index fe24c43a..f345cce4 100644 --- a/backend/routers/patients.py +++ b/backend/routers/patients.py @@ -18,7 +18,6 @@ class patientInsertRequest(BaseModel): doc_office_id: int class patientUpdateRequest(BaseModel): - idpatients: int id_no: str first_name: str last_name: str @@ -205,7 +204,7 @@ async def UpdatePatient(itemRequest : patientUpdateRequest): query = "update patients " query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid_name=%s, " query += "medical_aid_no=%s, medical_aid_scheme=%s, address=%s, doc_office_id=%s " - query += "where idpatients=%s" + query += "where id_no=%s and doc_office_id=%s" patientData = (itemRequest.id_no, itemRequest.first_name, itemRequest.last_name, @@ -216,7 +215,8 @@ async def UpdatePatient(itemRequest : patientUpdateRequest): itemRequest.medical_aid_scheme, itemRequest.address, itemRequest.doc_office_id, - itemRequest.idpatients) + itemRequest.id_no, + itemRequest.doc_office_id) try: cursor.execute(query, patientData) except Exception as error: diff --git a/database/#ib_16384_0.dblwr b/database/#ib_16384_0.dblwr index ea04f780..1c66f561 100644 Binary files a/database/#ib_16384_0.dblwr and b/database/#ib_16384_0.dblwr differ diff --git a/database/#innodb_redo/#ib_redo10 b/database/#innodb_redo/#ib_redo10 index 59d1780f..c820da6b 100644 Binary files a/database/#innodb_redo/#ib_redo10 and b/database/#innodb_redo/#ib_redo10 differ diff --git a/database/binlog.000014 b/database/binlog.000014 index 4892af23..8b985b3d 100644 Binary files a/database/binlog.000014 and b/database/binlog.000014 differ diff --git a/database/ibdata1 b/database/ibdata1 index 20f9dada..2db0c739 100644 Binary files a/database/ibdata1 and b/database/ibdata1 differ diff --git a/database/mysql.ibd b/database/mysql.ibd index 495bccd9..a5004352 100644 Binary files a/database/mysql.ibd and b/database/mysql.ibd differ diff --git a/database/patient_manager/patients.ibd b/database/patient_manager/patients.ibd index 95e174c7..8b8bcee6 100644 Binary files a/database/patient_manager/patients.ibd and b/database/patient_manager/patients.ibd differ diff --git a/database/undo_001 b/database/undo_001 index 8fd87f11..d401acde 100644 Binary files a/database/undo_001 and b/database/undo_001 differ diff --git a/database/undo_002 b/database/undo_002 index 6c421e29..29b07173 100644 Binary files a/database/undo_002 and b/database/undo_002 differ