From abd6ebb33109c70ebc1c989a57970958965b254b Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 28 May 2025 12:08:40 +0200 Subject: [PATCH] update patient manager window menu --- .../build_claim_statement_files_list.dart | 184 ++++++++++++-- .../list_builders/build_file_view.dart | 153 ++---------- .../list_builders/build_files_list.dart | 224 +++++++++++------- 3 files changed, 314 insertions(+), 247 deletions(-) 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 index 65b98116..f3f8dd58 100644 --- 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 @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:fl_downloader/fl_downloader.dart'; import 'package:flutter_speed_dial/flutter_speed_dial.dart'; import 'package:mzansi_innovation_hub/main.dart'; import 'package:mzansi_innovation_hub/mih_apis/mih_claim_statement_generation_api.dart'; @@ -5,6 +8,7 @@ import 'package:mzansi_innovation_hub/mih_apis/mih_file_api.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_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'; @@ -15,6 +19,9 @@ 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; +import 'package:http/http.dart' as http2; +import "package:universal_html/html.dart" as html; class BuildClaimStatementFileList extends StatefulWidget { final AppUser signedInUser; @@ -46,6 +53,8 @@ class _BuildClaimStatementFileListState final baseAPI = AppEnviroment.baseApiUrl; final basefile = AppEnviroment.baseFileUrl; String fileUrl = ""; + int progress = 0; + late StreamSubscription progressStream; Future getFileUrlApiCall(String filePath) async { String teporaryFileUrl = ""; @@ -106,16 +115,135 @@ class _BuildClaimStatementFileListState ); } + String getFileName(String path) { + //print(pdfLink.split(".")[1]); + return path.split("/").last; + } + + void printDocument(String link, String path) async { + http2.Response response = await http.get(Uri.parse(link)); + var pdfData = response.bodyBytes; + Navigator.of(context).pushNamed( + '/file-veiwer/print-preview', + arguments: PrintPreviewArguments( + pdfData, + getFileName(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"); + } + } + void viewFilePopUp(String fileName, String filePath, int fileID, String url) { bool hasAccessToDelete = false; if (widget.type == "business") { hasAccessToDelete = true; } + + List? menuList = [ + SpeedDialChild( + child: Icon( + Icons.download, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Download", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + if (MzanziInnovationHub.of(context)!.theme.getPlatform() == "Web") { + html.window.open(url, 'download'); + } else { + nativeFileDownload(url); + } + }, + ), + ]; + menuList.add( + SpeedDialChild( + child: Icon( + Icons.print, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Print", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + printDocument(url, filePath); + }, + ), + ); + menuList.add( + SpeedDialChild( + child: Icon( + Icons.fullscreen, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Full Screen", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + printDocument(url, filePath); + }, + ), + ); + + if (hasAccessToDelete) { + menuList.add( + SpeedDialChild( + child: Icon( + Icons.delete, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Delete Document", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + deleteFilePopUp(filePath, fileID); + }, + ), + ); + } + showDialog( context: context, barrierDismissible: false, builder: (context) => MihPackageWindow( - fullscreen: true, + fullscreen: false, windowTitle: fileName, windowBody: Column( children: [ @@ -129,30 +257,7 @@ class _BuildClaimStatementFileListState ) ], ), - menuOptions: hasAccessToDelete - ? [ - SpeedDialChild( - child: Icon( - Icons.delete, - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - ), - label: "Delete Document", - labelBackgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - labelStyle: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontWeight: FontWeight.bold, - ), - backgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - onTap: () { - deleteFilePopUp(filePath, fileID); - }, - ), - ] - : null, + menuOptions: menuList, onWindowTapClose: () { Navigator.pop(context); }, @@ -160,12 +265,41 @@ class _BuildClaimStatementFileListState ); } + void mihLoadingPopUp() { + showDialog( + context: context, + builder: (context) { + return const Mihloadingcircle(); + }, + ); + } + @override void dispose() { // TODO: implement dispose 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) { if (widget.files.isNotEmpty) { 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 index 96922521..3ab1d363 100644 --- 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 @@ -6,7 +6,6 @@ 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'; @@ -117,147 +116,27 @@ class _BuildFileViewState extends State { if (getExtType(widget.path).toLowerCase() == "pdf") { return SizedBox( height: 500, - 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(), - ), - ), - ), - ], + child: SfPdfViewerTheme( + data: SfPdfViewerThemeData( + backgroundColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + child: SfPdfViewer.network( + widget.link, + controller: pdfViewerController, + interactionMode: PdfInteractionMode.pan, + ), ), ); } else { return SizedBox( height: 500, - 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(), - ), - ), - ), - ], + child: InteractiveViewer( + //constrained: true, + //clipBehavior: Clip.antiAlias, + maxScale: 5.0, + //minScale: 0., + child: Image.network(widget.link), ), ); } 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 index d88674a1..9d85614d 100644 --- 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 @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'package:fl_downloader/fl_downloader.dart'; @@ -50,6 +51,8 @@ class _BuildFilesListState extends State { final baseAPI = AppEnviroment.baseApiUrl; final basefile = AppEnviroment.baseFileUrl; String fileUrl = ""; + int progress = 0; + late StreamSubscription progressStream; Future getFileUrlApiCall(String filePath) async { String teporaryFileUrl = ""; @@ -200,6 +203,121 @@ class _BuildFilesListState extends State { if (widget.type == "business") { hasAccessToDelete = true; } + + List? menuList = [ + SpeedDialChild( + child: Icon( + Icons.download, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Download", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + if (MzanziInnovationHub.of(context)!.theme.getPlatform() == "Web") { + html.window.open(url, 'download'); + } else { + nativeFileDownload(url); + } + }, + ), + ]; + if (filePath.split(".").last.toLowerCase() == "pdf") { + menuList.add( + SpeedDialChild( + child: Icon( + Icons.print, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Print", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + printDocument(url, filePath); + }, + ), + ); + menuList.add( + SpeedDialChild( + child: Icon( + Icons.fullscreen, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Full Screen", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + printDocument(url, filePath); + }, + ), + ); + } else { + menuList.add( + SpeedDialChild( + child: Icon( + Icons.fullscreen, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Full Screen", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + Navigator.of(context).pushNamed( + '/file-veiwer', + arguments: FileViewArguments( + url, + filePath, + ), + ); + }, + ), + ); + } + if (hasAccessToDelete) { + menuList.add( + SpeedDialChild( + child: Icon( + Icons.delete, + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + label: "Delete Document", + labelBackgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + labelStyle: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontWeight: FontWeight.bold, + ), + backgroundColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + onTap: () { + deleteFilePopUp(filePath, fileID); + }, + ), + ); + } showDialog( context: context, barrierDismissible: false, @@ -211,91 +329,7 @@ class _BuildFilesListState extends State { path: filePath, //pdfLink: '${AppEnviroment.baseFileUrl}/mih/$filePath', ), - menuOptions: [ - SpeedDialChild( - child: Icon( - Icons.download, - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - ), - label: "Download", - labelBackgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - labelStyle: TextStyle( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontWeight: FontWeight.bold, - ), - backgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - onTap: () { - if (MzanziInnovationHub.of(context)!.theme.getPlatform() == - "Web") { - html.window.open(url, 'download'); - } else { - nativeFileDownload(url); - } - printDocument(url, filePath); - }, - ), - SpeedDialChild( - child: Icon( - Icons.print, - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - ), - label: "Print", - labelBackgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - labelStyle: TextStyle( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontWeight: FontWeight.bold, - ), - backgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - onTap: () { - printDocument(url, filePath); - }, - ), - hasAccessToDelete == true - ? SpeedDialChild( - child: Icon( - Icons.delete, - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - ), - label: "Delete Document", - labelBackgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - labelStyle: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontWeight: FontWeight.bold, - ), - backgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - onTap: () { - deleteFilePopUp(filePath, fileID); - }, - ) - : SpeedDialChild( - child: Icon( - Icons.fullscreen, - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - ), - label: "Full Screen", - labelBackgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - labelStyle: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontWeight: FontWeight.bold, - ), - backgroundColor: - MzanziInnovationHub.of(context)!.theme.successColor(), - onTap: () { - printDocument(url, filePath); - }, - ), - ], + menuOptions: menuList, onWindowTapClose: () { Navigator.pop(context); }, @@ -318,6 +352,26 @@ class _BuildFilesListState extends State { 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) { if (widget.files.isNotEmpty) {