Skip to content

Commit

Permalink
feat: update incident status attribute in alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Aug 20, 2024
1 parent 734bd96 commit e39cf14
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/data/repositories/AlertD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { D2Api } from "@eyeseetea/d2-api/2.36";
import { apiToFuture, FutureData } from "../api-futures";
import {
RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID,
RTSL_ZEBRA_ALERTS_NATIONAL_INCIDENT_STATUS_TEA_ID,
RTSL_ZEBRA_ALERTS_PROGRAM_ID,
RTSL_ZEBRA_ORG_UNIT_ID,
} from "./consts/DiseaseOutbreakConstants";
Expand All @@ -17,8 +18,8 @@ import {
export class AlertD2Repository implements AlertRepository {
constructor(private api: D2Api) {}

updateEventIdInAlerts(alertOptions: AlertOptions): FutureData<void> {
const { eventId, filter } = alertOptions;
updateAlerts(alertOptions: AlertOptions): FutureData<void> {
const { eventId, filter, incidentStatus } = alertOptions;

return this.getTrackedEntitiesByTEACode(filter).flatMap(response => {
const alertsToMap = response.map(trackedEntity => ({
Expand All @@ -28,6 +29,10 @@ export class AlertD2Repository implements AlertRepository {
attribute: RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID,
value: eventId,
},
{
attribute: RTSL_ZEBRA_ALERTS_NATIONAL_INCIDENT_STATUS_TEA_ID,
value: incidentStatus,
},
],
}));

Expand Down
1 change: 1 addition & 0 deletions src/data/repositories/consts/DiseaseOutbreakConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const RTSL_ZEBRA_ALERTS_PROGRAM_ID = "MQtbs8UkBxy";
export const RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID = "Pq1drzz2HJk";
export const RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID = "agsVaIpit4S";
export const RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID = "ydsfY6zyvt7";
export const RTSL_ZEBRA_ALERTS_NATIONAL_INCIDENT_STATUS_TEA_ID = "IpGLuK0W5y2";

export const hazardTypeCodeMap: Record<HazardType, string> = {
"Biological:Human": "BIOLOGICAL_HUMAN",
Expand Down
2 changes: 1 addition & 1 deletion src/data/repositories/test/AlertTestRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AlertOptions, AlertRepository } from "../../../domain/repositories/Aler
import { FutureData } from "../../api-futures";

export class AlertTestRepository implements AlertRepository {
updateEventIdInAlerts(_alertOptions: AlertOptions): FutureData<void> {
updateAlerts(_alertOptions: AlertOptions): FutureData<void> {
return Future.success(undefined);
}
}
4 changes: 3 additions & 1 deletion src/domain/repositories/AlertRepository.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { FutureData } from "../../data/api-futures";
import { IncidentStatusType } from "../entities/disease-outbreak-event/DiseaseOutbreakEvent";
import { Id } from "../entities/Ref";

export interface AlertRepository {
updateEventIdInAlerts(alertOptions: AlertOptions): FutureData<void>;
updateAlerts(alertOptions: AlertOptions): FutureData<void>;
}

export type AlertOptions = {
eventId: Id;
filter: { id: Id; value: string };
incidentStatus: IncidentStatusType;
};
6 changes: 4 additions & 2 deletions src/domain/usecases/MapDiseaseOutbreakToAlertsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class MapDiseaseOutbreakToAlertsUseCase {
diseaseOutbreakEventId: Id,
diseaseOutbreakEventData: DiseaseOutbreakEventData
): FutureData<void> {
const { dataSourceCode, hazardType, suspectedDiseaseCode } = diseaseOutbreakEventData;
const { dataSourceCode, hazardType, incidentStatus, suspectedDiseaseCode } =
diseaseOutbreakEventData;
const hazardTypeCode = hazardTypeCodeMap[hazardType];

if (!diseaseOutbreakEventId)
Expand All @@ -35,9 +36,10 @@ export class MapDiseaseOutbreakToAlertsUseCase {
? { id: RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID, value: suspectedDiseaseCode }
: { id: RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID, value: hazardTypeCode };

return this.alertRepository.updateEventIdInAlerts({
return this.alertRepository.updateAlerts({
eventId: diseaseOutbreakEventId,
filter: filter,
incidentStatus: incidentStatus,
});
}
}

0 comments on commit e39cf14

Please sign in to comment.