Skip to content

Commit

Permalink
fix: only active enrolments should be listed
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Sep 30, 2024
1 parent 8321e43 commit aecd723
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/data/repositories/DiseaseOutbreakEventD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class DiseaseOutbreakEventTestRepository implements DiseaseOutbreakEventR
get(id: Id): FutureData<DiseaseOutbreakEventBaseAttrs> {
return Future.success({
id: id,
status: "ACTIVE",
name: "Disease Outbreak 1",
dataSource: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS,
created: new Date(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/data/repositories/utils/DiseaseOutbreakMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions src/data/repositories/utils/getAllTrackedEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export async function getAllTrackedEntitiesAsync(
orgUnit: true,
trackedEntity: true,
trackedEntityType: true,
enrollments: {
status: true,
},
},
})
.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type EarlyResponseActions = {
};

export type DiseaseOutbreakEventBaseAttrs = NamedRef & {
status: "ACTIVE" | "COMPLETED" | "CANCELLED";
created: Date;
lastUpdated: Date;
createdByName: Maybe<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aecd723

Please sign in to comment.