forked from yaso_meth/mih-project
Create Delete patient API & add functionality to delete patient on edit screen
This commit is contained in:
@@ -32,7 +32,8 @@ class _EditPatientState extends State<EditPatient> {
|
||||
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<EditPatient> {
|
||||
print(futureDocOfficeId.toString());
|
||||
print("Here3");
|
||||
var response = await http.put(
|
||||
Uri.parse(apiUrl),
|
||||
Uri.parse(apiUrlEdit),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
@@ -89,6 +90,37 @@ class _EditPatientState extends State<EditPatient> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> 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: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"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<void> getLoginUserEmail() async {
|
||||
userEmail =
|
||||
(await Supabase.instance.client.auth.currentUser?.email.toString())!;
|
||||
@@ -156,9 +188,36 @@ class _EditPatientState extends State<EditPatient> {
|
||||
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"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
Binary file not shown.
@@ -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"}
|
||||
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"}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
database/ibdata1
BIN
database/ibdata1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user