From 6bc287fdd1e327113396023445251fcbc48efb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Henrik=20=C3=98verland?= Date: Thu, 17 Oct 2024 17:06:57 +0200 Subject: [PATCH] feat: use enrollment aggregate endpoint (DHIS2-15691) (#1324) * feat: use new endpoint * distinguish des from attrs and pis * chore: remove logs * chore: formatting * chore: dev href --- src/api/Dimension.js | 3 ++- src/api/Layout.js | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/api/Dimension.js b/src/api/Dimension.js index 8f33781d..cde558de 100644 --- a/src/api/Dimension.js +++ b/src/api/Dimension.js @@ -54,7 +54,8 @@ Dimension.prototype.isIgnoreDimension = function() { // dep 1 -const getFullId = dim => (dim.programStage ? dim.programStage.id + '.' : '') + dim.dimension; +const getFullId = dim => (dim.programStage && dim.programStage.id ? + dim.programStage.id + '.' : '') + dim.dimension; Dimension.prototype.url = function(isSorted, response, isFilter) { if (this.isIgnoreDimension()) { diff --git a/src/api/Layout.js b/src/api/Layout.js index 5ccdb62e..969d57ba 100644 --- a/src/api/Layout.js +++ b/src/api/Layout.js @@ -6,7 +6,7 @@ import isNumeric from 'd2-utilizr/lib/isNumeric'; import isObject from 'd2-utilizr/lib/isObject'; import isString from 'd2-utilizr/lib/isString'; -import { Record, Layout as d2aLayout } from 'd2-analysis'; +import { Record, Layout as d2aLayout, dimensionsInit } from 'd2-analysis'; export var Layout = function(refs, c, applyConfig, forceApplyConfig) { var t = this; @@ -20,6 +20,22 @@ export var Layout = function(refs, c, applyConfig, forceApplyConfig) { // inherit Object.assign(t, new d2aLayout(refs, c, applyConfig)); + // data element dimensions + if (c.dataElementDimensions) { + t.dataElementDimensions = c.dataElementDimensions; + } + + // add isDataElement to distinguish from attributes and program indicators + if (t.dataElementDimensions) { + ([].concat(t.columns, t.rows, t.filters)) + .filter(dimension => dimension) + .forEach(dimension => { + if (c.dataElementDimensions.find(de => de.dataElement.id === dimension.dimension)) { + dimension.isDataElement = true + } + }) + } + // program t.program = isObject(c.program) ? c.program : null; t.programStage = isObject(c.programStage) ? c.programStage : null; @@ -122,11 +138,6 @@ export var Layout = function(refs, c, applyConfig, forceApplyConfig) { ? c.reportParams.paramParentOrganisationUnit : isBoolean(c.parentOrganisationUnit) ? c.parentOrganisationUnit : false; - // data element dimensions - if (c.dataElementDimensions) { - t.dataElementDimensions = c.dataElementDimensions; - } - // force apply Object.assign(t, forceApplyConfig); @@ -186,9 +197,18 @@ Layout.prototype.getDataTypeUrl = function() { var OUTPUT_TYPE_EVENT = optionConfig.getOutputType('event').id; var OUTPUT_TYPE_ENROLLMENT = optionConfig.getOutputType('enrollment').id; - var url = this.dataType === DATA_TYPE_AGG ? '/events/aggregate' : - this.outputType === OUTPUT_TYPE_EVENT ? '/events/query' : - '/enrollments/query'; + var urlMap = { + [OUTPUT_TYPE_EVENT]: { + [DATA_TYPE_AGG]: '/events/aggregate', + [DATA_TYPE_EVENT]: '/events/query', + }, + [OUTPUT_TYPE_ENROLLMENT]: { + [DATA_TYPE_AGG]: '/enrollments/aggregate', + [DATA_TYPE_EVENT]: '/enrollments/query', + } + } + + var url = urlMap[this.outputType][this.dataType] return url || dimensionConfig.dataTypeUrl[dimensionConfig.getDefaultDataType()] || ''; };