Skip to content

Commit

Permalink
Merge branch 'development' into feature/performace-overview-table-lin…
Browse files Browse the repository at this point in the history
…k-indicators
  • Loading branch information
fdelemarre committed Sep 16, 2024
2 parents 6b20cc8 + 55c75cf commit d31a21c
Show file tree
Hide file tree
Showing 23 changed files with 628 additions and 172 deletions.
10 changes: 8 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-09-12T14:10:04.460Z\n"
"PO-Revision-Date: 2024-09-12T14:10:04.460Z\n"
"POT-Creation-Date: 2024-09-16T15:12:17.095Z\n"
"PO-Revision-Date: 2024-09-16T15:12:17.095Z\n"

msgid "Low"
msgstr ""
Expand Down Expand Up @@ -78,6 +78,9 @@ msgstr ""
msgid "Cancel"
msgstr ""

msgid "Edit Details"
msgstr ""

msgid "Create Event"
msgstr ""

Expand Down Expand Up @@ -117,6 +120,9 @@ msgstr ""
msgid "Event Tracker"
msgstr ""

msgid "Add new Assessment"
msgstr ""

msgid "Page Not Found"
msgstr ""

Expand Down
15 changes: 9 additions & 6 deletions i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ msgstr ""
msgid "Cancel"
msgstr ""

msgid "Save"
msgstr ""

msgid "Edit Details"
msgstr ""

msgid "Create Event"
msgstr ""

Expand Down Expand Up @@ -104,18 +110,15 @@ msgstr ""
msgid "Respond, alert, watch"
msgstr ""

msgid "Duration"
msgstr ""

msgid "7-1-7 performance"
msgstr ""

msgid "Performance overview"
msgstr ""

msgid "Event Tracker"
msgstr ""

msgid "Add new Assessment"
msgstr ""

msgid "Page Not Found"
msgstr ""

Expand Down
13 changes: 5 additions & 8 deletions src/data/repositories/DiseaseOutbreakEventD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { D2TrackerTrackedEntity } from "@eyeseetea/d2-api/api/trackerTrackedEnti
import { getProgramTEAsMetadata } from "./utils/MetadataHelper";
import { assertOrError } from "./utils/AssertOrError";
import { Future } from "../../domain/entities/generic/Future";
import { getAllTrackedEntitiesAsync } from "./utils/getAllTrackedEntities";

export class DiseaseOutbreakEventD2Repository implements DiseaseOutbreakEventRepository {
constructor(private api: D2Api) {}
Expand All @@ -32,14 +33,10 @@ export class DiseaseOutbreakEventD2Repository implements DiseaseOutbreakEventRep
}

getAll(): FutureData<DiseaseOutbreakEventBaseAttrs[]> {
return apiToFuture(
this.api.tracker.trackedEntities.get({
program: RTSL_ZEBRA_PROGRAM_ID,
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
fields: { attributes: true, trackedEntity: true },
})
).map(response => {
return response.instances.map(trackedEntity => {
return Future.fromPromise(
getAllTrackedEntitiesAsync(this.api, RTSL_ZEBRA_PROGRAM_ID, RTSL_ZEBRA_ORG_UNIT_ID)
).map(trackedEntities => {
return trackedEntities.map(trackedEntity => {
return mapTrackedEntityAttributesToDiseaseOutbreak(trackedEntity);
});
});
Expand Down
32 changes: 28 additions & 4 deletions src/data/repositories/OptionsD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ import { OptionsRepository } from "../../domain/repositories/OptionsRepository";
import { assertOrError } from "./utils/AssertOrError";
import { getHazardTypeByCode } from "./consts/DiseaseOutbreakConstants";

const MAIN_SYNDROME_OPTION_SET_CODE = "AGENTS";
const SUSPECTED_DISEASE_OPTION_SET_CODE = "RTSL_ZEB_OS_DISEASE";
const NOTIFICATION_SOURCE_OPTION_SET_CODE = "RTSL_ZEB_OS_SOURCE";

export class OptionsD2Repository implements OptionsRepository {
constructor(private api: D2Api) {}

get(code: Code): FutureData<Option> {
getMainSyndrome(optionCode: Code): FutureData<Option> {
return this.get(optionCode, MAIN_SYNDROME_OPTION_SET_CODE);
}

getSuspectedDisease(optionCode: Code): FutureData<Option> {
return this.get(optionCode, SUSPECTED_DISEASE_OPTION_SET_CODE);
}

getNotificationSource(optionCode: Code): FutureData<Option> {
return this.get(optionCode, NOTIFICATION_SOURCE_OPTION_SET_CODE);
}

get(optionCode: Code, optionSetCode: Code): FutureData<Option> {
return apiToFuture(
this.api.metadata.get({
options: { fields: { code: true, name: true }, filter: { code: { eq: code } } },
options: {
fields: { code: true, name: true, optionSet: { id: true, code: true } },
filter: {
code: { eq: optionCode },
"optionSet.code": {
eq: optionSetCode,
},
},
},
})
)
.flatMap(response => assertOrError(response.options[0], "Option"))
Expand Down Expand Up @@ -50,11 +74,11 @@ export class OptionsD2Repository implements OptionsRepository {
}

getSuspectedDiseases(): FutureData<Option[]> {
return this.getOptionSetByCode("RTSL_ZEB_OS_DISEASE");
return this.getOptionSetByCode(SUSPECTED_DISEASE_OPTION_SET_CODE);
}

getNotificationSources(): FutureData<Option[]> {
return this.getOptionSetByCode("RTSL_ZEB_OS_SOURCE");
return this.getOptionSetByCode(NOTIFICATION_SOURCE_OPTION_SET_CODE);
}

getIncidentStatus(): FutureData<Option[]> {
Expand Down
17 changes: 15 additions & 2 deletions src/data/repositories/test/OptionsTestRepository.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { DataSource } from "../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent";
import { Future } from "../../../domain/entities/generic/Future";
import { Id, Option } from "../../../domain/entities/Ref";
import { Code, Id, Option } from "../../../domain/entities/Ref";
import { OptionsRepository } from "../../../domain/repositories/OptionsRepository";
import { FutureData } from "../../api-futures";

export class OptionsTestRepository implements OptionsRepository {
get(id: Id): FutureData<Option> {
return Future.success({ id: id, name: "Test Option" });
return Future.success({ id: id, name: "Test Main Syndrome", code: "MainSyndromeCode" });
}
getMainSyndrome(_optionCode: Code): FutureData<Option> {
return Future.success({ id: "1", name: "Test Main Syndrome", code: "MainSyndromeCode" });
}
getSuspectedDisease(_optionCode: Code): FutureData<Option> {
return Future.success({ id: "1", name: "Test Disease", code: "DiseaseCode" });
}
getNotificationSource(_optionCode: Code): FutureData<Option> {
return Future.success({
id: "1",
name: "Test Notification Source",
code: "TestNotificationSource",
});
}

getDataSources(): FutureData<Option[]> {
Expand Down
25 changes: 24 additions & 1 deletion src/data/repositories/utils/DateTimeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,28 @@ export function getCurrentTimeString(): string {
}

export function getDateAsIsoString(date: Maybe<Date>): string {
return date ? date.toISOString() : "";
try {
return date ? date.toISOString() : "";
} catch (e) {
console.debug(e);
return "";
}
}

export function getDateAsMonthYearString(date: Date): string {
try {
return date.toLocaleString("default", { month: "long", year: "numeric" });
} catch (e) {
console.debug(e);
return "";
}
}

export function getDateAsLocaleDateTimeString(date: Date): string {
try {
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
} catch (e) {
console.debug(e);
return "";
}
}
75 changes: 44 additions & 31 deletions src/data/repositories/utils/DiseaseOutbreakMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,38 +121,51 @@ export function mapDiseaseOutbreakEventToTrackedEntityAttributes(
return populatedAttribute;
});

const enrollment: D2TrackerEnrollment = {
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
program: RTSL_ZEBRA_PROGRAM_ID,
enrollment: "",
trackedEntityType: RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID,
notes: [],
relationships: [],
attributes: attributes,
events: [],
enrolledAt: diseaseOutbreak.created.toISOString(),
occurredAt: diseaseOutbreak.lastUpdated.toISOString(),
createdAt: getCurrentTimeString(),
createdAtClient: getCurrentTimeString(),
updatedAt: getCurrentTimeString(),
updatedAtClient: getCurrentTimeString(),
status: "ACTIVE",
orgUnitName: "",
followUp: false,
deleted: false,
storedBy: "",
};
const trackedEntity: D2TrackerTrackedEntity = {
trackedEntity: diseaseOutbreak.id,
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
trackedEntityType: RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID,
createdAt: diseaseOutbreak.created.toISOString(),
updatedAt: diseaseOutbreak.lastUpdated.toISOString(),
attributes: attributes,
enrollments: [enrollment],
};
const isExistingTEI = diseaseOutbreak.id !== "";

if (isExistingTEI) {
const trackedEntity: D2TrackerTrackedEntity = {
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
trackedEntityType: RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID,
trackedEntity: diseaseOutbreak.id,
attributes: attributes,
};

return trackedEntity;
} else {
const enrollment: D2TrackerEnrollment = {
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
program: RTSL_ZEBRA_PROGRAM_ID,
enrollment: "",
trackedEntityType: RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID,
notes: [],
relationships: [],
attributes: attributes,
events: [],
enrolledAt: getCurrentTimeString(),
occurredAt: getCurrentTimeString(),
createdAt: getCurrentTimeString(),
createdAtClient: getCurrentTimeString(),
updatedAt: getCurrentTimeString(),
updatedAtClient: getCurrentTimeString(),
status: "ACTIVE",
orgUnitName: "",
followUp: false,
deleted: false,
storedBy: "",
};
const trackedEntity: D2TrackerTrackedEntity = {
trackedEntity: diseaseOutbreak.id,
orgUnit: RTSL_ZEBRA_ORG_UNIT_ID,
trackedEntityType: RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID,
attributes: attributes,
createdAt: getCurrentTimeString(),
updatedAt: getCurrentTimeString(),
enrollments: [enrollment],
};

return trackedEntity;
return trackedEntity;
}
}

function getValueFromMap(
Expand Down
45 changes: 45 additions & 0 deletions src/data/repositories/utils/getAllTrackedEntities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { D2Api } from "@eyeseetea/d2-api/2.36";
import {
D2TrackerTrackedEntity,
TrackedEntitiesGetResponse,
} from "@eyeseetea/d2-api/api/trackerTrackedEntities";
import { Id } from "../../../domain/entities/Ref";

export async function getAllTrackedEntitiesAsync(
api: D2Api,
programId: Id,
orgUnitId: Id
): Promise<D2TrackerTrackedEntity[]> {
const d2TrackerTrackedEntities: D2TrackerTrackedEntity[] = [];

const pageSize = 250;
let page = 1;
let result: TrackedEntitiesGetResponse;

try {
do {
result = await api.tracker.trackedEntities
.get({
program: programId,
orgUnit: orgUnitId,
totalPages: true,
page: page,
pageSize: pageSize,
fields: {
attributes: true,
orgUnit: true,
trackedEntity: true,
trackedEntityType: true,
},
})
.getData();

d2TrackerTrackedEntities.push(...result.instances);

page++;
} while (result.page < Math.ceil((result.total as number) / pageSize));
return d2TrackerTrackedEntities;
} catch {
return [];
}
}
7 changes: 5 additions & 2 deletions src/domain/repositories/OptionsRepository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { FutureData } from "../../data/api-futures";
import { Id, Option } from "../entities/Ref";
import { Code, Option } from "../entities/Ref";

export interface OptionsRepository {
get(id: Id): FutureData<Option>;
get(optionCode: Code, optionSetCode: Code): FutureData<Option>;
getMainSyndrome(optionCode: Code): FutureData<Option>;
getSuspectedDisease(optionCode: Code): FutureData<Option>;
getNotificationSource(optionCode: Code): FutureData<Option>;
getDataSources(): FutureData<Option[]>;
getHazardTypes(): FutureData<Option[]>;
getMainSyndromes(): FutureData<Option[]>;
Expand Down
9 changes: 6 additions & 3 deletions src/domain/usecases/GetDiseaseOutbreakByIdUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ export class GetDiseaseOutbreakByIdUseCase {
} = diseaseOutbreakEventBase;
return Future.joinObj({
mainSyndrome: mainSyndromeCode
? this.options.optionsRepository.get(mainSyndromeCode)
? this.options.optionsRepository.getMainSyndrome(mainSyndromeCode)
: Future.success(undefined),
suspectedDisease: suspectedDiseaseCode
? this.options.optionsRepository.get(suspectedDiseaseCode)
? this.options.optionsRepository.getSuspectedDisease(suspectedDiseaseCode)
: Future.success(undefined),
notificationSource: this.options.optionsRepository.get(notificationSourceCode),
notificationSource:
this.options.optionsRepository.getNotificationSource(
notificationSourceCode
),
incidentManager: incidentManagerName
? this.options.teamMemberRepository.get(incidentManagerName)
: Future.success(undefined),
Expand Down
4 changes: 2 additions & 2 deletions src/webapp/components/form/FormFieldsState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Maybe } from "../../../utils/ts-utils";
import { validateFieldRequired, validateFieldRequiredWithNotApplicable } from "./validations";
import { UserOption } from "../user-selector/UserSelector";
import { User } from "../user-selector/UserSelector";
import { Option } from "../utils/option";
import { ValidationError, ValidationErrorKey } from "../../../domain/entities/ValidationError";
import { FormSectionState } from "./FormSectionsState";
Expand Down Expand Up @@ -52,7 +52,7 @@ export type FormDateFieldState = FormFieldStateBase<Date | null> & {

export type FormAvatarFieldState = FormFieldStateBase<Maybe<string>> & {
type: "user";
options: UserOption[];
options: User[];
};

export type FormFieldState =
Expand Down
Loading

0 comments on commit d31a21c

Please sign in to comment.