Skip to content

Commit

Permalink
fix(scopetree): limit expand to min scope type
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Jul 6, 2023
1 parent 4475845 commit 299f2a3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { buildCohortCreation, CohortCreationState } from 'state/cohortCreation'
import { fetchScopesList, ScopeState } from 'state/scope'
import { MeState } from 'state/me'

import { CriteriaNameType, ScopeTreeRow } from 'types'
import { CriteriaNameType, ScopeType, ScopeTreeRow } from 'types'
import { getSelectedScopes } from 'utils/scopeTree'
import scopeTypes from 'data/scope_type.json'

import useStyles from './styles'

Expand Down Expand Up @@ -221,7 +222,7 @@ const PopulationCard: React.FC<populationCardPropsType> = (props) => {
title={title}
isAcceptEmptySelection={isAcceptEmptySelection}
selectedPopulation={selectedItems}
executiveUnitType={form ?? undefined}
executiveUnitType={form ? (scopeTypes.criteriaType[form] as ScopeType) : undefined}
onConfirm={_onSubmit}
onClose={() => onChangeOpenDrawer(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import Drawer from '@mui/material/Drawer'
import Typography from '@mui/material/Typography'

import ScopeTree from 'components/ScopeTree/ScopeTree'
import { CriteriaNameType, ScopeTreeRow } from 'types'
import { ScopeType, ScopeTreeRow } from 'types'

import useStyles from './styles'
import ScopeSearchBar from 'components/Inputs/ScopeSearchBar/ScopeSearchBar'

type PopulationRightPanelProps = {
open: boolean
title?: string
executiveUnitType?: CriteriaNameType
executiveUnitType?: ScopeType
selectedPopulation: ScopeTreeRow[]
isAcceptEmptySelection?: boolean
onConfirm: (selectedPopulation: ScopeTreeRow[]) => void
Expand Down
8 changes: 4 additions & 4 deletions src/components/ScopeTree/ScopeTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { CriteriaNameType, ScopeTreeRow, TreeElement } from 'types'
import { ScopeType, ScopeTreeRow, TreeElement } from 'types'

import { useAppDispatch, useAppSelector } from 'state'
import { expandScopeElement, fetchScopesList, ScopeState, updateScopeList } from 'state/scope'
Expand Down Expand Up @@ -91,7 +91,7 @@ const ScopeTreeListItem: React.FC<ScopeTreeListItemProps> = (props) => {
}}
>
<TableCell>
{row.subItems && row.subItems.length > 0 && (
{row.subItems && row.subItems.length > 0 && row.type !== executiveUnitType && (
<IconButton
onClick={() => onExpand(row.id)}
style={{ marginLeft: level * 35, padding: 0, marginRight: -30 }}
Expand Down Expand Up @@ -150,7 +150,7 @@ type ScopeTreeProps = {
defaultSelectedItems: ScopeTreeRow[]
onChangeSelectedItem: (selectedItems: ScopeTreeRow[]) => void
searchInput: string
executiveUnitType?: CriteriaNameType
executiveUnitType?: ScopeType
}

const ScopeTree: React.FC<ScopeTreeProps> = ({
Expand Down Expand Up @@ -189,7 +189,7 @@ const ScopeTree: React.FC<ScopeTreeProps> = ({
const isHeadIndetermined: boolean =
!isAllSelected && selectedItems && selectedItems.length > 0 && rootRows && !isHeadChecked

const fetchScopeTree = async (executiveUnitType?: CriteriaNameType, signal?: AbortSignal) => {
const fetchScopeTree = async (executiveUnitType?: ScopeType, signal?: AbortSignal) => {
return dispatch(fetchScopesList({ signal, type: executiveUnitType })).unwrap()
}

Expand Down
27 changes: 13 additions & 14 deletions src/services/aphp/servicePerimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ScopeTreeRow,
ScopeElement,
ChartCode,
CriteriaNameType
ScopeType
} from 'types'
import {
getAgeRepartitionMapAphp,
Expand Down Expand Up @@ -74,7 +74,7 @@ export interface IServicePerimeters {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => Promise<ScopePage[]>

Expand All @@ -89,7 +89,7 @@ export interface IServicePerimeters {
* Retour:
* - ScopeTreeRow[]
*/
getScopePerimeters: (practitionerId: string, type?: CriteriaNameType, signal?: AbortSignal) => Promise<ScopeTreeRow[]>
getScopePerimeters: (practitionerId: string, type?: ScopeType, signal?: AbortSignal) => Promise<ScopeTreeRow[]>

/**
* Cette fonction retoune l'ensemble des périmètres enfant d'un périmètre passé en argument
Expand All @@ -104,7 +104,7 @@ export interface IServicePerimeters {
getScopesWithSubItems: (
subScopesIds: string | null | undefined,
getSubItem?: boolean,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => Promise<ScopeTreeRow[]>

Expand All @@ -126,7 +126,7 @@ export interface IServicePerimeters {
buildScopeTreeRowList: (
subScopes: ScopePage[],
getSubItem?: boolean | undefined,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => Promise<ScopeTreeRow[]>

Expand All @@ -148,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?: CriteriaNameType) => string[]
getHigherTypes: (type?: ScopeType) => string[]
}

const servicesPerimeters: IServicePerimeters = {
Expand Down Expand Up @@ -256,7 +256,7 @@ const servicesPerimeters: IServicePerimeters = {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => {
try {
Expand Down Expand Up @@ -331,7 +331,7 @@ const servicesPerimeters: IServicePerimeters = {
}
},

getScopePerimeters: async (practitionerId, type?: CriteriaNameType, signal?: AbortSignal) => {
getScopePerimeters: async (practitionerId, type?: ScopeType, signal?: AbortSignal) => {
if (!practitionerId) return []

const scopeItemList: ScopePage[] =
Expand All @@ -348,7 +348,7 @@ const servicesPerimeters: IServicePerimeters = {
getScopesWithSubItems: async (
subScopesIds: string | null | undefined,
getSubItem?: boolean,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => {
if (!subScopesIds) return []
Expand Down Expand Up @@ -435,7 +435,7 @@ const servicesPerimeters: IServicePerimeters = {
buildScopeTreeRowList: async (
subScopes: ScopePage[],
getSubItem?: boolean | undefined,
type?: CriteriaNameType,
type?: ScopeType,
signal?: AbortSignal
) => {
let scopeRowList: ScopeTreeRow[] = []
Expand Down Expand Up @@ -485,18 +485,17 @@ const servicesPerimeters: IServicePerimeters = {
return `${perimeterID} - ${perimeter.name}`
},

getHigherTypes: (type?: CriteriaNameType) => {
getHigherTypes: (type?: ScopeType) => {
if (!type) {
return scopeTypes.typeLevel.flat()
}

const higherTypes: string[] = []
const scopeType = scopeTypes.criteriaType[type]
if (scopeType) {
if (type) {
let isFoundValue = false
for (const currentLevel of [...scopeTypes.typeLevel].reverse()) {
for (const valueInTheSameLevel of currentLevel) {
if (valueInTheSameLevel === scopeType) {
if (valueInTheSameLevel === type) {
isFoundValue = true
}
if (isFoundValue) {
Expand Down
10 changes: 5 additions & 5 deletions src/state/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logout, login } from './me'

import services from 'services/aphp'

import { CriteriaNameType, ScopeTreeRow } from 'types'
import { ScopeType, ScopeTreeRow } from 'types'

export type ScopeState = {
loading: boolean
Expand All @@ -27,7 +27,7 @@ type FetchScopeListReturn = {
}

type FetchScopeListArgs = {
type?: CriteriaNameType
type?: ScopeType
signal?: AbortSignal | undefined
}

Expand Down Expand Up @@ -58,7 +58,7 @@ const fetchScopesList = createAsyncThunk<FetchScopeListReturn, FetchScopeListArg
}
)
type fetchScopesListinBackgroundArgs = {
type?: CriteriaNameType
type?: ScopeType
signal?: AbortSignal | undefined
}
const fetchScopesListinBackground = createAsyncThunk<
Expand Down Expand Up @@ -102,7 +102,7 @@ type ExpandScopeElementParams = {
scopesList?: ScopeTreeRow[]
selectedItems?: ScopeTreeRow[]
openPopulation?: number[]
type?: CriteriaNameType
type?: ScopeType
signal?: AbortSignal
}
type ExpandScopeElementReturn = {
Expand Down Expand Up @@ -135,7 +135,7 @@ const expandScopeElement = createAsyncThunk<ExpandScopeElementReturn, ExpandScop
} else {
_openPopulation = [..._openPopulation, params.rowId]

const replaceSubItems = async (items: ScopeTreeRow[], type?: CriteriaNameType) => {
const replaceSubItems = async (items: ScopeTreeRow[], type?: ScopeType) => {
let _items: ScopeTreeRow[] = []
for (let item of items) {
// Replace sub items element by response of back-end
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,14 @@ export type AgeRangeType = {
days?: number
}

export type ScopeType =
| 'AP-HP'
| 'Groupe hospitalier (GH)'
| 'GHU'
| 'Hôpital'
| 'Pôle/DMU'
| 'Unité Fonctionnelle (UF)'

export enum CriteriaName {
Cim10 = 'cim10',
Ccam = 'ccam',
Expand Down

0 comments on commit 299f2a3

Please sign in to comment.