diff --git a/Frontend/patient_manager/lib/pages/patientEdit.dart b/Frontend/patient_manager/lib/pages/patientEdit.dart index 575b3a97..e622cb1b 100644 --- a/Frontend/patient_manager/lib/pages/patientEdit.dart +++ b/Frontend/patient_manager/lib/pages/patientEdit.dart @@ -32,7 +32,8 @@ class _EditPatientState extends State { final medSchemeController = TextEditingController(); final addressController = TextEditingController(); final docOfficeIdApiUrl = "http://localhost:80/docOffices/user/"; - final apiUrl = "http://localhost:80/patients/update/"; + final apiUrlEdit = "http://localhost:80/patients/update/"; + final apiUrlDelete = "http://localhost:80/patients/delete/"; late int futureDocOfficeId; late String userEmail; @@ -60,7 +61,7 @@ class _EditPatientState extends State { print(futureDocOfficeId.toString()); print("Here3"); var response = await http.put( - Uri.parse(apiUrl), + Uri.parse(apiUrlEdit), headers: { "Content-Type": "application/json; charset=UTF-8" }, @@ -89,6 +90,37 @@ class _EditPatientState extends State { } } + Future deletePatientApiCall() async { + print("Here1"); + //userEmail = getLoginUserEmail() as String; + print(userEmail); + print("Here2"); + await getOfficeIdByUser(docOfficeIdApiUrl + userEmail); + print("Office ID: ${futureDocOfficeId.toString()}"); + print("OPatient ID No: ${idController.text}"); + print("Here3"); + var response = await http.delete( + Uri.parse(apiUrlDelete), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "id_no": idController.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 Deleted"; + messagePopUp(message); + } else { + messagePopUp("error ${response.statusCode}"); + } + } + Future getLoginUserEmail() async { userEmail = (await Supabase.instance.client.auth.currentUser?.email.toString())!; @@ -156,9 +188,36 @@ class _EditPatientState extends State { icon: const Icon(Icons.delete), alignment: Alignment.topRight, onPressed: () { - // Navigator.of(context).pushNamed( - // '/patient-manager/patient/edit', - // arguments: widget.selectedPatient); + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon(Icons.warning), + Text("Warning"), + ], + ), + content: Text( + "You are trying to delete the patient ${fnameController.text} ${lnameController.text}.\n\n" + + "Please note that this patient will be deleted permenantly and can not be retored\n\n" + + "Would you like to delete patient?"), + actions: [ + TextButton( + onPressed: () { + deletePatientApiCall(); + }, + child: const Text("Yes"), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text("No"), + ) + ], + ), + ); }, ) ], diff --git a/backend/routers/__pycache__/patients.cpython-310.pyc b/backend/routers/__pycache__/patients.cpython-310.pyc index cd0a9bc8..d14d565b 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 f345cce4..8ac344e8 100644 --- a/backend/routers/patients.py +++ b/backend/routers/patients.py @@ -29,6 +29,10 @@ class patientUpdateRequest(BaseModel): address: str doc_office_id: int +class patientDeleteRequest(BaseModel): + id_no: str + doc_office_id: int + # Get Patient By ID Number @router.get("/patients/{id_no}", tags="patients") @@ -225,4 +229,23 @@ async def UpdatePatient(itemRequest : patientUpdateRequest): db.commit() cursor.close() db.close() - return {"message": "Successfully Updated Record"} \ No newline at end of file + return {"message": "Successfully Updated Record"} + +# delete Patient on table +@router.delete("/patients/delete/", tags="patients") +async def DeletePatient(itemRequest : patientDeleteRequest): + db = dbConnection.dbConnect() + cursor = db.cursor() + query = "delete from patients " + query += "where id_no=%s and doc_office_id=%s" + patientData = (itemRequest.id_no, + itemRequest.doc_office_id) + try: + cursor.execute(query, patientData) + except Exception as error: + raise HTTPException(status_code=404, detail="Failed to delete Record") + #return {"query": query, "message": error} + db.commit() + cursor.close() + db.close() + return {"message": "Successfully delete Record"} \ No newline at end of file diff --git a/database/#ib_16384_0.dblwr b/database/#ib_16384_0.dblwr index 1c66f561..96d2c5fb 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 c820da6b..96890f48 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 8b985b3d..07028e43 100644 Binary files a/database/binlog.000014 and b/database/binlog.000014 differ diff --git a/database/ibdata1 b/database/ibdata1 index 2db0c739..41b6a88b 100644 Binary files a/database/ibdata1 and b/database/ibdata1 differ diff --git a/database/mysql.ibd b/database/mysql.ibd index a5004352..7b47a00b 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 8b8bcee6..c47f849a 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 d401acde..c9fa71e0 100644 Binary files a/database/undo_001 and b/database/undo_001 differ diff --git a/database/undo_002 b/database/undo_002 index 29b07173..20f47e2c 100644 Binary files a/database/undo_002 and b/database/undo_002 differ