diff --git a/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx b/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx index adc73ae58..ad3ec1c94 100644 --- a/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx +++ b/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx @@ -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 @@ -66,6 +67,9 @@ const PopulationCard: React.FC = (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 })) } diff --git a/src/state/cohortCreation.ts b/src/state/cohortCreation.ts index cba37680d..2c6950973 100644 --- a/src/state/cohortCreation.ts +++ b/src/state/cohortCreation.ts @@ -607,6 +607,9 @@ const cohortCreationSlice = createSlice({ state.criteriaGroup = [...state.criteriaGroup, action.payload] state.nextGroupId-- }, + editAllCriteria: (state: CohortCreationState, action: PayloadAction) => { + state.selectedCriteria = action.payload + }, editSelectedCriteria: (state: CohortCreationState, action: PayloadAction) => { const foundItem = state.selectedCriteria.find(({ id }) => id === action.payload.id) const index = foundItem ? state.selectedCriteria.indexOf(foundItem) : -1 @@ -771,6 +774,7 @@ export const { deleteCriteriaGroup, addNewSelectedCriteria, addNewCriteriaGroup, + editAllCriteria, editSelectedCriteria, editCriteriaGroup, duplicateSelectedCriteria, diff --git a/src/utils/cohortCreation.ts b/src/utils/cohortCreation.ts index 393946c11..44e777c8f 100644 --- a/src/utils/cohortCreation.ts +++ b/src/utils/cohortCreation.ts @@ -25,7 +25,8 @@ import { FormNames, FilterByDocumentStatus, LabelObject, - SearchByTypes + SearchByTypes, + DurationRangeType } from 'types/searchCriterias' import { Comparators, @@ -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' @@ -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 =>