diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_claim_statement_files_list.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_claim_statement_files_list.dart new file mode 100644 index 00000000..8456a0ab --- /dev/null +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_claim_statement_files_list.dart @@ -0,0 +1,227 @@ +import 'dart:convert'; + +import 'package:Mzansi_Innovation_Hub/main.dart'; +import 'package:Mzansi_Innovation_Hub/mih_apis/mih_claim_statement_generation_api.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_error_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_env/env.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/claim_statement_file.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart'; +import 'package:Mzansi_Innovation_Hub/mih_packages/patient_profile/pat_profile/list_builders/build_file_view.dart'; +import 'package:flutter/material.dart'; +import 'package:supertokens_flutter/http.dart' as http; + +class BuildClaimStatementFileList extends StatefulWidget { + final AppUser signedInUser; + final List files; + final Patient selectedPatient; + final Business? business; + final BusinessUser? businessUser; + final String type; + const BuildClaimStatementFileList({ + super.key, + required this.files, + required this.signedInUser, + required this.selectedPatient, + required this.business, + required this.businessUser, + required this.type, + }); + + @override + State createState() => + _BuildClaimStatementFileListState(); +} + +class _BuildClaimStatementFileListState + extends State { + int indexOn = 0; + final baseAPI = AppEnviroment.baseApiUrl; + final basefile = AppEnviroment.baseFileUrl; + String fileUrl = ""; + + Future getFileUrlApiCall(String filePath) async { + var url = "$baseAPI/minio/pull/file/${AppEnviroment.getEnv()}/$filePath"; + //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}"); + } + } + + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Internet Connection"); + }, + ); + } + + void successPopUp(String message) { + showDialog( + context: context, + builder: (context) { + return MIHSuccessMessage( + successType: "Success", + successMessage: message, + ); + }, + ); + } + + void deleteFilePopUp(String filePath, int fileID) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHDeleteMessage( + deleteType: "File", + onTap: () async { + //API Call here + await MIHClaimStatementGenerationApi + .deleteClaimStatementFilesByFileID( + PatientViewArguments( + widget.signedInUser, + widget.selectedPatient, + widget.businessUser, + widget.business, + "business", + ), + filePath, + fileID, + context, + ); + }, + ), + ); + } + + void viewFilePopUp(String fileName, String filePath, int fileID, String url) { + bool hasAccessToDelete = false; + if (widget.type == "business") { + hasAccessToDelete = true; + } + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHWindow( + fullscreen: true, + windowTitle: fileName, + windowBody: [ + BuildFileView( + link: url, + path: filePath, + //pdfLink: '${AppEnviroment.baseFileUrl}/mih/$filePath', + ), + const SizedBox( + height: 10, + ) + ], + windowTools: [ + Visibility( + visible: hasAccessToDelete, + child: IconButton( + onPressed: () { + deleteFilePopUp(filePath, fileID); + }, + icon: Icon( + size: 35, + Icons.delete, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + ], + onWindowTapClose: () { + Navigator.pop(context); + }, + ), + ); + } + + @override + void dispose() { + // TODO: implement dispose + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget.files.isNotEmpty) { + return ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (BuildContext context, int index) { + return Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + }, + itemCount: widget.files.length, + itemBuilder: (context, index) { + return ListTile( + title: Text( + widget.files[index].file_name, + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + subtitle: Text( + widget.files[index].insert_date, + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + // trailing: Icon( + // Icons.arrow_forward, + // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // ), + onTap: () async { + await getFileUrlApiCall(widget.files[index].file_path) + .then((urlHere) { + //print(url); + setState(() { + fileUrl = urlHere; + }); + }); + + viewFilePopUp( + widget.files[index].file_name, + widget.files[index].file_path, + widget.files[index].idclaim_statement_file, + fileUrl); + }, + ); + }, + ); + } else { + return const Center( + child: Text( + "No Documents Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), + ); + } + } +} diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_file_view.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_file_view.dart new file mode 100644 index 00000000..ba08bc62 --- /dev/null +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_file_view.dart @@ -0,0 +1,265 @@ +import 'dart:async'; + +import 'package:Mzansi_Innovation_Hub/main.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart'; +import 'package:flutter/material.dart'; +import 'package:syncfusion_flutter_core/theme.dart'; +import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; +import "package:universal_html/html.dart" as html; +import 'package:http/http.dart' as http; +import 'package:fl_downloader/fl_downloader.dart'; + +class BuildFileView extends StatefulWidget { + final String link; + final String path; + + const BuildFileView({ + super.key, + required this.link, + required this.path, + }); + + @override + State createState() => _BuildFileViewState(); +} + +class _BuildFileViewState extends State { + late PdfViewerController pdfViewerController = PdfViewerController(); + //late TextEditingController currentPageController = TextEditingController(); + double startZoomLevel = 1; + + int progress = 0; + late StreamSubscription progressStream; + + void mihLoadingPopUp() { + showDialog( + context: context, + builder: (context) { + return const Mihloadingcircle(); + }, + ); + } + + String getExtType(String path) { + //print(pdfLink.split(".")[1]); + return path.split(".").last; + } + + String getFileName(String path) { + //print(pdfLink.split(".")[1]); + return path.split("/").last; + } + + void printDocument() async { + print("Printing ${widget.path.split("/").last}"); + http.Response response = await http.get(Uri.parse(widget.link)); + var pdfData = response.bodyBytes; + Navigator.of(context).pushNamed( + '/file-veiwer/print-preview', + arguments: PrintPreviewArguments( + pdfData, + getFileName( + widget.path, + ), + ), + ); + } + + void nativeFileDownload(String fileLink) async { + var permission = await FlDownloader.requestPermission(); + if (permission == StoragePermissionStatus.granted) { + try { + mihLoadingPopUp(); + await FlDownloader.download(fileLink); + Navigator.of(context).pop(); + } on Exception catch (error) { + Navigator.of(context).pop(); + print(error); + } + } else { + print("denied"); + } + } + + @override + void dispose() { + pdfViewerController.dispose(); + progressStream.cancel(); + super.dispose(); + } + + @override + void initState() { + super.initState(); + FlDownloader.initialize(); + progressStream = FlDownloader.progressStream.listen((event) { + if (event.status == DownloadStatus.successful) { + setState(() { + progress = event.progress; + }); + //Navigator.of(context).pop(); + print("Progress $progress%: Success Downloading"); + FlDownloader.openFile(filePath: event.filePath); + } else if (event.status == DownloadStatus.failed) { + print("Progress $progress%: Error Downloading"); + } else if (event.status == DownloadStatus.running) { + print("Progress $progress%: Download Running"); + } + }); + } + + @override + Widget build(BuildContext context) { + // double width = MediaQuery.sizeOf(context).width; + //double height = MediaQuery.sizeOf(context).height; + debugPrint(widget.link); + if (getExtType(widget.path).toLowerCase() == "pdf") { + return Expanded( + child: Stack( + fit: StackFit.expand, + children: [ + SfPdfViewerTheme( + data: SfPdfViewerThemeData( + backgroundColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + child: SfPdfViewer.network( + widget.link, + controller: pdfViewerController, + interactionMode: PdfInteractionMode.pan, + ), + ), + Positioned( + bottom: 10, + right: 10, + width: 50, + height: 50, + child: IconButton.filled( + iconSize: 35, + padding: const EdgeInsets.all(0), + onPressed: () { + printDocument(); + }, + icon: Icon( + Icons.print, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ), + Positioned( + bottom: 10, + left: 10, + width: 50, + height: 50, + child: IconButton.filled( + iconSize: 35, + padding: const EdgeInsets.all(0), + onPressed: () async { + // debugPrint( + // "I'm here ${MzanziInnovationHub.of(context)!.theme.getPlatform()}"); + if (MzanziInnovationHub.of(context)!.theme.getPlatform() == + "Web") { + html.window.open( + widget.link, + // '${AppEnviroment.baseFileUrl}/mih/$filePath', + 'download'); + } else { + // print("Here"); + // var permission = await FlDownloader.requestPermission(); + // if (permission == StoragePermissionStatus.granted) { + // await FlDownloader.download(widget.link); + // } else { + // print("denied"); + // } + nativeFileDownload(widget.link); + } + }, + icon: Icon( + Icons.download, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ), + ], + ), + ); + } else { + return Expanded( + // height: height, + // padding: const EdgeInsets.all(10.0), + child: Stack( + fit: StackFit.expand, + children: [ + InteractiveViewer( + //constrained: true, + //clipBehavior: Clip.antiAlias, + maxScale: 5.0, + //minScale: 0., + child: Image.network(widget.link), + ), + Positioned( + bottom: 10, + right: 10, + width: 50, + height: 50, + child: IconButton.filled( + iconSize: 35, + padding: const EdgeInsets.all(0), + onPressed: () { + //expandImage(width, height); + Navigator.of(context).pushNamed( + '/file-veiwer', + arguments: FileViewArguments( + widget.link, + widget.path, + ), + ); + }, + icon: Icon( + Icons.fullscreen, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ), + Positioned( + bottom: 10, + left: 10, + width: 50, + height: 50, + child: IconButton.filled( + iconSize: 35, + padding: const EdgeInsets.all(0), + onPressed: () async { + // debugPrint("I'm here "); + // debugPrint( + // "I'm here ${MzanziInnovationHub.of(context)!.theme.getPlatform()}"); + if (MzanziInnovationHub.of(context)!.theme.getPlatform() == + "Web") { + html.window.open( + widget.link, + // '${AppEnviroment.baseFileUrl}/mih/$filePath', + 'download'); + } else { + //print("Here"); + // var permission = await FlDownloader.requestPermission(); + // if (permission == StoragePermissionStatus.granted) { + // await FlDownloader.download(widget.link); + // } else { + // print("denied"); + // } + nativeFileDownload(widget.link); + } + }, + icon: Icon( + Icons.download, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ), + ], + ), + ); + } + } +} diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_files_list.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_files_list.dart new file mode 100644 index 00000000..7e440891 --- /dev/null +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_files_list.dart @@ -0,0 +1,397 @@ +import 'dart:convert'; + +import 'package:Mzansi_Innovation_Hub/main.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_error_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_env/env.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/files.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart'; +import 'package:Mzansi_Innovation_Hub/mih_packages/patient_profile/pat_profile/list_builders/build_file_view.dart'; +import 'package:flutter/material.dart'; +import 'package:supertokens_flutter/http.dart' as http; + +class BuildFilesList extends StatefulWidget { + final AppUser signedInUser; + final List files; + final Patient selectedPatient; + final Business? business; + final BusinessUser? businessUser; + final String type; + const BuildFilesList({ + super.key, + required this.files, + required this.signedInUser, + required this.selectedPatient, + required this.business, + required this.businessUser, + required this.type, + }); + + @override + State createState() => _BuildFilesListState(); +} + +class _BuildFilesListState extends State { + int indexOn = 0; + final baseAPI = AppEnviroment.baseApiUrl; + final basefile = AppEnviroment.baseFileUrl; + String fileUrl = ""; + + Future getFileUrlApiCall(String filePath) async { + var url = "$baseAPI/minio/pull/file/${AppEnviroment.getEnv()}/$filePath"; + //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}"); + } + + //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 deleteFileApiCall(String filePath, int fileID) async { + showDialog( + context: context, + builder: (context) { + return const Mihloadingcircle(); + }, + ); + // delete file from minio + var response = await http.delete( + Uri.parse("$baseAPI/minio/delete/file/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({"file_path": filePath}), + ); + //print("Here4"); + //print(response.statusCode); + if (response.statusCode == 200) { + //SQL delete + var response2 = await http.delete( + Uri.parse("$baseAPI/files/delete/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({"idpatient_files": fileID}), + ); + if (response2.statusCode == 200) { + 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 { + internetConnectionPopUp(); + } + } else { + internetConnectionPopUp(); + } + } + + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Internet Connection"); + }, + ); + } + + void successPopUp(String message) { + showDialog( + context: context, + builder: (context) { + return MIHSuccessMessage( + successType: "Success", + successMessage: message, + ); + }, + ); + } + + void deleteFilePopUp(String filePath, int fileID) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHDeleteMessage( + deleteType: "File", + onTap: () async { + await deleteFileApiCall(filePath, fileID); + }, + ), + ); + } + + void viewFilePopUp(String fileName, String filePath, int fileID, String url) { + bool hasAccessToDelete = false; + if (widget.type == "business") { + hasAccessToDelete = true; + } + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHWindow( + fullscreen: true, + windowTitle: fileName, + windowBody: [ + BuildFileView( + link: url, + path: filePath, + //pdfLink: '${AppEnviroment.baseFileUrl}/mih/$filePath', + ), + const SizedBox( + height: 10, + ) + ], + windowTools: [ + Visibility( + visible: hasAccessToDelete, + child: IconButton( + onPressed: () { + deleteFilePopUp(filePath, fileID); + }, + icon: Icon( + size: 35, + Icons.delete, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + ], + onWindowTapClose: () { + Navigator.pop(context); + }, + ), + ); + // showDialog( + // context: context, + // barrierDismissible: false, + // builder: (context) => Dialog( + // child: Stack( + // children: [ + // Container( + // padding: const EdgeInsets.all(10.0), + // width: 800.0, + // //height: 475.0, + // decoration: BoxDecoration( + // color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + // borderRadius: BorderRadius.circular(25.0), + // border: Border.all( + // color: + // MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // width: 5.0), + // ), + // child: Column( + // mainAxisSize: MainAxisSize.min, + // children: [ + // const SizedBox( + // height: 25, + // ), + // Text( + // fileName, + // textAlign: TextAlign.center, + // style: TextStyle( + // color: MzanziInnovationHub.of(context)! + // .theme + // .secondaryColor(), + // fontSize: 35.0, + // fontWeight: FontWeight.bold, + // ), + // ), + // const SizedBox(height: 25.0), + // Expanded( + // child: BuildFileView( + // link: url, + // path: filePath, + // //pdfLink: '${AppEnviroment.baseFileUrl}/mih/$filePath', + // )), + // const SizedBox(height: 30.0), + // SizedBox( + // width: 300, + // height: 50, + // child: MIHButton( + // onTap: () { + // html.window.open( + // url, + // // '${AppEnviroment.baseFileUrl}/mih/$filePath', + // 'download'); + // }, + // buttonText: "Dowload", + // buttonColor: MzanziInnovationHub.of(context)! + // .theme + // .secondaryColor(), + // textColor: + // MzanziInnovationHub.of(context)!.theme.primaryColor(), + // ), + // ) + // ], + // ), + // ), + // Positioned( + // top: 5, + // right: 5, + // width: 50, + // height: 50, + // child: IconButton( + // onPressed: () { + // Navigator.pop(context); + // }, + // icon: Icon( + // Icons.close, + // color: MzanziInnovationHub.of(context)!.theme.errorColor(), + // size: 35, + // ), + // ), + // ), + // Positioned( + // top: 5, + // left: 5, + // width: 50, + // height: 50, + // child: IconButton( + // onPressed: () { + // deleteFilePopUp(filePath, fileID); + // }, + // icon: Icon( + // Icons.delete, + // color: + // MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // ), + // ), + // ), + // ], + // ), + // ), + // ); + } + + @override + void dispose() { + // TODO: implement dispose + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget.files.isNotEmpty) { + return ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (BuildContext context, int index) { + return Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + }, + itemCount: widget.files.length, + itemBuilder: (context, index) { + return ListTile( + title: Text( + widget.files[index].file_name, + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + subtitle: Text( + widget.files[index].insert_date, + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + // trailing: Icon( + // Icons.arrow_forward, + // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // ), + onTap: () async { + await getFileUrlApiCall(widget.files[index].file_path) + .then((urlHere) { + //print(url); + setState(() { + fileUrl = urlHere; + }); + }); + + viewFilePopUp( + widget.files[index].file_name, + widget.files[index].file_path, + widget.files[index].idpatient_files, + fileUrl); + }, + ); + }, + ); + } else { + return const Center( + child: Text( + "No Documents Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), + ); + } + } +} diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart new file mode 100644 index 00000000..66f28cc3 --- /dev/null +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart @@ -0,0 +1,396 @@ +import 'dart:convert'; + +import 'package:Mzansi_Innovation_Hub/main.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_multiline_text_input.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_text_input.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_error_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; +import 'package:Mzansi_Innovation_Hub/mih_env/env.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/notes.dart'; +import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart'; +import 'package:flutter/material.dart'; +import 'package:supertokens_flutter/http.dart' as http; + +class BuildNotesList extends StatefulWidget { + final AppUser signedInUser; + final List notes; + final Patient selectedPatient; + final Business? business; + final BusinessUser? businessUser; + final String type; + const BuildNotesList({ + super.key, + required this.notes, + required this.signedInUser, + required this.selectedPatient, + required this.business, + required this.businessUser, + required this.type, + }); + + @override + State createState() => _BuildNotesListState(); +} + +class _BuildNotesListState extends State { + final noteTitleController = TextEditingController(); + final noteTextController = TextEditingController(); + final businessNameController = TextEditingController(); + final userNameController = TextEditingController(); + final dateController = TextEditingController(); + int indexOn = 0; + final baseAPI = AppEnviroment.baseApiUrl; + + Future deleteNoteApiCall(int NoteId) async { + var response = await http.delete( + Uri.parse("$baseAPI/notes/delete/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({"idpatient_notes": NoteId}), + ); + //print("Here4"); + //print(response.statusCode); + if (response.statusCode == 200) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + 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")); + } + setState(() {}); + String message = + "The note has been deleted successfully. This means it will no longer be visible on your and cannot be used for future appointments."; + successPopUp(message); + } else { + internetConnectionPopUp(); + } + } + + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Internet Connection"); + }, + ); + } + + void successPopUp(String message) { + showDialog( + context: context, + builder: (context) { + return MIHSuccessMessage( + successType: "Success", + successMessage: message, + ); + }, + ); + } + + void deletePatientPopUp(int NoteId) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHDeleteMessage( + deleteType: "Note", + onTap: () { + deleteNoteApiCall(NoteId); + }, + ), + ); + } + + void viewNotePopUp(Note selectednote) { + setState(() { + noteTitleController.text = selectednote.note_name; + noteTextController.text = selectednote.note_text; + businessNameController.text = selectednote.doc_office; + userNameController.text = selectednote.doctor; + dateController.text = selectednote.insert_date; + }); + bool hasAccessToDelete = false; + if (widget.type == "business" && + selectednote.doc_office == widget.business!.Name) { + hasAccessToDelete = true; + } + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHWindow( + fullscreen: true, + windowTitle: selectednote.note_name, + windowTools: [ + Visibility( + visible: hasAccessToDelete, + child: IconButton( + onPressed: () { + deletePatientPopUp(selectednote.idpatient_notes); + }, + icon: Icon( + Icons.delete, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + ], + onWindowTapClose: () { + Navigator.pop(context); + }, + windowBody: [ + MIHTextField( + controller: businessNameController, + hintText: "Office", + editable: false, + required: false, + ), + const SizedBox(height: 10.0), + MIHTextField( + controller: userNameController, + hintText: "Created By", + editable: false, + required: false, + ), + const SizedBox(height: 10.0), + MIHTextField( + controller: dateController, + hintText: "Created Date", + editable: false, + required: false, + ), + const SizedBox(height: 10.0), + MIHTextField( + controller: noteTitleController, + hintText: "Note Title", + editable: false, + required: false, + ), + const SizedBox(height: 10.0), + Expanded( + child: MIHMLTextField( + controller: noteTextController, + hintText: "Note Details", + editable: false, + required: false, + ), + ), + ], + ), + ); + // showDialog( + // context: context, + // barrierDismissible: false, + // builder: (context) => Dialog( + // child: Stack( + // children: [ + // Container( + // padding: const EdgeInsets.all(15.0), + // width: 700.0, + // //height: 475.0, + // decoration: BoxDecoration( + // color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + // borderRadius: BorderRadius.circular(25.0), + // border: Border.all( + // color: + // MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // width: 5.0), + // ), + // child: Column( + // mainAxisSize: MainAxisSize.max, + // children: [ + // const SizedBox( + // height: 25, + // ), + // Text( + // selectednote.note_name, + // textAlign: TextAlign.center, + // style: TextStyle( + // color: MzanziInnovationHub.of(context)! + // .theme + // .secondaryColor(), + // fontSize: 35.0, + // fontWeight: FontWeight.bold, + // ), + // ), + // const SizedBox(height: 25.0), + // SizedBox( + // width: 700, + // child: MIHTextField( + // controller: businessNameController, + // hintText: "Office", + // editable: false, + // required: false, + // ), + // ), + // const SizedBox(height: 10.0), + // SizedBox( + // width: 700, + // child: MIHTextField( + // controller: userNameController, + // hintText: "Created By", + // editable: false, + // required: false, + // ), + // ), + // const SizedBox(height: 10.0), + // SizedBox( + // width: 700, + // child: MIHTextField( + // controller: dateController, + // hintText: "Created Date", + // editable: false, + // required: false, + // ), + // ), + // const SizedBox(height: 10.0), + // SizedBox( + // width: 700, + // child: MIHTextField( + // controller: noteTitleController, + // hintText: "Note Title", + // editable: false, + // required: false, + // ), + // ), + // const SizedBox(height: 10.0), + // Expanded( + // child: MIHMLTextField( + // controller: noteTextController, + // hintText: "Note Details", + // editable: false, + // required: false, + // ), + // ), + // //const SizedBox(height: 25.0), + // // SizedBox( + // // width: 300, + // // height: 100, + // // child: MIHButton( + // // onTap: () { + // // Navigator.pop(context); + // // }, + // // buttonText: "Close", + // // buttonColor: Colors.blueAccent, + // // textColor: Colors.white, + // // ), + // // ) + // ], + // ), + // ), + // Positioned( + // top: 5, + // right: 5, + // width: 50, + // height: 50, + // child: IconButton( + // onPressed: () { + // Navigator.pop(context); + // }, + // icon: Icon( + // Icons.close, + // color: MzanziInnovationHub.of(context)!.theme.errorColor(), + // size: 35, + // ), + // ), + // ), + // Positioned( + // top: 5, + // left: 5, + // width: 50, + // height: 50, + // child: IconButton( + // onPressed: () { + // deletePatientPopUp(selectednote.idpatient_notes); + // }, + // icon: Icon( + // Icons.delete, + // color: + // MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // ), + // ), + // ), + // ], + // ), + // ), + // ); + } + + @override + void dispose() { + noteTextController.dispose(); + businessNameController.dispose(); + userNameController.dispose(); + dateController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + if (widget.notes.isNotEmpty) { + return ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (BuildContext context, int index) { + return Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + }, + itemCount: widget.notes.length, + itemBuilder: (context, index) { + String notePreview = widget.notes[index].note_text; + if (notePreview.length > 30) { + notePreview = "${notePreview.substring(0, 30)} ..."; + } + return ListTile( + title: Text( + "${widget.notes[index].note_name}\n${widget.notes[index].doc_office} - ${widget.notes[index].doctor}", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + subtitle: Text( + "${widget.notes[index].insert_date}:\n$notePreview", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), //Text(widget.notes[index].note_text), + trailing: Icon( + Icons.arrow_forward, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + onTap: () { + viewNotePopUp(widget.notes[index]); + }, + ); + }, + ); + } else { + return const Center( + child: Text( + "No Notes Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), + ); + } + } +}