diff --git a/src/app/app-modules/nurse-doctor/case-record/general-case-record/prescription/prescription.component.ts b/src/app/app-modules/nurse-doctor/case-record/general-case-record/prescription/prescription.component.ts index 88ffbeeb..9a007bcf 100644 --- a/src/app/app-modules/nurse-doctor/case-record/general-case-record/prescription/prescription.component.ts +++ b/src/app/app-modules/nurse-doctor/case-record/general-case-record/prescription/prescription.component.ts @@ -390,10 +390,61 @@ export class PrescriptionComponent implements OnInit, DoCheck, OnDestroy { } submitForUpload() { + const validationErrors = this.validateCurrentPrescription(); + + if (validationErrors.length > 0) { + const errorMessage = + 'Please fill the following required fields:\n' + + validationErrors.map((e, i) => `${i + 1}. ${e}`).join('\n'); + this.confirmationService.alert(errorMessage, 'error'); + return; + } + this.addMedicine(); this.clearCurrentaddDetails(); } + validateCurrentPrescription(): string[] { + const errors: string[] = []; + + if (!this.currentPrescription.formName) { + errors.push('Medicine Form'); + } + if (!this.currentPrescription.drugName || !this.tempDrugName) { + errors.push('Medicine Name'); + } + if (!this.currentPrescription.dose) { + errors.push('Dosage'); + } + if (!this.currentPrescription.frequency) { + errors.push('Frequency'); + } + + // Conditional validations + if ( + this.currentPrescription.frequency && + this.currentPrescription.frequency !== 'SOS' + ) { + if (!this.currentPrescription.duration) { + errors.push('Duration'); + } + if (!this.currentPrescription.unit) { + errors.push('Unit'); + } + } + + // Quantity required for non-liquid forms + if ( + this.currentPrescription.formID && + this.currentPrescription.formID > 2 && + !this.currentPrescription.qtyPrescribed + ) { + errors.push('Quantity'); + } + + return errors; + } + addMedicine() { const medicine: FormArray = ( this.drugPrescriptionForm.controls['prescribedDrugs'] 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 fbba9152..9de001b2 100644 --- a/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts +++ b/src/app/app-modules/nurse-doctor/workarea/workarea.component.ts @@ -2930,6 +2930,33 @@ 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, @@ -3723,6 +3750,31 @@ export class WorkareaComponent } } } + // For quick consult doctor flow, ensure at least one prescription exists + if (this.attendant === 'doctor') { + try { + const prescription = + form && form.controls ? form.controls['prescription'] : 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( diff --git a/src/assets/English.json b/src/assets/English.json index 21231850..c3961778 100644 --- a/src/assets/English.json +++ b/src/assets/English.json @@ -113,7 +113,7 @@ "district": "District / Village", "registrationDate": "Registration Date", "image": "Image", - "advanceSearch": "Advance Search", + "advanceSearch": "Advanced Search", "externalSearch": "Higher Health Facility Search", "status": "Status", "visitCategory": "Visit Category / Visit No", @@ -308,7 +308,7 @@ "toTime": "To Time", "Kindlyuploadthefiles": "Kindly upload the files", "clearslots":"Clear Slot", - "advanceBeneficiarySearch": "Advance Beneficiary Search", + "advanceBeneficiarySearch": "Advanced Beneficiary Search", "externalBeneficiarySearch": "External Beneficiary Search", "firstNameisrequired": "First Name is required", "pleaseprovideatleast2character": "Please provide atleast 2 character", @@ -2145,4 +2145,4 @@ } -} \ No newline at end of file +} diff --git a/src/assets/language.json b/src/assets/language.json index 57a0d1f9..5723cbdb 100644 --- a/src/assets/language.json +++ b/src/assets/language.json @@ -87,7 +87,7 @@ "district": "District / Village", "registrationDate": "Registration Date", "image": "Image", - "advanceSearch": "Advance Search", + "advanceSearch": "Advanced Search", "status": "Status", "visitCategory": "Visit Category / Visit No", "tcDate": "TC Date",