From 9526c777f3756ccf2d7bc106c19937ecb7caed31 Mon Sep 17 00:00:00 2001 From: EdsonNhancale Date: Fri, 20 Sep 2024 15:42:49 +0200 Subject: [PATCH 1/2] feat: added function to only show the data marked with display in report --- src/hooks/exportTemplate/useExportTemplate.ts | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/hooks/exportTemplate/useExportTemplate.ts b/src/hooks/exportTemplate/useExportTemplate.ts index d5d7832..8c3403e 100644 --- a/src/hooks/exportTemplate/useExportTemplate.ts +++ b/src/hooks/exportTemplate/useExportTemplate.ts @@ -119,31 +119,9 @@ export default function useExportTemplate() { const { getDataStoreData: programConfigDataStore } = getSelectedKey() async function generateInformations(inputValues: useExportTemplateProps) { - const sectionType: string | null = searchParams.get("sectionType") - - if (!sectionType) { - throw new Error("Couldn't find section type in url params") - } - if (!programConfigDataStore?.program) { - throw Error("Couldn't get program uid from datastore << values >>") - } - const { program: programId, registration }: any = programConfigDataStore - const correspondingProgram: any = await engine.query(oneProgramQuery, { variables: { programId } }) - - if (!correspondingProgram?.program) { - throw Error(`Couldn't find program << ${programId} >> in DHIS2`) - } - - if (!registration) { - throw Error(`Couldn't find registration config in datastore`) - } - - if (!programConfigDataStore?.["performance"]) { - throw Error(`Couldn't find performance config in datastore`) - } const currentAttributes = - correspondingProgram?.program?.programTrackedEntityAttributes?.map( + programConfig?.programTrackedEntityAttributes?.filter(x => x.displayInList)?.map( (p: { mandatory: boolean; trackedEntityAttribute: any }) => { return { mandatory: p.mandatory, ...p.trackedEntityAttribute } } @@ -171,17 +149,8 @@ export default function useExportTemplate() { const reserveValuePayload: any = {} - for (let attr of newHeaders) { - if (attr.unique && attr.generated) { - const reserveValueResponse: any = await engine.query(reserveValuesQuery, { variables: { numberOfReserve: +inputValues.studentsNumber, attributeID: attr.id } }) - if (reserveValueResponse?.values?.length > 0) { - reserveValuePayload[`${attr.id}`] = reserveValueResponse.values - } - } - } - const registrationProgramStageDataElements = - correspondingProgram?.program?.programStages?.reduce( + programConfig?.programStages?.reduce( (prev: any, curr: any) => { if (curr.id === registration.programStage) { const newDataElements = @@ -213,8 +182,8 @@ export default function useExportTemplate() { [] ) || [] - const finalResultsProgramStageDataElements = - correspondingProgram?.program?.programStages?.reduce( + const performanceProgramStageDataElements = + programConfig?.programStages?.reduce( (prev: any, curr: any) => { if (curr.id === programStage) { const newDataElements = @@ -339,7 +308,7 @@ export default function useExportTemplate() { ...newBeginHeadersFormatted, ...newHeaders, ...registrationProgramStageDataElements, - ...finalResultsProgramStageDataElements + ...performanceProgramStageDataElements ] if (+inputValues.studentsNumber > 0) { @@ -382,7 +351,7 @@ export default function useExportTemplate() { return { headers: newHeaders || [], datas: newDataList || [], - currentProgram: correspondingProgram + currentProgram: programConfig } } From 8ed668ea7615eb216ac8b0290dbd2f50bf340b4b Mon Sep 17 00:00:00 2001 From: EdsonNhancale Date: Fri, 20 Sep 2024 15:42:49 +0200 Subject: [PATCH 2/2] feat: added function to only show the data marked with display in report --- src/hooks/exportTemplate/useExportTemplate.ts | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/hooks/exportTemplate/useExportTemplate.ts b/src/hooks/exportTemplate/useExportTemplate.ts index d5d7832..8c3403e 100644 --- a/src/hooks/exportTemplate/useExportTemplate.ts +++ b/src/hooks/exportTemplate/useExportTemplate.ts @@ -119,31 +119,9 @@ export default function useExportTemplate() { const { getDataStoreData: programConfigDataStore } = getSelectedKey() async function generateInformations(inputValues: useExportTemplateProps) { - const sectionType: string | null = searchParams.get("sectionType") - - if (!sectionType) { - throw new Error("Couldn't find section type in url params") - } - if (!programConfigDataStore?.program) { - throw Error("Couldn't get program uid from datastore << values >>") - } - const { program: programId, registration }: any = programConfigDataStore - const correspondingProgram: any = await engine.query(oneProgramQuery, { variables: { programId } }) - - if (!correspondingProgram?.program) { - throw Error(`Couldn't find program << ${programId} >> in DHIS2`) - } - - if (!registration) { - throw Error(`Couldn't find registration config in datastore`) - } - - if (!programConfigDataStore?.["performance"]) { - throw Error(`Couldn't find performance config in datastore`) - } const currentAttributes = - correspondingProgram?.program?.programTrackedEntityAttributes?.map( + programConfig?.programTrackedEntityAttributes?.filter(x => x.displayInList)?.map( (p: { mandatory: boolean; trackedEntityAttribute: any }) => { return { mandatory: p.mandatory, ...p.trackedEntityAttribute } } @@ -171,17 +149,8 @@ export default function useExportTemplate() { const reserveValuePayload: any = {} - for (let attr of newHeaders) { - if (attr.unique && attr.generated) { - const reserveValueResponse: any = await engine.query(reserveValuesQuery, { variables: { numberOfReserve: +inputValues.studentsNumber, attributeID: attr.id } }) - if (reserveValueResponse?.values?.length > 0) { - reserveValuePayload[`${attr.id}`] = reserveValueResponse.values - } - } - } - const registrationProgramStageDataElements = - correspondingProgram?.program?.programStages?.reduce( + programConfig?.programStages?.reduce( (prev: any, curr: any) => { if (curr.id === registration.programStage) { const newDataElements = @@ -213,8 +182,8 @@ export default function useExportTemplate() { [] ) || [] - const finalResultsProgramStageDataElements = - correspondingProgram?.program?.programStages?.reduce( + const performanceProgramStageDataElements = + programConfig?.programStages?.reduce( (prev: any, curr: any) => { if (curr.id === programStage) { const newDataElements = @@ -339,7 +308,7 @@ export default function useExportTemplate() { ...newBeginHeadersFormatted, ...newHeaders, ...registrationProgramStageDataElements, - ...finalResultsProgramStageDataElements + ...performanceProgramStageDataElements ] if (+inputValues.studentsNumber > 0) { @@ -382,7 +351,7 @@ export default function useExportTemplate() { return { headers: newHeaders || [], datas: newDataList || [], - currentProgram: correspondingProgram + currentProgram: programConfig } }