Skip to content

Commit

Permalink
Merge branch 'development' of github.com:EyeSeeTea/d2-reports into de…
Browse files Browse the repository at this point in the history
…velopment
  • Loading branch information
ifoche committed Feb 22, 2024
2 parents 9dd6959 + 3531b05 commit 454f911
Showing 1 changed file with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ interface MessageConversations {
}[];
}

type TrackedEntityInstance = {
attributes: {
value: string;
}[];
orgUnit: string;
};

type DataValueType = {
dataElement: string;
period: string;
Expand Down Expand Up @@ -228,13 +235,7 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission
orgUnit: string,
modules: GLASSDataSubmissionModule[]
): Promise<GLASSDataSubmissionItemIdentifier[]> {
const { instances } = await this.api
.get<{ instances: { attributes: { value: string }[]; orgUnit: string }[] }>("/tracker/trackedEntities", {
program: program,
orgUnit: orgUnit,
fields: "attributes[value],orgUnit",
})
.getData();
const instances = await this.getTrackedEntityInstances(program, orgUnit);

const dataSubmissionPeriods = getDataSubmissionPeriods();
const orgUnitModules: { orgUnit: string; module: string }[] = _(instances)
Expand All @@ -258,6 +259,34 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission
});
}

private async getTrackedEntityInstances(program: string, orgUnit: string): Promise<TrackedEntityInstance[]> {
let instances: TrackedEntityInstance[] = [];
let currentPage = 1;
let totalPages = 1;
const pageSize = 200;

while (currentPage <= totalPages) {
const response = await this.api
.get<{ instances: TrackedEntityInstance[] }>("/tracker/trackedEntities", {
program: program,
orgUnit: orgUnit,
fields: "attributes[value],orgUnit",
pageSize: pageSize,
page: currentPage,
})
.getData();

instances = instances.concat(response.instances);

if (response.instances.length === pageSize) {
totalPages++;
}
currentPage++;
}

return instances;
}

private async getCountriesOutsideNARegion(): Promise<string[]> {
const { organisationUnits: kosovoOu } = await this.api.metadata
.get({
Expand Down Expand Up @@ -1034,7 +1063,7 @@ const emptyPage: PaginatedObjects<GLASSDataSubmissionItem> = {
const moduleMapping: Record<string, string> = {
AMC: "AMC",
AMR: "AMR",
AMR_FUNGAL: "AMR - Fungal",
AMR_FUNGHI: "AMR - Fungal",
AMR_INDIVIDUAL: "AMR - Individual",
EAR: "EAR",
EGASP: "EGASP",
Expand Down

0 comments on commit 454f911

Please sign in to comment.