Skip to content

Commit

Permalink
fix(perimeters): filter correct value when searching minimum scope level
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Jul 6, 2023
1 parent b8aeaa7 commit e185f7d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
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 { ScopeTreeRow } from 'types'
import { CriteriaNameType, ScopeTreeRow } from 'types'

import useStyles from './styles'
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
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 { ScopeTreeRow, TreeElement } from 'types'
import { CriteriaNameType, ScopeTreeRow, TreeElement } from 'types'

import { useAppDispatch, useAppSelector } from 'state'
import { expandScopeElement, fetchScopesList, ScopeState, updateScopeList } from 'state/scope'
Expand Down Expand Up @@ -150,7 +150,7 @@ type ScopeTreeProps = {
defaultSelectedItems: ScopeTreeRow[]
onChangeSelectedItem: (selectedItems: ScopeTreeRow[]) => void
searchInput: string
executiveUnitType?: string
executiveUnitType?: CriteriaNameType
}

const ScopeTree: React.FC<ScopeTreeProps> = ({
Expand Down Expand Up @@ -189,8 +189,8 @@ const ScopeTree: React.FC<ScopeTreeProps> = ({
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 = () => {
Expand Down
38 changes: 22 additions & 16 deletions src/services/aphp/servicePerimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ScopePage,
ScopeTreeRow,
ScopeElement,
ChartCode
ChartCode,
CriteriaNameType
} from 'types'
import {
getAgeRepartitionMapAphp,
Expand All @@ -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: [] }

Expand Down Expand Up @@ -73,7 +74,7 @@ export interface IServicePerimeters {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
type?: string,
type?: CriteriaNameType,
signal?: AbortSignal
) => Promise<ScopePage[]>

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

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

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

Expand All @@ -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 = {
Expand Down Expand Up @@ -255,7 +256,7 @@ const servicesPerimeters: IServicePerimeters = {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
type?: string,
type?: CriteriaNameType,
signal?: AbortSignal
) => {
try {
Expand Down Expand Up @@ -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[] =
Expand All @@ -347,7 +348,7 @@ const servicesPerimeters: IServicePerimeters = {
getScopesWithSubItems: async (
subScopesIds: string | null | undefined,
getSubItem?: boolean,
type?: string,
type?: CriteriaNameType,
signal?: AbortSignal
) => {
if (!subScopesIds) return []
Expand Down Expand Up @@ -434,7 +435,7 @@ const servicesPerimeters: IServicePerimeters = {
buildScopeTreeRowList: async (
subScopes: ScopePage[],
getSubItem?: boolean | undefined,
type?: string,
type?: CriteriaNameType,
signal?: AbortSignal
) => {
let scopeRowList: ScopeTreeRow[] = []
Expand Down Expand Up @@ -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) {
Expand All @@ -499,7 +505,7 @@ const servicesPerimeters: IServicePerimeters = {
}
}
}
return higherTypes.length > 0 ? higherTypes : scopeType.typeLevel.flat()
return higherTypes.length > 0 ? higherTypes : scopeTypes.typeLevel.flat()
}
}

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 { ScopeTreeRow } from 'types'
import { CriteriaNameType, ScopeTreeRow } from 'types'

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

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

Expand Down Expand Up @@ -58,7 +58,7 @@ const fetchScopesList = createAsyncThunk<FetchScopeListReturn, FetchScopeListArg
}
)
type fetchScopesListinBackgroundArgs = {
type?: string
type?: CriteriaNameType
signal?: AbortSignal | undefined
}
const fetchScopesListinBackground = createAsyncThunk<
Expand Down Expand Up @@ -102,7 +102,7 @@ type ExpandScopeElementParams = {
scopesList?: ScopeTreeRow[]
selectedItems?: ScopeTreeRow[]
openPopulation?: number[]
type?: string
type?: CriteriaNameType
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?: string) => {
const replaceSubItems = async (items: ScopeTreeRow[], type?: CriteriaNameType) => {
let _items: ScopeTreeRow[] = []
for (let item of items) {
// Replace sub items element by response of back-end
Expand Down

0 comments on commit e185f7d

Please sign in to comment.