Skip to content

Commit

Permalink
Add child count to all surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbgomes committed May 2, 2024
1 parent 53e0aa9 commit 9b14285
Show file tree
Hide file tree
Showing 16 changed files with 422 additions and 212 deletions.
43 changes: 29 additions & 14 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,58 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-04-01T18:30:50.736Z\n"
"PO-Revision-Date: 2024-04-01T18:30:50.736Z\n"
"POT-Creation-Date: 2024-04-30T16:29:46.275Z\n"
"PO-Revision-Date: 2024-04-30T16:29:46.275Z\n"

msgid "WHO privacy policy"
msgid "Facilities"
msgstr ""

msgid "HOME"
msgid "Sample Shipment"
msgstr ""

msgid "Log Out"
msgid "Central Ref Lab Results"
msgstr ""

msgid "Stage - Profile"
msgid "Pathogen Isolates Logs"
msgstr ""

msgid "Cancel"
msgid "Supranational Ref Results"
msgstr ""

msgid "Save"
msgid "Countries"
msgstr ""

msgid "PPS Surveys"
msgid "Hospitals"
msgstr ""

msgid "New Survey"
msgid "Wards"
msgstr ""

msgid "Countries"
msgid "Patients"
msgstr ""

msgid "Hospitals"
msgid "WHO privacy policy"
msgstr ""

msgid "Wards"
msgid "HOME"
msgstr ""

msgid "Patients"
msgid "Log Out"
msgstr ""

msgid "Stage - Profile"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Save"
msgstr ""

msgid "PPS Surveys"
msgstr ""

msgid "New Survey"
msgstr ""

msgid "Submission Success!"
Expand Down
41 changes: 28 additions & 13 deletions i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-04-01T18:30:50.736Z\n"
"POT-Creation-Date: 2024-04-30T16:29:46.275Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"

msgid "WHO privacy policy"
msgid "Facilities"
msgstr ""

msgid "HOME"
msgid "Sample Shipment"
msgstr ""

msgid "Log Out"
msgid "Central Ref Lab Results"
msgstr ""

msgid "Stage - Profile"
msgid "Pathogen Isolates Logs"
msgstr ""

msgid "Cancel"
msgid "Supranational Ref Results"
msgstr ""

msgid "Save"
msgid "Countries"
msgstr ""

msgid "PPS Surveys"
msgid "Hospitals"
msgstr ""

msgid "New Survey"
msgid "Wards"
msgstr ""

msgid "Countries"
msgid "Patients"
msgstr ""

msgid "Hospitals"
msgid "WHO privacy policy"
msgstr ""

msgid "Wards"
msgid "HOME"
msgstr ""

msgid "Patients"
msgid "Log Out"
msgstr ""

msgid "Stage - Profile"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Save"
msgstr ""

msgid "PPS Surveys"
msgstr ""

msgid "New Survey"
msgstr ""

msgid "Submission Success!"
Expand Down
19 changes: 19 additions & 0 deletions src/data/repositories/PaginatedSurveyD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
} from "../entities/D2Survey";
import { TrackerEventsResponse } from "@eyeseetea/d2-api/api/trackerEvents";
import { mapEventToSurvey, mapTrackedEntityToSurvey } from "../utils/surveyListMappers";
import { getSurveyChildCount } from "../utils/surveyCountHelper";
import { ProgramCountMap } from "../../domain/entities/Program";

export class PaginatedSurveyD2Repository implements PaginatedSurveyRepository {
constructor(private api: D2Api) {}
Expand Down Expand Up @@ -154,4 +156,21 @@ export class PaginatedSurveyD2Repository implements PaginatedSurveyRepository {
return Future.success(paginatedSurveys);
});
}

getSurveyChildCount(
parentProgram: Id,
orgUnitId: Id,
parentSurveyId: Id,
secondaryparentId: Id | undefined
):
| { type: "value"; value: FutureData<number> }
| { type: "map"; value: FutureData<ProgramCountMap> } {
return getSurveyChildCount(
parentProgram,
orgUnitId,
parentSurveyId,
secondaryparentId,
this.api
);
}
}
121 changes: 8 additions & 113 deletions src/data/repositories/SurveyFormD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
TrackedEntitiesGetResponse,
} from "@eyeseetea/d2-api/api/trackerTrackedEntities";
import {
getChildProgramId,
getParentDataElementForProgram,
getSurveyType,
getTrackedEntityAttributeType,
isTrackerProgram,
Expand All @@ -26,7 +24,6 @@ import {
PPS_PATIENT_REGISTER_ID,
SURVEY_NAME_DATAELEMENT_ID,
PREVALENCE_SURVEY_NAME_DATAELEMENT_ID,
PPS_COUNTRY_QUESTIONNAIRE_ID,
} from "../entities/D2Survey";
import { ProgramDataElement, ProgramMetadata } from "../entities/D2Program";
import {
Expand All @@ -36,6 +33,7 @@ import {
} from "../utils/surveyFormMappers";
import { mapEventToSurvey, mapTrackedEntityToSurvey } from "../utils/surveyListMappers";
import { Questionnaire } from "../../domain/entities/Questionnaire/Questionnaire";
import { getSurveyChildCount } from "../utils/surveyCountHelper";

export class SurveyD2Repository implements SurveyRepository {
constructor(private api: D2Api) {}
Expand Down Expand Up @@ -316,116 +314,13 @@ export class SurveyD2Repository implements SurveyRepository {
):
| { type: "value"; value: FutureData<number> }
| { type: "map"; value: FutureData<ProgramCountMap> } {
const childIds = getChildProgramId(parentProgram);

//As of now, all child programs for a given program are of the same type,
//so we will check only the first child

const childId = childIds.type === "singleChild" ? childIds.value : childIds.value[0];

if (childId) {
const isTracker = isTrackerProgram(childId);

if (isTracker) {
if (childIds.type === "singleChild") {
const eventCount = this.getTrackerSurveyCount(
childId,
orgUnitId,
parentSurveyId
);

return { type: "value", value: eventCount };
} else {
const eventCounts = childIds.value.map(id => {
return this.getTrackerSurveyCount(id, orgUnitId, parentSurveyId).map(
count => {
return { id: id, count: count };
}
);
});

return { type: "map", value: Future.sequential(eventCounts) };
}
} else {
if (childIds.type === "singleChild") {
const eventCount = this.getEventSurveyCount(
childIds.value,
orgUnitId,
parentSurveyId,
secondaryparentId
);

return { type: "value", value: eventCount };
} else {
return {
type: "map",
value: Future.error(
new Error(
"Event programs in AMR Surveys have single child. It should not contain multiple children"
)
),
};
}
}
} else {
return {
type: "value",
value: Future.error(new Error("Unknown Child program ")),
};
}
}

private getEventSurveyCount(
programId: Id,
orgUnitId: Id,
parentSurveyId: Id,
secondaryParentId: Id | undefined
): FutureData<number> {
const ouId = programId === PPS_COUNTRY_QUESTIONNAIRE_ID ? "" : orgUnitId;
const ouMode = programId === PPS_HOSPITAL_FORM_ID ? "DESCENDANTS" : undefined;
const filterParentDEId = getParentDataElementForProgram(programId);

const filterStr =
secondaryParentId === ""
? `${filterParentDEId}:eq:${parentSurveyId}`
: `${filterParentDEId}:eq:${secondaryParentId} `;

return apiToFuture(
this.api.tracker.events.get({
fields: { event: true },
program: programId,
orgUnit: ouId,
ouMode: ouMode,
filter: filterStr,
})
).flatMap(response => {
return Future.success(response.instances.length);
});
}

private getTrackerSurveyCount(
programId: Id,
orgUnitId: Id,
parentSurveyId: Id
): FutureData<number> {
const filterParentDEId = getParentDataElementForProgram(programId);

const ouMode =
orgUnitId !== "" && programId === PREVALENCE_FACILITY_LEVEL_FORM_ID
? "DESCENDANTS"
: undefined;

return apiToFuture(
this.api.tracker.trackedEntities.get({
fields: { trackedEntity: true },
program: programId,
orgUnit: orgUnitId,
ouMode: ouMode,
filter: `${filterParentDEId}:eq:${parentSurveyId}`,
})
).flatMap((trackedEntities: TrackedEntitiesGetResponse) => {
return Future.success(trackedEntities.instances.length);
});
return getSurveyChildCount(
parentProgram,
orgUnitId,
parentSurveyId,
secondaryparentId,
this.api
);
}

deleteSurvey(id: Id, orgUnitId: Id, programId: Id): FutureData<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ProgramCountMap } from "../../../domain/entities/Program";
import { SURVEY_FORM_TYPES, Survey } from "../../../domain/entities/Survey";
import { PaginatedReponse } from "../../../domain/entities/TablePagination";
import { PaginatedSurveyRepository } from "../../../domain/repositories/PaginatedSurveyRepository";
Expand All @@ -21,4 +22,14 @@ export class PaginatedSurveyTestRepository implements PaginatedSurveyRepository
): FutureData<PaginatedReponse<Survey[]>> {
throw new Error("Method not implemented.");
}
getSurveyChildCount(
parentProgram: string,
orgUnitId: string,
parentSurveyId: string,
secondaryparentId: string | undefined
):
| { type: "value"; value: FutureData<number> }
| { type: "map"; value: FutureData<ProgramCountMap> } {
throw new Error("Method not implemented.");
}
}
Loading

0 comments on commit 9b14285

Please sign in to comment.