diff --git a/src/data/repositories/PerformanceOverviewD2Repository.ts b/src/data/repositories/PerformanceOverviewD2Repository.ts index 4f88ea4c..fc603952 100644 --- a/src/data/repositories/PerformanceOverviewD2Repository.ts +++ b/src/data/repositories/PerformanceOverviewD2Repository.ts @@ -606,39 +606,98 @@ export class PerformanceOverviewD2Repository implements PerformanceOverviewRepos .value(); } - getDashboard717Performance(): FutureData { - return this.datastore - .getObject(PERFORMANCE_717_PROGRAM_INDICATORS_DATASTORE_KEY) - .flatMap(nullable717PerformanceProgramIndicators => { - return assertOrError( - nullable717PerformanceProgramIndicators, - PERFORMANCE_717_PROGRAM_INDICATORS_DATASTORE_KEY - ).flatMap(performance717ProgramIndicators => { - const dashboard717PerformanceIndicator = performance717ProgramIndicators.filter( - indicator => indicator.key === "dashboard" + getNational717Performance(): FutureData { + return this.getAll717PerformanceIndicators().flatMap(performance717ProgramIndicators => { + const dashboard717PerformanceIndicator = performance717ProgramIndicators.filter( + indicator => indicator.key === "national" + ); + return apiToFuture( + this.api.analytics.get({ + dimension: [ + `dx:${dashboard717PerformanceIndicator.map(({ id }) => id).join(";")}`, + ], + startDate: DEFAULT_START_DATE, + endDate: DEFAULT_END_DATE, + includeMetadataDetails: true, + }) + ).map(res => { + return this.mapIndicatorsTo717PerformanceMetrics( + res.rows, + dashboard717PerformanceIndicator + ); + }); + }); + } + + getAlerts717Performance(): FutureData { + return this.getAll717PerformanceIndicators().flatMap(performance717ProgramIndicators => { + const dashboard717PerformanceIndicator = performance717ProgramIndicators.filter( + indicator => indicator.key === "alerts" + ); + + return apiToFuture( + this.api.analytics.get({ + dimension: [ + `dx:${dashboard717PerformanceIndicator.map(({ id }) => id).join(";")}`, + ], + startDate: DEFAULT_START_DATE, + endDate: DEFAULT_END_DATE, + includeMetadataDetails: true, + }) + ).map(res => { + return this.mapIndicatorsTo717PerformanceMetrics( + res.rows, + dashboard717PerformanceIndicator + ); + }); + }); + } + + getEvent717Performance(diseaseOutbreakEventId: Id): FutureData { + return this.getAll717PerformanceIndicators().flatMap(performance717ProgramIndicators => { + const eventTracker717PerformanceIndicator = performance717ProgramIndicators.filter( + indicator => indicator.key === "event" + ); + return apiToFuture( + this.api.analytics.getEnrollmentsQuery({ + programId: RTSL_ZEBRA_PROGRAM_ID, + dimension: [...eventTracker717PerformanceIndicator.map(({ id }) => id)], + startDate: DEFAULT_START_DATE, + endDate: DEFAULT_END_DATE, + }) + ).flatMap(response => { + const filteredRow = filterAnalyticsEnrollmentDataByDiseaseOutbreakEvent( + diseaseOutbreakEventId, + response.rows, + response.headers + ); + + if (!filteredRow) + return Future.error( + new Error("No data found for event tracker 7-1-7 performance") ); - return apiToFuture( - this.api.analytics.get({ - dimension: [ - `dx:${dashboard717PerformanceIndicator - .map(({ id }) => id) - .join(";")}`, - ], - startDate: DEFAULT_START_DATE, - endDate: DEFAULT_END_DATE, - includeMetadataDetails: true, - }) - ).map(res => { - return this.mapIndicatorsTo717PerformanceMetrics( - res.rows, - dashboard717PerformanceIndicator - ); - }); - }); + + const mappedIndicatorsToRows: string[][] = eventTracker717PerformanceIndicator.map( + ({ id }) => { + return [ + id, + filteredRow[response.headers.findIndex(header => header.name === id)] || + "", + ]; + } + ); + + return Future.success( + this.mapIndicatorsTo717PerformanceMetrics( + mappedIndicatorsToRows, + eventTracker717PerformanceIndicator + ) + ); }); + }); } - getEventTracker717Performance(diseaseOutbreakEventId: Id): FutureData { + private getAll717PerformanceIndicators(): FutureData { return this.datastore .getObject(PERFORMANCE_717_PROGRAM_INDICATORS_DATASTORE_KEY) .flatMap(nullable717PerformanceProgramIndicators => { @@ -646,46 +705,7 @@ export class PerformanceOverviewD2Repository implements PerformanceOverviewRepos nullable717PerformanceProgramIndicators, PERFORMANCE_717_PROGRAM_INDICATORS_DATASTORE_KEY ).flatMap(performance717ProgramIndicators => { - const eventTracker717PerformanceIndicator = - performance717ProgramIndicators.filter( - indicator => indicator.key === "event_tracker" - ); - return apiToFuture( - this.api.analytics.getEnrollmentsQuery({ - programId: RTSL_ZEBRA_PROGRAM_ID, - dimension: [...eventTracker717PerformanceIndicator.map(({ id }) => id)], - startDate: DEFAULT_START_DATE, - endDate: DEFAULT_END_DATE, - }) - ).flatMap(response => { - const filteredRow = filterAnalyticsEnrollmentDataByDiseaseOutbreakEvent( - diseaseOutbreakEventId, - response.rows, - response.headers - ); - - if (!filteredRow) - return Future.error( - new Error("No data found for event tracker 7-1-7 performance") - ); - - const mappedIndicatorsToRows: string[][] = - eventTracker717PerformanceIndicator.map(({ id }) => { - return [ - id, - filteredRow[ - response.headers.findIndex(header => header.name === id) - ] || "", - ]; - }); - - return Future.success( - this.mapIndicatorsTo717PerformanceMetrics( - mappedIndicatorsToRows, - eventTracker717PerformanceIndicator - ) - ); - }); + return Future.success(performance717ProgramIndicators); }); }); } diff --git a/src/data/repositories/test/PerformanceOverviewTestRepository.ts b/src/data/repositories/test/PerformanceOverviewTestRepository.ts index 311d911c..986c637c 100644 --- a/src/data/repositories/test/PerformanceOverviewTestRepository.ts +++ b/src/data/repositories/test/PerformanceOverviewTestRepository.ts @@ -6,9 +6,7 @@ import { PerformanceOverviewRepository } from "../../../domain/repositories/Perf import { FutureData } from "../../api-futures"; export class PerformanceOverviewTestRepository implements PerformanceOverviewRepository { - getEventTracker717Performance( - _diseaseOutbreakEventId: Id - ): FutureData { + getEvent717Performance(_diseaseOutbreakEventId: Id): FutureData { return Future.success([]); } getEventTrackerOverviewMetrics(): FutureData { @@ -17,7 +15,11 @@ export class PerformanceOverviewTestRepository implements PerformanceOverviewRep getTotalCardCounts(): FutureData { return Future.success(0); } - getDashboard717Performance(): FutureData { + getNational717Performance(): FutureData { + return Future.success(0); + } + + getAlerts717Performance(): FutureData { return Future.success(0); } diff --git a/src/domain/entities/disease-outbreak-event/PerformanceOverviewMetrics.ts b/src/domain/entities/disease-outbreak-event/PerformanceOverviewMetrics.ts index cbad5dfd..87b5c552 100644 --- a/src/domain/entities/disease-outbreak-event/PerformanceOverviewMetrics.ts +++ b/src/domain/entities/disease-outbreak-event/PerformanceOverviewMetrics.ts @@ -79,5 +79,5 @@ export type PerformanceMetrics717 = { name: string; type: "primary" | "secondary"; value?: number | "Inc"; - key: "dashboard" | "event_tracker"; + key: "national" | "event" | "alerts"; }; diff --git a/src/domain/repositories/PerformanceOverviewRepository.ts b/src/domain/repositories/PerformanceOverviewRepository.ts index 6704844a..8920bab6 100644 --- a/src/domain/repositories/PerformanceOverviewRepository.ts +++ b/src/domain/repositories/PerformanceOverviewRepository.ts @@ -21,8 +21,9 @@ export interface PerformanceOverviewRepository { multiSelectFilters?: Record, dateRangeFilter?: string[] ): FutureData; - getDashboard717Performance(): FutureData; - getEventTracker717Performance(diseaseOutbreakEventId: Id): FutureData; + getNational717Performance(): FutureData; + getEvent717Performance(diseaseOutbreakEventId: Id): FutureData; + getAlerts717Performance(): FutureData; getEventTrackerOverviewMetrics( type: string, casesDataSource: CasesDataSource diff --git a/src/domain/usecases/Get717PerformanceUseCase.ts b/src/domain/usecases/Get717PerformanceUseCase.ts index bdd78f59..40b0555f 100644 --- a/src/domain/usecases/Get717PerformanceUseCase.ts +++ b/src/domain/usecases/Get717PerformanceUseCase.ts @@ -11,15 +11,17 @@ export class Get717PerformanceUseCase { ) {} public execute( - type: "dashboard" | "event_tracker", + type: "national" | "event" | "alerts", diseaseOutbreakEventId: Id | undefined ): FutureData { - if (type === "event_tracker" && diseaseOutbreakEventId) { - return this.options.performanceOverviewRepository.getEventTracker717Performance( + if (type === "event" && diseaseOutbreakEventId) { + return this.options.performanceOverviewRepository.getEvent717Performance( diseaseOutbreakEventId ); - } else if (type === "dashboard") { - return this.options.performanceOverviewRepository.getDashboard717Performance(); + } else if (type === "national") { + return this.options.performanceOverviewRepository.getNational717Performance(); + } else if (type === "alerts") { + return this.options.performanceOverviewRepository.getAlerts717Performance(); } else throw new Error(`Unknown 717 type: ${type} `); } } diff --git a/src/webapp/pages/dashboard/DashboardPage.tsx b/src/webapp/pages/dashboard/DashboardPage.tsx index 93d95dfe..397ae4a4 100644 --- a/src/webapp/pages/dashboard/DashboardPage.tsx +++ b/src/webapp/pages/dashboard/DashboardPage.tsx @@ -40,7 +40,14 @@ export const DashboardPage: React.FC = React.memo(() => { isLoading: performanceOverviewLoading, } = usePerformanceOverview(); - const { performanceMetrics717, isLoading: _717CardsLoading } = use717Performance("dashboard"); + const { + performanceMetrics717: nationalPerformanceMetrics717, + isLoading: national717CardsLoading, + } = use717Performance("national"); + + const { performanceMetrics717: alertsPerformanceMetrics717, isLoading: alerts717CardsLoading } = + use717Performance("alerts"); + const { cardCounts, isLoading: cardCountsLoading } = useCardCounts( singleSelectFilters, multiSelectFilters, @@ -55,7 +62,7 @@ export const DashboardPage: React.FC = React.memo(() => { resetCurrentEventTrackerId(); }, [resetCurrentEventTrackerId]); - return performanceOverviewLoading || _717CardsLoading ? ( + return performanceOverviewLoading || national717CardsLoading || alerts717CardsLoading ? ( ) : ( { dateRangeFilter={dateRangeFilter.value} /> +
+ + {alertsPerformanceMetrics717.map( + (perfMetric717: PerformanceMetric717, index: number) => ( + + ) + )} + +
- {performanceMetrics717.map( + {nationalPerformanceMetrics717.map( (perfMetric717: PerformanceMetric717, index: number) => ( { - if (type === "dashboard") { + (key: string, value: number | "Inc", type: "national" | "event" | "alerts"): CardColors => { + if (type === "national") { switch (key) { case "allTargets": return "grey"; diff --git a/src/webapp/pages/event-tracker/EventTrackerPage.tsx b/src/webapp/pages/event-tracker/EventTrackerPage.tsx index 5901bda0..b2aa8740 100644 --- a/src/webapp/pages/event-tracker/EventTrackerPage.tsx +++ b/src/webapp/pages/event-tracker/EventTrackerPage.tsx @@ -74,10 +74,7 @@ export const EventTrackerPage: React.FC = React.memo(() => { }); }, [goTo]); - const { performanceMetrics717, isLoading: _717CardsLoading } = use717Performance( - "event_tracker", - id - ); + const { performanceMetrics717, isLoading: _717CardsLoading } = use717Performance("event", id); useEffect(() => { if (eventTrackerDetails) {