From d4f96bd63c194e5902f9603ee68275defb9c50a5 Mon Sep 17 00:00:00 2001 From: gkbishnoi07 Date: Fri, 11 Sep 2026 08:18:16 +0000 Subject: [PATCH] fix(prescription): require at least one prescription on doctor submit restore the doctor prescription-required gate in the workarea validation (standard submit + quick-consult paths) so a doctor cannot submit without adding a prescription. gated on attendantType === 'doctor', so the nurse flow is unchanged. added drug rows carry createdBy, so the presence check counts real prescriptions only. --- .../workarea/workarea-validation.service.ts | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) 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(