Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Integrate d2-logger (coding dojo ----DO NOT MERGE----- ) #23

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
28 changes: 6 additions & 22 deletions src/data/repositories/AlertD2Repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { D2Api } from "@eyeseetea/d2-api/2.36";
import { apiToFuture, FutureData } from "../api-futures";
import {
RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID,
RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID,
RTSL_ZEBRA_ALERTS_NATIONAL_INCIDENT_STATUS_TEA_ID,
RTSL_ZEBRA_ALERTS_PROGRAM_ID,
Expand All @@ -16,8 +14,9 @@ import { D2TrackerTrackedEntity } from "@eyeseetea/d2-api/api/trackerTrackedEnti
import { Maybe } from "../../utils/ts-utils";
import { DataSource } from "../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent";
import { Alert } from "../../domain/entities/alert/Alert";
import { OutbreakData, OutbreakDataType } from "../../domain/entities/alert/OutbreakAlert";
import { OutbreakData } from "../../domain/entities/alert/OutbreakAlert";
import { getAllTrackedEntitiesAsync } from "./utils/getAllTrackedEntities";
import { outbreakDataSourceMapping, outbreakTEAMapping } from "./utils/AlertOutbreakMapper";

export class AlertD2Repository implements AlertRepository {
constructor(private api: D2Api) {}
Expand Down Expand Up @@ -94,31 +93,16 @@ export class AlertD2Repository implements AlertRepository {
}

private getOutbreakFilterId(filter: OutbreakData): string {
const mapping: Record<OutbreakDataType, TrackedEntityAttributeId> = {
disease: RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID,
hazard: RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
};

return mapping[filter.type];
return outbreakTEAMapping[filter.type];
}

private getAlertOutbreakData(
dataSource: DataSource,
outbreakValue: Maybe<string>
): OutbreakData {
const mapping: Record<DataSource, OutbreakData> = {
[DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS]: {
type: "disease",
value: outbreakValue,
},
[DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS]: {
type: "hazard",
value: outbreakValue,
},
return {
type: outbreakDataSourceMapping[dataSource],
value: outbreakValue,
};
tokland marked this conversation as resolved.
Show resolved Hide resolved

return mapping[dataSource];
}
}

type TrackedEntityAttributeId = Id;
19 changes: 19 additions & 0 deletions src/data/repositories/utils/AlertOutbreakMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { D2TrackerTrackedEntity } from "@eyeseetea/d2-api/api/trackerTrackedEnti
import { alertOutbreakCodes } from "../consts/AlertConstants";
import { getValueFromMap } from "./DiseaseOutbreakMapper";
import { NotificationOptions } from "../../../domain/repositories/NotificationRepository";
import { OutbreakDataType } from "../../../domain/entities/alert/OutbreakAlert";
import { Id } from "../../../domain/entities/Ref";
import {
RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID,
RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
} from "../consts/DiseaseOutbreakConstants";
Copy link

Choose a reason for hiding this comment

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

No need to change, but to avoid long imports and dispersion of info, values can be grouped in the constants file by some criteria.

import { DataSource } from "../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent";

export function mapTrackedEntityAttributesToNotificationOptions(
trackedEntity: D2TrackerTrackedEntity
Expand Down Expand Up @@ -30,3 +37,15 @@ export function getAlertValueFromMap(
?.value ?? ""
);
}

export const outbreakTEAMapping: Record<OutbreakDataType, TrackedEntityAttributeId> = {
disease: RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID,
hazard: RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
};

export const outbreakDataSourceMapping: Record<DataSource, OutbreakDataType> = {
[DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS]: "disease",
[DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS]: "hazard",
};

type TrackedEntityAttributeId = Id;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import i18n from "@eyeseetea/feedback-component/locales";
import i18n from "../../../utils/i18n";
import { Code, Ref } from "../Ref";
import { Struct } from "../generic/Struct";
import { Either } from "../generic/Either";
Expand Down
10 changes: 5 additions & 5 deletions src/domain/usecases/MapAndSaveAlertsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ export class MapAndSaveAlertsUseCase {
}

private getDataSource(outbreakData: OutbreakData): DataSource {
const mapping: Record<OutbreakDataType, DataSource> = {
disease: DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS,
hazard: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS,
};

return mapping[outbreakData.type];
}

Expand Down Expand Up @@ -213,4 +208,9 @@ function getUniqueFilters(alerts: OutbreakAlert[]): OutbreakData[] {
.value();
}

const mapping: Record<OutbreakDataType, DataSource> = {
disease: DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS,
hazard: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS,
};

const RTSL_ZEBRA_NATIONAL_WATCH_STAFF_USER_GROUP_CODE = "RTSL_ZEBRA_NATONAL_WATCH_STAFF";
5 changes: 2 additions & 3 deletions src/scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ export function getApiInstanceFromEnvVariables() {
if (!process.env.VITE_DHIS2_AUTH)
throw new Error("VITE_DHIS2_AUTH must be set in the .env file");

const username = process.env.VITE_DHIS2_AUTH.split(":")[0] ?? "";
const password = process.env.VITE_DHIS2_AUTH.split(":")[1] ?? "";
const [username, password] = process.env.VITE_DHIS2_AUTH.split(":");

if (username === "" || password === "") {
if (!username || !password) {
throw new Error("VITE_DHIS2_AUTH must be in the format 'username:password'");
}

Expand Down
Loading