|
|
|
|
@ -1,3 +1,7 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/core/enum/filter_type.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/labs/LabOrderResult.dart';
|
|
|
|
|
@ -9,6 +13,8 @@ import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.da
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
|
|
|
|
|
import 'package:open_filex/open_filex.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../locator.dart';
|
|
|
|
|
import '../base_view_model.dart';
|
|
|
|
|
@ -139,6 +145,9 @@ class LabsViewModel extends BaseViewModel {
|
|
|
|
|
case ResultFlag.CH: //6
|
|
|
|
|
percentage = division * 3.8;
|
|
|
|
|
break;
|
|
|
|
|
case ResultFlag.IRR:
|
|
|
|
|
percentage = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return percentage * 100;
|
|
|
|
|
@ -177,14 +186,35 @@ class LabsViewModel extends BaseViewModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendLabReportEmail({PatientLabOrders? patientLabOrder, String? mes, AuthenticatedUser? userObj, required bool isVidaPlus, bool isDownload = false}) async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
|
|
|
|
|
await _labsService.sendLabReportEmail(patientLabOrder: patientLabOrder, userObj: userObj, isVidaPlus: isVidaPlus, isDownload: isDownload);
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
|
|
|
|
|
if (_labsService.hasError) {
|
|
|
|
|
error = _labsService.error!;
|
|
|
|
|
} else {
|
|
|
|
|
if (isDownload) {
|
|
|
|
|
if (labReportPDF.isNotEmpty) {
|
|
|
|
|
String path = await _createFileFromString(labReportPDF, "pdf");
|
|
|
|
|
try {
|
|
|
|
|
OpenFilex.open(path);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
AppToast.showErrorToast(message: "Cannot open file.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AppToast.showSuccessToast(message: mes!);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|