import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_model.dart'; import 'package:doctor_app_flutter/core/service/patient_medical_file/ucaf/patient-ucaf-service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/models/SOAP/ChiefComplaint/GetChiefComplaintResModel.dart'; import 'package:doctor_app_flutter/models/SOAP/GetAssessmentResModel.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/models/SOAP/order-procedure.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/models/patient/vital_sign/patient-vital-sign-history.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:flutter/material.dart'; import '../../locator.dart'; class UcafViewModel extends BaseViewModel { UcafService _ucafService = locator(); List get patientChiefComplaintList => _ucafService.patientChiefComplaintList; List get patientVitalSignsHistory => _ucafService.patientVitalSignsHistory; List get patientAssessmentList => _ucafService.patientAssessmentList; List get diagnosisTypes => _ucafService.listOfDiagnosisType; List get diagnosisConditions => _ucafService.listOfDiagnosisCondition; PrescriptionModel get prescriptionList => _ucafService.prescriptionList; List get orderProcedures => _ucafService.orderProcedureList; String selectedLanguage; String heightCm = "0"; String weightKg = "0"; String bodyMax = "0"; String temperatureCelcius = "0"; String hartRat = "0"; String respirationBeatPerMinute = "0"; String bloodPressure = "0 / 0"; resetDataInFirst() { _ucafService.patientAssessmentList = []; _ucafService.orderProcedureList = []; _ucafService.prescriptionList = null; } Future getLanguage() async { selectedLanguage = await sharedPref.getString(APP_Language); } Future getUCAFData(PatiantInformtion patient) async { setState(ViewState.Busy); String from; String to; if (from == null || from == "0") { from = AppDateUtils.convertDateToFormat(DateTime.now(), 'yyyy-MM-dd'); } if (to == null || to == "0") { to = AppDateUtils.convertDateToFormat(DateTime.now(), 'yyyy-MM-dd'); } // await _ucafService.getPatientVitalSignsHistory(patient, from, to); await _ucafService.getInPatientVitalSignHistory(patient, false); await _ucafService.getPatientChiefComplaint(patient); if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.Error); } else { patientVitalSignsHistory.forEach((element) { if (heightCm == "0" || heightCm == null || heightCm == 'null') { heightCm = element.heightCm.toString(); } if (weightKg == "0" || weightKg == null || weightKg == 'null') { weightKg = element.weightKg.toString(); } if (bodyMax == "0" || bodyMax == null || bodyMax == 'null') { bodyMax = element.bodyMassIndex.toString(); } if (temperatureCelcius == "0" || temperatureCelcius == null || temperatureCelcius == 'null') { temperatureCelcius = element.temperatureCelcius.toString(); } if (hartRat == "0" || hartRat == null || hartRat == 'null') { hartRat = element.pulseBeatPerMinute.toString(); } if (respirationBeatPerMinute == "0" || respirationBeatPerMinute == null || respirationBeatPerMinute == 'null') { respirationBeatPerMinute = element.respirationBeatPerMinute.toString(); } if (bloodPressure == "0 / 0" || bloodPressure == null || bloodPressure == 'null') { bloodPressure = element.bloodPressure.toString(); } }); setState(ViewState.Idle); } } Future getPatientAssessment(PatiantInformtion patient) async { if (patientAssessmentList.isEmpty) { setState(ViewState.Busy); await _ucafService.getPatientAssessment(patient); if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.Error); } else { if (patientAssessmentList.isNotEmpty) { if (diagnosisConditions.length == 0) { await _ucafService .getMasterLookup(MasterKeysService.DiagnosisCondition); } if (diagnosisTypes.length == 0) { await _ucafService.getMasterLookup(MasterKeysService.DiagnosisType); } if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.Error); } else setState(ViewState.Idle); } else setState(ViewState.Idle); // but with empty list } } } Future getOrderProcedures(PatiantInformtion patient) async { if (orderProcedures.isEmpty) { setState(ViewState.Busy); await _ucafService.getOrderProcedures(patient); if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.Error); } else { setState(ViewState.Idle); } } } Future getPrescription(PatiantInformtion patient) async { if (prescriptionList == null) { setState(ViewState.Busy); await _ucafService.getPrescription(patient); if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.Error); } else { setState(ViewState.Idle); } } } MasterKeyModel findMasterDataById( {@required MasterKeysService masterKeys, dynamic id}) { switch (masterKeys) { case MasterKeysService.DiagnosisCondition: List result = diagnosisConditions.where((element) { return element.id == id && element.typeId == masterKeys.getMasterKeyService(); }).toList(); if (result.isNotEmpty) { return result.first; } return null; case MasterKeysService.DiagnosisType: List result = diagnosisTypes.where((element) { return element.id == id && element.typeId == masterKeys.getMasterKeyService(); }).toList(); if (result.isNotEmpty) { return result.first; } return null; default: return null; } } Future postUCAF(PatiantInformtion patient) async { setState(ViewState.Busy); await _ucafService.postUCAF(patient); if (_ucafService.hasError) { error = _ucafService.error; setState(ViewState.ErrorLocal); } else { setState(ViewState.Idle); // but with empty list } } }