Skip to content

Commit

Permalink
Merge pull request #138 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
glass-submission release 1.0.1
  • Loading branch information
ifoche authored Feb 22, 2024
2 parents 1c942b0 + 454f911 commit 547ec13
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"csy-summary-mortality": "1.0.0",
"csy-summary-patient": "1.0.0",
"glass-admin": "1.0.0",
"glass-submission": "1.0.0",
"glass-submission": "1.0.1",
"mal": "0.1.3",
"mal-subscription": "1.0.0",
"nhwa": "1.0.0"
Expand Down
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 547ec13

Please sign in to comment.