From 31dca183003618b41b5380c3c055ee7b63eed65a Mon Sep 17 00:00:00 2001 From: Paul Bui-Quang Date: Mon, 9 Dec 2024 16:11:23 +0100 Subject: [PATCH] feat(imaging): add new diagnostic report linkage for doc ref (#1082) --- src/components/DataTable/DataTableImaging.tsx | 8 +++++- src/config.tsx | 8 ++++++ src/services/aphp/callApi.ts | 1 + src/services/aphp/serviceCohorts.ts | 4 ++- src/services/aphp/serviceImaging.ts | 27 +++++++++++++++++++ src/state/patient.ts | 4 ++- src/types.ts | 2 ++ 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/services/aphp/serviceImaging.ts diff --git a/src/components/DataTable/DataTableImaging.tsx b/src/components/DataTable/DataTableImaging.tsx index 99479f694..d0cb650b2 100644 --- a/src/components/DataTable/DataTableImaging.tsx +++ b/src/components/DataTable/DataTableImaging.tsx @@ -112,7 +112,13 @@ 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 + // TODO remove the fetch by extension when fhir drop it (expected in 2.21.0 or 2.22.0) + 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 6f6c08d63..fa59f35ed 100644 --- a/src/config.tsx +++ b/src/config.tsx @@ -16,6 +16,10 @@ export 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 0d3a3fd84..c938cd524 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -20,6 +20,7 @@ import { Binary, Claim, Condition, + DiagnosticReport, DocumentReference, Encounter, ImagingStudy, diff --git a/src/services/aphp/serviceCohorts.ts b/src/services/aphp/serviceCohorts.ts index 7adc15eca..1ddddd3e0 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 } from 'mappers/pmsi' import { mapMedicationToOrderByCode } from 'mappers/medication' +import { linkToDiagnosticReport } from './serviceImaging' export interface IServiceCohorts { /** @@ -898,6 +899,7 @@ const servicesCohorts: IServiceCohorts = { groupId, signal ) + const imagingListWithDiagnosticReport = await linkToDiagnosticReport(completeImagingList, signal) const totalImaging = imagingResponse.data?.resourceType === 'Bundle' ? imagingResponse.data?.total : 0 const totalAllImaging = @@ -917,7 +919,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 573961894..1cc209758 100644 --- a/src/state/patient.ts +++ b/src/state/patient.ts @@ -55,6 +55,7 @@ import { PMSIResourceTypes, ResourceType } from 'types/requestCriterias' import { mapToAttribute } from 'mappers/pmsi' import { getExtension } from 'utils/fhir' import { getConfig } from 'config' +import { linkToDiagnosticReport } from 'services/aphp/serviceImaging' export type Medication = { administration?: IPatientMedication @@ -436,13 +437,14 @@ const fetchImaging = createAsyncThunk diff --git a/src/types.ts b/src/types.ts index cd2a6cae3..3437a0a64 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ import { Bundle, Claim, Condition, + DiagnosticReport, DocumentReference, Encounter, Extension, @@ -696,6 +697,7 @@ export type CohortImaging = ImagingStudy & { serviceProvider?: string NDA?: string IPP?: string + diagnosticReport?: DiagnosticReport } export type IPatientImaging = { loading: boolean