From 452cf789be56c79678317883027c395545d7a887 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Wed, 18 Feb 2026 07:26:49 +0530 Subject: [PATCH] fix: amm-2175 prescription validation --- .../workarea/workarea.component.ts | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts b/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts index 27773c0..740fad9 100644 --- a/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts +++ b/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts @@ -2122,6 +2122,34 @@ export class WorkareaComponent } } } + + // Ensure doctor has added at least one prescription + if (this.attendant === 'doctor') { + try { + 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( + this.current_language_set?.Prescription?.prescriptionRequired || + 'Please add at least one prescription', + ); + } + } + } catch (err) { + console.warn('Error validating prescription presence', err); + } + } + if (required.length) { this.confirmationService.notify( this.current_language_set.alerts.info.belowFields, @@ -2231,7 +2259,7 @@ export class WorkareaComponent !this.schedulerData ) required.push(this.current_language_set.nurseData.scheduleTM); - + if (required.length) { this.confirmationService.notify( this.current_language_set.alerts.info.belowFields, @@ -2680,6 +2708,37 @@ export class WorkareaComponent } } + // For quick consult doctor flow, ensure at least one prescription exists + if (this.attendant === 'doctor') { + try { + const caseRecordForm = ( + this.patientMedicalForm.controls['patientCaseRecordForm'] + ); + const prescription = + caseRecordForm && caseRecordForm.controls + ? caseRecordForm.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( + this.current_language_set?.Prescription?.prescriptionRequired || + 'Please add at least one prescription', + ); + } + } + } catch (err) { + console.warn( + 'Error validating quick consult prescription presence', + err, + ); + } + } + if (required.length) { this.confirmationService.notify( this.current_language_set.alerts.info.belowFields,