diff --git a/src/data/repositories/DiseaseOutbreakEventD2Repository.ts b/src/data/repositories/DiseaseOutbreakEventD2Repository.ts index ebb477d8..d0056f75 100644 --- a/src/data/repositories/DiseaseOutbreakEventD2Repository.ts +++ b/src/data/repositories/DiseaseOutbreakEventD2Repository.ts @@ -36,9 +36,11 @@ export class DiseaseOutbreakEventD2Repository implements DiseaseOutbreakEventRep return Future.fromPromise( getAllTrackedEntitiesAsync(this.api, RTSL_ZEBRA_PROGRAM_ID, RTSL_ZEBRA_ORG_UNIT_ID) ).map(trackedEntities => { - return trackedEntities.map(trackedEntity => { - return mapTrackedEntityAttributesToDiseaseOutbreak(trackedEntity); - }); + return trackedEntities + .map(trackedEntity => { + return mapTrackedEntityAttributesToDiseaseOutbreak(trackedEntity); + }) + .filter(outbreak => outbreak.status === "ACTIVE"); }); } diff --git a/src/data/repositories/test/DiseaseOutbreakEventTestRepository.ts b/src/data/repositories/test/DiseaseOutbreakEventTestRepository.ts index 1e73a76d..821e03ca 100644 --- a/src/data/repositories/test/DiseaseOutbreakEventTestRepository.ts +++ b/src/data/repositories/test/DiseaseOutbreakEventTestRepository.ts @@ -13,6 +13,7 @@ export class DiseaseOutbreakEventTestRepository implements DiseaseOutbreakEventR get(id: Id): FutureData { return Future.success({ id: id, + status: "ACTIVE", name: "Disease Outbreak 1", dataSource: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS, created: new Date(), @@ -46,6 +47,7 @@ export class DiseaseOutbreakEventTestRepository implements DiseaseOutbreakEventR return Future.success([ { id: "1", + status: "ACTIVE", name: "Disease Outbreak 1", dataSource: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS, created: new Date(), @@ -76,6 +78,7 @@ export class DiseaseOutbreakEventTestRepository implements DiseaseOutbreakEventR }, { id: "2", + status: "ACTIVE", name: "Disease Outbreak 2", dataSource: DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS, created: new Date(), diff --git a/src/data/repositories/utils/DiseaseOutbreakMapper.ts b/src/data/repositories/utils/DiseaseOutbreakMapper.ts index 7766c4b9..bf99d5d1 100644 --- a/src/data/repositories/utils/DiseaseOutbreakMapper.ts +++ b/src/data/repositories/utils/DiseaseOutbreakMapper.ts @@ -44,6 +44,7 @@ export function mapTrackedEntityAttributesToDiseaseOutbreak( const diseaseOutbreak: DiseaseOutbreakEventBaseAttrs = { id: trackedEntity.trackedEntity, + status: trackedEntity.enrollments?.[0]?.status ?? "ACTIVE", //Zebra Outbreak has only one enrollment name: fromMap("name"), dataSource: dataSource, created: trackedEntity.createdAt ? new Date(trackedEntity.createdAt) : new Date(), diff --git a/src/data/repositories/utils/getAllTrackedEntities.ts b/src/data/repositories/utils/getAllTrackedEntities.ts index 31e26798..845602b6 100644 --- a/src/data/repositories/utils/getAllTrackedEntities.ts +++ b/src/data/repositories/utils/getAllTrackedEntities.ts @@ -30,6 +30,9 @@ export async function getAllTrackedEntitiesAsync( orgUnit: true, trackedEntity: true, trackedEntityType: true, + enrollments: { + status: true, + }, }, }) .getData(); diff --git a/src/domain/entities/disease-outbreak-event/DiseaseOutbreakEvent.ts b/src/domain/entities/disease-outbreak-event/DiseaseOutbreakEvent.ts index f8608de2..f9181936 100644 --- a/src/domain/entities/disease-outbreak-event/DiseaseOutbreakEvent.ts +++ b/src/domain/entities/disease-outbreak-event/DiseaseOutbreakEvent.ts @@ -54,6 +54,7 @@ type EarlyResponseActions = { }; export type DiseaseOutbreakEventBaseAttrs = NamedRef & { + status: "ACTIVE" | "COMPLETED" | "CANCELLED"; created: Date; lastUpdated: Date; createdByName: Maybe; diff --git a/src/webapp/pages/form-page/disease-outbreak-event/utils/mapFormStateToEntityData.ts b/src/webapp/pages/form-page/disease-outbreak-event/utils/mapFormStateToEntityData.ts index 58a358e2..2bc5df0e 100644 --- a/src/webapp/pages/form-page/disease-outbreak-event/utils/mapFormStateToEntityData.ts +++ b/src/webapp/pages/form-page/disease-outbreak-event/utils/mapFormStateToEntityData.ts @@ -153,6 +153,7 @@ export function mapFormStateToEntityData( const diseaseOutbreakEventBase: DiseaseOutbreakEventBaseAttrs = { id: diseaseOutbreakEvent?.id || "", + status: diseaseOutbreakEvent?.status || "ACTIVE", created: diseaseOutbreakEvent?.created || new Date(), lastUpdated: diseaseOutbreakEvent?.lastUpdated || new Date(), createdByName: diseaseOutbreakEvent?.createdByName || currentUserName,