diff --git a/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx b/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx index 329f5e468..b28f05be9 100644 --- a/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx +++ b/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx @@ -5,7 +5,7 @@ import Drawer from '@mui/material/Drawer' import Typography from '@mui/material/Typography' import ScopeTree from 'components/ScopeTree/ScopeTree' -import { ScopeTreeRow } from 'types' +import { CriteriaNameType, ScopeTreeRow } from 'types' import useStyles from './styles' import ScopeSearchBar from 'components/Inputs/ScopeSearchBar/ScopeSearchBar' @@ -13,7 +13,7 @@ import ScopeSearchBar from 'components/Inputs/ScopeSearchBar/ScopeSearchBar' type PopulationRightPanelProps = { open: boolean title?: string - executiveUnitType?: string + executiveUnitType?: CriteriaNameType selectedPopulation: ScopeTreeRow[] isAcceptEmptySelection?: boolean onConfirm: (selectedPopulation: ScopeTreeRow[]) => void diff --git a/src/components/ScopeTree/ScopeTree.tsx b/src/components/ScopeTree/ScopeTree.tsx index 044c7586f..e5eba67dd 100644 --- a/src/components/ScopeTree/ScopeTree.tsx +++ b/src/components/ScopeTree/ScopeTree.tsx @@ -21,7 +21,7 @@ import { import KeyboardArrowRightIcon from '@mui/icons-material/ChevronRight' import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' import EnhancedTable from 'components/ScopeTree/ScopeTreeTable' -import { ScopeTreeRow, TreeElement } from 'types' +import { CriteriaNameType, ScopeTreeRow, TreeElement } from 'types' import { useAppDispatch, useAppSelector } from 'state' import { expandScopeElement, fetchScopesList, ScopeState, updateScopeList } from 'state/scope' @@ -150,7 +150,7 @@ type ScopeTreeProps = { defaultSelectedItems: ScopeTreeRow[] onChangeSelectedItem: (selectedItems: ScopeTreeRow[]) => void searchInput: string - executiveUnitType?: string + executiveUnitType?: CriteriaNameType } const ScopeTree: React.FC = ({ @@ -189,8 +189,8 @@ const ScopeTree: React.FC = ({ const isHeadIndetermined: boolean = !isAllSelected && selectedItems && selectedItems.length > 0 && rootRows && !isHeadChecked - const fetchScopeTree = async (executiveUnitType?: string, signal?: AbortSignal) => { - return dispatch(fetchScopesList({ signal })).unwrap() + const fetchScopeTree = async (executiveUnitType?: CriteriaNameType, signal?: AbortSignal) => { + return dispatch(fetchScopesList({ signal, type: executiveUnitType })).unwrap() } const _cancelPendingRequest = () => { diff --git a/src/services/aphp/servicePerimeters.ts b/src/services/aphp/servicePerimeters.ts index 8114302f6..76430656c 100644 --- a/src/services/aphp/servicePerimeters.ts +++ b/src/services/aphp/servicePerimeters.ts @@ -5,7 +5,8 @@ import { ScopePage, ScopeTreeRow, ScopeElement, - ChartCode + ChartCode, + CriteriaNameType } from 'types' import { getAgeRepartitionMapAphp, @@ -21,7 +22,7 @@ import apiBackend from '../apiBackend' import { sortByQuantityAndName } from 'utils/scopeTree' import { AxiosResponse } from 'axios' import { Group } from 'fhir/r4' -import scopeType from '../../data/scope_type.json' +import scopeTypes from '../../data/scope_type.json' export const loadingItem: ScopeTreeRow = { id: 'loading', name: 'loading', quantity: 0, subItems: [] } @@ -73,7 +74,7 @@ export interface IServicePerimeters { defaultPerimetersIds?: string[], cohortIds?: string[], noPerimetersIdsFetch?: boolean, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => Promise @@ -88,7 +89,7 @@ export interface IServicePerimeters { * Retour: * - ScopeTreeRow[] */ - getScopePerimeters: (practitionerId: string, type?: string, signal?: AbortSignal) => Promise + getScopePerimeters: (practitionerId: string, type?: CriteriaNameType, signal?: AbortSignal) => Promise /** * Cette fonction retoune l'ensemble des périmètres enfant d'un périmètre passé en argument @@ -103,7 +104,7 @@ export interface IServicePerimeters { getScopesWithSubItems: ( subScopesIds: string | null | undefined, getSubItem?: boolean, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => Promise @@ -125,7 +126,7 @@ export interface IServicePerimeters { buildScopeTreeRowList: ( subScopes: ScopePage[], getSubItem?: boolean | undefined, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => Promise @@ -147,7 +148,7 @@ export interface IServicePerimeters { * construire la liste des types des périmètres en haut du type. Sinon tous les types. * @param type */ - getHigherTypes: (type?: string) => string[] + getHigherTypes: (type?: CriteriaNameType) => string[] } const servicesPerimeters: IServicePerimeters = { @@ -255,7 +256,7 @@ const servicesPerimeters: IServicePerimeters = { defaultPerimetersIds?: string[], cohortIds?: string[], noPerimetersIdsFetch?: boolean, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => { try { @@ -330,7 +331,7 @@ const servicesPerimeters: IServicePerimeters = { } }, - getScopePerimeters: async (practitionerId, type?: string, signal?: AbortSignal) => { + getScopePerimeters: async (practitionerId, type?: CriteriaNameType, signal?: AbortSignal) => { if (!practitionerId) return [] const scopeItemList: ScopePage[] = @@ -347,7 +348,7 @@ const servicesPerimeters: IServicePerimeters = { getScopesWithSubItems: async ( subScopesIds: string | null | undefined, getSubItem?: boolean, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => { if (!subScopesIds) return [] @@ -434,7 +435,7 @@ const servicesPerimeters: IServicePerimeters = { buildScopeTreeRowList: async ( subScopes: ScopePage[], getSubItem?: boolean | undefined, - type?: string, + type?: CriteriaNameType, signal?: AbortSignal ) => { let scopeRowList: ScopeTreeRow[] = [] @@ -484,13 +485,18 @@ const servicesPerimeters: IServicePerimeters = { return `${perimeterID} - ${perimeter.name}` }, - getHigherTypes: (type?: string) => { + getHigherTypes: (type?: CriteriaNameType) => { + if (!type) { + return scopeTypes.typeLevel.flat() + } + const higherTypes: string[] = [] - if (type) { + const scopeType = scopeTypes.criteriaType[type] + if (scopeType) { let isFoundValue = false - for (const currentLevel of [...scopeType.typeLevel].reverse()) { + for (const currentLevel of [...scopeTypes.typeLevel].reverse()) { for (const valueInTheSameLevel of currentLevel) { - if (valueInTheSameLevel === type) { + if (valueInTheSameLevel === scopeType) { isFoundValue = true } if (isFoundValue) { @@ -499,7 +505,7 @@ const servicesPerimeters: IServicePerimeters = { } } } - return higherTypes.length > 0 ? higherTypes : scopeType.typeLevel.flat() + return higherTypes.length > 0 ? higherTypes : scopeTypes.typeLevel.flat() } } diff --git a/src/state/scope.ts b/src/state/scope.ts index 8c3d510a9..a7007478c 100644 --- a/src/state/scope.ts +++ b/src/state/scope.ts @@ -5,7 +5,7 @@ import { logout, login } from './me' import services from 'services/aphp' -import { ScopeTreeRow } from 'types' +import { CriteriaNameType, ScopeTreeRow } from 'types' export type ScopeState = { loading: boolean @@ -27,7 +27,7 @@ type FetchScopeListReturn = { } type FetchScopeListArgs = { - type?: string + type?: CriteriaNameType signal?: AbortSignal | undefined } @@ -58,7 +58,7 @@ const fetchScopesList = createAsyncThunk { + const replaceSubItems = async (items: ScopeTreeRow[], type?: CriteriaNameType) => { let _items: ScopeTreeRow[] = [] for (let item of items) { // Replace sub items element by response of back-end