diff --git a/lib/core/viewModel/SOAP_view_model.dart b/lib/core/viewModel/SOAP_view_model.dart index 7e339e49..78c309ca 100644 --- a/lib/core/viewModel/SOAP_view_model.dart +++ b/lib/core/viewModel/SOAP_view_model.dart @@ -114,120 +114,6 @@ class SOAPViewModel extends BaseViewModel { SubjectiveCallBack subjectiveCallBack; - onUpdateSubjectStepStart(PatiantInformtion patientInfo) async { - GetChiefComplaintReqModel getChiefComplaintReqModel = - GetChiefComplaintReqModel( - admissionNo: - patientInfo - .admissionNo != - null - ? int.parse(patientInfo.admissionNo) - : null, - patientMRN: patientInfo.patientMRN, - appointmentNo: patientInfo.appointmentNo != null - ? int.parse(patientInfo.appointmentNo.toString()) - : null, - episodeId: patientInfo.episodeNo, - episodeID: patientInfo.episodeNo, - doctorID: ''); - var services = [ - _SOAPService.getPatientChiefComplaint(getChiefComplaintReqModel) - ]; - - if (patientInfo.admissionNo == null) { - complaintsControllerError = ''; - medicationControllerError = ''; - illnessControllerError = ''; - GetHistoryReqModel getHistoryReqModel = GetHistoryReqModel( - patientMRN: patientInfo.patientMRN, - episodeID: patientInfo.episodeNo.toString(), - appointmentNo: int.parse(patientInfo.appointmentNo.toString()), - doctorID: '', - editedBy: ''); - services.add( - _SOAPService.getPatientHistories(getHistoryReqModel, isFirst: true)); - - GeneralGetReqForSOAP generalGetReqForSOAP = GeneralGetReqForSOAP( - patientMRN: patientInfo.patientMRN, - episodeId: patientInfo.episodeNo, - appointmentNo: int.parse(patientInfo.appointmentNo.toString()), - doctorID: '', - editedBy: ''); - - services.add(_SOAPService.getPatientAllergy(generalGetReqForSOAP)); - } - - final results = await Future.wait(services); - await callServicesAfterGetPatientInfoForUpdateSubject(); - } - - callServicesAfterGetPatientInfoForUpdateSubject() async { - var services; - if (patientHistoryList.isNotEmpty) { - if (historyFamilyList.isEmpty) { - if (services == null) { - services = [ - _SOAPService.getMasterLookup(MasterKeysService.HistoryFamily) - ]; - } else { - services.add( - _SOAPService.getMasterLookup(MasterKeysService.HistoryFamily)); - } - } - if (historyMedicalList.isEmpty) { - if (services == null) { - services = [ - _SOAPService.getMasterLookup(MasterKeysService.HistoryMedical) - ]; - } else - services.add( - _SOAPService.getMasterLookup(MasterKeysService.HistoryMedical)); - } - if (historySurgicalList.length == 0) { - if (services == null) { - services = [ - _SOAPService.getMasterLookup(MasterKeysService.HistorySurgical) - ]; - } else - services.add( - _SOAPService.getMasterLookup(MasterKeysService.HistorySurgical)); - } - if (historySportList.length == 0) { - if (services == null) { - services = [ - _SOAPService.getMasterLookup(MasterKeysService.HistorySports) - ]; - } else - services.add( - _SOAPService.getMasterLookup(MasterKeysService.HistorySports)); - } - } - - if (patientAllergiesList.isNotEmpty) { - if (allergiesList.isEmpty) if (services == null) { - services = [_SOAPService.getMasterLookup(MasterKeysService.Allergies)]; - } else - services.add(_SOAPService.getMasterLookup(MasterKeysService.Allergies)); - if (allergySeverityList.isEmpty) { - if (services == null) { - services = [ - _SOAPService.getMasterLookup(MasterKeysService.AllergySeverity) - ]; - } else - services.add( - _SOAPService.getMasterLookup(MasterKeysService.AllergySeverity)); - } - } - - final results = await Future.wait(services??[]); - - if (_SOAPService.hasError) { - error = _SOAPService.error; - setState(ViewState.Error); - } else - setState(ViewState.Idle); - } - setSubjectiveCallBack(SubjectiveCallBack callBack) { this.subjectiveCallBack = callBack; } @@ -697,4 +583,258 @@ class SOAPViewModel extends BaseViewModel { } else return -1; } + + onUpdateSubjectStepStart(PatiantInformtion patientInfo) async { + GetChiefComplaintReqModel getChiefComplaintReqModel = + GetChiefComplaintReqModel( + admissionNo: + patientInfo + .admissionNo != + null + ? int.parse(patientInfo.admissionNo) + : null, + patientMRN: patientInfo.patientMRN, + appointmentNo: patientInfo.appointmentNo != null + ? int.parse(patientInfo.appointmentNo.toString()) + : null, + episodeId: patientInfo.episodeNo, + episodeID: patientInfo.episodeNo, + doctorID: ''); + var services = [ + _SOAPService.getPatientChiefComplaint(getChiefComplaintReqModel) + ]; + + if (patientInfo.admissionNo == null) { + complaintsControllerError = ''; + medicationControllerError = ''; + illnessControllerError = ''; + GetHistoryReqModel getHistoryReqModel = GetHistoryReqModel( + patientMRN: patientInfo.patientMRN, + episodeID: patientInfo.episodeNo.toString(), + appointmentNo: int.parse(patientInfo.appointmentNo.toString()), + doctorID: '', + editedBy: ''); + services.add( + _SOAPService.getPatientHistories(getHistoryReqModel, isFirst: true)); + + GeneralGetReqForSOAP generalGetReqForSOAP = GeneralGetReqForSOAP( + patientMRN: patientInfo.patientMRN, + episodeId: patientInfo.episodeNo, + appointmentNo: int.parse(patientInfo.appointmentNo.toString()), + doctorID: '', + editedBy: ''); + + services.add(_SOAPService.getPatientAllergy(generalGetReqForSOAP)); + } + + final results = await Future.wait(services); + await callServicesAfterGetPatientInfoForUpdateSubject(); + } + + callServicesAfterGetPatientInfoForUpdateSubject() async { + var services; + if (patientHistoryList.isNotEmpty) { + if (historyFamilyList.isEmpty) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.HistoryFamily) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.HistoryFamily)); + } + } + if (historyMedicalList.isEmpty) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.HistoryMedical) + ]; + } else + services.add( + _SOAPService.getMasterLookup(MasterKeysService.HistoryMedical)); + } + if (historySurgicalList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.HistorySurgical) + ]; + } else + services.add( + _SOAPService.getMasterLookup(MasterKeysService.HistorySurgical)); + } + if (historySportList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.HistorySports) + ]; + } else + services.add( + _SOAPService.getMasterLookup(MasterKeysService.HistorySports)); + } + } + + if (patientAllergiesList.isNotEmpty) { + if (allergiesList.isEmpty) if (services == null) { + services = [_SOAPService.getMasterLookup(MasterKeysService.Allergies)]; + } else + services.add(_SOAPService.getMasterLookup(MasterKeysService.Allergies)); + if (allergySeverityList.isEmpty) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.AllergySeverity) + ]; + } else + services.add( + _SOAPService.getMasterLookup(MasterKeysService.AllergySeverity)); + } + } + + final results = await Future.wait(services ?? []); + + if (_SOAPService.hasError) { + error = _SOAPService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } + + onAddMedicationStart() async { + setState(ViewState.Busy); + var services; + if (medicationStrengthList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.MedicationStrength) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.MedicationStrength)); + } + } + if (medicationFrequencyList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.MedicationFrequency) + ]; + } else { + services.add(_SOAPService.getMasterLookup( + MasterKeysService.MedicationFrequency)); + } + } + if (medicationDoseTimeList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.MedicationDoseTime) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.MedicationDoseTime)); + } + } + if (medicationRouteList.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.MedicationRoute) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.MedicationRoute)); + } + } + if (allMedicationList.length == 0) { + await getMedicationList(); + if (services == null) { + services = [ + _prescriptionService.getMedicationList() + ]; + } else { + services.add( + _prescriptionService.getMedicationList()); + } + } + + final results = await Future.wait(services ?? []); + + if (_SOAPService.hasError ||_prescriptionService.hasError ) { + error = _SOAPService.error + _prescriptionService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + + callAddAssessmentLookupsServices({bool allowSetState = true}) async { + if(allowSetState) + setState(ViewState.Busy); + var services; + if (listOfDiagnosisCondition.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.DiagnosisCondition) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.DiagnosisCondition)); + } + } + if (listOfDiagnosisType.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.DiagnosisType) + ]; + } else { + services.add(_SOAPService.getMasterLookup( + MasterKeysService.DiagnosisType)); + } + } + if (listOfICD10.length == 0) { + if (services == null) { + services = [ + _SOAPService.getMasterLookup(MasterKeysService.ICD10) + ]; + } else { + services.add( + _SOAPService.getMasterLookup(MasterKeysService.ICD10)); + } + } + + final results = await Future.wait(services ?? []); + if(allowSetState) { + if (_SOAPService.hasError) { + error = _SOAPService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + + } + + onUpdateAssessmentStepStart(PatiantInformtion patientInfo) async { + + GetAssessmentReqModel getAssessmentReqModel = GetAssessmentReqModel( + patientMRN: patientInfo.patientMRN, + episodeID: patientInfo.episodeNo.toString(), + editedBy: '', + doctorID: '', + appointmentNo: + int.parse(patientInfo.appointmentNo.toString())); + + var services = [ + _SOAPService.getPatientAssessment(getAssessmentReqModel) + ]; + + final results = await Future.wait(services); + + + if (patientAssessmentList.isNotEmpty) { + await callAddAssessmentLookupsServices(allowSetState: false); + } + + if (_SOAPService.hasError) { + error = _SOAPService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + + + } } diff --git a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart index 9abc95cf..a0cdb39c 100644 --- a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart +++ b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart @@ -119,15 +119,9 @@ class _AddAssessmentDetailsState extends State { heightFactor: 1, child: BaseView( onModelReady: (model) async { - if (model.listOfDiagnosisCondition.length == 0) { - await model.getMasterLookup(MasterKeysService.DiagnosisCondition); - } - if (model.listOfDiagnosisType.length == 0) { - await model.getMasterLookup(MasterKeysService.DiagnosisType); - } - if (model.listOfICD10.length == 0) { - await model.getMasterLookup(MasterKeysService.ICD10); - } + + model.callAddAssessmentLookupsServices(); + }, builder: (_, model, w) => AppScaffold( baseViewModel: model, diff --git a/lib/screens/patients/profile/soap_update/assessment/update_assessment_page.dart b/lib/screens/patients/profile/soap_update/assessment/update_assessment_page.dart index 7740f308..80cdc34c 100644 --- a/lib/screens/patients/profile/soap_update/assessment/update_assessment_page.dart +++ b/lib/screens/patients/profile/soap_update/assessment/update_assessment_page.dart @@ -55,24 +55,10 @@ class _UpdateAssessmentPageState extends State onModelReady: (model) async { model.setAssessmentCallBack(this); mySelectedAssessmentList.clear(); - GetAssessmentReqModel getAssessmentReqModel = GetAssessmentReqModel( - patientMRN: widget.patientInfo.patientMRN, - episodeID: widget.patientInfo.episodeNo.toString(), - editedBy: '', - doctorID: '', - appointmentNo: - int.parse(widget.patientInfo.appointmentNo.toString())); - await model.getPatientAssessment(getAssessmentReqModel); + + await model.onUpdateAssessmentStepStart(widget.patientInfo); + if (model.patientAssessmentList.isNotEmpty) { - if (model.listOfDiagnosisCondition.length == 0) { - await model.getMasterLookup(MasterKeysService.DiagnosisCondition); - } - if (model.listOfDiagnosisType.length == 0) { - await model.getMasterLookup(MasterKeysService.DiagnosisType); - } - if (model.listOfICD10.length == 0) { - await model.getMasterLookup(MasterKeysService.ICD10); - } model.patientAssessmentList.forEach((element) { MasterKeyModel diagnosisType = model.getOneMasterKey( masterKeys: MasterKeysService.DiagnosisType, diff --git a/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart b/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart index 84bdaf9a..553c2f17 100644 --- a/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart +++ b/lib/screens/patients/profile/soap_update/subjective/medication/add_medication.dart @@ -56,23 +56,7 @@ class _AddMedicationState extends State { return FractionallySizedBox( child: BaseView( onModelReady: (model) async { - if (model.medicationStrengthList.length == 0) { - await model.getMasterLookup( - MasterKeysService.MedicationStrength, - ); - } - if (model.medicationFrequencyList.length == 0) { - await model.getMasterLookup( - MasterKeysService.MedicationFrequency); - } - if (model.medicationDoseTimeList.length == 0) { - await model.getMasterLookup(MasterKeysService.MedicationDoseTime); - } - if (model.medicationRouteList.length == 0) { - await model.getMasterLookup(MasterKeysService.MedicationRoute); - } - if (model.allMedicationList.length == 0) - await model.getMedicationList(); + model.onAddMedicationStart(); }, builder: (_, model, w) => AppScaffold(