delete patient file

This commit is contained in:
2025-05-20 13:02:17 +02:00
parent 209994b473
commit 4501fe0e28

View File

@@ -1,6 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_apis/mih_file_api.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_window.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_window.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_delete_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_delete_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
@@ -24,6 +25,7 @@ class BuildFilesList extends StatefulWidget {
final Business? business; final Business? business;
final BusinessUser? businessUser; final BusinessUser? businessUser;
final String type; final String type;
final String env;
const BuildFilesList({ const BuildFilesList({
super.key, super.key,
required this.files, required this.files,
@@ -32,6 +34,7 @@ class BuildFilesList extends StatefulWidget {
required this.business, required this.business,
required this.businessUser, required this.businessUser,
required this.type, required this.type,
required this.env,
}); });
@override @override
@@ -45,109 +48,73 @@ class _BuildFilesListState extends State<BuildFilesList> {
String fileUrl = ""; String fileUrl = "";
Future<String> getFileUrlApiCall(String filePath) async { Future<String> getFileUrlApiCall(String filePath) async {
var url = "$baseAPI/minio/pull/file/${AppEnviroment.getEnv()}/$filePath"; String teporaryFileUrl = "";
//print(url); await MihFileApi.getMinioFileUrl(
var response = await http.get(Uri.parse(url)); filePath,
// print("here1"); context,
//print(response.statusCode); ).then((value) {
teporaryFileUrl = value;
if (response.statusCode == 200) { });
//print("here2"); return teporaryFileUrl;
String body = response.body;
//print(body);
//print("here3");
var decodedData = jsonDecode(body);
//print("Dedoced: ${decodedData['minioURL']}");
return decodedData['minioURL'];
//AppUser u = AppUser.fromJson(decodedData);
// print(u.email);
//return "AlometThere";
} else {
throw Exception("Error: GetUserData status code ${response.statusCode}");
}
//print(url);
// var response = await http.get(Uri.parse(url));
// // print("here1");
// //print(response.statusCode);
// if (response.statusCode == 200) {
// //print("here2");
// String body = response.body;
// //print(body);
// //print("here3");
// var decodedData = jsonDecode(body);
// //print("Dedoced: ${decodedData['minioURL']}");
// return decodedData['minioURL'];
// //AppUser u = AppUser.fromJson(decodedData);
// // print(u.email);
// //return "AlometThere";
// } else {
// throw Exception("Error: GetUserData status code ${response.statusCode}");
// }
} }
Future<void> deleteFileApiCall(String filePath, int fileID) async { Future<void> deleteFileApiCall(String filePath, int fileID) async {
var response = await MihFileApi.deleteFile(
widget.signedInUser.app_id,
widget.env,
"patient_files",
filePath.split("/").last,
context,
);
if (response == 200) {
// delete file from database
await deletePatientFileLocationToDB(fileID);
} else {
Navigator.of(context).pop();
String message =
"The File has not been deleted successfully. Please try again.";
successPopUp(message);
}
}
Future<void> deletePatientFileLocationToDB(int fileID) async {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const Mihloadingcircle(); return const Mihloadingcircle();
}, },
); );
// delete file from minio var response2 = await http.delete(
var response = await http.delete( Uri.parse("$baseAPI/patient_files/delete/"),
Uri.parse("$baseAPI/minio/delete/file/"),
headers: <String, String>{ headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
}, },
body: jsonEncode(<String, dynamic>{"file_path": filePath}), body: jsonEncode(<String, dynamic>{"idpatient_files": fileID}),
); );
//print("Here4"); if (response2.statusCode == 200) {
//print(response.statusCode); Navigator.of(context).pop();
if (response.statusCode == 200) { Navigator.of(context).pop();
//SQL delete //print(widget.business);
var response2 = await http.delete( if (widget.business == null) {
Uri.parse("$baseAPI/files/delete/"), Navigator.of(context).pushNamed('/patient-manager/patient',
headers: <String, String>{ arguments: PatientViewArguments(
"Content-Type": "application/json; charset=UTF-8" widget.signedInUser,
}, widget.selectedPatient,
body: jsonEncode(<String, dynamic>{"idpatient_files": fileID}), widget.businessUser,
); widget.business,
if (response2.statusCode == 200) { "personal"));
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop();
//print(widget.business);
if (widget.business == null) {
Navigator.of(context).pushNamed('/patient-manager/patient',
arguments: PatientViewArguments(
widget.signedInUser,
widget.selectedPatient,
widget.businessUser,
widget.business,
"personal"));
} else {
Navigator.of(context).pushNamed('/patient-manager/patient',
arguments: PatientViewArguments(
widget.signedInUser,
widget.selectedPatient,
widget.businessUser,
widget.business,
"business"));
}
// Navigator.of(context)
// .pushNamed('/patient-profile', arguments: widget.signedInUser);
// setState(() {});
String message =
"The File has been deleted successfully. This means it will no longer be visible on your and cannot be used for future appointments.";
successPopUp(message);
} else { } else {
internetConnectionPopUp(); Navigator.of(context).pushNamed('/patient-manager/patient',
arguments: PatientViewArguments(
widget.signedInUser,
widget.selectedPatient,
widget.businessUser,
widget.business,
"business"));
} }
String message =
"The File has been deleted successfully. This means it will no longer be visible on your and cannot be used for future appointments.";
successPopUp(message);
} else { } else {
internetConnectionPopUp(); internetConnectionPopUp();
} }