Skip to content

Commit

Permalink
refactor: refacto of patientfilter and chip - Ref gestion-de-projet#2119
Browse files Browse the repository at this point in the history
* fix: remove all patients filter - Ref gestion-de-projet#2119

* checkbox replace radio buttons
  • Loading branch information
aetchego authored Jul 28, 2023
1 parent 6f12cc2 commit 6752f0d
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 130 deletions.
26 changes: 13 additions & 13 deletions src/components/Dashboard/PatientList/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
PatientFilters as PatientFiltersType,
SearchByTypes,
SimpleChartDataType,
VitalStatus,
DTTB_ResultsType as ResultsType
} from 'types'

Expand Down Expand Up @@ -63,9 +62,9 @@ const PatientList: React.FC<PatientListProps> = ({
const [open, setOpen] = useState(false)

const [filters, setFilters] = useState<PatientFiltersType>({
gender: null,
gender: [],
birthdatesRanges: ['', ''],
vitalStatus: null
vitalStatus: []
})

const [order, setOrder] = useState<Order>({
Expand Down Expand Up @@ -160,12 +159,12 @@ const PatientList: React.FC<PatientListProps> = ({
}
}

const handleDeleteChip = (filterName: string) => {
const handleDeleteChip = <S extends string, T>(filterName: S, value?: T) => {
switch (filterName) {
case 'gender':
setFilters((prevFilters) => ({
...prevFilters,
gender: null
gender: [...prevFilters.gender.filter((elem) => elem !== value)]
}))
break
case 'birthdates':
Expand All @@ -177,7 +176,7 @@ const PatientList: React.FC<PatientListProps> = ({
case 'vitalStatus':
setFilters((prevFilters) => ({
...prevFilters,
vitalStatus: VitalStatus.all
vitalStatus: [...prevFilters.vitalStatus.filter((elem) => elem !== value)]
}))
break
}
Expand Down Expand Up @@ -224,13 +223,14 @@ const PatientList: React.FC<PatientListProps> = ({
total={patientsResult.nb}
/>

<PatientFilters
open={open}
onClose={() => setOpen(false)}
onSubmit={() => setOpen(false)}
filters={filters}
onChangeFilters={setFilters}
/>
{open && (
<PatientFilters
onClose={() => setOpen(false)}
onSubmit={() => setOpen(false)}
filters={filters}
onChangeFilters={setFilters}
/>
)}
</Grid>
)
}
Expand Down
12 changes: 5 additions & 7 deletions src/components/DataTable/DataTablePatient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ReactComponent as UnknownIcon } from 'assets/icones/autre-inconnu.svg'

import DataTable from 'components/DataTable/DataTable'

import { CohortPatient, Column, Order, PatientGenderKind } from 'types'
import { CohortPatient, Column, Order, GenderStatus } from 'types'

import { getAge } from 'utils/age'
import { capitalizeFirstLetter } from 'utils/capitalize'
Expand Down Expand Up @@ -115,9 +115,7 @@ const DataTablePatientLine: React.FC<{
}
>
<TableCell align="center">
{patient.gender && (
<PatientGender gender={patient.gender as PatientGenderKind} className={classes.genderIcon} />
)}
{patient.gender && <PatientGender gender={patient.gender as GenderStatus} className={classes.genderIcon} />}
</TableCell>
<TableCell>{deidentified ? 'Prénom' : capitalizeFirstLetter(patient.name?.[0].given?.[0])}</TableCell>
<TableCell>{deidentified ? 'Nom' : patient.name?.map((e) => e.family).join(' ')}</TableCell>
Expand Down Expand Up @@ -156,16 +154,16 @@ const DataTablePatientLine: React.FC<{
export default DataTablePatient

type PatientGenderProps = {
gender?: PatientGenderKind
gender?: GenderStatus
className?: string
}

const PatientGender: React.FC<PatientGenderProps> = ({ gender, className }) => {
switch (gender) {
case PatientGenderKind._male:
case GenderStatus.MALE:
return <MaleIcon className={className} />

case PatientGenderKind._female:
case GenderStatus.FEMALE:
return <FemaleIcon className={className} />

default:
Expand Down
93 changes: 59 additions & 34 deletions src/components/Filters/PatientFilters/PatientFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'

import {
Button,
Checkbox,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
FormControlLabel,
FormGroup,
Grid,
Radio,
RadioGroup,
Typography
} from '@mui/material'

import { PatientFilters as PatientFiltersType, PatientGenderKind, VitalStatus } from 'types'
import { PatientFilters as PatientFiltersType, GenderStatus, VitalStatus } from 'types'

import useStyles from './styles'
import { InputAgeRange } from '../../Inputs'

type PatientFiltersProps = {
open: boolean
onClose: () => void
onSubmit: () => void
filters: PatientFiltersType
onChangeFilters: (newFilters: PatientFiltersType) => void
}

const PatientFilters: React.FC<PatientFiltersProps> = ({ open, onClose, onSubmit, filters, onChangeFilters }) => {
const PatientFilters: React.FC<PatientFiltersProps> = ({ onClose, onSubmit, filters, onChangeFilters }) => {
const { classes } = useStyles()

const [_gender, setGender] = useState<PatientGenderKind | null>(filters.gender)
const [birthdatesRanges, setBirthdatesRanges] = useState<[string, string]>(filters.birthdatesRanges)
const [_vitalStatus, setVitalStatus] = useState<VitalStatus | null>(filters.vitalStatus)
const [gender, setGender] = useState<GenderStatus[]>(filters.gender)
const [vitalStatus, setVitalStatus] = useState<VitalStatus[]>(filters.vitalStatus)

const [error, setError] = useState(false)
const [errorMessage, setErrorMessage] = useState('')

useEffect(() => {
setGender(filters.gender)
setBirthdatesRanges(filters.birthdatesRanges)
setVitalStatus(filters.vitalStatus)
_onError(false)
}, [open]) // eslint-disable-line
const checkIfChecked = <T,>(value: T, arr: T[]): boolean => {
return arr.includes(value)
}

const _onChangeGender = (event: React.ChangeEvent<HTMLInputElement>, value: string) => {
setGender(value as PatientGenderKind)
const onChangeGender = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value as GenderStatus
if (gender.includes(value)) {
setGender([...gender.filter((elem) => elem !== value)])
} else {
setGender([...gender, value])
}
}

const _onChangeVitalStatus = (event: React.ChangeEvent<HTMLInputElement>, value: string) => {
setVitalStatus(value as VitalStatus)
const onChangeVitalStatus = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value as VitalStatus
if (vitalStatus.includes(value)) {
setVitalStatus([...vitalStatus.filter((elem) => elem !== value)])
} else {
setVitalStatus([...vitalStatus, value])
}
}

const _onSubmit = () => {
onChangeFilters({
gender: _gender,
gender: gender,
birthdatesRanges: birthdatesRanges,
vitalStatus: _vitalStatus
vitalStatus: vitalStatus
})

onSubmit()
Expand All @@ -67,21 +73,31 @@ const PatientFilters: React.FC<PatientFiltersProps> = ({ open, onClose, onSubmit
}

return (
<Dialog open={open} onClose={onClose}>
<Dialog open onClose={onClose}>
<DialogTitle>Filtrer les patients :</DialogTitle>
<DialogContent className={classes.dialog}>
<Grid container direction="column" className={classes.filter}>
<Typography variant="h3">Genre :</Typography>
<RadioGroup name="Gender" value={_gender} onChange={_onChangeGender} row={true}>
<FormControlLabel value={PatientGenderKind._male} control={<Radio color="secondary" />} label="Hommes" />
<FormControlLabel value={PatientGenderKind._female} control={<Radio color="secondary" />} label="Femmes" />
<FormControlLabel value={PatientGenderKind._other} control={<Radio color="secondary" />} label="Autres" />
<FormGroup onChange={onChangeGender} row={true}>
<FormControlLabel
checked={checkIfChecked(GenderStatus.MALE, gender)}
value={GenderStatus.MALE}
control={<Checkbox color="secondary" />}
label="Hommes"
/>
<FormControlLabel
checked={checkIfChecked(GenderStatus.FEMALE, gender)}
value={GenderStatus.FEMALE}
control={<Checkbox color="secondary" />}
label="Femmes"
/>
<FormControlLabel
value={PatientGenderKind._unknown}
control={<Radio color="secondary" />}
label="Tous les genres"
checked={checkIfChecked(`${GenderStatus.OTHER},${GenderStatus.UNKNOWN}`, gender)}
value={`${GenderStatus.OTHER},${GenderStatus.UNKNOWN}`}
control={<Checkbox color="secondary" />}
label="Autres"
/>
</RadioGroup>
</FormGroup>
</Grid>
<Grid container direction="column" className={classes.filter}>
<InputAgeRange
Expand All @@ -96,11 +112,20 @@ const PatientFilters: React.FC<PatientFiltersProps> = ({ open, onClose, onSubmit

<Grid container direction="column">
<Typography variant="h3">Statut vital :</Typography>
<RadioGroup name="VitalStatus" value={_vitalStatus} onChange={_onChangeVitalStatus} row={true}>
<FormControlLabel value="alive" control={<Radio color="secondary" />} label="Patients vivants" />
<FormControlLabel value="deceased" control={<Radio color="secondary" />} label="Patients décédés" />
<FormControlLabel value="all" control={<Radio color="secondary" />} label="Tous les patients" />
</RadioGroup>
<FormGroup onChange={onChangeVitalStatus} row={true}>
<FormControlLabel
checked={checkIfChecked(VitalStatus.ALIVE, vitalStatus)}
value={VitalStatus.ALIVE}
control={<Checkbox color="secondary" />}
label="Patients vivants"
/>
<FormControlLabel
checked={checkIfChecked(VitalStatus.DECEASED, vitalStatus)}
value={VitalStatus.DECEASED}
control={<Checkbox color="secondary" />}
label="Patients décédés"
/>
</FormGroup>
</Grid>
</DialogContent>
<DialogActions>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Patient/PatientHeader/PatientHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { CohortPatient, IPatientDetails, PatientGenderKind } from 'types'
import { CohortPatient, IPatientDetails, GenderStatus } from 'types'

import Grid from '@mui/material/Grid'

Expand Down Expand Up @@ -40,7 +40,7 @@ const PatientHeader: React.FC<PatientHeaderProps> = ({
<PatientTitle firstName={firstName} lastName={lastName} />
</Grid>
<Grid container item justifyContent="flex-end" xs={3}>
<PatientInfo age={age} ipp={ipp} gender={patient.gender as PatientGenderKind} />
<PatientInfo age={age} ipp={ipp} gender={patient.gender as GenderStatus} />
</Grid>
</Grid>
</Grid>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Patient/PatientHeader/PatientInfo/PatientInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import { ReactComponent as MaleIcon } from 'assets/icones/mars.svg'
import { ReactComponent as UnknownIcon } from 'assets/icones/autre-inconnu.svg'

import useStyles from './styles'
import { PatientGenderKind } from 'types'
import { GenderStatus } from 'types'

type GenderIconTypes = {
gender?: PatientGenderKind
gender?: GenderStatus
}
const GenderIcon: React.FC<GenderIconTypes> = ({ gender }) => {
const { classes } = useStyles()

switch (gender) {
case PatientGenderKind._female:
case GenderStatus.FEMALE:
return <FemaleIcon className={classes.genderIcon} />
case PatientGenderKind._male:
case GenderStatus.MALE:
return <MaleIcon className={classes.genderIcon} />
default:
return <UnknownIcon className={classes.genderIcon} />
}
}

type PatientInfoTypes = {
gender?: PatientGenderKind
gender?: GenderStatus
age: React.ReactText
ipp?: string
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/Patient/PatientSidebar/PatientSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ChevronRightIcon from '@mui/icons-material/ChevronRight'

import { getAge, substructAgeString } from 'utils/age'
import services from 'services/aphp'
import { CohortPatient, PatientFilters as PatientFiltersType, PatientGenderKind, SearchByTypes, Sort } from 'types'
import { CohortPatient, PatientFilters as PatientFiltersType, GenderStatus, SearchByTypes, Sort } from 'types'

import useStyles from './styles'
import moment from 'moment/moment'
Expand Down Expand Up @@ -48,9 +48,9 @@ const PatientSidebar: React.FC<PatientSidebarTypes> = ({
const [loadingStatus, setLoadingStatus] = useState(false)

const [filters, setFilters] = useState<PatientFiltersType>({
gender: null,
gender: [],
birthdatesRanges: ['', ''],
vitalStatus: null
vitalStatus: []
})

const [openSort, setOpenSort] = useState(false)
Expand Down Expand Up @@ -168,7 +168,7 @@ const PatientSidebar: React.FC<PatientSidebarTypes> = ({
firstName={deidentifiedBoolean ? 'Prénom' : patient.name?.[0].given?.[0] ?? ''}
lastName={deidentifiedBoolean ? 'Nom' : patient.name?.map((e) => e.family).join(' ') ?? ''}
age={getAge(patient)}
gender={patient.gender as PatientGenderKind}
gender={patient.gender as GenderStatus}
deceased={patient.deceasedDateTime ?? patient.deceasedBoolean}
ipp={
deidentifiedBoolean
Expand Down
Loading

0 comments on commit 6752f0d

Please sign in to comment.