Skip to content

Commit

Permalink
fix: fixed patient total and document datatable dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ManelleG authored and Mehdi-BOUYAHIA committed Nov 19, 2024
1 parent 5f8bc10 commit 7d4b546
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/Dashboard/PatientList/PatientList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 3 additions & 10 deletions src/components/DataTable/DataTableComposition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
<React.Fragment key={documentId}>
<TableRow className={classes.tableBodyRows}>
<TableCellWrapper align="left">
<Typography variant="button">{title ?? 'Document sans titre'}</Typography>
<Typography>
{date} à {hour}
</Typography>
<Typography>{date}</Typography>
{getStatusChip(status)}
</TableCellWrapper>

Expand Down
65 changes: 43 additions & 22 deletions src/services/aphp/serviceCohorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface IServiceCohorts {
) => Promise<
| {
totalPatients: number
totalAllPatients: number
originalPatients: Patient[] | undefined
agePyramidData?: AgeRepartitionType
genderRepartitionMap?: GenderRepartitionType
Expand Down Expand Up @@ -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)

Expand All @@ -459,6 +479,7 @@ const servicesCohorts: IServiceCohorts = {

return {
totalPatients: totalPatients ?? 0,
totalAllPatients: totalAllPatients ?? 0,
originalPatients,
genderRepartitionMap,
agePyramidData
Expand Down

0 comments on commit 7d4b546

Please sign in to comment.