Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
aetchego committed Dec 20, 2024
1 parent ab562bc commit d2f8249
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 87 deletions.
41 changes: 30 additions & 11 deletions src/components/CreationCohort/DataList_Criteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { createHierarchyRoot } from 'utils/hierarchy'

const async = (fetch: () => Promise<Back_API_Response<FhirItem>>) => async () => (await fetch()).results

const getCodesForValueSet = async (code: string, system: string) => {
try {
if (code === HIERARCHY_ROOT) return [createHierarchyRoot(system)]
else return (await getChildrenFromCodes(system, [code])).results
} catch {
return []
const getCodesForValueSet = async (code: string, systems: string[]) => {
if (code === HIERARCHY_ROOT && systems.length) return [createHierarchyRoot(systems[0])]
for (const system of systems) {
try {
return (await getChildrenFromCodes(system, [code])).results
} catch {}

Check failure on line 34 in src/components/CreationCohort/DataList_Criteria.tsx

View workflow job for this annotation

GitHub Actions / test

Empty block statement
}
}

Expand Down Expand Up @@ -126,7 +126,8 @@ const criteriaList: () => CriteriaItemType[] = () => {
components: Cim10Form,
fetch: {
diagnosticTypes: async(() => getCodeList(getConfig().features.condition.valueSets.conditionStatus.url)),
cim10Diagnostic: (code: string, system: string) => getCodesForValueSet(code, system),
cim10Diagnostic: (code: string, system: string) =>
getCodesForValueSet(code, [system ?? getConfig().features.condition.valueSets.conditionHierarchy.url]),
encounterStatus: async(() => getCodeList(getConfig().core.valueSets.encounterStatus.url))
}
},
Expand All @@ -137,7 +138,8 @@ const criteriaList: () => CriteriaItemType[] = () => {
fontWeight: 'normal',
components: CCAMForm,
fetch: {
ccamData: (code: string, system: string) => getCodesForValueSet(code, system),
ccamData: (code: string, system: string) =>
getCodesForValueSet(code, [system ?? getConfig().features.procedure.valueSets.procedureHierarchy.url]),
encounterStatus: async(() => getCodeList(getConfig().core.valueSets.encounterStatus.url))
}
},
Expand All @@ -148,7 +150,8 @@ const criteriaList: () => CriteriaItemType[] = () => {
fontWeight: 'normal',
components: GhmForm,
fetch: {
ghmData: (code: string, system: string) => getCodesForValueSet(code, system),
ghmData: (code: string, system: string) =>
getCodesForValueSet(code, [system ?? getConfig().features.claim.valueSets.claimHierarchy.url]),
encounterStatus: async(() => getCodeList(getConfig().core.valueSets.encounterStatus.url))
}
}
Expand All @@ -162,7 +165,15 @@ const criteriaList: () => CriteriaItemType[] = () => {
components: MedicationForm,
disabled: !ODD_MEDICATION,
fetch: {
medicationData: (code: string, system: string) => getCodesForValueSet(code, system),
medicationData: (code: string, system: string) => {
const valueSets = system
? [system]
: [
getConfig().features.medication.valueSets.medicationAtc.url,
getConfig().features.medication.valueSets.medicationUcd.url
]
return getCodesForValueSet(code, valueSets)
},
prescriptionTypes: async(() =>
getCodeList(getConfig().features.medication.valueSets.medicationPrescriptionTypes.url)
),
Expand All @@ -187,7 +198,15 @@ const criteriaList: () => CriteriaItemType[] = () => {
components: BiologyForm,
disabled: !ODD_BIOLOGY,
fetch: {
biologyData: (code: string, system: string) => getCodesForValueSet(code, system),
biologyData: (code: string, system: string) => {
const valueSets = system
? [system]
: [
getConfig().features.observation.valueSets.biologyHierarchyAnabio.url,
getConfig().features.observation.valueSets.biologyHierarchyLoinc.url
]
return getCodesForValueSet(code, valueSets)
},
encounterStatus: async(() => getCodeList(getConfig().core.valueSets.encounterStatus.url))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import AdvancedInputs from '../AdvancedInputs'
import { SourceType } from 'types/scope'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria, mappingHierarchyCriteria } from 'utils/mappers'

enum Error {
NO_ERROR,
Expand Down Expand Up @@ -121,16 +121,10 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => {
}, [])

useEffect(() => {
const foundCodes = currentCriteria.code
.map((code) =>
criteriaData.data.biologyData.find(
(cacheCode: any) => cacheCode.id === code.id && cacheCode.system === code.system
)
)
.filter((e) => e)
const encounterStatus =
mappingCriteria(currentCriteria?.encounterStatus, CriteriaDataKey.ENCOUNTER_STATUS, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code: foundCodes, encounterStatus })
const code = mappingHierarchyCriteria(currentCriteria?.code, CriteriaDataKey.BIOLOGY_DATA, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code, encounterStatus })
}, [])

Check warning on line 128 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has missing dependencies: 'criteriaData' and 'currentCriteria'. Either include them or remove the dependency array. You can also do a functional update 'setCurrentCriteria(c => ...)' if you only need 'currentCriteria' in the 'setCurrentCriteria' call

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { SourceType } from 'types/scope'
import ValueSetField from 'components/SearchValueSet/ValueSetField'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria, mappingHierarchyCriteria } from 'utils/mappers'

enum Error {
ADVANCED_INPUTS_ERROR,
Expand Down Expand Up @@ -64,16 +64,10 @@ const CcamForm = (props: CriteriaDrawerComponentProps) => {
}, [])

useEffect(() => {
const foundCodes = currentCriteria.code
.map((code) =>
criteriaData.data.ccamData.find(
(cacheCode: any) => cacheCode.id === code.id && cacheCode.system === code.system
)
)
.filter((e) => e)
const code = mappingHierarchyCriteria(currentCriteria?.code, CriteriaDataKey.CCAM_DATA, criteriaData) || []
const encounterStatus =
mappingCriteria(currentCriteria?.encounterStatus, CriteriaDataKey.ENCOUNTER_STATUS, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code: foundCodes, encounterStatus })
setCurrentCriteria({ ...currentCriteria, code, encounterStatus })
}, [])

Check warning on line 71 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/CcamForm/index.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has missing dependencies: 'criteriaData' and 'currentCriteria'. Either include them or remove the dependency array. You can also do a functional update 'setCurrentCriteria(c => ...)' if you only need 'currentCriteria' in the 'setCurrentCriteria' call

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getConfig } from 'config'
import ValueSetField from 'components/SearchValueSet/ValueSetField'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { LabelObject } from 'types/searchCriterias'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria, mappingHierarchyCriteria } from 'utils/mappers'

enum Error {
ADVANCED_INPUTS_ERROR,
Expand Down Expand Up @@ -77,16 +77,10 @@ const Cim10Form = (props: CriteriaDrawerComponentProps) => {
}, [])

useEffect(() => {
const foundCodes = currentCriteria.code
.map((code) =>
criteriaData.data.cim10Diagnostic.find(
(cacheCode: any) => cacheCode.id === code.id && cacheCode.system === code.system
)
)
.filter((e) => e)
const code = mappingHierarchyCriteria(currentCriteria?.code, CriteriaDataKey.CIM_10_DIAGNOSTIC, criteriaData) || []
const encounterStatus =
mappingCriteria(currentCriteria?.encounterStatus, CriteriaDataKey.ENCOUNTER_STATUS, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code: foundCodes, encounterStatus })
setCurrentCriteria({ ...currentCriteria, code, encounterStatus })
}, [])

Check warning on line 84 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/Cim10Form/index.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has missing dependencies: 'criteriaData' and 'currentCriteria'. Either include them or remove the dependency array. You can also do a functional update 'setCurrentCriteria(c => ...)' if you only need 'currentCriteria' in the 'setCurrentCriteria' call
return (
<Grid className={classes.root}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,15 @@ import CalendarRange from 'components/ui/Inputs/CalendarRange'
import DurationRange from 'components/ui/Inputs/DurationRange'
import { CriteriaDataKey, DemographicDataType, CriteriaType } from 'types/requestCriterias'
import { BlockWrapper } from 'components/ui/Layout'
import { CriteriaDrawerComponentProps, CriteriaItemDataCache } from 'types'
import { CriteriaDrawerComponentProps } from 'types'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import { mappingCriteria } from 'utils/mappers'

enum Error {
INCOHERENT_AGE_ERROR,
NO_ERROR
}

export const mappingCriteria = (
criteriaToMap: LabelObject[] | null,
key: CriteriaDataKey,
mapping: CriteriaItemDataCache
) => {
if (criteriaToMap) {
return criteriaToMap.map((criteria) => {
const mappedCriteria = mapping.data?.[key]?.find((c: LabelObject) => c?.id === criteria?.id)
return mappedCriteria
})
} else {
return []
}
}

const DemographicForm = (props: CriteriaDrawerComponentProps) => {
const { criteriaData, onChangeSelectedCriteria, goBack } = props
const selectedCriteria: DemographicDataType | null = props.selectedCriteria as DemographicDataType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import SearchInput from 'components/ui/Searchbar/SearchInput'
import { BlockWrapper } from 'components/ui/Layout'
import OccurenceInput from 'components/ui/Inputs/Occurences'
import { SourceType } from 'types/scope'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria } from 'utils/mappers'

const defaultComposition: Omit<DocumentDataType, 'id'> = {
type: CriteriaType.DOCUMENTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import OccurenceInput from 'components/ui/Inputs/Occurences'
import Collapse from 'components/ui/Collapse'
import CalendarRange from 'components/ui/Inputs/CalendarRange'
import DurationRange from 'components/ui/Inputs/DurationRange'
import { mappingCriteria } from '../DemographicForm'
import { SourceType } from 'types/scope'
import { Hierarchy } from 'types/hierarchy'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import ExecutiveUnitsInput from 'components/ui/Inputs/ExecutiveUnits'
import { mappingCriteria } from 'utils/mappers'

enum Error {
EMPTY_FORM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { SourceType } from 'types/scope'
import ValueSetField from 'components/SearchValueSet/ValueSetField'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria, mappingHierarchyCriteria } from 'utils/mappers'

enum Error {
ADVANCED_INPUTS_ERROR,
Expand Down Expand Up @@ -59,14 +59,10 @@ const GhmForm = (props: CriteriaDrawerComponentProps) => {
}, [])

useEffect(() => {
const foundCodes = currentCriteria.code
.map((code) =>
criteriaData.data.ghmData.find((cacheCode: any) => cacheCode.id === code.id && cacheCode.system === code.system)
)
.filter((e) => e)
const code = mappingHierarchyCriteria(currentCriteria?.code, CriteriaDataKey.GHM_DATA, criteriaData) || []
const encounterStatus =
mappingCriteria(currentCriteria?.encounterStatus, CriteriaDataKey.ENCOUNTER_STATUS, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code: foundCodes, encounterStatus })
setCurrentCriteria({ ...currentCriteria, code, encounterStatus })
}, [])

Check warning on line 66 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/GHMForm/index.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has missing dependencies: 'criteriaData' and 'currentCriteria'. Either include them or remove the dependency array. You can also do a functional update 'setCurrentCriteria(c => ...)' if you only need 'currentCriteria' in the 'setCurrentCriteria' call

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { BlockWrapper } from 'components/ui/Layout'
import OccurenceInput from 'components/ui/Inputs/Occurences'
import Collapse from 'components/ui/Collapse'
import SearchbarWithCheck from 'components/ui/Inputs/SearchbarWithCheck'
import { mappingCriteria } from '../DemographicForm'
import CriteriaLayout from 'components/ui/CriteriaLayout'
import CalendarRange from 'components/ui/Inputs/CalendarRange'
import NumericConditionInput from 'components/ui/Inputs/OccurencesWithFloats'
import { SourceType } from 'types/scope'
import { Hierarchy } from 'types/hierarchy'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import ExecutiveUnitsInput from 'components/ui/Inputs/ExecutiveUnits'
import { mappingCriteria } from 'utils/mappers'

enum Error {
EMPTY_FORM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
DurationRangeType,
LabelObject
} from 'types/searchCriterias'
import { mappingCriteria } from '../DemographicForm'
import SearchbarWithCheck from 'components/ui/Inputs/SearchbarWithCheck'
import UidTextfield from 'components/ui/Inputs/UidTextfield'
import { SourceType } from 'types/scope'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import { AppConfig } from 'config'
import { mappingCriteria } from 'utils/mappers'

enum Error {
INCOHERENT_AGE_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import AdvancedInputs from '../AdvancedInputs'
import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { LabelObject } from 'types/searchCriterias'
import { mappingCriteria } from '../DemographicForm'
import { mappingCriteria, mappingHierarchyCriteria } from 'utils/mappers'

enum Error {
ADVANCED_INPUTS_ERROR,
Expand Down Expand Up @@ -71,17 +71,10 @@ const MedicationForm = (props: CriteriaDrawerComponentProps) => {
}, [])

useEffect(() => {
const foundCodes = currentCriteria.code
.map((code) =>
criteriaData.data.medicationData.find(
(cacheCode: any) => cacheCode.id === code.id && cacheCode.system === code.system
)
)
.filter((e) => e)
.filter((e) => e)
const encounterStatus =
mappingCriteria(currentCriteria?.encounterStatus, CriteriaDataKey.ENCOUNTER_STATUS, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code: foundCodes, encounterStatus })
const code = mappingHierarchyCriteria(currentCriteria?.code, CriteriaDataKey.MEDICATION_DATA, criteriaData) || []
setCurrentCriteria({ ...currentCriteria, code, encounterStatus })
}, [])

if (criteriaData?.data?.prescriptionTypes === 'loading' || criteriaData?.data?.administrations === 'loading') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import OccurenceInput from 'components/ui/Inputs/Occurences'
import Collapse from 'components/ui/Collapse'
import SearchbarWithCheck from 'components/ui/Inputs/SearchbarWithCheck'
import CalendarRange from 'components/ui/Inputs/CalendarRange'
import { mappingCriteria } from '../DemographicForm'
import CriteriaLayout from 'components/ui/CriteriaLayout'
import { SourceType } from 'types/scope'
import { Hierarchy } from 'types/hierarchy'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import ExecutiveUnitsInput from 'components/ui/Inputs/ExecutiveUnits'
import { mappingCriteria } from 'utils/mappers'

enum Error {
EMPTY_FORM,
Expand Down
3 changes: 2 additions & 1 deletion src/components/SearchValueSet/ValueSetField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormLabel, Grid, IconButton } from '@mui/material'
import React, { useState } from 'react'
import React, { useMemo, useState } from 'react'
import { Hierarchy } from 'types/hierarchy'
import { FhirItem, Reference } from 'types/valueSet'
import SearchValueSet from '.'
Expand All @@ -8,6 +8,7 @@ import { SearchOutlined } from '@mui/icons-material'
import CloseIcon from '@mui/icons-material/Close'
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'
import CodesWithSystems from 'components/Hierarchy/CodesWithSystems'
import { mappingCriteria } from 'utils/mappers'

type ValueSetFieldProps = {
value: Hierarchy<FhirItem>[]
Expand Down
4 changes: 3 additions & 1 deletion src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,9 @@ export const getDataFromFetch = async (
currentcriterion.code.length > 0
) {
for (const code of currentcriterion.code) {
const prevData = prevDataCache[dataKey]?.find((data: any) => data.id === code?.id)
const prevData = prevDataCache[dataKey]?.find(
(data: any) => data.id === code?.id && data.system && code?.system
)
const codeData = prevData ? [prevData] : await _criterion.fetch[dataKey]?.(code?.id, code?.system)
const existingCodes = criteriaDataCache.data[dataKey] || []
criteriaDataCache.data[dataKey] = [...existingCodes, ...((codeData as Hierarchy<FhirItem>[]) || [])]
Expand Down
Loading

0 comments on commit d2f8249

Please sign in to comment.