Skip to content

Commit

Permalink
feat: request cleanup if pseudo - Ref gestion-de-projet#2563 (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManelleG authored Apr 16, 2024
1 parent 4c8ac20 commit 2de4b6a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import scopeTypes from 'data/scope_type.json'
import useStyles from './styles'
import { findEquivalentRowInItemAndSubItems } from 'utils/pmsi'
import { getCurrentScopeList } from 'utils/scopeTree'
import { cleanCriterias } from 'utils/cohortCreation'

export type PopulationCardPropsType = {
label?: string
Expand Down Expand Up @@ -66,6 +67,9 @@ const PopulationCard: React.FC<PopulationCardPropsType> = (props) => {
const selectionAndPopulationWithRightError = [...selectedItems, ...populationWithRightError]

const _onChangePopulation = async (selectedPopulations: ScopeTreeRow[]) => {
if (selectedPopulations?.some((perimeter) => perimeter?.access === 'Pseudonymisé')) {
cleanCriterias(requestState.selectedCriteria, dispatch)
}
dispatch(buildCohortCreation({ selectedPopulation: selectedPopulations }))
}

Expand Down
4 changes: 4 additions & 0 deletions src/state/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ const cohortCreationSlice = createSlice({
state.criteriaGroup = [...state.criteriaGroup, action.payload]
state.nextGroupId--
},
editAllCriteria: (state: CohortCreationState, action: PayloadAction<SelectedCriteriaType[]>) => {
state.selectedCriteria = action.payload
},
editSelectedCriteria: (state: CohortCreationState, action: PayloadAction<SelectedCriteriaType>) => {
const foundItem = state.selectedCriteria.find(({ id }) => id === action.payload.id)
const index = foundItem ? state.selectedCriteria.indexOf(foundItem) : -1
Expand Down Expand Up @@ -771,6 +774,7 @@ export const {
deleteCriteriaGroup,
addNewSelectedCriteria,
addNewCriteriaGroup,
editAllCriteria,
editSelectedCriteria,
editCriteriaGroup,
duplicateSelectedCriteria,
Expand Down
44 changes: 43 additions & 1 deletion src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
FormNames,
FilterByDocumentStatus,
LabelObject,
SearchByTypes
SearchByTypes,
DurationRangeType
} from 'types/searchCriterias'
import {
Comparators,
Expand Down Expand Up @@ -75,6 +76,8 @@ import {
} from './mappers'
import { pregnancyForm } from 'data/pregnancyData'
import { hospitForm } from 'data/hospitData'
import { editAllCriteria } from 'state/cohortCreation'
import { AppDispatch } from 'state'

const REQUETEUR_VERSION = 'v1.4.4'

Expand Down Expand Up @@ -228,6 +231,45 @@ type RequeteurSearchType = {
request: RequeteurGroupType | undefined
}

export const cleanCriterias = (selectedCriteria: SelectedCriteriaType[], dispatch: AppDispatch) => {
const cleanDurationRange = (value: DurationRangeType) => {
const regex = /\/[^/]*$/
return [
value[0] ? value[0].replace(regex, '/0') : null,
value[1] ? value[1].replace(regex, '/0') : null
] as DurationRangeType
}
const cleanedSelectedCriteria = selectedCriteria
.filter(
(criteria) =>
criteria.type !== CriteriaType.IPP_LIST &&
criteria.type !== CriteriaType.PREGNANCY &&
criteria.type !== CriteriaType.HOSPIT
)
.map((criterion) => {
switch (criterion.type) {
case CriteriaType.PATIENT: {
return {
...criterion,
birthdates: [null, null] as DurationRangeType,
deathDates: [null, null] as DurationRangeType,
age: cleanDurationRange(criterion.age)
}
}
case CriteriaType.ENCOUNTER: {
return {
...criterion,
age: cleanDurationRange(criterion.age)
}
}
default:
return criterion
}
})

dispatch(editAllCriteria(cleanedSelectedCriteria))
}

const constructFilterFhir = (criterion: SelectedCriteriaType, deidentified: boolean): string => {
let filterFhir = ''
const filterReducer = (accumulator: string, currentValue: string): string =>
Expand Down

0 comments on commit 2de4b6a

Please sign in to comment.