Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling/issue 501 #535

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "NODE_OPTIONS=--max_old_space_size=8192 ng serve",
"build": "NODE_OPTIONS=--max_old_space_size=8192 ng build",
"start": "set NODE_OPTIONS=--max_old_space_size=8192 && ng serve",
"build": "set NODE_OPTIONS=--max_old_space_size=8192 && ng build",
"build:prod": "ng build --aot --configuration production",
"test": "ng test",
"test:headless": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class PatientMedicationSummaryComponent implements OnInit {
patientDrugOrdersStatuses$: Observable<any>;
filteredDrugOrders$: Observable<any>;
visitDetails$: Observable<any>;

constructor(
private store: Store<AppState>,
private ordersService: OrdersService,
Expand Down Expand Up @@ -145,32 +146,55 @@ export class PatientMedicationSummaryComponent implements OnInit {

onAddOrder(e: Event) {
e.stopPropagation();
const dialog = this.dialog.open(DispensingFormComponent, {
width: "80%",
disableClose: true,
data: {
drugOrder: null,
patient: this.patientVisit?.patientUuid,
patientUuid: this.patientVisit?.patientUuid,
visit: this.patientVisit,
location: localStorage.getItem("currentLocation")
? JSON.parse(localStorage.getItem("currentLocation"))
: null,
encounterUuid: JSON.parse(localStorage.getItem("patientConsultation"))[
"encounterUuid"
],
fromDispensing: this.fromDispensing,
showAddButton: false,
forConsultation: this.forConsultation,
},
});
// function to add prescription

// Check for active orders before allowing new order
const activeOrders = this.filteredDrugOrders$; // You already have the filtered drug orders
activeOrders.subscribe((ordersData) => {
const activeMedication = ordersData.toBeDispensedDrugOrders.find(
(order) => new Date(order.stopDatetime) > new Date()
);

dialog.afterClosed().subscribe((data) => {
this.loadVisit();
if (data?.updateConsultationOrder) {
this.updateMedicationComponent.emit();
this.updateConsultationOrder.emit();
if (activeMedication) {
// Show error dialog: There's an active medication that needs to be completed
this.dialog.open(DispensingFormComponent, {
width: "80%",
disableClose: true,
data: {
message: "Cannot add a new dosage until the previous one is completed.",
},
});
return; // Prevent adding a new dosage
}

// Proceed to open the dispensing form if no active medication is found
const dialog = this.dialog.open(DispensingFormComponent, {
width: "80%",
disableClose: true,
data: {
drugOrder: null,
patient: this.patientVisit?.patientUuid,
patientUuid: this.patientVisit?.patientUuid,
visit: this.patientVisit,
location: localStorage.getItem("currentLocation")
? JSON.parse(localStorage.getItem("currentLocation"))
: null,
encounterUuid: JSON.parse(localStorage.getItem("patientConsultation"))[
"encounterUuid"
],
fromDispensing: this.fromDispensing,
showAddButton: false,
forConsultation: this.forConsultation,
},
});

dialog.afterClosed().subscribe((data) => {
this.loadVisit();
if (data?.updateConsultationOrder) {
this.updateMedicationComponent.emit();
this.updateConsultationOrder.emit();
}
});
});
}
}
}