Skip to content

Commit

Permalink
Registered notifyDoctor effect
Browse files Browse the repository at this point in the history
KISOWILE, Nayabasetsi
2022-04-04501
  • Loading branch information
rahel21charles authored Jan 19, 2025
1 parent d2e17aa commit 6c964ef
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions ui/src/app/store/effects/drug-orders.effects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from "@angular/core";
import { createEffect, Actions, ofType } from "@ngrx/effects";
import { HttpClient } from "@angular/common/http";
import {
saveDrugOrder,
addDrugsOrdered,
Expand All @@ -17,6 +18,7 @@ import {
catchError,
concatMap,
withLatestFrom,
mergeMap
} from "rxjs/operators";
import { of } from "rxjs";
import {
Expand All @@ -32,14 +34,16 @@ import { getActiveVisit } from "../selectors/visit.selectors";
import { getEncounterTypeByUuid } from "../selectors/encounter-type.selectors";
import { ICARE_CONFIG } from "src/app/shared/resources/config";
import { DrugOrdersService } from "src/app/shared/resources/order/services";
import * as drugOrderActions from '../actions/drug-orders.actions';

@Injectable()
export class DrugOrdersEffects {
constructor(
private drugOrderService: DrugOrdersService,
private actions$: Actions,
private notificationService: NotificationService,
private store: Store<AppState>
private store: Store<AppState>,
private httpClient: HttpClient // Added missing HttpClient
) {}

loadDrugOrders$ = createEffect(() =>
Expand All @@ -53,7 +57,6 @@ export class DrugOrdersEffects {
)
)
);

// drugOrder$ = createEffect(() =>
// this.actions$.pipe(
// ofType(saveDrugOrder),
Expand Down Expand Up @@ -159,7 +162,7 @@ export class DrugOrdersEffects {
// )
// )
// );

updateDrugOrder$ = createEffect(() =>
this.actions$.pipe(
ofType(updateDrugOrder),
Expand All @@ -180,7 +183,7 @@ export class DrugOrdersEffects {
);

return addDrugsOrdered({
drugOrders: { ...response, id: response.uuid },
drugOrders: [{ ...response, id: response.uuid }] // Fixed array syntax
});
}),
catchError((error) => {
Expand Down Expand Up @@ -233,4 +236,62 @@ export class DrugOrdersEffects {
})
)
);

notifyDoctor$ = createEffect(() =>
this.actions$.pipe(
ofType(drugOrderActions.notifyDoctor),
mergeMap((action) => {
const notificationData = {
doctorUuid: action.doctorUuid,
drugOrder: action.drugOrder,
patientInfo: action.patientInfo,
timestamp: new Date().toISOString()
};

return this.httpClient
.post(`/api/notification/doctor/${action.doctorUuid}`, notificationData)
.pipe(
map(() =>
drugOrderActions.notifyDoctorSuccess({
doctorUuid: action.doctorUuid,
drugOrder: action.drugOrder
})
),
catchError((error) =>
of(
drugOrderActions.notifyDoctorFail({
error,
doctorUuid: action.doctorUuid
})
)
)
);
})
)
);

batchNotifyDoctors$ = createEffect(() =>
this.actions$.pipe(
ofType(drugOrderActions.batchNotifyDoctors),
mergeMap((action) => {
const notifications = action.drugOrders.map((drugOrder) => {
const doctorUuid = drugOrder?.orderer?.uuid;
if (!doctorUuid) {
return drugOrderActions.notifyDoctorFail({
error: 'No doctor UUID found',
doctorUuid: 'unknown'
});
}

return drugOrderActions.notifyDoctor({
doctorUuid,
drugOrder,
patientInfo: action.patientInfo
});
});

return notifications;
})
)
);
}

1 comment on commit 6c964ef

@rahel21charles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: The commit should be "Added notify doctor effect", and no "registered...". Pardon the confusion

Please sign in to comment.