Skip to content

Commit

Permalink
corrections search by value / biology
Browse files Browse the repository at this point in the history
  • Loading branch information
aetchego committed Dec 4, 2024
1 parent 5a87288 commit 5d29b2b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 deletions.
12 changes: 5 additions & 7 deletions src/__tests__/cohortCreation/cohortCreation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,51 +58,50 @@ const BiologyForm = (props: CriteriaDrawerComponentProps) => {
const [currentCriteria, setCurrentCriteria] = useState((selectedCriteria as ObservationDataType) || defaultBiology)
const isEdition = selectedCriteria !== null
const [multiFields, setMultiFields] = useState<string | null>(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])

Check warning on line 104 in src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/BiologyForm/index.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useEffect has a missing dependency: 'currentCriteria'. Either include it or remove the dependency array. You can also do a functional update 'setCurrentCriteria(c => ...)' if you only need 'currentCriteria' in the 'setCurrentCriteria' call

const biologyReferences = useMemo(() => {
return getValueSetsFromSystems([
Expand Down Expand Up @@ -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}
>
Expand All @@ -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}
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const PatientTitle: React.FC<PatientTitleProps> = ({ 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)
Expand Down
15 changes: 5 additions & 10 deletions src/utils/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5d29b2b

Please sign in to comment.