From 76431b2025931c5daff1f195e9e835b030e8a06b Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Wed, 21 Feb 2024 20:06:53 +0100 Subject: [PATCH 1/3] feat: get all TEIs iteratively --- .../GLASSDataSubmissionDefaultRepository.ts | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts index f82b2b7d..6d7054e1 100644 --- a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts +++ b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts @@ -56,6 +56,13 @@ interface MessageConversations { }[]; } +interface TrackedEntityInstance { + attributes: { + value: string; + }[]; + orgUnit: string; +} + type DataValueType = { dataElement: string; period: string; @@ -228,13 +235,7 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission orgUnit: string, modules: GLASSDataSubmissionModule[] ): Promise { - 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) @@ -258,6 +259,34 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission }); } + private async getTrackedEntityInstances(program: string, orgUnit: string): Promise { + let instances: TrackedEntityInstance[] = []; + let currentPage = 1; + let totalPages = 1; + const pageSize = 50; + + 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 { const { organisationUnits: kosovoOu } = await this.api.metadata .get({ @@ -1034,7 +1063,7 @@ const emptyPage: PaginatedObjects = { const moduleMapping: Record = { AMC: "AMC", AMR: "AMR", - AMR_FUNGAL: "AMR - Fungal", + AMR_FUNGHI: "AMR - Fungal", AMR_INDIVIDUAL: "AMR - Individual", EAR: "EAR", EGASP: "EGASP", From 5ca5952c0e4f1f48708bec5b31d9e6207b590d84 Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Thu, 22 Feb 2024 08:17:31 +0100 Subject: [PATCH 2/3] refactor: change TEI interface to type --- .../GLASSDataSubmissionDefaultRepository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts index 6d7054e1..bab558fb 100644 --- a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts +++ b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts @@ -56,12 +56,12 @@ interface MessageConversations { }[]; } -interface TrackedEntityInstance { +type TrackedEntityInstance = { attributes: { value: string; }[]; orgUnit: string; -} +}; type DataValueType = { dataElement: string; From cc977ca9263cedd2eca2792c0791cdbe08d83f14 Mon Sep 17 00:00:00 2001 From: deeonwuli Date: Thu, 22 Feb 2024 10:17:40 +0100 Subject: [PATCH 3/3] feat: increase page size to reduce number of api iterations --- .../GLASSDataSubmissionDefaultRepository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts index bab558fb..13efc08c 100644 --- a/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts +++ b/src/data/reports/glass-data-submission/GLASSDataSubmissionDefaultRepository.ts @@ -263,7 +263,7 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission let instances: TrackedEntityInstance[] = []; let currentPage = 1; let totalPages = 1; - const pageSize = 50; + const pageSize = 200; while (currentPage <= totalPages) { const response = await this.api