Skip to content

Commit

Permalink
fix: resolve remaining bug on refacto - Ref gestion-de-projet#1799 ge…
Browse files Browse the repository at this point in the history
…stion-de-projet#2373 gestion-de-projet#2385 (#908)

* fix: resolve blank page when click on medication exploration

* fix: fixed medication total label

* fix: fixed displayDigits style

* fix: fixed text sizes - Ref gestion-de-projet#2385

* fix: fixed administrationtypes filter - Ref gestion-de-projet#2373

* fix: fixed filters not resetting when changing tabs - Ref gestion-de-projet#2375

* fix: fixed display of demographic criteria - Ref gestion-de-projet#1799

* fix: tried to fix reset of demographic age criteria - Ref gestion-de-projet#1799

* fix: fix error on filters

* fix: fix placeholder demographic criteria

---------

Co-authored-by: manelleg <manelle.gueriouz@aphp.fr>
  • Loading branch information
Mehdi-BOUYAHIA and ManelleG authored Nov 30, 2023
1 parent 336131f commit 0389672
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace'

import useStyles from './styles'

import { DurationRangeType, LabelObject, VitalStatus } from 'types/searchCriterias'
import { DurationRangeType, LabelObject, VitalStatusLabel } from 'types/searchCriterias'
import CalendarRange from 'components/ui/Inputs/CalendarRange'
import DurationRange from 'components/ui/Inputs/DurationRange'
import { CriteriaDataKey, SelectedCriteriaType, RessourceType } from 'types/requestCriterias'
import { BlockWrapper } from 'components/ui/Layout'
import { convertStringToDuration, checkMinMaxValue } from 'utils/age'

enum Error {
EMPTY_FORM,
Expand Down Expand Up @@ -64,6 +65,8 @@ const DemographicForm = (props: DemographicFormProps) => {

useEffect(() => {
setError(Error.NO_ERROR)
const _age0 = convertStringToDuration(age[0])
const _age1 = convertStringToDuration(age[1])
if (
vitalStatus?.length === 0 &&
genders?.length === 0 &&
Expand All @@ -76,6 +79,9 @@ const DemographicForm = (props: DemographicFormProps) => {
) {
setError(Error.EMPTY_FORM)
}
if (_age0 !== null && _age1 !== null && !checkMinMaxValue(_age0, _age1)) {
setError(Error.INCOHERENT_AGE_ERROR)
}
}, [vitalStatus, genders, birthdates, age, deathDates])

const onSubmit = () => {
Expand Down Expand Up @@ -165,7 +171,10 @@ const DemographicForm = (props: DemographicFormProps) => {
getOptionLabel={(option) => option.label}
isOptionEqualToValue={(option, value) => option.id === value.id}
value={vitalStatus}
onChange={(e, value) => setVitalStatus(value)}
onChange={(e, value) => {
setVitalStatus(value)
if (value.length === 1 && value[0].label === VitalStatusLabel.ALIVE) setDeathDates([null, null])
}}
renderInput={(params) => <TextField {...params} label="Statut vital" />}
/>

Expand All @@ -187,18 +196,17 @@ const DemographicForm = (props: DemographicFormProps) => {
label={
vitalStatus &&
vitalStatus.length === 1 &&
vitalStatus.find((status: LabelObject) => status.id === VitalStatus.DECEASED)
vitalStatus.find((status: LabelObject) => status.label === VitalStatusLabel.DECEASED)
? 'Âge au décès'
: 'Âge actuel'
}
onChange={(value) => setAge(value)}
onError={(isError) => setError(isError ? Error.INCOHERENT_AGE_ERROR : Error.NO_ERROR)}
/>
</BlockWrapper>

{vitalStatus &&
vitalStatus.length > 0 &&
vitalStatus.find((status: LabelObject) => status.id === VitalStatus.DECEASED) && (
(vitalStatus.length === 0 ||
vitalStatus.find((status: LabelObject) => status.label === VitalStatusLabel.DECEASED)) && (
<BlockWrapper margin="1em">
<CalendarRange
inline
Expand Down
58 changes: 30 additions & 28 deletions src/components/Patient/PatientMedication/PatientMedication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,35 +212,37 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
<Button width={'30%'} icon={<FilterList height="15px" fill="#FFF" />} onClick={() => setToggleModal(true)}>
Filtrer
</Button>
<Modal
title="Filtrer par :"
open={toggleModal}
width={'600px'}
onClose={() => setToggleModal(false)}
onSubmit={(newFilters) => addFilters({ ...filters, ...newFilters })}
>
{!searchResults.deidentified && <NdaFilter name={FilterKeys.NDA} value={nda} />}
{selectedTab.id === Medication.PRESCRIPTION && (
<PrescriptionTypesFilter
value={prescriptionTypes}
name={FilterKeys.PRESCRIPTION_TYPES}
allAdministrationTypes={allPrescriptionTypes}
/>
)}
{selectedTab.id === Medication.ADMINISTRATION && (
<AdministrationTypesFilter
value={administrationRoutes}
name={FilterKeys.ADMINISTRATION_ROUTES}
allAdministrationTypes={allAdministrationRoutes}
{toggleModal && (
<Modal
title="Filtrer par :"
open={toggleModal}
width={'600px'}
onClose={() => setToggleModal(false)}
onSubmit={(newFilters) => addFilters({ ...filters, ...newFilters })}
>
{!searchResults.deidentified && <NdaFilter name={FilterKeys.NDA} value={nda} />}
{selectedTab.id === Medication.PRESCRIPTION && (
<PrescriptionTypesFilter
value={prescriptionTypes}
name={FilterKeys.PRESCRIPTION_TYPES}
allAdministrationTypes={allPrescriptionTypes}
/>
)}
{selectedTab.id === Medication.ADMINISTRATION && (
<AdministrationTypesFilter
value={administrationRoutes}
name={FilterKeys.ADMINISTRATION_ROUTES}
allAdministrationTypes={allAdministrationRoutes}
/>
)}
<DatesRangeFilter values={[startDate, endDate]} names={[FilterKeys.START_DATE, FilterKeys.END_DATE]} />
<ExecutiveUnitsFilter
value={executiveUnits}
name={FilterKeys.EXECUTIVE_UNITS}
criteriaName={CriteriaName.Medication}
/>
)}
<DatesRangeFilter values={[startDate, endDate]} names={[FilterKeys.START_DATE, FilterKeys.END_DATE]} />
<ExecutiveUnitsFilter
value={executiveUnits}
name={FilterKeys.EXECUTIVE_UNITS}
criteriaName={CriteriaName.Medication}
/>
</Modal>
</Modal>
)}
</Grid>
</Searchbar>
</BlockWrapper>
Expand Down
46 changes: 24 additions & 22 deletions src/components/Patient/PatientPMSI/PatientPMSI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,31 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
<Button width={'30%'} icon={<FilterList height="15px" fill="#FFF" />} onClick={() => setToggleModal(true)}>
Filtrer
</Button>
<Modal
title="Filtrer par :"
open={toggleModal}
width={'600px'}
onClose={() => setToggleModal(false)}
onSubmit={(newFilters) => addFilters({ ...filters, ...newFilters })}
>
{!searchResults.deidentified && <NdaFilter name={FilterKeys.NDA} value={nda} />}
<CodeFilter name={FilterKeys.CODE} value={code} />
{selectedTab.id === PMSI.DIAGNOSTIC && (
<DiagnosticTypesFilter
name={FilterKeys.DIAGNOSTIC_TYPES}
value={diagnosticTypes}
allDiagnosticTypesList={allDiagnosticTypesList}
{toggleModal && (
<Modal
title="Filtrer par :"
open={toggleModal}
width={'600px'}
onClose={() => setToggleModal(false)}
onSubmit={(newFilters) => addFilters({ ...filters, ...newFilters })}
>
{!searchResults.deidentified && <NdaFilter name={FilterKeys.NDA} value={nda} />}
<CodeFilter name={FilterKeys.CODE} value={code} />
{selectedTab.id === PMSI.DIAGNOSTIC && (
<DiagnosticTypesFilter
name={FilterKeys.DIAGNOSTIC_TYPES}
value={diagnosticTypes}
allDiagnosticTypesList={allDiagnosticTypesList}
/>
)}
<DatesRangeFilter values={[startDate, endDate]} names={[FilterKeys.START_DATE, FilterKeys.END_DATE]} />
<ExecutiveUnitsFilter
value={executiveUnits}
name={FilterKeys.EXECUTIVE_UNITS}
criteriaName={mapToCriteriaName(selectedTab.id)}
/>
)}
<DatesRangeFilter values={[startDate, endDate]} names={[FilterKeys.START_DATE, FilterKeys.END_DATE]} />
<ExecutiveUnitsFilter
value={executiveUnits}
name={FilterKeys.EXECUTIVE_UNITS}
criteriaName={mapToCriteriaName(selectedTab.id)}
/>
</Modal>
</Modal>
)}
</Grid>
</Searchbar>
</BlockWrapper>
Expand Down
14 changes: 8 additions & 6 deletions src/components/ui/Inputs/DurationRange/DurationInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type DurationProps = {
disabled?: boolean
deidentified?: boolean
onChange: (newDuration: DurationType) => void
name?: string
}

const DurationInput = ({ value, label, deidentified = false, disabled = false, onChange }: DurationProps) => {
const DurationInput = ({ value, label, deidentified = false, disabled = false, onChange, name }: DurationProps) => {
const [duration, setDuration] = useState(value)

useEffect(() => {
Expand All @@ -29,20 +30,21 @@ const DurationInput = ({ value, label, deidentified = false, disabled = false, o
<Grid container item xs={deidentified ? 5 : 3} alignItems="center">
<Grid item xs={6}>
<TextFieldWrapper
active={!disabled}
active={!!duration.year}
disabled={disabled}
placeholder={duration.year ? undefined : name === 'max' ? '130' : '0'}
value={duration.year}
variant="standard"
size="small"
onChange={(e) => {
if (!isNaN(+e.target.value) && +e.target.value <= 130) {
setDuration({ ...duration, year: +e.target.value })
setDuration({ ...duration, year: e.target.value !== '' ? +e.target.value : null })
}
}}
/>
</Grid>
<Grid item xs={6}>
<DurationUnitWrapper active={!disabled}>{CalendarRequestLabel.YEAR}</DurationUnitWrapper>
<DurationUnitWrapper active={!!duration.year}>{CalendarRequestLabel.YEAR}</DurationUnitWrapper>
</Grid>
</Grid>
<Grid container item xs={deidentified ? 5 : 3} alignItems="center">
Expand All @@ -56,7 +58,7 @@ const DurationInput = ({ value, label, deidentified = false, disabled = false, o
size="small"
onChange={(e) => {
if (!isNaN(+e.target.value) && +e.target.value <= 12) {
setDuration({ ...duration, month: +e.target.value })
setDuration({ ...duration, month: e.target.value !== '' ? +e.target.value : null })
}
}}
/>
Expand All @@ -77,7 +79,7 @@ const DurationInput = ({ value, label, deidentified = false, disabled = false, o
size="small"
onChange={(e) => {
if (!isNaN(+e.target.value) && +e.target.value <= 31) {
setDuration({ ...duration, day: +e.target.value })
setDuration({ ...duration, day: e.target.value !== '' ? +e.target.value : null })
}
}}
/>
Expand Down
9 changes: 4 additions & 5 deletions src/components/ui/Inputs/DurationRange/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type DurationRangeProps = {
onError: (isError: boolean) => void
}
const defaultMinDuration: DurationType = {
year: 0,
year: null,
month: null,
day: null
}
const defaultMaxDuration: DurationType = {
year: 130,
year: null,
month: null,
day: null
}
Expand All @@ -47,9 +47,7 @@ const DurationRange: React.FC<DurationRangeProps> = ({
if (!checkMinMaxValue(minDuration, maxDuration)) {
setError({ isError: true, errorMessage: 'La date maximale doit être supérieure à la date minimale.' })
onError(true)
} else if (maxDuration.year === 0 && !maxDuration.month && !maxDuration.day) {
setError({ isError: true, errorMessage: 'Au moins une des valeurs maximales ne doit pas être égale à 0' })
onError(true)
onChange([convertDurationToString(minDuration), convertDurationToString(maxDuration)])
} else {
onChange([convertDurationToString(minDuration), convertDurationToString(maxDuration)])
}
Expand All @@ -76,6 +74,7 @@ const DurationRange: React.FC<DurationRangeProps> = ({
<DurationInput
disabled={disabled}
value={maxDuration}
name="max"
deidentified={deidentified}
label={`${unit} maximum`}
onChange={(newDuration) => setMaxDuration(newDuration)}
Expand Down
1 change: 1 addition & 0 deletions src/utils/age.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const convertStringToDuration = (age: string | null): DurationType | null
}

export const convertDurationToString = (ageDate: DurationType): string | null => {
if (ageDate.year === null && ageDate.month === null && ageDate.day === null) return null
if ((ageDate.year === 130 || ageDate.year === 0) && !ageDate.month && !ageDate.day) return null
return `${ageDate.day || 0}/${ageDate.month || 0}/${ageDate.year || 0}`
}
Expand Down
44 changes: 22 additions & 22 deletions src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type RequeteurCriteriaType = {
timeDelayMin?: number
timeDelayMax?: number
}
DurationRangeList?: {
dateRangeList?: {
minDate?: string // YYYY-MM-DD
maxDate?: string // YYYY-MM-DD
datePreference?: 'event_date' | 'encounter_end_date' | 'encounter_start_date'
Expand Down Expand Up @@ -200,8 +200,8 @@ const constructFilterFhir = (criterion: SelectedCriteriaType): string => {
.reduce(searchReducer)}`
: ''
}`,
`${ageMinCriterion}`,
`${ageMaxCriterion}`,
criterion.birthdates[0] === null && criterion.birthdates[1] === null ? `${ageMinCriterion}` : '',
criterion.birthdates[0] === null && criterion.birthdates[1] === null ? `${ageMaxCriterion}` : '',
criterion.birthdates[0]
? `${PATIENT_BIRTHDATE}=ge${moment(criterion.birthdates[0]).format('YYYY-MM-DD[T00:00:00Z]')}`
: '',
Expand Down Expand Up @@ -583,7 +583,7 @@ export function buildRequest(
operator: item?.occurrenceComparator || undefined
}
: undefined,
DurationRangeList:
dateRangeList:
!(item.type === RessourceType.PATIENT || item.type === RessourceType.IPP_LIST) &&
(item.startOccurrence || item.endOccurrence)
? [
Expand Down Expand Up @@ -1019,9 +1019,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down Expand Up @@ -1097,9 +1097,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down Expand Up @@ -1173,9 +1173,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down Expand Up @@ -1237,9 +1237,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down Expand Up @@ -1304,9 +1304,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down Expand Up @@ -1389,9 +1389,9 @@ export async function unbuildRequest(_json: string): Promise<any> {
currentCriterion.occurrenceComparator = element.occurrence ? element.occurrence.operator : null
}

if (element.DurationRangeList) {
currentCriterion.startOccurrence = element.DurationRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.DurationRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
if (element.dateRangeList) {
currentCriterion.startOccurrence = element.dateRangeList[0].minDate?.replace('T00:00:00Z', '') ?? null
currentCriterion.endOccurrence = element.dateRangeList[0].maxDate?.replace('T00:00:00Z', '') ?? null
}

if (element.encounterDateRange) {
Expand Down
Loading

0 comments on commit 0389672

Please sign in to comment.