Skip to content

Commit

Permalink
feat: changement du mapping Front→ Back pour filtres sauvegardés, TOD…
Browse files Browse the repository at this point in the history
…O Back← Front
  • Loading branch information
FlorentGouyon committed Dec 20, 2023
1 parent 036abde commit fe014e9
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 115 deletions.
46 changes: 32 additions & 14 deletions src/components/Dashboard/Documents/Documents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,16 @@ const Documents: React.FC<DocumentsProps> = ({ groupId, deidentified }) => {
const startDate = newFilters.startDate
const endDate = newFilters.endDate
const executiveUnits = newFilters.executiveUnits
patchSavedFilter(name, {
searchBy,
searchInput,
orderBy: { orderBy: Order.FAMILY, orderDirection: Direction.ASC },
filters: { nda, ipp, docTypes, onlyPdfAvailable, startDate, endDate, executiveUnits }
})
patchSavedFilter(
name,
{
searchBy,
searchInput,
orderBy: { orderBy: Order.FAMILY, orderDirection: Direction.ASC },
filters: { nda, ipp, docTypes, onlyPdfAvailable, startDate, endDate, executiveUnits }
},
deidentified ?? true
)
}}
validationText={isReadonlyFilterInfoModal ? 'Fermer' : 'Sauvegarder'}
>
Expand All @@ -435,13 +439,25 @@ const Documents: React.FC<DocumentsProps> = ({ groupId, deidentified }) => {
maxLimit={50}
/>
</Grid>
<Grid item>
<TextInput
name="searchInput"
label="Recherche textuelle :"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchInput}
/>
<Grid item container direction="column" paddingBottom="16px">
<Grid item>
<TextInput
name="searchInput"
label="Recherche textuelle :"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchInput}
/>
</Grid>
<Grid item>
<Select
label="Rechercher dans"
width="60%"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchBy}
items={searchByListDocuments}
name="searchBy"
/>
</Grid>
</Grid>
<Grid item>
{!deidentified && (
Expand Down Expand Up @@ -498,7 +514,9 @@ const Documents: React.FC<DocumentsProps> = ({ groupId, deidentified }) => {
setToggleSaveFiltersModal(false)
resetSavedFilterError()
}}
onSubmit={({ filtersName }) => postSavedFilter(filtersName, { searchBy, searchInput, filters, orderBy })}
onSubmit={({ filtersName }) =>
postSavedFilter(filtersName, { searchBy, searchInput, filters, orderBy }, deidentified ?? true)
}
>
<TextInput name="filtersName" error={savedFiltersErrors} />
</Modal>
Expand Down
68 changes: 32 additions & 36 deletions src/components/Dashboard/PatientList/PatientList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect, useRef, useMemo } from 'react'
import moment from 'moment'

import { CircularProgress, Grid, Tooltip } from '@mui/material'

Expand All @@ -20,7 +19,6 @@ import {

import { getGenderRepartitionSimpleData } from 'utils/graphUtils'
import { Save, SavedSearch } from '@mui/icons-material'
import { substructAgeString } from 'utils/age'
import { cancelPendingRequest } from 'utils/abortController'
import { CanceledError } from 'axios'
import Searchbar from 'components/ui/Searchbar'
Expand Down Expand Up @@ -116,10 +114,6 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
const fetchPatients = async () => {
try {
const includeFacets = page === 1
const birthdates: [string, string] = [
moment(substructAgeString(birthdatesRanges?.[0] || '')).format('MM/DD/YYYY'),
moment(substructAgeString(birthdatesRanges?.[1] || '')).format('MM/DD/YYYY')
]
setLoadingStatus(LoadingStatus.FETCHING)
const result = await services.cohorts.fetchPatientList(
{
Expand All @@ -128,7 +122,7 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
orderBy,
searchInput,
searchBy,
filters: { genders, vitalStatuses, birthdatesRanges: birthdates }
filters: { genders, vitalStatuses, birthdatesRanges }
}
},
deidentified ?? true,
Expand Down Expand Up @@ -315,7 +309,7 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
<BirthdatesRangesFilter
name={FilterKeys.BIRTHDATES}
value={birthdatesRanges}
deidentified={deidentified || false}
deidentified={deidentified ?? false}
/>
</Modal>
<Modal
Expand Down Expand Up @@ -355,16 +349,20 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
const genders = newFilters.genders as GenderStatus[]
const vitalStatuses = newFilters.vitalStatuses as VitalStatus[]
const birthdatesRanges = newFilters.birthdatesRanges as DurationRangeType
patchSavedFilter(name, {
searchInput,
searchBy,
orderBy: { orderBy: Order.FAMILY, orderDirection: Direction.ASC },
filters: { genders, vitalStatuses, birthdatesRanges }
})
patchSavedFilter(
name,
{
searchInput,
searchBy,
orderBy: { orderBy: Order.FAMILY, orderDirection: Direction.ASC },
filters: { genders, vitalStatuses, birthdatesRanges }
},
deidentified ?? true
)
}}
validationText={isReadonlyFilterInfoModal ? 'Fermer' : 'Sauvegarder'}
>
<Grid container direction="column" sx={{ gap: '16px' }}>
<Grid container direction="column" gap="8px">
<Grid item container direction="column">
<TextInput
name="filterName"
Expand All @@ -376,26 +374,22 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
maxLimit={50}
/>
</Grid>

<Grid item container direction="column" sx={{ gap: '16px' }}>
<Grid item container direction="column" sx={{ gap: '8px' }}>
<TextInput
name="searchInput"
label="Recherche textuelle :"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchInput}
/>
<Select
label="Rechercher dans"
width="60%"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchBy}
items={searchByListPatients}
name="searchBy"
/>
</Grid>
<Grid item container direction="column" paddingBottom="8px">
<TextInput
name="searchInput"
label="Recherche textuelle :"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchInput}
/>
<Select
label="Rechercher dans"
width="60%"
disabled={isReadonlyFilterInfoModal}
value={selectedSavedFilter?.filterParams.searchBy}
items={searchByListPatients}
name="searchBy"
/>
</Grid>
<Grid item container direction="column" sx={{ gap: '8px' }}></Grid>
<Grid item>
<GendersFilter
disabled={isReadonlyFilterInfoModal}
Expand All @@ -411,7 +405,7 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
disabled={isReadonlyFilterInfoModal}
name={FilterKeys.BIRTHDATES}
value={selectedSavedFilter?.filterParams.filters.birthdatesRanges || [null, null]}
deidentified={deidentified || false}
deidentified={deidentified ?? false}
/>
</Grid>
</Grid>
Expand All @@ -425,7 +419,9 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => {
setToggleSaveFiltersModal(false)
resetSavedFilterError()
}}
onSubmit={({ filtersName }) => postSavedFilter(filtersName, { searchBy, searchInput, filters, orderBy })}
onSubmit={({ filtersName }) =>
postSavedFilter(filtersName, { searchBy, searchInput, filters, orderBy }, deidentified ?? true)
}
>
<TextInput name="filtersName" error={savedFiltersErrors} label="Nom" minLimit={2} maxLimit={50} />
</Modal>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Inputs/DurationRange/DurationInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const DurationInput = ({ value, label, deidentified = false, disabled = false, o
}, [duration])

return (
<BlockWrapper container justifyContent="space-between" xs={12} alignItems="flex-end">
<BlockWrapper container justifyContent="space-between" alignItems="flex-end">
<Grid item xs={deidentified ? 4 : 3} container alignItems="flex-start">
<DurationLegendWrapper variant="h5">{label}</DurationLegendWrapper>
</Grid>
Expand Down
4 changes: 4 additions & 0 deletions src/components/ui/Searchbar/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const Select = <T,>({ value, label, items, width = '100%', disabled, name, oncha
if (onchange) onchange(activeValue)
}, [activeValue])

useEffect(() => {
setActiveValue(value)
}, [value])

return (
<SelectWrapper width={width}>
<FormControl variant="outlined">
Expand Down
14 changes: 9 additions & 5 deletions src/hooks/filters/useSavedFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'services/aphp/servicePatients'
import { ErrorType } from 'types/error'
import { RessourceType } from 'types/requestCriterias'
import { SavedFilter, SavedFiltersResults, SearchCriterias } from 'types/searchCriterias'
import { Filters, SavedFilter, SavedFiltersResults, SearchCriterias } from 'types/searchCriterias'

export type SelectedFilter<T> = {
filterUuid: string
Expand Down Expand Up @@ -37,9 +37,9 @@ export const useSavedFilters = <T>(type: RessourceType) => {
}
}

const postSavedFilter = async <T>(name: string, searchCriterias: SearchCriterias<T>) => {
const postSavedFilter = async (name: string, searchCriterias: SearchCriterias<Filters>, deidentified: boolean) => {
try {
await postFiltersService(type, name, searchCriterias)
await postFiltersService(type, name, searchCriterias, deidentified)
setSavedFiltersErrors({ isError: false })
await getSavedFilters()
} catch {
Expand All @@ -53,9 +53,13 @@ export const useSavedFilters = <T>(type: RessourceType) => {
await getSavedFilters()
}

const patchSavedFilter = async <T>(name: string, newSearchCriterias: SearchCriterias<T>): Promise<void> => {
const patchSavedFilter = async (
name: string,
newSearchCriterias: SearchCriterias<Filters>,
deidentified: boolean
): Promise<void> => {
if (selectedSavedFilter) {
await patchFiltersService(type, selectedSavedFilter?.filterUuid, name, newSearchCriterias)
await patchFiltersService(type, selectedSavedFilter?.filterUuid, name, newSearchCriterias, deidentified)
await getSavedFilters()
}
}
Expand Down
Loading

0 comments on commit fe014e9

Please sign in to comment.