Skip to content

Commit

Permalink
fix: types and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Jan 14, 2025
1 parent 5bc8b0a commit cce8ec9
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 92 deletions.
96 changes: 46 additions & 50 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/__tests__/data/cohortCreation/conditionCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/Cim10Form'
import { Comparators } from 'types/requestCriterias'
import { System } from 'types/scope'

export const defaultConditionCriteria: Cim10DataType = {
id: 1,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/data/cohortCreation/documentCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/DocumentsForm'
import { Comparators } from 'types/requestCriterias'
import { System } from 'types/scope'
import { DocumentStatuses, SearchByTypes } from 'types/searchCriterias'

export const defaultDocumentCriteria: DocumentDataType = {
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/data/cohortCreation/encounterCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/EncounterForm'
import { Comparators } from 'types/requestCriterias'
import { System } from 'types/scope'

export const defaultEncounterCriteira: EncounterDataType = {
id: 1,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/data/cohortCreation/medicationCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/MedicationForm'
import { Comparators, CriteriaType } from 'types/requestCriterias'
import { System } from 'types/scope'

export const defaultMedicationCriteria: MedicationDataType = {
id: 1,
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/data/cohortCreation/observationCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/BiologyForm'
import { Comparators } from 'types/requestCriterias'
import { System } from 'types/scope'

export const defaultObservationCriteria: ObservationDataType = {
id: 1,
Expand All @@ -21,6 +22,8 @@ export const completeObservationCriteria: ObservationDataType = {
id: 'I3356',
label: 'I3356 - Erythrocytes Foetaux /érythrocytes Adultes_sang_cytochimie_hf/10000 Ha',
system: 'https://terminology.eds.aphp.fr/aphp-itm-anabio',
above_levels_ids: '*',
inferior_levels_ids: '',
isLeaf: true
}
],
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/data/cohortCreation/procedureCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
form
} from 'components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/forms/CCAMForm'
import { Comparators } from 'types/requestCriterias'
import { System } from 'types/scope'

export const defaultProcedureCriteria: CcamDataType = {
id: 1,
Expand Down
3 changes: 0 additions & 3 deletions src/components/CreationCohort/DataList_Criteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export enum CriteriaTypeLabels {
HOSPIT = "Fiche d'hospitalisation"
}

import docTypes from 'assets/docTypes.json'
import { birthStatusData, booleanFieldsData, booleanOpenChoiceFieldsData, vmeData } from 'data/questionnaire_data'
import { VitalStatusLabel } from 'types/searchCriterias'
import { FhirItem } from 'types/valueSet'
import { createHierarchyRoot } from 'utils/hierarchy'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function CriteriaForm<T extends CommonCriteriaData>(props: Criter
...item,
data: criteriaData,
getValueSetOptions: (valueSetId) => {
return (valueSets.entities[valueSetId]?.options || []) as LabelObject[]
return Object.values(valueSets.entities[valueSetId]?.options || {})
},
updateData: (newData: T) => {
setCriteriaData({ ...criteriaData, ...newData })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const unbuildEncounterServiceFilter = async (
existingValue?: Hierarchy<ScopeElement, string>[]
) => {
if (value) {
const encounterServices: ScopeElement[] = (await services.perimeters.getPerimeters({ ids: value })).results
const encounterServices: Hierarchy<ScopeElement>[] = (await services.perimeters.getPerimeters({ ids: value }))
.results
return encounterServices.concat(existingValue || [])
}
return Promise.resolve(existingValue || [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import allDocTypes from 'assets/docTypes.json'
import moment from 'moment'
import { getDurationRangeLabel } from 'utils/age'
import { getConfig } from 'config'
import { FhirItem } from 'types/valueSet'

/************************************************************************************/
/* Criteria Form Item Chip Display */
Expand Down Expand Up @@ -138,7 +139,9 @@ const getLabelsForCodeSearchItem = (
return val
.map((value) => {
return (
(value.system ? valueSets.cache[value.system] : item.valueSetIds.flatMap((vid) => valueSets.cache[vid])) || []
(value.system
? valueSets.cache[value.system]
: item.valueSetsInfo.flatMap((valueset) => valueSets.cache[valueset.url])) || []
).find((code) => code && code.id === value.id) as LabelObject
})
.filter((code) => code !== undefined)
Expand All @@ -152,10 +155,10 @@ const getLabelsForAutoCompleteItem = (
return val
.map((value) => {
return (item.valueSetData || Object.values(valueSets.entities[item.valueSetId]?.options || {}) || []).find(

Check failure on line 157 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/CriteriaForm/mappers/chipDisplayMapper.tsx

View workflow job for this annotation

GitHub Actions / test

This expression is not callable.
(code) => code.id === value.id
(code: LabelObject | Hierarchy<FhirItem, string>) => code.id === value.id
)
})
.filter((code) => code !== undefined)
.filter((code: LabelObject | Hierarchy<FhirItem, string> | undefined) => code !== undefined)
}

const chipFromAutoComplete = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import { Comparators } from 'types/requestCriterias'
import SimpleSelect from 'components/ui/Inputs/SimpleSelect'
import ValueSetField from 'components/SearchValueSet/ValueSetField'
import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets'

/************************************************************************************/
/* Criteria Form Item Renderer */
Expand Down Expand Up @@ -288,7 +289,19 @@ const FORM_ITEM_RENDERER: { [key in CriteriaFormItemType]: CriteriaFormItemView<
<ValueSetField
value={valueWithLabels}
references={props.definition.valueSetsInfo}
onSelect={(value) => props.updateData(value)}
onSelect={(value) => {
if (props.definition.checkIsLeaf) {
const valuesWithLeafInfo = value.map((v) => {
return {
...v,
isLeaf: !v.inferior_levels_ids && v.id !== HIERARCHY_ROOT
}
})
props.updateData(valuesWithLeafInfo)
} else {
props.updateData(value)
}
}}
placeholder={props.definition.label ?? 'Code(s) sélectionné(s)'}
/>
// <AsyncAutocomplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SourceType } from 'types/scope'
import { LabelObject } from 'types/searchCriterias'
import { CHIPS_DISPLAY_METHODS } from './mappers/chipDisplayMapper'
import { BUILD_MAPPERS, UNBUILD_MAPPERS } from './mappers/buildMappers'
import { Reference } from 'types/valueSet'
import { FhirItem, Reference } from 'types/valueSet'

/********************************************************************************/
/* Criteria Types */
Expand Down Expand Up @@ -124,8 +124,6 @@ export type CodeSearchItem = BaseCriteriaItem & {
type: 'codeSearch'
noOptionsText: string
checkIsLeaf?: boolean
/** Ids (urls) of valuesets that are allowed to be used for this code search */
valueSetIds: string[]
valueSetsInfo: Reference[]
}

Expand Down Expand Up @@ -180,6 +178,7 @@ export type DataTypes =
| string
| string[]
| LabelObject[]
| Hierarchy<FhirItem>[]
| number
| Hierarchy<ScopeElement, string>[]
| NumberAndComparatorDataType
Expand Down Expand Up @@ -207,7 +206,7 @@ export type DataTypeMapping = {
numberAndComparator: CriteriaTypeMapping<NumberWithComparatorCriteriaItem, NumberAndComparatorDataType>
boolean: CriteriaTypeMapping<BooleanCriteriaItem, boolean>
textWithCheck: CriteriaTypeMapping<TextWithCheckItem, string>
codeSearch: CriteriaTypeMapping<CodeSearchItem, LabelObject[]>
codeSearch: CriteriaTypeMapping<CodeSearchItem, Hierarchy<FhirItem>[]>
textWithRegex: CriteriaTypeMapping<TextWithRegexCriteriaItem, string>
radioChoice: CriteriaTypeMapping<RadioChoiceCriteriaItem, string>
info: CriteriaTypeMapping<InfoCriteriaItem, string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
WithEncounterStatusDataType,
WithOccurenceCriteriaDataType
} from '../CriteriaForm/types'
import { LabelObject } from 'types/searchCriterias'
import { SourceType } from 'types/scope'
import { getConfig } from 'config'
import { BiologyStatus } from 'types'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { FhirItem } from 'types/valueSet'
import { Hierarchy } from 'types/hierarchy'

export type ObservationDataType = CommonCriteriaData &
WithOccurenceCriteriaDataType &
WithEncounterDateDataType &
WithEncounterStatusDataType & {
type: CriteriaType.OBSERVATION
code: LabelObject[] | null
code: Hierarchy<FhirItem & { isLeaf?: boolean }>[] | null
searchByValue: NumberAndComparatorDataType | null
enableSearchByValue: boolean
}
Expand Down Expand Up @@ -66,13 +68,13 @@ export const form: () => CriteriaForm<ObservationDataType> = () => ({
type: 'codeSearch',
label: 'Codes de biologie',
checkIsLeaf: true,
valueSetIds: [
valueSetsInfo: getValueSetsFromSystems([
getConfig().features.observation.valueSets.biologyHierarchyAnabio.url,
getConfig().features.observation.valueSets.biologyHierarchyLoinc.url
],
]),
noOptionsText: 'Veuillez entrer un code de biologie',
buildInfo: {
fhirKey: ObservationParamsKeys.ANABIO_LOINC,
fhirKey: ObservationParamsKeys.CODE,
buildMethodExtraArgs: [
{ type: 'string', value: getConfig().features.observation.valueSets.biologyHierarchyAnabio.url },
{ type: 'boolean', value: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {
WithEncounterStatusDataType,
WithOccurenceCriteriaDataType
} from '../CriteriaForm/types'
import { LabelObject } from 'types/searchCriterias'
import { SourceType } from 'types/scope'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { Hierarchy } from 'types/hierarchy'
import { FhirItem } from 'types/valueSet'

export type CcamDataType = CommonCriteriaData &
WithOccurenceCriteriaDataType &
WithEncounterDateDataType &
WithEncounterStatusDataType & {
type: CriteriaType.PROCEDURE
code: LabelObject[] | null
code: Hierarchy<FhirItem>[] | null
source: string | null
}

Expand Down Expand Up @@ -86,7 +88,7 @@ export const form: () => CriteriaForm<CcamDataType> = () => ({
valueKey: 'code',
type: 'codeSearch',
label: "Codes d'actes CCAM",
valueSetIds: [getConfig().features.procedure.valueSets.procedureHierarchy.url],
valueSetsInfo: getValueSetsFromSystems([getConfig().features.procedure.valueSets.procedureHierarchy.url]),
noOptionsText: 'Veuillez entrer un code ou un acte CCAM',
buildInfo: {
fhirKey: ProcedureParamsKeys.CODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {
WithEncounterStatusDataType,
WithOccurenceCriteriaDataType
} from '../CriteriaForm/types'
import { LabelObject } from 'types/searchCriterias'
import { SourceType } from 'types/scope'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { FhirItem } from 'types/valueSet'
import { Hierarchy } from 'types/hierarchy'

export type Cim10DataType = CommonCriteriaData &
WithOccurenceCriteriaDataType &
WithEncounterDateDataType &
WithEncounterStatusDataType & {
type: CriteriaType.CONDITION
code: LabelObject[] | null
code: Hierarchy<FhirItem>[] | null
source: string | null
diagnosticType: string[] | null
}
Expand Down Expand Up @@ -87,7 +89,7 @@ export const form: () => CriteriaForm<Cim10DataType> = () => ({
{
valueKey: 'code',
type: 'codeSearch',
valueSetIds: [getConfig().features.condition.valueSets.conditionHierarchy.url],
valueSetsInfo: getValueSetsFromSystems([getConfig().features.condition.valueSets.conditionHierarchy.url]),
noOptionsText: 'Veuillez entrer un code ou un diagnostic CIM10',
label: 'Code CIM10',
buildInfo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
WithEncounterStatusDataType,
WithOccurenceCriteriaDataType
} from '../CriteriaForm/types'
import { LabelObject } from 'types/searchCriterias'
import { Link } from '@mui/material'
import { SourceType } from 'types/scope'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { Hierarchy } from 'types/hierarchy'
import { FhirItem } from 'types/valueSet'

export type GhmDataType = CommonCriteriaData &
WithOccurenceCriteriaDataType &
WithEncounterDateDataType &
WithEncounterStatusDataType & {
type: CriteriaType.CLAIM
code: LabelObject[] | null
code: Hierarchy<FhirItem>[] | null
}

export const form: () => CriteriaForm<GhmDataType> = () => ({
Expand Down Expand Up @@ -71,7 +73,7 @@ export const form: () => CriteriaForm<GhmDataType> = () => ({
{
valueKey: 'code',
type: 'codeSearch',
valueSetIds: [getConfig().features.claim.valueSets.claimHierarchy.url],
valueSetsInfo: getValueSetsFromSystems([getConfig().features.claim.valueSets.claimHierarchy.url]),
noOptionsText: 'Aucun GHM trouvé',
label: 'Code GHM',
buildInfo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import {
WithEncounterStatusDataType,
WithOccurenceCriteriaDataType
} from '../CriteriaForm/types'
import { LabelObject } from 'types/searchCriterias'
import { SourceType } from 'types/scope'
import { getConfig } from 'config'
import { getValueSetsFromSystems } from 'utils/valueSets'
import { Hierarchy } from 'types/hierarchy'
import { FhirItem } from 'types/valueSet'

export type MedicationDataType = CommonCriteriaData &
WithOccurenceCriteriaDataType &
WithEncounterDateDataType &
WithEncounterStatusDataType & {
code: LabelObject[] | null
code: Hierarchy<FhirItem>[] | null
administration: string[] | null
type: CriteriaType.MEDICATION_REQUEST | CriteriaType.MEDICATION_ADMINISTRATION
prescriptionType: string[] | null
Expand Down Expand Up @@ -90,10 +92,10 @@ export const form: () => CriteriaForm<MedicationDataType> = () => ({
type: 'codeSearch',
label: 'Code(s) sélectionné(s)',
noOptionsText: 'Veuillez entrer un code de médicament',
valueSetIds: [
valueSetsInfo: getValueSetsFromSystems([
getConfig().features.medication.valueSets.medicationAtc.url,
getConfig().features.medication.valueSets.medicationUcd.url
],
]),
buildInfo: {
fhirKey: PrescriptionParamsKeys.CODE,
buildMethodExtraArgs: [
Expand Down
6 changes: 3 additions & 3 deletions src/state/valueSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
createSelector
} from '@reduxjs/toolkit'
import { CriteriaItemType } from 'types'
import { CodesCache } from 'types/hierarchy'
import { CodesCache, Hierarchy } from 'types/hierarchy'
import { logout } from './me'
import { LabelObject } from 'types/searchCriterias'
import { RootState } from 'state'
Expand All @@ -18,7 +18,7 @@ import { getCodeList } from 'services/aphp/serviceValueSets'

const valueSetsAdapter = createEntityAdapter<CodesCache<FhirItem>>()

export type CodeCache = { [system: string]: LabelObject[] }
export type CodeCache = { [system: string]: Hierarchy<FhirItem>[] }

export type ValueSetStore = { entities: Dictionary<CodesCache<FhirItem>>; cache: CodeCache }

Expand Down Expand Up @@ -84,7 +84,7 @@ const valueSetsSlice = createSlice({
}),
reducers: {
saveValueSets: (state, action) => valueSetsAdapter.setMany(state, action.payload),
updateCache: (state, action: PayloadAction<{ [system: string]: LabelObject[] }>) => {
updateCache: (state, action: PayloadAction<{ [system: string]: Hierarchy<FhirItem>[] }>) => {
return {
...state,
cache: action.payload
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ export type CriteriaDrawerComponentProps = {
isOpen?: boolean
parentId?: number | null
selectedCriteria: SelectedCriteriaType | null
// TODO remove this when we have the new code search component
onChangeValue?: (key: string, value: any, hierarchy: Hierarchy<any, any>[]) => void
onChangeSelectedCriteria: (newCriteria: SelectedCriteriaType) => void
goBack: () => void
}
Expand Down
Loading

0 comments on commit cce8ec9

Please sign in to comment.