Skip to content

Commit

Permalink
fix: Card should be displayed for incident status all
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Oct 30, 2024
1 parent 75cc212 commit b348cfc
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 148 deletions.
126 changes: 86 additions & 40 deletions src/data/repositories/PerformanceOverviewD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { RTSL_ZEBRA_PROGRAM_ID } from "./consts/DiseaseOutbreakConstants";
import _ from "../../domain/entities/generic/Collection";
import { Future } from "../../domain/entities/generic/Future";
import {
eventTrackerCountsIndicatorMap,
PERFORMANCE_METRICS_717_IDS,
IndicatorsId,
EVENT_TRACKER_717_IDS,
EventTrackerCountIndicator,
} from "./consts/PerformanceOverviewConstants";
import moment from "moment";
import {
Expand All @@ -23,11 +23,17 @@ import {
PerformanceOverviewMetrics,
DiseaseNames,
PerformanceMetrics717,
IncidentStatus,
} from "../../domain/entities/disease-outbreak-event/PerformanceOverviewMetrics";
import { OrgUnit } from "../../domain/entities/OrgUnit";
import { Id } from "../../domain/entities/Ref";
import { OverviewCard } from "../../domain/entities/PerformanceOverview";
import { assertOrError } from "./utils/AssertOrError";
import {
getProgramIndicatorsFromDatastore,
ProgramIndicatorsDatastore,
ProgramIndicatorsDatastoreKey,
} from "./common/getProgramIndicatorsFromDatastore";

const formatDate = (date: Date): string => {
const year = date.getFullYear();
Expand Down Expand Up @@ -62,50 +68,90 @@ export class PerformanceOverviewD2Repository implements PerformanceOverviewRepos
multiSelectFilters?: Record<string, string[]>,
dateRangeFilter?: string[]
): FutureData<TotalCardCounts[]> {
return apiToFuture(
this.api.analytics.get({
dimension: [
`dx:${eventTrackerCountsIndicatorMap.map(({ id }) => id).join(";")}`,
`ou:${
multiSelectFilters && multiSelectFilters?.province?.length
? multiSelectFilters.province.join(";")
: allProvincesIds.join(";")
}`,
],
startDate:
dateRangeFilter?.length && dateRangeFilter[0]
? dateRangeFilter[0]
: DEFAULT_START_DATE,
endDate:
dateRangeFilter?.length && dateRangeFilter[1]
? dateRangeFilter[1]
: DEFAULT_END_DATE,
includeMetadataDetails: true,
})
).map(analyticsResponse => {
const totalCardCounts =
this.mapAnalyticsRowsToTotalCardCounts(
analyticsResponse.rows,
singleSelectFilters
) || [];

const uniqueTotalCardCounts = totalCardCounts.reduce((acc, totalCardCount) => {
const existingEntry = acc[totalCardCount.name];

if (existingEntry) {
existingEntry.total += totalCardCount.total;
acc[totalCardCount.name] = existingEntry;
} else {
acc[totalCardCount.name] = totalCardCount;
}
return acc;
}, {} as Record<string, TotalCardCounts>);
return getProgramIndicatorsFromDatastore(
this.datastore,
ProgramIndicatorsDatastoreKey.ActiveVerifiedAlerts
).flatMap(activeVerifiedAlerts => {
const eventTrackerCountsIndicatorMap =
this.mapActiveVerfiedAlertsToEventTrackerCountIndicator(activeVerifiedAlerts);
return apiToFuture(
this.api.analytics.get({
dimension: [
`dx:${eventTrackerCountsIndicatorMap.map(({ id }) => id).join(";")}`,
`ou:${
multiSelectFilters && multiSelectFilters?.province?.length
? multiSelectFilters.province.join(";")
: allProvincesIds.join(";")
}`,
],
startDate:
dateRangeFilter?.length && dateRangeFilter[0]
? dateRangeFilter[0]
: DEFAULT_START_DATE,
endDate:
dateRangeFilter?.length && dateRangeFilter[1]
? dateRangeFilter[1]
: DEFAULT_END_DATE,
includeMetadataDetails: true,
})
).map(analyticsResponse => {
const totalCardCounts =
this.mapAnalyticsRowsToTotalCardCounts(
eventTrackerCountsIndicatorMap,
analyticsResponse.rows,
singleSelectFilters
) || [];

const uniqueTotalCardCounts = totalCardCounts.reduce((acc, totalCardCount) => {
const existingEntry = acc[totalCardCount.name];

if (existingEntry) {
existingEntry.total += totalCardCount.total;
acc[totalCardCount.name] = existingEntry;
} else {
acc[totalCardCount.name] = totalCardCount;
}
return acc;
}, {} as Record<string, TotalCardCounts>);

return Object.values(uniqueTotalCardCounts);
return Object.values(uniqueTotalCardCounts);
});
});
}

mapActiveVerfiedAlertsToEventTrackerCountIndicator(
activeVerifiedAlerts: Maybe<ProgramIndicatorsDatastore[]>
): EventTrackerCountIndicator[] {
if (!activeVerifiedAlerts) return [];
return _(
activeVerifiedAlerts.map(activeVerified => {
if (activeVerified.disease === "ALL") return;

if (activeVerified.disease) {
const eventTrackerCount: EventTrackerCountIndicator = {
id: activeVerified.id,
type: "disease",
name: activeVerified.disease as DiseaseNames,
incidentStatus: activeVerified.incidentStatus as IncidentStatus,
};
return eventTrackerCount;
} else {
const eventTrackerCount: EventTrackerCountIndicator = {
id: activeVerified.id,
type: "hazard",
name: activeVerified.hazardType as HazardNames,
incidentStatus: activeVerified.incidentStatus as IncidentStatus,
};
return eventTrackerCount;
}
})
)
.compact()
.value();
}

mapAnalyticsRowsToTotalCardCounts = (
eventTrackerCountsIndicatorMap: EventTrackerCountIndicator[],
rowData: string[][],
filters?: Record<string, string>
): TotalCardCounts[] => {
Expand Down
75 changes: 0 additions & 75 deletions src/data/repositories/consts/PerformanceOverviewConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,81 +47,6 @@ export type EventTrackerCountIndicator =
| EventTrackerCountDiseaseIndicator
| EventTrackerCountHazardIndicator;

export const eventTrackerCountsIndicatorMap: EventTrackerCountIndicator[] = [
{ id: "SGGbbu0AKUv", type: "disease", name: "Acute respiratory", incidentStatus: "Watch" },
{ id: "QnhsQnEsp1p", type: "disease", name: "Acute respiratory", incidentStatus: "Alert" },
{ id: "Rt5KNVqBEO7", type: "disease", name: "Acute respiratory", incidentStatus: "Respond" },
{ id: "bcI9Rmx2ycH", type: "disease", name: "Acute VHF", incidentStatus: "Watch" },
{ id: "u4XTtjm9nEh", type: "disease", name: "Acute VHF", incidentStatus: "Alert" },
{ id: "gpKelVBHhRZ", type: "disease", name: "Acute VHF", incidentStatus: "Respond" },
{ id: "pqob28cwd3i", type: "disease", name: "AFP", incidentStatus: "Watch" },
{ id: "PHhaZK4KeOA", type: "disease", name: "AFP", incidentStatus: "Alert" },
{ id: "SyemUCen8zf", type: "disease", name: "AFP", incidentStatus: "Respond" },
{ id: "YPPhLHgwiKV", type: "disease", name: "Anthrax", incidentStatus: "Watch" },
{ id: "FhdaufdE8l3", type: "disease", name: "Anthrax", incidentStatus: "Alert" },
{ id: "vuhm2b5D076", type: "disease", name: "Anthrax", incidentStatus: "Respond" },
{ id: "qeQSDdPTeVq", type: "disease", name: "Bacterial meningitis", incidentStatus: "Watch" },
{ id: "WXlyJHUKI8T", type: "disease", name: "Bacterial meningitis", incidentStatus: "Alert" },
{ id: "DCwOujun1ED", type: "disease", name: "Bacterial meningitis", incidentStatus: "Respond" },
{ id: "zNctWJj7Ncl", type: "disease", name: "Cholera", incidentStatus: "Watch" },
{ id: "U31oe2BwJtt", type: "disease", name: "Cholera", incidentStatus: "Alert" },
{ id: "WCrE9mP80q4", type: "disease", name: "Cholera", incidentStatus: "Respond" },
{ id: "m2LBISybVDA", type: "disease", name: "COVID19", incidentStatus: "Watch" },
{ id: "sY5lGlHpcuN", type: "disease", name: "COVID19", incidentStatus: "Alert" },
{ id: "LQ128PeTF8x", type: "disease", name: "COVID19", incidentStatus: "Respond" },
{ id: "oKSsu6q3MJW", type: "disease", name: "Diarrhoea with blood", incidentStatus: "Watch" },
{ id: "EgGc7XxZjmC", type: "disease", name: "Diarrhoea with blood", incidentStatus: "Alert" },
{ id: "uAMXUxp3XBa", type: "disease", name: "Diarrhoea with blood", incidentStatus: "Respond" },
{ id: "yesuR8ho9vY", type: "disease", name: "Measles", incidentStatus: "Watch" },
{ id: "OvxA9yqaH7q", type: "disease", name: "Measles", incidentStatus: "Alert" },
{ id: "q9HlUfaQj3p", type: "disease", name: "Measles", incidentStatus: "Respond" },
{ id: "mw7Qxti6Fk5", type: "disease", name: "Monkeypox", incidentStatus: "Watch" },
{ id: "kMsSxdZMqJV", type: "disease", name: "Monkeypox", incidentStatus: "Alert" },
{ id: "qL6WGfcoh1l", type: "disease", name: "Monkeypox", incidentStatus: "Respond" },
{ id: "eo2RAoIRYiV", type: "disease", name: "Neonatal tetanus", incidentStatus: "Watch" },
{ id: "EuIc8gJYAhP", type: "disease", name: "Neonatal tetanus", incidentStatus: "Alert" },
{ id: "H7Fmb58GUF9", type: "disease", name: "Neonatal tetanus", incidentStatus: "Respond" },
{ id: "IYktWOGBTtj", type: "disease", name: "Plague", incidentStatus: "Watch" },
{ id: "qdLWFsb7Ghk", type: "disease", name: "Plague", incidentStatus: "Alert" },
{ id: "nbG4Lnl1JUz", type: "disease", name: "Plague", incidentStatus: "Respond" },
{ id: "fEdwx7X6BLI", type: "disease", name: "SARIs", incidentStatus: "Watch" },
{ id: "FSstKrL8oys", type: "disease", name: "SARIs", incidentStatus: "Alert" },
{ id: "SkkAznpVZzr", type: "disease", name: "SARIs", incidentStatus: "Respond" },
{ id: "JcfEcfD64Gy", type: "disease", name: "Typhoid fever", incidentStatus: "Watch" },
{ id: "wfsBvSq7Hn1", type: "disease", name: "Typhoid fever", incidentStatus: "Alert" },
{ id: "FMKLwKkOUzx", type: "disease", name: "Typhoid fever", incidentStatus: "Respond" },
{ id: "XieBgoffFRd", type: "disease", name: "Zika fever", incidentStatus: "Watch" },
{ id: "tIYANWCiMoR", type: "disease", name: "Zika fever", incidentStatus: "Alert" },
{ id: "qJjRR8EwYgB", type: "disease", name: "Zika fever", incidentStatus: "Respond" },
{ id: "gMoRiHe1Z0Z", type: "hazard", name: "Biological: Animal", incidentStatus: "Watch" },
{ id: "tKLdMcWUg9l", type: "hazard", name: "Biological: Animal", incidentStatus: "Alert" },
{ id: "TJhGnX8E7CP", type: "hazard", name: "Biological: Animal", incidentStatus: "Respond" },
{ id: "YfkOUZPhCY1", type: "hazard", name: "Biological: Human", incidentStatus: "Watch" },
{ id: "NzpH7Y76JBw", type: "hazard", name: "Biological: Human", incidentStatus: "Alert" },
{ id: "jWDbWYr85DP", type: "hazard", name: "Biological: Human", incidentStatus: "Respond" },
{
id: "kLtsjiyIzer",
type: "hazard",
name: "Biological: Human and Animal",
incidentStatus: "Watch",
},
{
id: "ge4Jwq2MGrF",
type: "hazard",
name: "Biological: Human and Animal",
incidentStatus: "Alert",
},
{
id: "GQ6Yg9ZN4xL",
type: "hazard",
name: "Biological: Human and Animal",
incidentStatus: "Respond",
},
{ id: "Bu4bafAjFXN", type: "hazard", name: "Environmental", incidentStatus: "Watch" },
{ id: "z3EbI98pgjG", type: "hazard", name: "Environmental", incidentStatus: "Alert" },
{ id: "gRcZNqpKyYg", type: "hazard", name: "Environmental", incidentStatus: "Respond" },
];

export const PERFORMANCE_METRICS_717_IDS: PerformanceMetrics717[] = [
{ id: "MFk8jiMSlfC", name: "detection", type: "primary" }, // % of number of alerts that were detected within 7 days of date of emergence
{ id: "jD8CfKvvdXt", name: "detection", type: "secondary" }, // Number of alerts notified to public health authorities within 1 day of detection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { Id } from "../Ref";

export type DiseaseNames =
| "AFP"
| "Acute VHF"
| "Acute respiratory"
| "Anthrax"
| "Bacterial meningitis"
| "COVID19"
| "Cholera"
| "Diarrhoea with blood"
| "Measles"
| "Monkeypox"
| "Neonatal tetanus"
| "Plague"
| "SARIs"
| "Typhoid fever"
| "Zika fever";
export const diseaseNames = [
"AFP",
"Acute VHF",
"Acute respiratory",
"Anthrax",
"Bacterial meningitis",
"COVID19",
"Cholera",
"Diarrhoea with blood",
"Measles",
"Monkeypox",
"Neonatal tetanus",
"Plague",
"SARIs",
"Typhoid fever",
"Zika fever",
] as const;
export type DiseaseNames = (typeof diseaseNames)[number];

export type HazardNames =
| "Biological: Animal"
| "Biological: Human"
| "Biological: Human and Animal"
| "Environmental";
export const hazardNames = [
"Biological: Animal",
"Biological: Human",
"Biological: Human and Animal",
"Environmental",
// "Chemical",
// "Unknown",
] as const;

export type HazardNames = (typeof hazardNames)[number];

export type PerformanceOverviewMetrics = {
id: Id;
Expand All @@ -46,7 +53,7 @@ export type PerformanceOverviewMetrics = {
nationalIncidentStatus: string;
};

export type IncidentStatus = "Watch" | "Alert" | "Respond";
export type IncidentStatus = "Watch" | "Alert" | "Respond" | "All";

type BaseCounts = {
name: DiseaseNames | HazardNames;
Expand Down
28 changes: 17 additions & 11 deletions src/webapp/pages/dashboard/useAlertsActiveVerifiedFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import _c from "../../../domain/entities/generic/Collection";
import { useAppContext } from "../../contexts/app-context";
import { OrgUnit } from "../../../domain/entities/OrgUnit";
import { Option } from "../../components/utils/option";
import { eventTrackerCountsIndicatorMap } from "../../../data/repositories/consts/PerformanceOverviewConstants";
import {
diseaseNames,
hazardNames,
} from "../../../domain/entities/disease-outbreak-event/PerformanceOverviewMetrics";

export type SelectorFiltersConfig = {
id: string;
Expand Down Expand Up @@ -76,16 +79,19 @@ export function useAlertsActiveVerifiedFilters(): State {
// Initialize filter options based on eventTrackerCountsIndicatorMap
useEffect(() => {
const buildSelectorFiltersConfig = (): SelectorFiltersConfig[] => {
const createOptions = (key: "disease" | "hazard") =>
_c(eventTrackerCountsIndicatorMap)
.filter(value => value.type === key)
.uniqBy(value => value.name)
.map(value => ({
value: value.name,
label: value.name,
}))

.value();
const createOptions = (key: "disease" | "hazard") => {
if (key === "disease") {
return diseaseNames.map(diseaseName => ({
value: diseaseName,
label: diseaseName,
}));
} else {
return hazardNames.map(hazardName => ({
value: hazardName,
label: hazardName,
}));
}
};

const diseaseOptions = createOptions("disease");
const hazardOptions = createOptions("hazard");
Expand Down

0 comments on commit b348cfc

Please sign in to comment.