diff --git a/src/components/DataTable/DataTableImaging.tsx b/src/components/DataTable/DataTableImaging.tsx index 99479f694..3c40d4fe3 100644 --- a/src/components/DataTable/DataTableImaging.tsx +++ b/src/components/DataTable/DataTableImaging.tsx @@ -112,7 +112,12 @@ const DataTableImagingLine: React.FC<{ const nbSeries = imagingItem.numberOfSeries ?? '-' const accessNumber = imagingItem.identifier?.find((identifier) => identifier.system?.includes('accessNumber'))?.value ?? '-' - const documentId = getExtension(imagingItem, 'docId')?.valueString + const documentId = imagingItem.diagnosticReport + ? imagingItem.diagnosticReport.presentedForm + ?.find((el) => el.contentType === 'application/pdf') + ?.url?.split('/') + .pop() + : getExtension(imagingItem, 'docId')?.valueString const serviceProvider = imagingItem.serviceProvider return ( diff --git a/src/config.tsx b/src/config.tsx index d42062635..ea53b8237 100644 --- a/src/config.tsx +++ b/src/config.tsx @@ -16,6 +16,10 @@ type AppConfig = { enabled: boolean shortCohortLimit: number } + diagnosticReport: { + enabled: boolean + useStudyParam: boolean + } export: { enabled: boolean exportLinesLimit: number @@ -197,6 +201,10 @@ let config: AppConfig = { enabled: true, shortCohortLimit: 2000 }, + diagnosticReport: { + enabled: false, + useStudyParam: false + }, export: { enabled: true, exportLinesLimit: 300000 diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 0efff21af..7e59e6e32 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -21,6 +21,7 @@ import { Binary, Claim, Condition, + DiagnosticReport, DocumentReference, Encounter, Extension, @@ -1085,6 +1086,44 @@ export const fetchLocation = async (args: fetchLocationProps) => { return response } +type fetchDiagnosticReportProps = { + _elements?: string[] + size?: number + offset?: number + code?: string + date?: string + patient?: string[] + study?: string[] + encounter?: string[] + _list?: string[] + signal?: AbortSignal +} +export const fetchDiagnosticReport = async (args: fetchDiagnosticReportProps) => { + const { _list, _elements, code, date, patient, study, encounter, size, offset, signal } = args + const config = getConfig() + + let options: string[] = [] + if (size !== undefined) options = [...options, `_count=${size}`] + if (offset) options = [...options, `_offset=${offset}`] + if (config.features.diagnosticReport.useStudyParam && study) + options = [...options, `study=${study.reduce(paramValuesReducer, '')}`] + if (encounter) options = [...options, `encounter=${encounter.reduce(paramValuesReducer, '')}`] + if (patient) options = [...options, `patient=${patient.reduce(paramValuesReducer, '')}`] + if (date) options = [...options, `date=${date}`] + if (code) options = [...options, `code=${code}`] + if (_elements && _elements.length > 0) + options = [...options, `_elements=${_elements.filter(uniq).reduce(paramValuesReducer, '')}`] + + if (_list && _list.length > 0) options = [...options, `_list=${_list.filter(uniq).reduce(paramValuesReducer, '')}`] + + const queryString = options.length > 0 ? `?${options.reduce(paramsReducer, '')}` : '' + const response = await apiFhir.get>(`/DiagnosticReport${queryString}`, { + signal + }) + + return response +} + /** * * Retrieve the codeList from FHIR api either from expanding a code or fetching the roots of the valueSet diff --git a/src/services/aphp/serviceCohorts.ts b/src/services/aphp/serviceCohorts.ts index 7a4cf0381..0c3ba5906 100644 --- a/src/services/aphp/serviceCohorts.ts +++ b/src/services/aphp/serviceCohorts.ts @@ -79,6 +79,7 @@ import { getExtension } from 'utils/fhir' import { PMSIResourceTypes, ResourceType } from 'types/requestCriterias' import { mapToOrderByCode, mapToUrlCode } from 'mappers/pmsi' import { mapMedicationToOrderByCode } from 'mappers/medication' +import { linkToDiagnosticReport } from './serviceImaging' export interface IServiceCohorts { /** @@ -897,6 +898,7 @@ const servicesCohorts: IServiceCohorts = { groupId, signal ) + const imagingListWithDiagnosticReport = await linkToDiagnosticReport(completeImagingList, signal) const totalImaging = imagingResponse.data?.resourceType === 'Bundle' ? imagingResponse.data?.total : 0 const totalAllImaging = @@ -916,7 +918,7 @@ const servicesCohorts: IServiceCohorts = { totalAllResults: totalAllImaging ?? 0, totalPatients: totalPatientImaging ?? 0, totalAllPatients: totalAllPatientsImaging ?? 0, - list: completeImagingList ?? [] + list: imagingListWithDiagnosticReport ?? [] } }, diff --git a/src/services/aphp/serviceImaging.ts b/src/services/aphp/serviceImaging.ts new file mode 100644 index 000000000..fffd7747f --- /dev/null +++ b/src/services/aphp/serviceImaging.ts @@ -0,0 +1,27 @@ +import { getConfig } from 'config' +import { CohortImaging } from 'types' +import { getApiResponseResources } from 'utils/apiHelpers' +import { fetchDiagnosticReport } from './callApi' +import { ImagingStudy } from 'fhir/r4' + +export const linkToDiagnosticReport = async ( + imagingList: ImagingStudy[], + signal?: AbortSignal +): Promise => { + const config = getConfig() + if (!config.features.diagnosticReport.enabled || !config.features.diagnosticReport.useStudyParam) { + return Promise.resolve(imagingList) + } + const diagnosticReports = getApiResponseResources( + await fetchDiagnosticReport({ + study: imagingList.map((study) => study.id as string), + signal + }) + ) + return imagingList.map((imaging) => ({ + ...imaging, + diagnosticReport: diagnosticReports?.find((report) => + report.imagingStudy?.find((study) => study.reference === `ImagingStudy/${imaging.id}`) + ) + })) +} diff --git a/src/state/patient.ts b/src/state/patient.ts index f90916ef2..9efbf64f5 100644 --- a/src/state/patient.ts +++ b/src/state/patient.ts @@ -55,6 +55,7 @@ import { PMSIResourceTypes, ResourceType } from 'types/requestCriterias' import { mapToAttribute, mapToUrlCode } from 'mappers/pmsi' import { getExtension } from 'utils/fhir' import { getConfig } from 'config' +import { linkToDiagnosticReport } from 'services/aphp/serviceImaging' export type Medication = { administration?: IPatientMedication @@ -445,13 +446,14 @@ const fetchImaging = createAsyncThunk diff --git a/src/types.ts b/src/types.ts index e1354f2d2..51de0a8f3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ import { Bundle, Claim, Condition, + DiagnosticReport, DocumentReference, Encounter, Extension, @@ -697,6 +698,7 @@ export type CohortImaging = ImagingStudy & { serviceProvider?: string NDA?: string IPP?: string + diagnosticReport?: DiagnosticReport } export type IPatientImaging = { loading: boolean