-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f23372
commit 51ace42
Showing
27 changed files
with
162 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/modules/__tests__/utils.spec.js → src/modules/__tests__/dimensionIds.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { OUTPUT_TYPE_TRACKED_ENTITY } from './visualization.js' | ||
|
||
export const formatDimensionId = ({ | ||
dimensionId, | ||
programStageId, | ||
programId, | ||
outputType, | ||
}) => { | ||
return [ | ||
outputType === OUTPUT_TYPE_TRACKED_ENTITY ? programId : undefined, | ||
programStageId, | ||
dimensionId, | ||
] | ||
.filter((p) => p) | ||
.join('.') | ||
} | ||
|
||
export const extractDimensionIdParts = (id, inputType) => { | ||
let rawStageId | ||
const [dimensionId, part2, part3] = id.split('.').reverse() | ||
let programId = part3 | ||
if (part3 || inputType !== OUTPUT_TYPE_TRACKED_ENTITY) { | ||
rawStageId = part2 | ||
} | ||
if (inputType === OUTPUT_TYPE_TRACKED_ENTITY && !part3) { | ||
programId = part2 | ||
} | ||
const [programStageId, repetitionIndex] = (rawStageId || '').split('[') | ||
return { | ||
dimensionId, | ||
programStageId, | ||
...(programId ? { programId } : {}), | ||
repetitionIndex: | ||
repetitionIndex?.length && | ||
repetitionIndex.substring(0, repetitionIndex.indexOf(']')), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
DIMENSION_TYPE_DATA_ELEMENT, | ||
DIMENSION_TYPE_ORGANISATION_UNIT, | ||
DIMENSION_TYPE_PERIOD, | ||
} from '@dhis2/analytics' | ||
import { DIMENSION_TYPE_STATUS } from './dimensionConstants.js' | ||
import { extractDimensionIdParts } from './dimensionIds.js' | ||
import { | ||
OUTPUT_TYPE_ENROLLMENT, | ||
OUTPUT_TYPE_TRACKED_ENTITY, | ||
} from './visualization.js' | ||
|
||
export const getDimensionsWithSuffix = ({ | ||
dimensionIds, | ||
metadata, | ||
inputType, | ||
}) => { | ||
const dimensions = dimensionIds.map((id) => { | ||
const { dimensionId, programStageId, programId } = | ||
extractDimensionIdParts(id, inputType) | ||
const dimension = { | ||
...metadata[id], | ||
dimensionId, | ||
programStageId, | ||
programId, | ||
} | ||
if (!dimension.id) { | ||
dimension.id = id | ||
} | ||
return dimension | ||
}) | ||
|
||
if ( | ||
![OUTPUT_TYPE_ENROLLMENT, OUTPUT_TYPE_TRACKED_ENTITY].includes( | ||
inputType | ||
) | ||
) { | ||
return dimensions | ||
} | ||
|
||
return dimensions.map((dimension) => { | ||
if ( | ||
[DIMENSION_TYPE_DATA_ELEMENT, DIMENSION_TYPE_PERIOD].includes( | ||
dimension.dimensionType || dimension.dimensionItemType | ||
) | ||
) { | ||
const duplicates = dimensions.filter( | ||
(d) => | ||
d.dimensionId === dimension.dimensionId && | ||
d !== dimension && | ||
((dimension.programId && d.programId) || | ||
(dimension.programStageId && d.programStageId)) | ||
) | ||
|
||
if (duplicates.length > 0) { | ||
const sameProgramId = duplicates.find( | ||
(dup) => dup.programId === dimension.programId | ||
) | ||
const thirdPartyDuplicates = duplicates | ||
.filter((dup) => dup.programId !== dimension.programId) | ||
.find((dpid) => | ||
duplicates.find( | ||
(dup) => | ||
dup.programStageId !== dpid.programStageId && | ||
dup.programId === dpid.programId | ||
) | ||
) | ||
|
||
if (sameProgramId || thirdPartyDuplicates) { | ||
dimension.suffix = metadata[dimension.programStageId].name | ||
} else { | ||
dimension.suffix = metadata[dimension.programId].name | ||
} | ||
} | ||
} else if ( | ||
// always suffix ou and statuses for TE | ||
inputType === OUTPUT_TYPE_TRACKED_ENTITY && | ||
[DIMENSION_TYPE_ORGANISATION_UNIT, DIMENSION_TYPE_STATUS].includes( | ||
dimension.dimensionType || dimension.dimensionItemType | ||
) && | ||
dimension.programId | ||
) { | ||
dimension.suffix = metadata[dimension.programId].name | ||
} | ||
|
||
return dimension | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.