Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <FormArray>(
this.drugPrescriptionForm.controls['prescribedDrugs']
Expand Down
52 changes: 52 additions & 0 deletions src/app/app-modules/nurse-doctor/workarea/workarea.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,33 @@ export class WorkareaComponent
}
}
}
// Ensure doctor has added at least one prescription
if (this.attendant === 'doctor') {
try {
const drugPrescriptionForm = <FormGroup>(
(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,
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/assets/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2145,4 +2145,4 @@
}


}
}
2 changes: 1 addition & 1 deletion src/assets/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading