diff --git a/src/__tests__/cohortCreation/cohortCreation.test.ts b/src/__tests__/cohortCreation/cohortCreation.test.ts index 5e3908d16..80472e364 100644 --- a/src/__tests__/cohortCreation/cohortCreation.test.ts +++ b/src/__tests__/cohortCreation/cohortCreation.test.ts @@ -48,9 +48,7 @@ import { buildClaimFilter, buildMedicationFilter, buildObservationFilter, - buildImagingFilter, - buildPregnancyFilter, - buildHospitFilter + buildImagingFilter } from 'utils/cohortCreation' import { completeDocumentCriteria, defaultDocumentCriteria } from '__tests__/data/cohortCreation/documentCriteria' import { completeConditionCriteria, defaultConditionCriteria } from '__tests__/data/cohortCreation/conditionCriteria' @@ -301,7 +299,7 @@ describe('test of buildConditionFilter', () => { const selectedCriteria: Cim10DataType = completeConditionCriteria const result = [ 'subject.active=true', - 'code=I841,I842', + 'code=https://smt.esante.gouv.fr/terminologie-cim-10/|I841,https://smt.esante.gouv.fr/terminologie-cim-10/|I842', 'orbis-status=fp,f', '_source=AREM', 'encounter.encounter-care-site=8312016825', @@ -325,7 +323,7 @@ describe('test of buildProcedureFilter', () => { const selectedCriteria: CcamDataType = completeProcedureCriteria const result = [ 'subject.active=true', - 'code=000126,000127', + 'code=https://www.atih.sante.fr/plateformes-de-transmiss…ls/logiciels-espace-de-telechargement/id_lot/3550|000126,https://www.atih.sante.fr/plateformes-de-transmiss…ls/logiciels-espace-de-telechargement/id_lot/3550|000127', 'encounter.encounter-care-site=8312016825', 'encounter.status=entered-in-error', 'date=ge2024-09-06T00:00:00Z', @@ -348,7 +346,7 @@ describe('test of buildClaimFilter', () => { const selectedCriteria: GhmDataType = completeClaimCriteria const result = [ 'patient.active=true', - 'diagnosis=05C021,05C022,05C023,05C024', + 'diagnosis=https://terminology.eds.aphp.fr/aphp-orbis-ghm|05C021,https://terminology.eds.aphp.fr/aphp-orbis-ghm|05C022,https://terminology.eds.aphp.fr/aphp-orbis-ghm|05C023,https://terminology.eds.aphp.fr/aphp-orbis-ghm|05C024', 'encounter.encounter-care-site=8312016825', 'encounter.status=cancelled', 'created=ge2024-09-03T00:00:00Z', @@ -414,7 +412,7 @@ describe('test of buildObservationFilter', () => { const selectedCriteria: ObservationDataType = completeObservationCriteria const result = [ 'subject.active=true&status=Val', - 'code=I3356', + 'code=https://terminology.eds.aphp.fr/aphp-itm-anabio|I3356', 'encounter.encounter-care-site=8312016825', 'encounter.status=cancelled', 'date=ge2024-09-03T00:00:00Z', diff --git a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx index a60b8f37f..04f0e59c0 100644 --- a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx +++ b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx @@ -27,6 +27,7 @@ import { ErrorWrapper } from 'components/ui/Searchbar/styles' import AdvancedInputs from '../AdvancedInputs' import { SourceType } from 'types/scope' import { getValueSetsFromSystems } from 'utils/valueSets' +import { HIERARCHY_ROOT } from 'services/aphp/serviceValueSets' enum Error { NO_ERROR, @@ -57,51 +58,50 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => { const [currentCriteria, setCurrentCriteria] = useState((selectedCriteria as ObservationDataType) || defaultBiology) const isEdition = selectedCriteria !== null const [multiFields, setMultiFields] = useState(localStorage.getItem('multiple_fields')) - const [searchByValuesInput, setSearchByValuesInput] = useState<[string, string]>([ - currentCriteria.searchByValue[0]?.toString() || '', - currentCriteria.searchByValue[1]?.toString() || '' - ]) const [error, setError] = useState(Error.NO_ERROR) + const [isLeaf, setIsLeaf] = useState(false) - const isLeaf = useMemo( - () => currentCriteria.code.length === 1 && currentCriteria.code?.[0].inferior_levels_ids.split(',').length < 2, - [currentCriteria.code] - ) - - const handleSearchValue = (newValue: string, index: number) => { + const handleSearchValues = (newValue: string, index: number) => { const invalidCharRegex = /[^0-9.-]/ // matches everything that is not a number, a "," or a "." - if (!newValue.match(invalidCharRegex)) - setSearchByValuesInput(index === 0 ? [newValue, searchByValuesInput[1]] : [searchByValuesInput[0], newValue]) + if (!newValue.match(invalidCharRegex)) { + const newVal = isNaN(parseFloat(newValue)) ? null : parseFloat(newValue) + const values: [number | null, number | null] = + index === 0 ? [newVal, currentCriteria.searchByValue[1]] : [currentCriteria.searchByValue[0], newVal] + checkSearchValues(values, currentCriteria.valueComparator) + } } - useEffect(() => { - const floatRegex = /^-?\d*\.?\d*$/ // matches numbers, with decimals or not, negative or not - if (!searchByValuesInput[0].match(floatRegex) || !searchByValuesInput[1].match(floatRegex)) { - setError(Error.INVALID_VALUE_ERROR) - } else if ( - searchByValuesInput[0] && - searchByValuesInput[1] && - parseFloat(searchByValuesInput[0]) > parseFloat(searchByValuesInput[1]) - ) { + const checkSearchValues = (values: [null | number, null | number], comparator: Comparators) => { + setError(Error.NO_ERROR) + const val1 = comparator !== Comparators.BETWEEN ? null : values[1] + if (values[0] !== null && val1 !== null && values[0] > val1) { setError(Error.INCOHERENT_VALUE_ERROR) - } else if ( - currentCriteria.valueComparator === Comparators.BETWEEN && - (!searchByValuesInput[0] || !searchByValuesInput[1]) - ) { + } else if (comparator === Comparators.BETWEEN && (values[0] === null || val1 === null)) { setError(Error.MISSING_VALUE_ERROR) - } else { - const first = isLeaf && searchByValuesInput[0] ? parseFloat(searchByValuesInput[0]) : null - const second = - isLeaf && searchByValuesInput[1] && currentCriteria.valueComparator === Comparators.BETWEEN - ? parseFloat(searchByValuesInput[1]) - : null + } + setCurrentCriteria({ + ...currentCriteria, + searchByValue: [values[0], val1], + valueComparator: comparator + }) + } + + useEffect(() => { + setError(Error.NO_ERROR) + if ( + currentCriteria.code.length === 1 && + !currentCriteria.code?.[0]?.inferior_levels_ids && + currentCriteria.code?.[0]?.id !== HIERARCHY_ROOT + ) + setIsLeaf(true) + else { + setIsLeaf(false) setCurrentCriteria({ ...currentCriteria, - searchByValue: [first, second] + searchByValue: [null, null] }) - setError(Error.NO_ERROR) } - }, [searchByValuesInput, currentCriteria.valueComparator, isLeaf]) + }, [currentCriteria.code]) const biologyReferences = useMemo(() => { return getValueSetsFromSystems([ @@ -230,7 +230,7 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => { id="biology-value-comparator-select" value={currentCriteria.valueComparator ?? Comparators.GREATER_OR_EQUAL} onChange={(event) => - setCurrentCriteria({ ...currentCriteria, valueComparator: event.target.value as Comparators }) + checkSearchValues(currentCriteria.searchByValue, event.target.value as Comparators) } disabled={!isLeaf} > @@ -245,8 +245,8 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => { type="text" id="criteria-value" variant="outlined" - value={searchByValuesInput[0]} - onChange={(e) => handleSearchValue(e.target.value, 0)} + value={currentCriteria.searchByValue[0] ?? ''} + onChange={(e) => handleSearchValues(e.target.value, 0)} placeholder={currentCriteria.valueComparator === Comparators.BETWEEN ? 'Valeur minimale' : '0'} disabled={!isLeaf} error={error !== Error.NO_ERROR && error !== Error.ADVANCED_INPUTS_ERROR} @@ -257,8 +257,8 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => { type="text" id="criteria-value" variant="outlined" - value={searchByValuesInput[1]} - onChange={(e) => handleSearchValue(e.target.value, 1)} + value={currentCriteria.searchByValue[1] ?? ''} + onChange={(e) => handleSearchValues(e.target.value, 1)} sx={{ marginLeft: '10px' }} placeholder="Valeur maximale" disabled={!isLeaf} diff --git a/src/components/Patient/PatientHeader/PatientTitle/PatientTitle.tsx b/src/components/Patient/PatientHeader/PatientTitle/PatientTitle.tsx index 8df04e36a..5f6e4d809 100644 --- a/src/components/Patient/PatientHeader/PatientTitle/PatientTitle.tsx +++ b/src/components/Patient/PatientHeader/PatientTitle/PatientTitle.tsx @@ -21,7 +21,6 @@ const PatientTitle: React.FC = ({ firstName, lastName }) => { const location = useLocation() const search = new URLSearchParams(location.search) const groupId = search.get('groupId') ?? undefined - console.log('manelle groupId', groupId) const cohort = useAppSelector((state) => state.exploredCohort) const [anchorEl, setAnchorEl] = useState(null) diff --git a/src/utils/mappers.ts b/src/utils/mappers.ts index 973584897..6b6b847cd 100644 --- a/src/utils/mappers.ts +++ b/src/utils/mappers.ts @@ -30,7 +30,6 @@ import { comparatorToFilter, parseOccurence } from './valueComparator' import services from 'services/aphp' import extractFilterParams, { FhirFilterValue } from './fhirFilterParser' import { Condition } from 'fhir/r4' -import { getChildrenFromCodes } from 'services/aphp/serviceValueSets' export const getLastDiagnosisLabels = (mainDiagnosisList: Condition[]) => { const mainDiagnosisLabels = mainDiagnosisList.map((diagnosis) => diagnosis.code?.coding?.[0].display) @@ -137,15 +136,11 @@ export const buildObservationValueFilter = (criterion: ObservationDataType, fhir criterion.valueComparator && (typeof criterion.searchByValue[0] === 'number' || typeof criterion.searchByValue[1] === 'number') ) { - getChildrenFromCodes(criterion.code[0].system, [criterion.code[0].id]).then((resp) => { - if (resp.results.length === 0) { - if (criterion.valueComparator === Comparators.BETWEEN && criterion.searchByValue[1]) { - filter = `${fhirKey}=le${criterion.searchByValue[1]}&${fhirKey}=ge${criterion.searchByValue[0]}` - } else { - filter = `${fhirKey}=${valueComparatorFilter}${criterion.searchByValue[0]}` - } - } - }) + if (criterion.valueComparator === Comparators.BETWEEN && criterion.searchByValue[1]) { + return `${fhirKey}=le${criterion.searchByValue[1]}&${fhirKey}=ge${criterion.searchByValue[0]}` + } else { + return `${fhirKey}=${valueComparatorFilter}${criterion.searchByValue[0]}` + } } return filter }