diff --git a/Frontend/patient_manager/lib/components/buildFilesList.dart b/Frontend/patient_manager/lib/components/buildFilesList.dart index 25c857c4..e4dbb84b 100644 --- a/Frontend/patient_manager/lib/components/buildFilesList.dart +++ b/Frontend/patient_manager/lib/components/buildFilesList.dart @@ -21,7 +21,7 @@ class BuildFilesList extends StatefulWidget { class _BuildFilesListState extends State { int indexOn = 0; - void viewFilePopUp(String filename) { + void viewFilePopUp(String fileName, String filePath) { showDialog( context: context, barrierDismissible: false, @@ -44,7 +44,7 @@ class _BuildFilesListState extends State { mainAxisSize: MainAxisSize.min, children: [ Text( - filename, + fileName, textAlign: TextAlign.center, style: TextStyle( color: MzanziInnovationHub.of(context)! @@ -58,14 +58,14 @@ class _BuildFilesListState extends State { Expanded( child: BuildFileView( pdfLink: - "${AppEnviroment.baseFileUrl}/mih/$filename")), + "${AppEnviroment.baseFileUrl}/mih/$filePath")), SizedBox( width: 300, height: 100, child: MyButton( onTap: () { html.window.open( - '${AppEnviroment.baseFileUrl}/mih/$filename', + '${AppEnviroment.baseFileUrl}/mih/$filePath', 'download'); }, buttonText: "Dowload", @@ -135,7 +135,10 @@ class _BuildFilesListState extends State { color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), onTap: () { - viewFilePopUp(widget.files[index].file_name); + viewFilePopUp( + widget.files[index].file_name, + widget.files[index].file_path, + ); }, ); }, diff --git a/Frontend/patient_manager/lib/components/patientFiles.dart b/Frontend/patient_manager/lib/components/patientFiles.dart index 46e7b30c..0a8c604e 100644 --- a/Frontend/patient_manager/lib/components/patientFiles.dart +++ b/Frontend/patient_manager/lib/components/patientFiles.dart @@ -132,8 +132,68 @@ class _PatientFilesState extends State { ); }, ); + //print("here1"); + var request = http2.MultipartRequest( + 'POST', Uri.parse("${AppEnviroment.baseApiUrl}/minio/upload/file/")); + request.headers['accept'] = 'application/json'; + request.fields['app_id'] = widget.selectedPatient.app_id; + request.headers['Content-Type'] = 'multipart/form-data'; + request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!, + filename: file.name.replaceAll(RegExp(r' '), '-'))); + //print("here2"); + var response1 = await request.send(); + //print("here3"); + //print(response1.statusCode); + if (response1.statusCode == 200) { + //print("here3"); + var fname = file.name.replaceAll(RegExp(r' '), '-'); + var filePath = "${widget.selectedPatient.app_id}/$fname"; + var response2 = await http.post( + Uri.parse("${AppEnviroment.baseApiUrl}/files/insert/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "file_path": filePath, + "file_name": fname, + "app_id": widget.selectedPatient.app_id + }), + ); + //print("here5"); + //print(response2.statusCode); + if (response2.statusCode == 201) { + setState(() { + selectedFileController.clear(); + futueFiles = fetchFiles(); + }); + // end loading circle + Navigator.of(context).pop(); + String message = + "The medical certificate ${file.name.replaceAll(RegExp(r' '), '-')} has been successfully generated and added to ${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}'s record. You can now access and download it for their use."; + successPopUp(message); + } else { + internetConnectionPopUp(); + } + } else { + internetConnectionPopUp(); + } + } - var request = http2.MultipartRequest('POST', Uri.parse(endpointFileUpload)); + Future uploadSelectedFilev1(PlatformFile file) async { + //var strem = new http.ByteStream.fromBytes(file.bytes.) + //start loading circle + showDialog( + context: context, + builder: (context) { + return const Center( + child: CircularProgressIndicator(), + ); + }, + ); + + var request = http2.MultipartRequest( + 'POST', Uri.parse("${AppEnviroment.baseApiUrl}/files/upload/file/")); + request.fields['app_id'] = widget.selectedPatient.app_id; request.headers['Content-Type'] = 'multipart/form-data'; request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!, filename: file.name.replaceAll(RegExp(r' '), '-'))); diff --git a/Frontend/patient_manager/lib/objects/files.dart b/Frontend/patient_manager/lib/objects/files.dart index 463a4b97..1f73fbea 100644 --- a/Frontend/patient_manager/lib/objects/files.dart +++ b/Frontend/patient_manager/lib/objects/files.dart @@ -2,15 +2,15 @@ class PFile { final int idpatient_files; final String file_path; final String file_name; - final String app_id; final String insert_date; + final String app_id; const PFile( this.idpatient_files, this.file_path, this.file_name, - this.app_id, this.insert_date, + this.app_id, ); factory PFile.fromJson(dynamic json) {