|
|
|
@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_repor
|
|
|
|
import 'package:diplomaticquarterapp/core/model/prescriptions/prescriptions_order.dart';
|
|
|
|
import 'package:diplomaticquarterapp/core/model/prescriptions/prescriptions_order.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
import 'package:open_filex/open_filex.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../core/enum/filter_type.dart';
|
|
|
|
import '../../../core/enum/filter_type.dart';
|
|
|
|
import '../../../core/enum/viewstate.dart';
|
|
|
|
import '../../../core/enum/viewstate.dart';
|
|
|
|
@ -15,17 +16,20 @@ import '../../../core/service/medical/prescriptions_service.dart';
|
|
|
|
import '../../../locator.dart';
|
|
|
|
import '../../../locator.dart';
|
|
|
|
import '../base_view_model.dart';
|
|
|
|
import '../base_view_model.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PrescriptionsViewModel extends BaseViewModel {
|
|
|
|
class PrescriptionsViewModel extends BaseViewModel {
|
|
|
|
FilterType filterType = FilterType.Clinic;
|
|
|
|
FilterType filterType = FilterType.Clinic;
|
|
|
|
PrescriptionsService _prescriptionsService = locator<PrescriptionsService>();
|
|
|
|
PrescriptionsService _prescriptionsService = locator<PrescriptionsService>();
|
|
|
|
|
|
|
|
|
|
|
|
List<PrescriptionsList> _prescriptionsOrderListClinic =[];
|
|
|
|
List<PrescriptionsList> _prescriptionsOrderListClinic = [];
|
|
|
|
List<PrescriptionsList> _prescriptionsOrderListHospital =[];
|
|
|
|
List<PrescriptionsList> _prescriptionsOrderListHospital = [];
|
|
|
|
|
|
|
|
|
|
|
|
List<PrescriptionReport> get prescriptionReportList => _prescriptionsService.prescriptionReportList;
|
|
|
|
List<PrescriptionReport> get prescriptionReportList => _prescriptionsService.prescriptionReportList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<PrescriptionReportINP> get prescriptionReportListINP => _prescriptionsService.prescriptionReportListINP;
|
|
|
|
List<PrescriptionReportINP> get prescriptionReportListINP => _prescriptionsService.prescriptionReportListINP;
|
|
|
|
|
|
|
|
|
|
|
|
List<Prescriptions> get prescriptionsList => _prescriptionsService.prescriptionsList;
|
|
|
|
List<Prescriptions> get prescriptionsList => _prescriptionsService.prescriptionsList;
|
|
|
|
@ -45,6 +49,9 @@ class PrescriptionsViewModel extends BaseViewModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get isMedDeliveryAllowed => _prescriptionsService.isMedDeliveryAllowed;
|
|
|
|
get isMedDeliveryAllowed => _prescriptionsService.isMedDeliveryAllowed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String get prescriptionReportPDF => _prescriptionsService.prescriptionReportPDF;
|
|
|
|
|
|
|
|
|
|
|
|
getPrescriptions() async {
|
|
|
|
getPrescriptions() async {
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
await _prescriptionsService.getPrescriptions();
|
|
|
|
await _prescriptionsService.getPrescriptions();
|
|
|
|
@ -114,15 +121,36 @@ class PrescriptionsViewModel extends BaseViewModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sendPrescriptionEmail({required String appointmentDate, required int patientID, required String clinicName, required String doctorName, required int doctorID, required String mes, required int projectID, required bool isInOutPatient}) async {
|
|
|
|
sendPrescriptionEmail(
|
|
|
|
|
|
|
|
{required String appointmentDate,
|
|
|
|
|
|
|
|
required int patientID,
|
|
|
|
|
|
|
|
required String clinicName,
|
|
|
|
|
|
|
|
required String doctorName,
|
|
|
|
|
|
|
|
required int doctorID,
|
|
|
|
|
|
|
|
required String mes,
|
|
|
|
|
|
|
|
required int projectID,
|
|
|
|
|
|
|
|
required bool isInOutPatient,
|
|
|
|
|
|
|
|
required bool isDownload}) async {
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
await _prescriptionsService.sendPrescriptionEmail(appointmentDate, patientID, clinicName, doctorName, doctorID, projectID, isInOutPatient);
|
|
|
|
await _prescriptionsService.sendPrescriptionEmail(appointmentDate, patientID, clinicName, doctorName, doctorID, projectID, isInOutPatient, isDownload);
|
|
|
|
if (_prescriptionsService.hasError) {
|
|
|
|
if (_prescriptionsService.hasError) {
|
|
|
|
error = _prescriptionsService.error!;
|
|
|
|
error = _prescriptionsService.error!;
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
AppToast.showErrorToast(message: error);
|
|
|
|
AppToast.showErrorToast(message: error);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (isDownload) {
|
|
|
|
|
|
|
|
if (prescriptionReportPDF.isNotEmpty) {
|
|
|
|
|
|
|
|
String path = await _createFileFromString(prescriptionReportPDF, "pdf");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
OpenFilex.open(path);
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
AppToast.showErrorToast(message: "Cannot open file.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
AppToast.showSuccessToast(message: mes);
|
|
|
|
AppToast.showSuccessToast(message: mes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppToast.showSuccessToast(message: mes);
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -160,6 +188,14 @@ class PrescriptionsViewModel extends BaseViewModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> _createFileFromString(String encodedStr, String ext) async {
|
|
|
|
|
|
|
|
Uint8List bytes = base64.decode(encodedStr);
|
|
|
|
|
|
|
|
String dir = (await getApplicationDocumentsDirectory()).path;
|
|
|
|
|
|
|
|
File file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + "." + ext);
|
|
|
|
|
|
|
|
await file.writeAsBytes(bytes);
|
|
|
|
|
|
|
|
return file.path;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future updatePressOrder({required int presOrderID}) async {
|
|
|
|
Future updatePressOrder({required int presOrderID}) async {
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
// await _prescriptionsService.updatePressOrder(presOrderID: presOrderID);
|
|
|
|
// await _prescriptionsService.updatePressOrder(presOrderID: presOrderID);
|
|
|
|
|