From 63754c28a4d0e5823f29a8f4b006abc2454bb1f3 Mon Sep 17 00:00:00 2001 From: aetchego Date: Fri, 8 Nov 2024 15:34:00 +0100 Subject: [PATCH] fields --- .../Dashboard/MedicationList/index.tsx | 146 ++++++++---------- src/components/Filters/CodeFilter/index.tsx | 2 +- .../Filters/ExecutiveUnitsFilter/index.tsx | 2 +- src/components/Hierarchy/CodesWithSystems.tsx | 56 +++++++ src/components/Hierarchy/SelectedCodes.tsx | 26 +--- .../Patient/PatientMedication/index.tsx | 6 - .../SearchValueSet/ValueSetField.tsx | 51 ++---- .../SearchValueSet/ValueSetTable.tsx | 20 +-- src/components/SearchValueSet/index.tsx | 13 +- src/components/ui/Chip/Chips.tsx | 35 ----- .../ui/Inputs/AsyncAutocomplete/index.tsx | 106 ------------- .../ui/Inputs/ExecutiveUnits/styles.tsx | 12 -- src/hooks/hierarchy/useHierarchy.ts | 7 +- src/hooks/scopeTree/useScopeTree.ts | 4 +- src/services/aphp/callApi.ts | 15 -- src/services/aphp/serviceCohortCreation.ts | 117 -------------- src/utils/filters.ts | 13 +- src/utils/valueSets.ts | 42 +++-- 18 files changed, 195 insertions(+), 478 deletions(-) create mode 100644 src/components/Hierarchy/CodesWithSystems.tsx delete mode 100644 src/components/ui/Chip/Chips.tsx delete mode 100644 src/components/ui/Inputs/AsyncAutocomplete/index.tsx delete mode 100644 src/components/ui/Inputs/ExecutiveUnits/styles.tsx diff --git a/src/components/Dashboard/MedicationList/index.tsx b/src/components/Dashboard/MedicationList/index.tsx index 56f9ca539..ef8266324 100644 --- a/src/components/Dashboard/MedicationList/index.tsx +++ b/src/components/Dashboard/MedicationList/index.tsx @@ -261,12 +261,12 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { setTriggerClean(!triggerClean) }, [selectedTab]) - const references = useMemo(() => { - return getValueSetsFromSystems([ - getConfig().features.medication.valueSets.medicationAtc.url, - getConfig().features.medication.valueSets.medicationUcd.url - ]) - }, []) + const references = useMemo(() => { + return getValueSetsFromSystems([ + getConfig().features.medication.valueSets.medicationAtc.url, + getConfig().features.medication.valueSets.medicationUcd.url + ]) + }, []) return ( @@ -473,89 +473,79 @@ const MedicationList = ({ groupId, deidentified }: MedicationListProps) => { validationText="Sauvegarder" > - + + {!deidentified && ( - + )} {!deidentified && ( - - - + )} - - {!deidentified && ( - - )} - {!deidentified && ( - - - - )} - {selectedTab.id === ResourceType.MEDICATION_REQUEST && ( - - )} - {selectedTab.id === ResourceType.MEDICATION_ADMINISTRATION && ( - - )} - - - - - - - + )} + + + + diff --git a/src/components/Filters/CodeFilter/index.tsx b/src/components/Filters/CodeFilter/index.tsx index f60ffc714..223016d19 100644 --- a/src/components/Filters/CodeFilter/index.tsx +++ b/src/components/Filters/CodeFilter/index.tsx @@ -19,7 +19,7 @@ const CodeFilter = ({ name, value, references, disabled = false }: CodeFilterPro useEffect(() => { if (context?.updateFormData) context.updateFormData(name, code) - }, [code]) + }, [code, name]) return ( diff --git a/src/components/Filters/ExecutiveUnitsFilter/index.tsx b/src/components/Filters/ExecutiveUnitsFilter/index.tsx index ec7c72936..c3dbbdf5d 100644 --- a/src/components/Filters/ExecutiveUnitsFilter/index.tsx +++ b/src/components/Filters/ExecutiveUnitsFilter/index.tsx @@ -18,7 +18,7 @@ const ExecutiveUnitsFilter = ({ name, value, sourceType, disabled = false }: Exe useEffect(() => { context?.updateFormData(name, population) - }, [population, context, name]) + }, [population, name]) return ( = { + codes: Hierarchy[] + disabled?: boolean + isExtended?: boolean + onDelete: (node: Hierarchy) => void +} + +const CodesWithSystems = ({ codes, disabled = false, isExtended = true, onDelete }: CodesWithSystemsProps) => { + const groupedBySystem = useMemo(() => groupBySystem(codes), [codes]) + + const ChipGroup = ({ codes }: { codes: Hierarchy[] }) => ( + <> + {codes.map((code) => ( + onDelete(code)} + /> + ))} + + ) + + return ( + <> + {codes.length > 0 && isExtended && ( + + {groupedBySystem.map((group) => ( + + {isDisplayedWithSystem(group.system) && ( + + {`${getLabelFromSystem(group.system)} (${group.codes.length})`} + + )} + + + ))} + + )} + {codes.length > 0 && !isExtended && ( +
+ +
+ )} + + ) +} + +export default CodesWithSystems diff --git a/src/components/Hierarchy/SelectedCodes.tsx b/src/components/Hierarchy/SelectedCodes.tsx index 5cf1ca013..76778f27d 100644 --- a/src/components/Hierarchy/SelectedCodes.tsx +++ b/src/components/Hierarchy/SelectedCodes.tsx @@ -1,19 +1,16 @@ import React, { useState } from 'react' import { Collapse, Grid, Typography } from '@mui/material' -import Chip from 'components/ui/Chip' import { KeyboardArrowDown, KeyboardArrowRight } from '@mui/icons-material' import { Hierarchy } from 'types/hierarchy' -import { v4 as uuidv4 } from 'uuid' -import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets' +import CodesWithSystems from './CodesWithSystems' type SelectedCodesProps = { values: Hierarchy[] - joinDisplayWithCode?: (code: Hierarchy) => boolean - onDelete: (hierarchyElement: Hierarchy) => void + onDelete: (node: Hierarchy) => void } -const SelectedCodes = ({ values, joinDisplayWithCode = () => false, onDelete }: SelectedCodesProps) => { +const SelectedCodes = ({ values, onDelete }: SelectedCodesProps) => { const [openSelectedCodesDrawer, setOpenSelectedCodesDrawer] = useState(false) return ( @@ -26,26 +23,13 @@ const SelectedCodes = ({ values, joinDisplayWithCode = () => false, onDelete justifyContent="space-between" style={{ maxHeight: 200, overflowX: 'hidden', overflowY: 'auto', marginBottom: 20 }} > - {values?.length > 0 && ( - - {values.map((code) => ( - onDelete(code)} - /> - ))} - - )} +
- {values?.length} sélectionné(s) + {values.length} sélectionné(s) diff --git a/src/components/Patient/PatientMedication/index.tsx b/src/components/Patient/PatientMedication/index.tsx index e41da59dc..05e96d033 100644 --- a/src/components/Patient/PatientMedication/index.tsx +++ b/src/components/Patient/PatientMedication/index.tsx @@ -467,7 +467,6 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => { validationText="Sauvegarder" > - { minLimit={2} maxLimit={50} /> - {!searchResults.deidentified && ( - - )} - {!searchResults.deidentified && ( { encounterStatusList={encounterStatusList} /> - diff --git a/src/components/SearchValueSet/ValueSetField.tsx b/src/components/SearchValueSet/ValueSetField.tsx index c95f1b2dd..2d0bbbc94 100644 --- a/src/components/SearchValueSet/ValueSetField.tsx +++ b/src/components/SearchValueSet/ValueSetField.tsx @@ -1,5 +1,5 @@ -import { Chip, FormLabel, Grid, IconButton } from '@mui/material' -import React, { useCallback, useState } from 'react' +import { FormLabel, Grid, IconButton } from '@mui/material' +import React, { useState } from 'react' import { FhirItem, Hierarchy } from 'types/hierarchy' import { Reference } from 'types/valueSet' import SearchValueSet from '.' @@ -7,7 +7,7 @@ import Panel from 'components/ui/Panel' import { SearchOutlined } from '@mui/icons-material' import CloseIcon from '@mui/icons-material/Close' import MoreHorizIcon from '@mui/icons-material/MoreHoriz' -import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets' +import CodesWithSystems from 'components/Hierarchy/CodesWithSystems' type ValueSetFieldProps = { value: Hierarchy[] @@ -20,50 +20,32 @@ type ValueSetFieldProps = { const ValueSetField = ({ value, references, placeholder, disabled = false, onSelect }: ValueSetFieldProps) => { const [openCodeResearch, setOpenCodeResearch] = useState(false) const [isExtended, setIsExtended] = useState(false) - const MAX_CHIP_NUMBER = 1 - const joinDisplayWithCode = useCallback( - (node: Hierarchy) => references.find((ref) => ref.url === node.system)?.joinDisplayWithCode || false, - [references] - ) + const handleDelete = (node: Hierarchy) => { + const newCodes = value.filter((item) => item.id !== node.id) + onSelect(newCodes) + } return ( <> - - - {value.length < 1 && {placeholder}} - {value.length > 0 && ( - - {value.slice(0, isExtended ? value.length : MAX_CHIP_NUMBER).map((code) => ( - - ))} - - )} - + + + {!value.length && {placeholder}} - {isExtended && value.length > MAX_CHIP_NUMBER && ( + {isExtended && ( setIsExtended(false)}> )} - {!isExtended && value.length > MAX_CHIP_NUMBER && ( + {!isExtended && ( setIsExtended(true)}> @@ -83,12 +65,7 @@ const ValueSetField = ({ value, references, placeholder, disabled = false, onSel onConfirm={() => setOpenCodeResearch(false)} open={openCodeResearch} > - + ) diff --git a/src/components/SearchValueSet/ValueSetTable.tsx b/src/components/SearchValueSet/ValueSetTable.tsx index e74a67874..1386f5e19 100644 --- a/src/components/SearchValueSet/ValueSetTable.tsx +++ b/src/components/SearchValueSet/ValueSetTable.tsx @@ -13,14 +13,14 @@ import { Typography } from '@mui/material' import { LoadingStatus, SelectedStatus } from 'types' -import { FhirHierarchy, FhirItem, Hierarchy, HierarchyInfo, Mode, SearchMode } from 'types/hierarchy' +import { FhirHierarchy, FhirItem, Hierarchy, HierarchyInfo, SearchMode } from 'types/hierarchy' import { KeyboardArrowDown, KeyboardArrowRight, IndeterminateCheckBoxOutlined } from '@mui/icons-material' import { CellWrapper, RowContainerWrapper, RowWrapper } from '../Hierarchy/styles' import { sortArray } from 'utils/arrays' import { v4 as uuidv4 } from 'uuid' import { LIMIT_PER_PAGE } from 'hooks/search/useSearchParameters' import { Pagination } from 'components/ui/Pagination' -import { HIERARCHY_ROOT, UNKOWN_HIERARCHY_CHAPTER } from 'services/aphp/serviceValueSets' +import { getLabelFromCode, isDisplayedWithCode } from 'utils/valueSets' type ValueSetRowProps = { item: Hierarchy @@ -29,7 +29,6 @@ type ValueSetRowProps = { path: string[] mode: SearchMode isHierarchy: boolean - joinDisplayWithCode: (code: Hierarchy) => boolean onExpand: (node: Hierarchy) => void onSelect: (node: Hierarchy, toAdd: boolean) => void } @@ -41,15 +40,13 @@ const ValueSetRow = ({ path, mode, isHierarchy, - joinDisplayWithCode, onSelect, onExpand }: ValueSetRowProps) => { const [open, setOpen] = useState(false) const [internalLoading, setInternalLoading] = useState(false) const { label, subItems, status, id } = item - const isCodeDisplayed = joinDisplayWithCode(item) - const canExpand = !(subItems?.length === 0 || subItems) + //const canExpand = !(subItems?.length === 0 || subItems) const handleOpen = () => { setOpen(true) @@ -61,6 +58,8 @@ const ValueSetRow = ({ if (loading.expand === LoadingStatus.SUCCESS) setInternalLoading(false) }, [loading.expand]) + console.log('test label') + return ( <> @@ -79,8 +78,7 @@ const ValueSetRow = ({ )} (open ? setOpen(false) : handleOpen())}> - {isCodeDisplayed && id !== HIERARCHY_ROOT && id !== UNKOWN_HIERARCHY_CHAPTER && <>{id} - } - {label} + {getLabelFromCode(item)} { + sortArray(subItems || [], isDisplayedWithCode(item.system) ? 'id' : 'label').map((subItem) => { return ( @@ -123,7 +120,6 @@ type ValueSetTableProps = { loading: { expand: LoadingStatus; list: LoadingStatus } isHierarchy?: boolean mode: SearchMode - joinDisplayWithCode: (code: Hierarchy) => boolean onExpand: (node: Hierarchy) => void onSelect: (node: Hierarchy, toAdd: boolean) => void onSelectAll: (toAdd: boolean) => void @@ -136,7 +132,6 @@ const ValueSetTable = ({ loading, mode, isHierarchy = true, - joinDisplayWithCode, onSelect, onSelectAll, onExpand, @@ -178,7 +173,6 @@ const ValueSetTable = ({ path={[item.id]} key={item.id} item={item} - joinDisplayWithCode={joinDisplayWithCode} onExpand={onExpand} onSelect={onSelect} /> diff --git a/src/components/SearchValueSet/index.tsx b/src/components/SearchValueSet/index.tsx index f03313f63..faa1cd98f 100644 --- a/src/components/SearchValueSet/index.tsx +++ b/src/components/SearchValueSet/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect } from 'react' +import React, { useEffect } from 'react' import { Grid, Divider, Paper, Collapse, Typography, Input, IconButton } from '@mui/material' import Tabs from 'components/ui/Tabs' import { LoadingStatus, TabType } from 'types' @@ -15,11 +15,10 @@ import { cleanNode } from 'utils/hierarchy/hierarchy' type SearchValueSetProps = { references: Reference[] selectedNodes: Hierarchy[] - joinDisplayWithCode: (code: Hierarchy) => boolean onSelect: (selectedItems: Hierarchy[]) => void } -const SearchValueSet = ({ references, selectedNodes, joinDisplayWithCode, onSelect }: SearchValueSetProps) => { +const SearchValueSet = ({ references, selectedNodes, onSelect }: SearchValueSetProps) => { const { mode, searchInput, @@ -98,7 +97,6 @@ const SearchValueSet = ({ references, selectedNodes, joinDisplayWithCode, onSele isHierarchy={refs.find((ref) => ref.checked)?.isHierarchy} loading={{ list: loadingStatus.init, expand: loadingStatus.expand }} hierarchy={exploration} - joinDisplayWithCode={joinDisplayWithCode} selectAllStatus={selectAllStatus} onSelect={select} onSelectAll={selectAll} @@ -112,7 +110,6 @@ const SearchValueSet = ({ references, selectedNodes, joinDisplayWithCode, onSele selectAllStatus={selectAllStatus} isHierarchy={false} loading={{ list: loadingStatus.search, expand: loadingStatus.expand }} - joinDisplayWithCode={joinDisplayWithCode} hierarchy={research} onSelect={select} onSelectAll={selectAll} @@ -124,11 +121,7 @@ const SearchValueSet = ({ references, selectedNodes, joinDisplayWithCode, onSele
- select(code, false)} - joinDisplayWithCode={joinDisplayWithCode} - /> + select(code, false)} />
diff --git a/src/components/ui/Chip/Chips.tsx b/src/components/ui/Chip/Chips.tsx deleted file mode 100644 index e10b400db..000000000 --- a/src/components/ui/Chip/Chips.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react' - -import Grid from '@mui/material/Grid' -import Chip from '@mui/material/Chip' - -import { useStyles } from './styles' - -export type ChipsProps = { - value: { - id: T - label: TL - onDelete: (value: T) => void - }[] -} -const Chips = ({ value }: ChipsProps) => { - const { classes } = useStyles() - - return ( - - {value?.length > 0 && - value.map(({ label, id, onDelete }) => ( - - ))} - - ) -} - -export default Chips diff --git a/src/components/ui/Inputs/AsyncAutocomplete/index.tsx b/src/components/ui/Inputs/AsyncAutocomplete/index.tsx deleted file mode 100644 index 64af8b42b..000000000 --- a/src/components/ui/Inputs/AsyncAutocomplete/index.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import React, { useEffect, useState, Fragment, useRef, SyntheticEvent, ReactNode } from 'react' - -import { Autocomplete, CircularProgress, TextField } from '@mui/material' -import { cancelPendingRequest } from 'utils/abortController' -import { LabelObject } from 'types/searchCriterias' -import { useDebounce } from 'utils/debounce' - -type AsyncAutocompleteProps = { - variant?: 'standard' | 'filled' | 'outlined' - label?: ReactNode - className?: string - values?: LabelObject[] - noOptionsText?: string - helperText?: string - disabled?: boolean - onFetch: (options: string, signal: AbortSignal) => Promise - onChange: (elem: LabelObject[]) => void -} - -const AsyncAutocomplete = ({ - variant, - label, - className, - values = [], - noOptionsText, - helperText, - disabled = false, - onChange, - onFetch -}: AsyncAutocompleteProps) => { - const [open, setOpen] = useState(false) - const [searchValue, setSearchValue] = useState('') - const debouncedSearchValue = useDebounce(500, searchValue) - const [options, setOptions] = useState([]) - const [loading, setLoading] = useState(false) - const controllerRef = useRef(null) - - useEffect(() => { - const handleRequest = async () => { - if (!onFetch) return - setLoading(true) - controllerRef.current = cancelPendingRequest(controllerRef.current) - const response = (await onFetch(debouncedSearchValue, controllerRef.current?.signal)) || [] - setOptions(response) - setLoading(false) - } - handleRequest() - }, [debouncedSearchValue]) - - useEffect(() => { - if (!open) { - setOptions([]) - } - }, [open]) - - return ( - { - setOpen(true) - }} - onClose={() => { - setOpen(false) - }} - open={open} - className={className} - multiple - noOptionsText={noOptionsText} - loadingText={'Chargement en cours...'} - loading={loading} - value={values} - autoComplete - filterSelectedOptions - onChange={(event: SyntheticEvent, newValue: LabelObject[]) => { - onChange(newValue) - }} - options={options} - filterOptions={(x) => x} - isOptionEqualToValue={(option, value) => option.id === value.id} - getOptionLabel={(option) => option.label} - renderInput={(params) => ( - { - setSearchValue(e.target.value) - }} - InputProps={{ - ...params.InputProps, - endAdornment: ( - - {loading ? : null} - {params.InputProps.endAdornment} - - ) - }} - /> - )} - /> - ) -} - -export default AsyncAutocomplete diff --git a/src/components/ui/Inputs/ExecutiveUnits/styles.tsx b/src/components/ui/Inputs/ExecutiveUnits/styles.tsx deleted file mode 100644 index 37d87b3b2..000000000 --- a/src/components/ui/Inputs/ExecutiveUnits/styles.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { styled } from '@mui/material' - -export const ExecutiveUnitsWrapper = styled('div')(() => ({ - display: 'flex', - alignItems: 'center', - justifyContent: 'space-between', - border: '1px solid rgba(0,0,0,0.25)', - padding: '5px 14px', - width: '100%', - borderRadius: '4px', - color: 'rgba(0, 0, 0, 0.6)' -})) diff --git a/src/hooks/hierarchy/useHierarchy.ts b/src/hooks/hierarchy/useHierarchy.ts index 270bb76f6..47e01c884 100644 --- a/src/hooks/hierarchy/useHierarchy.ts +++ b/src/hooks/hierarchy/useHierarchy.ts @@ -10,7 +10,7 @@ import { getHierarchyRootCodes, mapHierarchyToMap } from '../../utils/hierarchy/hierarchy' -import { useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { Back_API_Response, LoadingStatus, SelectedStatus } from 'types' import { getSelectedCodes } from 'utils/hierarchy/hierarchy' import { Codes, Hierarchy, HierarchyInfo, HierarchyLoadingStatus, Mode, SearchMode } from '../../types/hierarchy' @@ -27,6 +27,7 @@ export const useHierarchy = ( onCache: (codes: Codes>) => void, fetchHandler: (ids: string, system: string) => Promise[]> ) => { + console.log('test loop hier') const DEFAULT_HIERARCHY_INFO = { tree: [], count: 0, @@ -124,7 +125,7 @@ export const useHierarchy = ( setSelectedCodes(replaceInMap(hierarchyId, newSelectedCodes, selectedCodes)) } - const selectAll = (toAdd: boolean) => { + const selectAll = useCallback((toAdd: boolean) => { /*const mode = toAdd ? Mode.SELECT_ALL : Mode.UNSELECT_ALL const newTree = buildHierarchy(currentHierarchy.tree, currentHierarchy.display, codes, selectedCodes, mode) const newDisplay = getHierarchyDisplay(currentHierarchy.display, newTree) @@ -132,7 +133,7 @@ export const useHierarchy = ( setElemInHierarchies(currentHierarchy.id, newTree, newDisplay) setSelectedCodes(newSelectedCodes)*/ /* test*/ - } + }, []) const expand = async (node: Hierarchy) => { setLoadingStatus({ ...loadingStatus, expand: LoadingStatus.FETCHING }) diff --git a/src/hooks/scopeTree/useScopeTree.ts b/src/hooks/scopeTree/useScopeTree.ts index a0311790e..46c7c7f48 100644 --- a/src/hooks/scopeTree/useScopeTree.ts +++ b/src/hooks/scopeTree/useScopeTree.ts @@ -41,10 +41,10 @@ export const useScopeTree = ( return results } - const handleSaveCodes = useCallback((codes: Codes>) => { + const handleSaveCodes = (codes: Codes>) => { const entity = mapCodesToCache(codes)?.[0] dispatch(saveScopeCodes({ isRights: sourceType === SourceType.ALL, values: entity })) - }, []) + } const { hierarchies, diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 1a1e9c900..9ed0784f8 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -1042,21 +1042,6 @@ export const fetchLocation = async (args: fetchLocationProps) => { return response } -export type FetchValueSetOptions = { - // the first 3 param are mutually exclusive - valueSetTitle?: string // an optional valueset node title for fetching valueset roots - codes?: string[] // an optional list of codes to fetch - search?: string // an optional search query - // other optional params - exactSearch?: boolean // legacy param, if set to true, the search param will be considered to be a single code - joinDisplayWithCode?: boolean // join the code and display for the label of nodes - offset?: number // offset for pagination (only used for searching codes or query search), default = 0 - count?: number // count for pagination (only used for searching codes or query search), default = 100 - orderBy?: OrderBy // legacy param, unused for now with the new search endpoint TODO: should be passed someway if needed - filterRoots?: (code: HierarchyWithLabel) => boolean // legacy param used to filter in only some roots results (for some broken valuesets) - filterOut?: (code: HierarchyWithLabel) => boolean // same usage as filterRoots but to filter out some results (should be merged with prev param ...) -} - export const fetchAccessExpirations: ( args: AccessExpirationsProps ) => Promise>> = async (args: AccessExpirationsProps) => { diff --git a/src/services/aphp/serviceCohortCreation.ts b/src/services/aphp/serviceCohortCreation.ts index bbba75f36..0250ad55d 100644 --- a/src/services/aphp/serviceCohortCreation.ts +++ b/src/services/aphp/serviceCohortCreation.ts @@ -176,123 +176,6 @@ const servicesCohortCreation: IServiceCohortCreation = { return snapshotResponse.data || {} } - /*fetchCim10Diagnostic: async (searchValue: string, signal?: AbortSignal) => - ( - await searchInValueSets( - [getConfig().features.condition.valueSets.conditionHierarchy.url], - searchValue, - undefined, - undefined, - signal - ) - ).results, - //remplacer par Harmonisation - fetchCim10Hierarchy: async (cim10Parent?: string) => - fetchValueSet(getConfig().features.condition.valueSets.conditionHierarchy.url, { - valueSetTitle: 'Toute la hiérarchie CIM10', - codes: cim10Parent ? [cim10Parent] : [] - }), - //remplacer par Harmonisation - fetchCcamData: async (searchValue?: string, exactSearch?: boolean, signal?: AbortSignal) => - fetchValueSet( - getConfig().features.procedure.valueSets.procedureHierarchy.url, - { valueSetTitle: 'Toute la hiérarchie', search: searchValue || '', exactSearch }, - signal - ), - //remplacer par Harmonisation - fetchCcamHierarchy: async (ccamParent?: string) => - fetchValueSet(getConfig().features.procedure.valueSets.procedureHierarchy.url, { - valueSetTitle: 'Toute la hiérarchie CCAM', - codes: ccamParent ? [ccamParent] : [] - }), - //remplacer par Harmonisation - fetchGhmData: async (searchValue?: string, exactSearch?: boolean, signal?: AbortSignal) => - fetchValueSet( - getConfig().features.claim.valueSets.claimHierarchy.url, - { valueSetTitle: 'Toute la hiérarchie', search: searchValue || '', exactSearch }, - signal - ), - //remplacer par Harmonisation - fetchGhmHierarchy: async (ghmParent?: string) => - fetchValueSet(getConfig().features.claim.valueSets.claimHierarchy.url, { - valueSetTitle: 'Toute la hiérarchie GHM', - codes: [ghmParent] - }), - fetchMedicationData: async (searchValue?: string, exactSearch?: boolean, signal?: AbortSignal) => - fetchValueSet( - `${getConfig().features.medication.valueSets.medicationAtc.url},${ - getConfig().features.medication.valueSets.medicationUcd.url - }`, - { - valueSetTitle: 'Toute la hiérarchie', - search: searchValue || '', - exactSearch - }, - signal - ), - fetchSingleCodeHierarchy: async (resourceType: string, code: string) => { - const codeSystemPerResourceType: { [type: string]: string } = { - Claim: getConfig().features.claim.valueSets.claimHierarchy.url, - Condition: getConfig().features.condition.valueSets.conditionHierarchy.url, - MedicationAdministration: `${getConfig().features.medication.valueSets.medicationAtc.url},${ - getConfig().features.medication.valueSets.medicationUcd.url - }`, - MedicationRequest: `${getConfig().features.medication.valueSets.medicationAtc.url},${ - getConfig().features.medication.valueSets.medicationUcd.url - }`, - Observation: `${getConfig().features.observation.valueSets.biologyHierarchyAnabio.url},${ - getConfig().features.observation.valueSets.biologyHierarchyLoinc.url - }`, - Procedure: getConfig().features.procedure.valueSets.procedureHierarchy.url - } - if (!(resourceType in codeSystemPerResourceType)) { - // TODO log error - return Promise.resolve([] as string[]) - } - const fhirCode = await getChildrenFromCodes(codeSystemPerResourceType[resourceType], [code]) - return fhirCode.results[0]?.parentIds || [] - }, - fetchAtcHierarchy: async (atcParent?: string) => - fetchValueSet(getConfig().features.medication.valueSets.medicationAtc.url, { - valueSetTitle: 'Toute la hiérarchie Médicament', - codes: atcParent ? [atcParent] : [], - orderBy: { orderBy: Order.CODE, orderDirection: Direction.ASC }, - filterRoots: (atcData) => - // V--[ @TODO: This is a hot fix, remove this after a clean of data ]--V - atcData.label.search(new RegExp(/^[A-Z] - /, 'gi')) !== -1 && - atcData.label.search(new RegExp(/^[X-Y] - /, 'gi')) !== 0 - }), - fetchUCDList: async (ucd?: string) => - fetchValueSet(getConfig().features.medication.valueSets.medicationUcd.url, { codes: [ucd] }), - fetchBiologyData: async (searchValue?: string, exactSearch?: boolean) => - fetchValueSet( - `${getConfig().features.observation.valueSets.biologyHierarchyAnabio.url},${ - getConfig().features.observation.valueSets.biologyHierarchyLoinc.url - }`, - { - valueSetTitle: 'Toute la hiérarchie', - search: searchValue || '', - exactSearch, - joinDisplayWithCode: false - } - ), - fetchBiologyHierarchy: async (biologyParent?: string) => - fetchValueSet(getConfig().features.observation.valueSets.biologyHierarchyAnabio.url, { - valueSetTitle: 'Toute la hiérarchie de Biologie', - codes: biologyParent ? [biologyParent] : [], - joinDisplayWithCode: false, - filterRoots: (biologyItem) => - biologyItem.id !== '527941' && - biologyItem.id !== '547289' && - biologyItem.id !== '528247' && - biologyItem.id !== '981945' && - biologyItem.id !== '834019' && - biologyItem.id !== '528310' && - biologyItem.id !== '528049' && - biologyItem.id !== '527570' && - biologyItem.id !== '527614' - }), - fetchBiologySearch: fetchBiologySearch*/ } export default servicesCohortCreation diff --git a/src/utils/filters.ts b/src/utils/filters.ts index a5c2c1c1a..111997f19 100644 --- a/src/utils/filters.ts +++ b/src/utils/filters.ts @@ -17,8 +17,7 @@ import { ScopeElement, SimpleCodeType, ValueSet } from 'types' import { getDurationRangeLabel } from './age' import { CohortsType, CohortsTypeLabel } from 'types/cohorts' import { Hierarchy } from 'types/hierarchy' -import { getValueSetsFromSystems } from './valueSets' -import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets' +import { getFullLabelFromCode } from './valueSets' export const getCohortsTypeLabel = (type: CohortsType): string => { switch (type) { @@ -124,15 +123,7 @@ export const getFilterLabel = (key: FilterKeys, value: FilterValue): string => { return `IPP : ${value}` } if (key === FilterKeys.CODE) { - const casted = value as LabelObject - let label = 'Code : ' - if (casted.system) { - const system = getValueSetsFromSystems([casted.system])?.[0] - if (system.joinDisplayWithSystem) label += `${system.label} - ` - if (casted.id !== HIERARCHY_ROOT && system.joinDisplayWithCode) label += `${casted.id} - ` - } - label += casted.label - return label + return `Code : ${getFullLabelFromCode(value as LabelObject)}` } if (key === FilterKeys.SOURCE) { return `Source : ${value}` diff --git a/src/utils/valueSets.ts b/src/utils/valueSets.ts index a2053a087..6403a7fc7 100644 --- a/src/utils/valueSets.ts +++ b/src/utils/valueSets.ts @@ -1,19 +1,41 @@ import { getConfig } from 'config' import { getReferences } from 'data/valueSets' +import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets' +import { Hierarchy } from 'types/hierarchy' import { LabelObject } from 'types/searchCriterias' export const getValueSetsFromSystems = (systems: string[]) => { return getReferences(getConfig()).filter((reference) => systems.includes(reference.url)) } -export const displaySystem = (labelObject: LabelObject) => { - console.log('test criterion display ', labelObject) - let display = "" - const valueSet = getValueSetsFromSystems([labelObject.system || ''])?.[0] || null - if (valueSet) { - if (valueSet.joinDisplayWithSystem) display += `${valueSet.label} : ` - if (valueSet.joinDisplayWithCode) display += `${labelObject.id} - ` - } - display += labelObject.label - return display +export const isDisplayedWithCode = (system: string) => { + const isFound = getValueSetsFromSystems([system])?.[0] + if (isFound && isFound.joinDisplayWithCode) return true + return false +} + +export const isDisplayedWithSystem = (system: string) => { + const isFound = getValueSetsFromSystems([system])?.[0] + if (isFound && isFound.joinDisplayWithSystem) return true + return false +} + +export const getLabelFromCode = (code: Hierarchy) => { + if (isDisplayedWithCode(code.system) && code.id !== HIERARCHY_ROOT) return `${code.id} - ${code.label}` + return code.label +} + +export const getFullLabelFromCode = (code: LabelObject) => { + let label = '' + if (code.system) { + if (isDisplayedWithSystem(code.system)) label+= `${getLabelFromSystem(code.system)} - ` + if (isDisplayedWithCode(code.system) && code.id !== HIERARCHY_ROOT) label += `${code.id} - ` + } + label += code.label + return label +} + +export const getLabelFromSystem = (system: string) => { + const isFound = getValueSetsFromSystems([system])?.[0] + return isFound?.label || '' }