Skip to content

Commit

Permalink
Merge pull request #24 from EyeSeeTea/feature/add-event-tracker-map-w…
Browse files Browse the repository at this point in the history
…ith-merge

Add dashboard and event tracker maps
  • Loading branch information
bhavananarayanan authored Oct 3, 2024
2 parents 49a6927 + 0c1b32a commit 41973df
Show file tree
Hide file tree
Showing 44 changed files with 2,082 additions and 256 deletions.
18 changes: 18 additions & 0 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,18 @@ msgstr ""
msgid "Notes"
msgstr ""

msgid "Notes"
msgstr ""

msgid "Create Event"
msgstr ""

msgid "The map with these filters could not be found."
msgstr ""

msgid "Map not found."
msgstr ""

msgid "Close"
msgstr ""

Expand All @@ -117,9 +126,15 @@ msgstr ""
msgid "Respond, alert, watch"
msgstr ""

msgid "Select duration"
msgstr ""

msgid "Duration"
msgstr ""

msgid "All public health events"
msgstr ""

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

Expand All @@ -129,6 +144,9 @@ msgstr ""
msgid "Event Tracker"
msgstr ""

msgid "Districts Affected"
msgstr ""

msgid "Create Risk Assessment"
msgstr ""

Expand Down
24 changes: 21 additions & 3 deletions i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ msgstr ""
msgid "Cancel"
msgstr ""

msgid "Save"
msgstr ""

msgid "Edit Details"
msgstr ""

msgid "Create Event"
msgstr ""

msgid "The map with these filters could not be found."
msgstr ""

msgid "Map not found."
msgstr ""

msgid "Close"
msgstr ""

Expand All @@ -116,12 +119,27 @@ msgstr ""
msgid "Respond, alert, watch"
msgstr ""

msgid "Select duration"
msgstr ""

msgid "Duration"
msgstr ""

msgid "All public health events"
msgstr ""

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

msgid "Performance overview"
msgstr ""

msgid "Event Tracker"
msgstr ""

msgid "Districts Affected"
msgstr ""

msgid "Create Risk Assessment"
msgstr ""

Expand Down
28 changes: 21 additions & 7 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ import { OptionsTestRepository } from "./data/repositories/test/OptionsTestRepos
import { TeamMemberTestRepository } from "./data/repositories/test/TeamMemberTestRepository";
import { OrgUnitTestRepository } from "./data/repositories/test/OrgUnitTestRepository";
import { GetAllDiseaseOutbreaksUseCase } from "./domain/usecases/GetAllDiseaseOutbreaksUseCase";
import { MapDiseaseOutbreakToAlertsUseCase } from "./domain/usecases/MapDiseaseOutbreakToAlertsUseCase";
import { AlertRepository } from "./domain/repositories/AlertRepository";
import { AlertTestRepository } from "./data/repositories/test/AlertTestRepository";
import { GetEntityWithOptionsUseCase } from "./domain/usecases/GetEntityWithOptionsUseCase";
import { SaveEntityUseCase } from "./domain/usecases/SaveEntityUseCase";
import { RiskAssessmentRepository } from "./domain/repositories/RiskAssessmentRepository";
import { RiskAssessmentD2Repository } from "./data/repositories/RiskAssessmentD2Repository";
import { RiskAssessmentTestRepository } from "./data/repositories/test/RiskAssessmentTestRepository";
import { MapConfigRepository } from "./domain/repositories/MapConfigRepository";
import { MapConfigD2Repository } from "./data/repositories/MapConfigD2Repository";
import { MapConfigTestRepository } from "./data/repositories/test/MapConfigTestRepository";
import { GetMapConfigUseCase } from "./domain/usecases/GetMapConfigUseCase";
import { GetProvincesOrgUnits } from "./domain/usecases/GetProvincesOrgUnits";
import { GetAllOrgUnitsUseCase } from "./domain/usecases/GetAllOrgUnitsUseCase";
import { PerformanceOverviewRepository } from "./domain/repositories/PerformanceOverviewRepository";
import { GetAllPerformanceOverviewMetricsUseCase } from "./domain/usecases/GetAllPerformanceOverviewMetricsUseCase";
import { PerformanceOverviewD2Repository } from "./data/repositories/PerformanceOverviewD2Repository";
import { PerformanceOverviewTestRepository } from "./data/repositories/test/PerformanceOverviewTestRepository";
import { GetTotalCardCountsUseCase } from "./domain/usecases/GetDiseasesTotalUseCase";
import { MapDiseaseOutbreakToAlertsUseCase } from "./domain/usecases/MapDiseaseOutbreakToAlertsUseCase";
import { AlertRepository } from "./domain/repositories/AlertRepository";
import { AlertTestRepository } from "./data/repositories/test/AlertTestRepository";
import { AlertSyncDataStoreRepository } from "./data/repositories/AlertSyncDataStoreRepository";
import { AlertSyncDataStoreTestRepository } from "./data/repositories/test/AlertSyncDataStoreTestRepository";
import { AlertSyncRepository } from "./domain/repositories/AlertSyncRepository";
import { DataStoreClient } from "./data/DataStoreClient";
import { GetTotalCardCountsUseCase } from "./domain/usecases/GetTotalCardCountsUseCase";

export type CompositionRoot = ReturnType<typeof getCompositionRoot>;

Expand All @@ -47,6 +53,7 @@ type Repositories = {
teamMemberRepository: TeamMemberRepository;
orgUnitRepository: OrgUnitRepository;
riskAssessmentRepository: RiskAssessmentRepository;
mapConfigRepository: MapConfigRepository;
performanceOverviewRepository: PerformanceOverviewRepository;
};

Expand All @@ -73,9 +80,14 @@ function getCompositionRoot(repositories: Repositories) {
getPerformanceOverviewMetrics: new GetAllPerformanceOverviewMetricsUseCase(
repositories
),
getTotalCardCounts: new GetTotalCardCountsUseCase(
repositories.performanceOverviewRepository
),
getTotalCardCounts: new GetTotalCardCountsUseCase(repositories),
},
maps: {
getConfig: new GetMapConfigUseCase(repositories.mapConfigRepository),
},
orgUnits: {
getAll: new GetAllOrgUnitsUseCase(repositories.orgUnitRepository),
getProvinces: new GetProvincesOrgUnits(repositories.orgUnitRepository),
},
};
}
Expand All @@ -91,6 +103,7 @@ export function getWebappCompositionRoot(api: D2Api) {
teamMemberRepository: new TeamMemberD2Repository(api),
orgUnitRepository: new OrgUnitD2Repository(api),
riskAssessmentRepository: new RiskAssessmentD2Repository(api),
mapConfigRepository: new MapConfigD2Repository(api),
performanceOverviewRepository: new PerformanceOverviewD2Repository(api, dataStoreClient),
};

Expand All @@ -107,6 +120,7 @@ export function getTestCompositionRoot() {
teamMemberRepository: new TeamMemberTestRepository(),
orgUnitRepository: new OrgUnitTestRepository(),
riskAssessmentRepository: new RiskAssessmentTestRepository(),
mapConfigRepository: new MapConfigTestRepository(),
performanceOverviewRepository: new PerformanceOverviewTestRepository(),
};

Expand Down
2 changes: 1 addition & 1 deletion src/data/DataStoreClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { D2Api, DataStore } from "@eyeseetea/d2-api/2.36";
import { apiToFuture, FutureData } from "./api-futures";

const dataStoreNamespace = "zebra";
export const dataStoreNamespace = "zebra";

export class DataStoreClient {
private dataStore: DataStore;
Expand Down
95 changes: 95 additions & 0 deletions src/data/repositories/MapConfigD2Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Future } from "../../domain/entities/generic/Future";
import {
MapKey,
MapConfig,
MapProgramIndicatorsDatastoreKey,
MAP_CURRENT_APP,
} from "../../domain/entities/MapConfig";
import { MapConfigRepository } from "../../domain/repositories/MapConfigRepository";
import { D2Api } from "../../types/d2-api";
import { FutureData } from "../api-futures";
import { DataStoreClient, dataStoreNamespace } from "../DataStoreClient";
import {
getProgramIndicatorsFromDatastore,
ProgramIndicatorsDatastore,
ProgramIndicatorsDatastoreKey,
} from "./common/getProgramIndicatorsFromDatastore";

const MAPS_CONFIG_KEY = "maps-config";

export class MapConfigD2Repository implements MapConfigRepository {
private dataStoreClient: DataStoreClient;

constructor(private api: D2Api) {
this.dataStoreClient = new DataStoreClient(api);
}

public get(mapKey: MapKey): FutureData<MapConfig> {
const programIndicatorsDatastoreKey =
mapKey === "dashboard"
? ProgramIndicatorsDatastoreKey.ActiveVerifiedAlerts
: ProgramIndicatorsDatastoreKey.CasesAlerts;
return this.dataStoreClient
.getObject<MapsConfigDatastore>(MAPS_CONFIG_KEY)
.flatMap(mapsConfigDatastore => {
if (!mapsConfigDatastore)
return Future.error(
new Error(
`Maps configuration not found in datastore: key ${MAPS_CONFIG_KEY}`
)
);

const mapConfigDataStore =
mapKey === "dashboard"
? mapsConfigDatastore?.dashboard
: mapsConfigDatastore?.event_tracker;
return getProgramIndicatorsFromDatastore(
this.dataStoreClient,
programIndicatorsDatastoreKey
).flatMap(programIndicatorsDatastore => {
if (!programIndicatorsDatastore)
return Future.error(
new Error(
`Program indicators needed for the map not found in datastore: key ${programIndicatorsDatastoreKey}`
)
);

return Future.success(
this.buildMapConfig(mapConfigDataStore, programIndicatorsDatastore)
);
});
});
}

private buildMapConfig(
mapConfigDatastore: MapConfigDatastore,
programIndicatorsDatastore: ProgramIndicatorsDatastore[]
): MapConfig {
return {
currentApp: MAP_CURRENT_APP,
currentPage: mapConfigDatastore.currentPage,
mapId: mapConfigDatastore.mapId,
programId: mapConfigDatastore.programId,
programName: mapConfigDatastore.programName,
startDate: mapConfigDatastore.startDate,
timeField: mapConfigDatastore.timeField,
programIndicators: programIndicatorsDatastore,
zebraNamespace: dataStoreNamespace,
dashboardDatastoreKey: MapProgramIndicatorsDatastoreKey.ActiveVerifiedAlerts,
};
}
}

type MapsConfigDatastore = {
dashboard: MapConfigDatastore;
event_tracker: MapConfigDatastore;
};

type MapConfigDatastore = {
currentPage: string;
mapId: string;
programId: string;
programName: string;
startDate: string;
timeField: string;
};
12 changes: 12 additions & 0 deletions src/data/repositories/OrgUnitD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export class OrgUnitD2Repository implements OrgUnitRepository {
});
}

getByLevel(level: number): FutureData<OrgUnit[]> {
return apiToFuture(
this.api.models.organisationUnits.get({
fields: d2OrgUnitFields,
paging: false,
level: level,
})
).map(response => {
return this.mapD2OrgUnitsToOrgUnits(response.objects);
});
}

private mapD2OrgUnitsToOrgUnits(d2OrgUnit: D2OrgUnit[]): OrgUnit[] {
return d2OrgUnit.map(
(ou): OrgUnit => ({
Expand Down
Loading

0 comments on commit 41973df

Please sign in to comment.