From 7d4b546b1e4557248fa19217a161b016311934ff Mon Sep 17 00:00:00 2001 From: ManelleG Date: Tue, 19 Nov 2024 10:10:24 +0100 Subject: [PATCH] fix: fixed patient total and document datatable dates --- .../Dashboard/PatientList/PatientList.tsx | 4 +- .../DataTable/DataTableComposition.tsx | 13 +--- src/services/aphp/serviceCohorts.ts | 65 ++++++++++++------- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/components/Dashboard/PatientList/PatientList.tsx b/src/components/Dashboard/PatientList/PatientList.tsx index 5a38c174c..10d9260b1 100644 --- a/src/components/Dashboard/PatientList/PatientList.tsx +++ b/src/components/Dashboard/PatientList/PatientList.tsx @@ -134,13 +134,13 @@ const PatientList = ({ groupId, total, deidentified }: PatientListProps) => { controllerRef.current?.signal ) if (result) { - const { totalPatients, originalPatients, genderRepartitionMap, agePyramidData } = result + const { totalPatients, totalAllPatients, originalPatients, genderRepartitionMap, agePyramidData } = result if (originalPatients) setPatientsList(originalPatients) if (includeFacets) { if (genderRepartitionMap) setPatientData(getGenderRepartitionSimpleData(genderRepartitionMap)) if (agePyramidData) setAgePyramid(agePyramidData) } - setPatientsResult((ps) => ({ ...ps, nb: totalPatients, label: 'patient(s)' })) + setPatientsResult((ps) => ({ ...ps, nb: totalPatients, total: totalAllPatients, label: 'patient(s)' })) checkIfPageAvailable(totalPatients, page, setPage, dispatch) } diff --git a/src/components/DataTable/DataTableComposition.tsx b/src/components/DataTable/DataTableComposition.tsx index d086f0063..9c872f3c5 100644 --- a/src/components/DataTable/DataTableComposition.tsx +++ b/src/components/DataTable/DataTableComposition.tsx @@ -29,6 +29,7 @@ import { Visibility } from '@mui/icons-material' import { DocumentStatuses, Order, OrderBy } from 'types/searchCriterias' import StatusChip, { ChipStyles } from 'components/ui/StatusChip' import { DocumentReference } from 'fhir/r4' +import moment from 'moment' type DataTableCompositionProps = { loading: boolean @@ -137,22 +138,14 @@ const DataTableCompositionLine: React.FC<{ const documentContent = findContent?.attachment?.data ? Buffer.from(findContent?.attachment.data, 'base64').toString('utf-8') : '' + const date = document.date ? moment(document.date).format('DD/MM/YYYY [à] HH:mm') : 'Date inconnue' - const date = document.date ? new Date(document.date).toLocaleDateString('fr-FR') : '' - const hour = document.date - ? new Date(document.date).toLocaleTimeString('fr-FR', { - hour: '2-digit', - minute: '2-digit' - }) - : '' return ( {title ?? 'Document sans titre'} - - {date} à {hour} - + {date} {getStatusChip(status)} diff --git a/src/services/aphp/serviceCohorts.ts b/src/services/aphp/serviceCohorts.ts index a92454d62..7a4cf0381 100644 --- a/src/services/aphp/serviceCohorts.ts +++ b/src/services/aphp/serviceCohorts.ts @@ -138,6 +138,7 @@ export interface IServiceCohorts { ) => Promise< | { totalPatients: number + totalAllPatients: number originalPatients: Patient[] | undefined agePyramidData?: AgeRepartitionType genderRepartitionMap?: GenderRepartitionType @@ -420,30 +421,49 @@ const servicesCohorts: IServiceCohorts = { birthdates && Math.abs(moment(birthdates[0]).diff(moment(), deidentified ? 'months' : 'days')) const maxBirthdate = birthdates && Math.abs(moment(birthdates[1]).diff(moment(), deidentified ? 'months' : 'days')) - const patientsResp = await fetchPatient({ - size: 20, - offset: page ? (page - 1) * 20 : 0, - _sort: orderBy.orderBy, - sortDirection: orderBy.orderDirection, - pivotFacet: includeFacets ? ['age-month_gender', 'deceased_gender'] : [], - _list: groupId ? [groupId] : [], - gender: filters && filters.genders.join(','), - searchBy, - _text: searchInput.trim(), - minBirthdate: minBirthdate, - maxBirthdate: maxBirthdate, - deceased: - filters && filters.vitalStatuses && filters.vitalStatuses.length === 1 - ? filters.vitalStatuses.includes(VitalStatus.DECEASED) - ? true - : false - : undefined, - deidentified: deidentified, - signal: signal, - _elements: ['gender', 'name', 'birthDate', 'deceased', 'identifier', 'extension'] - }) + + const atLeastAFilter = + !!searchInput || + (filters?.genders && filters?.genders.length > 0) || + filters?.birthdatesRanges?.[0] || + filters?.birthdatesRanges?.[1] || + (filters?.vitalStatuses && filters?.vitalStatuses.length > 0) + + const [patientsResp, allPatientsResp] = await Promise.all([ + fetchPatient({ + size: 20, + offset: page ? (page - 1) * 20 : 0, + _sort: orderBy.orderBy, + sortDirection: orderBy.orderDirection, + pivotFacet: includeFacets ? ['age-month_gender', 'deceased_gender'] : [], + _list: groupId ? [groupId] : [], + gender: filters && filters.genders.join(','), + searchBy, + _text: searchInput.trim(), + minBirthdate: minBirthdate, + maxBirthdate: maxBirthdate, + deceased: + filters && filters.vitalStatuses && filters.vitalStatuses.length === 1 + ? filters.vitalStatuses.includes(VitalStatus.DECEASED) + ? true + : false + : undefined, + deidentified: deidentified, + signal: signal, + _elements: ['gender', 'name', 'birthDate', 'deceased', 'identifier', 'extension'] + }), + atLeastAFilter + ? fetchPatient({ + size: 0, + _list: groupId ? [groupId] : [], + signal: signal + }) + : null + ]) const totalPatients = patientsResp.data.resourceType === 'Bundle' ? patientsResp.data.total : 0 + const totalAllPatients = + allPatientsResp?.data?.resourceType === 'Bundle' ? allPatientsResp.data.total ?? totalPatients : totalPatients const originalPatients = getApiResponseResources(patientsResp) @@ -459,6 +479,7 @@ const servicesCohorts: IServiceCohorts = { return { totalPatients: totalPatients ?? 0, + totalAllPatients: totalAllPatients ?? 0, originalPatients, genderRepartitionMap, agePyramidData