Skip to content

Commit 624a21d

Browse files
committed
refactor(valuesets)!: use separate codesystem and valueset urls
1 parent 3fdbb7f commit 624a21d

File tree

22 files changed

+296
-145
lines changed

22 files changed

+296
-145
lines changed

src/__tests__/utilsFunction/hierarchy.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getHierarchyRootCodes,
66
cleanNode,
77
mapHierarchyToMap,
8-
getMissingCodesWithSystems,
8+
getMissingCodesWithValueSets,
99
getMissingCodes,
1010
buildMultipleTrees,
1111
buildTree,
@@ -136,9 +136,9 @@ describe('Utility Functions', () => {
136136
['system1', [{ id: 'root1', label: 'Root1', system: 'system1' }]],
137137
['system2', [{ id: 'root1', label: 'Root1', system: 'system2', inferior_levels_ids: 'root3' }]]
138138
])
139-
const groupBySystem = [
139+
const groupByValueSet = [
140140
{
141-
system: 'system2',
141+
valueSetUrl: 'system2',
142142
codes: [{ id: 'root4', label: 'Root4', system: 'system2', above_levels_ids: 'root1,root3' }]
143143
}
144144
]
@@ -154,7 +154,7 @@ describe('Utility Functions', () => {
154154
.mockResolvedValue([
155155
{ id: 'root3', label: 'Root3', system: 'system2', above_levels_ids: 'root1', inferior_levels_ids: 'root4' }
156156
])
157-
const result = await getMissingCodesWithSystems(trees, groupBySystem, codes, fetchHandler)
157+
const result = await getMissingCodesWithValueSets(trees, groupByValueSet, codes, fetchHandler)
158158
expect(fetchHandler).toHaveBeenCalledWith('root3', 'system2')
159159
expect(result.get('system1')).toEqual(new Map([['root1', { id: 'root1', label: 'Root1', system: 'system1' }]]))
160160
expect(result.get('system2')).toEqual(
@@ -233,6 +233,7 @@ describe('Utility Functions', () => {
233233
above_levels_ids: '',
234234
inferior_levels_ids: '',
235235
system,
236+
valueSetUrl: system,
236237
status
237238
})
238239
})
@@ -464,9 +465,9 @@ describe('Utility Functions', () => {
464465

465466
describe('buildMultipleTrees', () => {
466467
it('should build multiple trees according to different systems', () => {
467-
const groupBySystem: GroupedBySystem<any>[] = [
468+
const groupByValueSet: Array<{ valueSetUrl: string; codes: any[] }> = [
468469
{
469-
system: 'system1',
470+
valueSetUrl: 'system1',
470471
codes: [
471472
{
472473
id: HIERARCHY_ROOT,
@@ -476,7 +477,7 @@ describe('Utility Functions', () => {
476477
]
477478
},
478479
{
479-
system: 'system2',
480+
valueSetUrl: 'system2',
480481
codes: [
481482
{
482483
id: 'code1',
@@ -560,7 +561,7 @@ describe('Utility Functions', () => {
560561
]
561562
])
562563
const mode = Mode.INIT
563-
const result = buildMultipleTrees(baseTrees, groupBySystem, codes, new Map(), mode)
564+
const result = buildMultipleTrees(baseTrees, groupByValueSet, codes, new Map(), mode)
564565
expect(result.get('system1')).toEqual([
565566
{
566567
id: HIERARCHY_ROOT,

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/CriteriaForm/mappers/chipDisplayMapper.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import allDocTypes from 'assets/docTypes.json'
2323
import moment from 'moment'
2424
import { getAgeLabel } from 'utils/age'
2525
import { getConfig } from 'config'
26+
import { getValueSetFromCodeSystem } from 'utils/valueSets'
2627

2728
/************************************************************************************/
2829
/* Criteria Form Item Chip Display */
@@ -137,9 +138,22 @@ const getLabelsForCodeSearchItem = (
137138
): LabelObject[] => {
138139
return val
139140
.map((value) => {
141+
let cacheKey: string | undefined
142+
143+
if (value.system) {
144+
// value.system is a CodeSystem URL, we need to find the corresponding ValueSet URL
145+
const valueSetUrl = getValueSetFromCodeSystem(value.system)
146+
if (valueSetUrl) {
147+
cacheKey = valueSetUrl
148+
} else {
149+
// Fallback: try to find in any of the configured valueSets
150+
cacheKey = item.valueSetsInfo.find((valueset) => valueSets.cache[valueset.url])?.url
151+
}
152+
}
153+
140154
return (
141-
(value.system
142-
? valueSets.cache[value.system]
155+
(cacheKey
156+
? valueSets.cache[cacheKey]
143157
: item.valueSetsInfo.flatMap((valueset) => valueSets.cache[valueset.url])) || []
144158
).find((code) => code && code.id === value.id) as LabelObject
145159
})
@@ -194,7 +208,12 @@ const chipFromCodeSearch = (
194208

195209
// TODO refacto this to be more generic using config
196210
const displaySystem = (system?: string) => {
197-
switch (system) {
211+
if (!system) return ''
212+
213+
// system might be a CodeSystem URL, so we need to find the corresponding ValueSet URL first
214+
const valueSetUrl = getValueSetFromCodeSystem(system) || system
215+
216+
switch (valueSetUrl) {
198217
case getConfig().features.medication.valueSets.medicationAtc.url:
199218
return `${getConfig().features.medication.valueSets.medicationAtc.title}: `
200219
case getConfig().features.medication.valueSets.medicationUcd.url:

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/BiologyForm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { SourceType } from 'types/scope'
1111
import { getConfig } from 'config'
1212
import { BiologyStatus } from 'types'
13-
import { getValueSetsFromSystems } from 'utils/valueSets'
13+
import { getValueSetsByUrls } from 'utils/valueSets'
1414
import { FhirItem } from 'types/valueSet'
1515
import { Hierarchy } from 'types/hierarchy'
1616

@@ -68,15 +68,18 @@ export const form: () => CriteriaForm<ObservationDataType> = () => ({
6868
type: 'codeSearch',
6969
label: 'Sélectionner les codes',
7070
checkIsLeaf: true,
71-
valueSetsInfo: getValueSetsFromSystems([
71+
valueSetsInfo: getValueSetsByUrls([
7272
getConfig().features.observation.valueSets.biologyHierarchyAnabio.url,
7373
getConfig().features.observation.valueSets.biologyHierarchyLoinc.url
7474
]),
7575
noOptionsText: 'Veuillez entrer un code de biologie',
7676
buildInfo: {
7777
fhirKey: ObservationParamsKeys.CODE,
7878
buildMethodExtraArgs: [
79-
{ type: 'string', value: getConfig().features.observation.valueSets.biologyHierarchyAnabio.url },
79+
{
80+
type: 'string',
81+
value: getConfig().features.observation.valueSets.biologyHierarchyAnabio.codeSystemUrls?.at(0) || ''
82+
},
8083
{ type: 'boolean', value: true }
8184
]
8285
}

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/CCAMForm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../CriteriaForm/types'
99
import { SourceType } from 'types/scope'
1010
import { getConfig } from 'config'
11-
import { getValueSetsFromSystems } from 'utils/valueSets'
11+
import { getValueSetsByUrls } from 'utils/valueSets'
1212
import { Hierarchy } from 'types/hierarchy'
1313
import { FhirItem } from 'types/valueSet'
1414

@@ -88,12 +88,15 @@ export const form: () => CriteriaForm<CcamDataType> = () => ({
8888
valueKey: 'code',
8989
type: 'codeSearch',
9090
label: "Sélectionner les codes d'actes CCAM",
91-
valueSetsInfo: getValueSetsFromSystems([getConfig().features.procedure.valueSets.procedureHierarchy.url]),
91+
valueSetsInfo: getValueSetsByUrls([getConfig().features.procedure.valueSets.procedureHierarchy.url]),
9292
noOptionsText: 'Veuillez entrer un code ou un acte CCAM',
9393
buildInfo: {
9494
fhirKey: ProcedureParamsKeys.CODE,
9595
buildMethodExtraArgs: [
96-
{ type: 'string', value: getConfig().features.procedure.valueSets.procedureHierarchy.url }
96+
{
97+
type: 'string',
98+
value: getConfig().features.procedure.valueSets.procedureHierarchy.codeSystemUrls?.at(0) || ''
99+
}
97100
],
98101
chipDisplayMethodExtraArgs: [
99102
{ type: 'string', value: '' },

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/Cim10Form.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../CriteriaForm/types'
99
import { SourceType } from 'types/scope'
1010
import { getConfig } from 'config'
11-
import { getValueSetsFromSystems } from 'utils/valueSets'
11+
import { getValueSetsByUrls } from 'utils/valueSets'
1212
import { FhirItem } from 'types/valueSet'
1313
import { Hierarchy } from 'types/hierarchy'
1414

@@ -89,13 +89,16 @@ export const form: () => CriteriaForm<Cim10DataType> = () => ({
8989
{
9090
valueKey: 'code',
9191
type: 'codeSearch',
92-
valueSetsInfo: getValueSetsFromSystems([getConfig().features.condition.valueSets.conditionHierarchy.url]),
92+
valueSetsInfo: getValueSetsByUrls([getConfig().features.condition.valueSets.conditionHierarchy.url]),
9393
noOptionsText: 'Veuillez entrer un code ou un diagnostic CIM10',
9494
label: 'Sélectionner les codes CIM10',
9595
buildInfo: {
9696
fhirKey: ConditionParamsKeys.CODE,
9797
buildMethodExtraArgs: [
98-
{ type: 'string', value: getConfig().features.condition.valueSets.conditionHierarchy.url }
98+
{
99+
type: 'string',
100+
value: getConfig().features.condition.valueSets.conditionHierarchy.codeSystemUrls?.at(0) || ''
101+
}
99102
],
100103
chipDisplayMethodExtraArgs: [
101104
{ type: 'string', value: '' },

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/GHMForm.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { Link } from '@mui/material'
1111
import { SourceType } from 'types/scope'
1212
import { getConfig } from 'config'
13-
import { getValueSetsFromSystems } from 'utils/valueSets'
13+
import { getValueSetsByUrls } from 'utils/valueSets'
1414
import { Hierarchy } from 'types/hierarchy'
1515
import { FhirItem } from 'types/valueSet'
1616

@@ -73,12 +73,14 @@ export const form: () => CriteriaForm<GhmDataType> = () => ({
7373
{
7474
valueKey: 'code',
7575
type: 'codeSearch',
76-
valueSetsInfo: getValueSetsFromSystems([getConfig().features.claim.valueSets.claimHierarchy.url]),
76+
valueSetsInfo: getValueSetsByUrls([getConfig().features.claim.valueSets.claimHierarchy.url]),
7777
noOptionsText: 'Aucun GHM trouvé',
7878
label: 'Sélectionner les codes GHM',
7979
buildInfo: {
8080
fhirKey: ClaimParamsKeys.CODE,
81-
buildMethodExtraArgs: [{ type: 'string', value: getConfig().features.claim.valueSets.claimHierarchy.url }],
81+
buildMethodExtraArgs: [
82+
{ type: 'string', value: getConfig().features.claim.valueSets.claimHierarchy.codeSystemUrls?.at(0) || '' }
83+
],
8284
chipDisplayMethodExtraArgs: [
8385
{ type: 'string', value: '' },
8486
{ type: 'boolean', value: true }

src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/MedicationForm.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../CriteriaForm/types'
1616
import { SourceType } from 'types/scope'
1717
import { getConfig } from 'config'
18-
import { getValueSetsFromSystems } from 'utils/valueSets'
18+
import { getValueSetsByUrls } from 'utils/valueSets'
1919
import { Hierarchy } from 'types/hierarchy'
2020
import { FhirItem } from 'types/valueSet'
2121

@@ -92,14 +92,17 @@ export const form: () => CriteriaForm<MedicationDataType> = () => ({
9292
type: 'codeSearch',
9393
label: 'Sélectionner les codes',
9494
noOptionsText: 'Veuillez entrer un code de médicament',
95-
valueSetsInfo: getValueSetsFromSystems([
95+
valueSetsInfo: getValueSetsByUrls([
9696
getConfig().features.medication.valueSets.medicationAtc.url,
9797
getConfig().features.medication.valueSets.medicationUcd.url
9898
]),
9999
buildInfo: {
100100
fhirKey: PrescriptionParamsKeys.CODE,
101101
buildMethodExtraArgs: [
102-
{ type: 'string', value: getConfig().features.medication.valueSets.medicationAtc.url },
102+
{
103+
type: 'string',
104+
value: getConfig().features.medication.valueSets.medicationAtc.codeSystemUrls?.at(0) || ''
105+
},
103106
{ type: 'boolean', value: true }
104107
],
105108
chipDisplayMethodExtraArgs: [

src/components/ExplorationBoard/config/biology.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
narrowSearchCriterias,
2828
resolveAdditionalInfos
2929
} from 'utils/exploration'
30-
import { getValueSetsFromSystems } from 'utils/valueSets'
30+
import { getValueSetsByUrls } from 'utils/valueSets'
3131

3232
const fetchAdditionalInfos = async (additionalInfo: AdditionalInfo): Promise<AdditionalInfo> => {
3333
const fetchersMap: Record<string, () => Promise<FhirItem[] | undefined>> = {
@@ -37,7 +37,7 @@ const fetchAdditionalInfos = async (additionalInfo: AdditionalInfo): Promise<Add
3737
: Promise.resolve(undefined)
3838
}
3939
const resolved = await resolveAdditionalInfos(fetchersMap)
40-
const references: Reference[] = getValueSetsFromSystems([
40+
const references: Reference[] = getValueSetsByUrls([
4141
getConfig().features.observation.valueSets.biologyHierarchyAnabio.url,
4242
getConfig().features.observation.valueSets.biologyHierarchyLoinc.url
4343
])

src/components/ExplorationBoard/config/medication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
narrowSearchCriterias,
3030
resolveAdditionalInfos
3131
} from 'utils/exploration'
32-
import { getValueSetsFromSystems } from 'utils/valueSets'
32+
import { getValueSetsByUrls } from 'utils/valueSets'
3333

3434
const fetchAdditionalInfos = async (additionalInfo: AdditionalInfo): Promise<AdditionalInfo> => {
3535
const config = getConfig().features
@@ -48,7 +48,7 @@ const fetchAdditionalInfos = async (additionalInfo: AdditionalInfo): Promise<Add
4848
: Promise.resolve(undefined)
4949
}
5050
const resolved = await resolveAdditionalInfos(fetchersMap)
51-
const references: Reference[] = getValueSetsFromSystems([
51+
const references: Reference[] = getValueSetsByUrls([
5252
getConfig().features.medication.valueSets.medicationAtc.url,
5353
getConfig().features.medication.valueSets.medicationUcd.url
5454
])

src/components/ExplorationBoard/config/pmsi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { CellType, Column, Row, Table } from 'types/table'
1313
import { FhirItem, Reference } from 'types/valueSet'
1414
import { fetchValueSet, narrowSearchCriterias, resolveAdditionalInfos } from 'utils/exploration'
1515
import { getCategory } from 'utils/fhir'
16-
import { getValueSetsFromSystems } from 'utils/valueSets'
16+
import { getValueSetsByUrls } from 'utils/valueSets'
1717

1818
const fetchAdditionalInfos = async (additionalInfo: AdditionalInfo): Promise<AdditionalInfo> => {
1919
const fetchersMap: Record<string, () => Promise<FhirItem[] | undefined>> = {
@@ -152,7 +152,7 @@ export const conditionConfig = (
152152
narrowSearchCriterias(deidentified, searchCriterias, !!patient, [], ['searchBy']),
153153
fetchAdditionalInfos: async (infos) => {
154154
const _infos = await fetchAdditionalInfos(infos)
155-
const references: Reference[] = getValueSetsFromSystems([
155+
const references: Reference[] = getValueSetsByUrls([
156156
getConfig().features.condition.valueSets.conditionHierarchy.url
157157
])
158158
const sourceType = SourceType.CIM10
@@ -183,7 +183,7 @@ export const procedureConfig = (
183183
narrowSearchCriterias(deidentified, searchCriterias, !!patient, ['diagnosticTypes'], ['searchBy']),
184184
fetchAdditionalInfos: async (infos) => {
185185
const _infos = await fetchAdditionalInfos(infos)
186-
const references: Reference[] = getValueSetsFromSystems([
186+
const references: Reference[] = getValueSetsByUrls([
187187
getConfig().features.procedure.valueSets.procedureHierarchy.url
188188
])
189189
const sourceType = SourceType.CCAM
@@ -213,7 +213,7 @@ export const claimConfig = (
213213
narrowSearchCriterias(deidentified, searchCriterias, !!patient, ['diagnosticTypes', 'source'], ['searchBy']),
214214
fetchAdditionalInfos: async (infos) => {
215215
const _infos = await fetchAdditionalInfos(infos)
216-
const references: Reference[] = getValueSetsFromSystems([getConfig().features.claim.valueSets.claimHierarchy.url])
216+
const references: Reference[] = getValueSetsByUrls([getConfig().features.claim.valueSets.claimHierarchy.url])
217217
const sourceType = SourceType.GHM
218218
return { ..._infos, references, sourceType }
219219
},

0 commit comments

Comments
 (0)