|
|
|
|
@ -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';
|
|
|
|
|
@ -76,13 +82,7 @@ class LabsViewModel extends BaseViewModel {
|
|
|
|
|
|
|
|
|
|
getLaboratoryResult({String? projectID, int? clinicID, String? invoiceNo, String? invoiceType, String? orderNo, String? setupID, bool? isVidaPlus}) async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
await _labsService.getLaboratoryResult(invoiceNo: invoiceNo,
|
|
|
|
|
invoiceType: invoiceType,
|
|
|
|
|
orderNo: orderNo,
|
|
|
|
|
projectID: projectID,
|
|
|
|
|
clinicID: clinicID,
|
|
|
|
|
setupID: setupID,
|
|
|
|
|
isVidaPlus: isVidaPlus);
|
|
|
|
|
await _labsService.getLaboratoryResult(invoiceNo: invoiceNo, invoiceType: invoiceType, orderNo: orderNo, projectID: projectID, clinicID: clinicID, setupID: setupID, isVidaPlus: isVidaPlus);
|
|
|
|
|
if (_labsService.hasError) {
|
|
|
|
|
error = _labsService.error!;
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
@ -109,7 +109,7 @@ class LabsViewModel extends BaseViewModel {
|
|
|
|
|
// })
|
|
|
|
|
// .toList();
|
|
|
|
|
// if (value.isEmpty)
|
|
|
|
|
labResultLists[labResultLists.indexOf(patientLabOrdersClinic[0])].patientLabResultList!.add(element);
|
|
|
|
|
labResultLists[labResultLists.indexOf(patientLabOrdersClinic[0])].patientLabResultList!.add(element);
|
|
|
|
|
} else {
|
|
|
|
|
labResultLists.add(LabResultList(filterName: element.testCode, lab: element));
|
|
|
|
|
}
|
|
|
|
|
@ -156,9 +156,25 @@ class LabsViewModel extends BaseViewModel {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|