diff --git a/src/app/app-modules/nurse-doctor/workarea/workarea-validation.service.ts b/src/app/app-modules/nurse-doctor/workarea/workarea-validation.service.ts index 9dd5c714..aeb9e90d 100644 --- a/src/app/app-modules/nurse-doctor/workarea/workarea-validation.service.ts +++ b/src/app/app-modules/nurse-doctor/workarea/workarea-validation.service.ts @@ -572,8 +572,35 @@ export class WorkareaValidationService { } } - // Note: the original app does NOT require a prescription on doctor submit, - // so no "at least one prescription" check is added here (kept faithful). + // Ensure the doctor has added at least one prescription before submit. + if (host.attendantType === 'doctor') { + try { + const caseRecordForm = ( + medicalForm.controls['patientCaseRecordForm'] + ); + const drugPrescriptionForm = ( + (caseRecordForm && caseRecordForm.controls + ? caseRecordForm.controls['drugPrescriptionForm'] + : null) + ); + if (drugPrescriptionForm) { + let prescribedDrugs = + drugPrescriptionForm.value && + drugPrescriptionForm.value.prescribedDrugs + ? drugPrescriptionForm.value.prescribedDrugs + : []; + prescribedDrugs = prescribedDrugs.filter((d: any) => !!d.createdBy); + if (!prescribedDrugs || prescribedDrugs.length === 0) { + required.push( + host.currentLanguageSet?.Prescription?.prescriptionRequired || + 'Please add at least one prescription' + ); + } + } + } catch (err) { + console.warn('Error validating prescription presence', err); + } + } if (required.length) { host.confirmationService.notify( @@ -1068,8 +1095,36 @@ export class WorkareaValidationService { } } - // Note: the original app does NOT require a prescription on submit (quick - // consult doctor flow included), so no such check is added here. + // Quick consult doctor flow: ensure at least one prescription exists. + if (host.attendantType === 'doctor') { + try { + const quickConsultCaseRecordForm = ( + host.patientMedicalForm.controls['patientCaseRecordForm'] + ); + const prescription = + quickConsultCaseRecordForm && quickConsultCaseRecordForm.controls + ? quickConsultCaseRecordForm.controls['drugPrescriptionForm'] + : null; + if (prescription) { + let prescribedDrugs = + prescription.value && prescription.value.prescribedDrugs + ? prescription.value.prescribedDrugs + : []; + prescribedDrugs = prescribedDrugs.filter((d: any) => !!d.createdBy); + if (!prescribedDrugs || prescribedDrugs.length === 0) { + required.push( + host.currentLanguageSet?.Prescription?.prescriptionRequired || + 'Please add at least one prescription' + ); + } + } + } catch (err) { + console.warn( + 'Error validating quick consult prescription presence', + err + ); + } + } if (required.length) { host.confirmationService.notify(