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: 717 performance section #21

Open
wants to merge 5 commits into
base: feature/add-event-tracker-map-with-merge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "7-1-7 performance"
msgstr ""

msgid "events"
msgstr ""

msgid "Performance overview"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-09-12T14:10:04.460Z\n"
"POT-Creation-Date: 2024-09-16T13:53:55.684Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
2 changes: 2 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { GetAllDiseaseOutbreaksUseCase } from "./domain/usecases/GetAllDiseaseOu
import { MapDiseaseOutbreakToAlertsUseCase } from "./domain/usecases/MapDiseaseOutbreakToAlertsUseCase";
import { AlertRepository } from "./domain/repositories/AlertRepository";
import { AlertTestRepository } from "./data/repositories/test/AlertTestRepository";
import { Get717PerformanceUseCase } from "./domain/usecases/Get717PerformanceUseCase";
import { GetEntityWithOptionsUseCase } from "./domain/usecases/GetEntityWithOptionsUseCase";
import { SaveEntityUseCase } from "./domain/usecases/SaveEntityUseCase";
import { RiskAssessmentRepository } from "./domain/repositories/RiskAssessmentRepository";
Expand Down Expand Up @@ -81,6 +82,7 @@ function getCompositionRoot(repositories: Repositories) {
repositories
),
getTotalCardCounts: new GetTotalCardCountsUseCase(repositories),
get717Performance: new Get717PerformanceUseCase(repositories),
},
maps: {
getConfig: new GetMapConfigUseCase(repositories.mapConfigRepository),
Expand Down
53 changes: 52 additions & 1 deletion src/data/repositories/PerformanceOverviewD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { apiToFuture, FutureData } from "../api-futures";
import { RTSL_ZEBRA_PROGRAM_ID } from "./consts/DiseaseOutbreakConstants";
import _ from "../../domain/entities/generic/Collection";
import { Future } from "../../domain/entities/generic/Future";
import { evenTrackerCountsIndicatorMap, IndicatorsId } from "./consts/PerformanceOverviewConstants";
import {
evenTrackerCountsIndicatorMap,
INDICATORS_717_PERFORMANCE,
IndicatorsId,
} from "./consts/PerformanceOverviewConstants";
import moment from "moment";
import {
DiseaseOutbreakEventBaseAttrs,
Expand All @@ -21,6 +25,13 @@ import {
import { AlertSynchronizationData } from "../../domain/entities/alert/AlertData";
import { OrgUnit } from "../../domain/entities/OrgUnit";

export type Indicator717PerformanceBaseAttrs = {
id: string;
name: string;
type: "count" | "percent";
value: number;
};

const formatDate = (date: Date): string => {
const year = date.getFullYear();
const month = ("0" + (date.getMonth() + 1)).slice(-2);
Expand Down Expand Up @@ -204,6 +215,46 @@ export class PerformanceOverviewD2Repository implements PerformanceOverviewRepos
});
}

get717Performance(): FutureData<Indicator717PerformanceBaseAttrs[]> {
const transformData = (
data: string[][],
indicators717Performance: typeof INDICATORS_717_PERFORMANCE
): Indicator717PerformanceBaseAttrs[] => {
return data.flatMap(([id, , value]) => {
const indicator = indicators717Performance.find(d => d.id === id);
if (!indicator || !value) {
return [];
}

// Ensure the type is either 'count' or 'percent'
const type: "count" | "percent" =
indicator.type === "count" || indicator.type === "percent"
? indicator.type
: "count"; // Default to 'count' if type is not valid

return [
{
...indicator,
value: parseFloat(value),
type, // Set the valid type here with narrowed types
},
];
});
};

return apiToFuture(
this.api.analytics.get({
dimension: [
`dx:${INDICATORS_717_PERFORMANCE.map(({ id }) => id).join(";")}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future we can get these Program Indicators from DataStore like Maps.

"pe:THIS_YEAR",
Copy link
Contributor

Choose a reason for hiding this comment

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

Period dimension has to be this year?

],
includeMetadataDetails: true,
})
).map(res => {
return transformData(res.rows, INDICATORS_717_PERFORMANCE) || [];
});
}

private getCasesAndDeathsFromDatastore(
key: string | undefined
): FutureData<{ cases: number; deaths: number }> {
Expand Down
Loading
Loading