Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(imaging): add new diagnostic report linkage for doc ref #1082

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/DataTable/DataTableImaging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 8 additions & 0 deletions src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type AppConfig = {
enabled: boolean
shortCohortLimit: number
}
diagnosticReport: {
enabled: boolean
useStudyParam: boolean
}
export: {
enabled: boolean
exportLinesLimit: number
Expand Down Expand Up @@ -197,6 +201,10 @@ let config: AppConfig = {
enabled: true,
shortCohortLimit: 2000
},
diagnosticReport: {
enabled: false,
useStudyParam: false
},
export: {
enabled: true,
exportLinesLimit: 300000
Expand Down
39 changes: 39 additions & 0 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Binary,
Claim,
Condition,
DiagnosticReport,
DocumentReference,
Encounter,
Extension,
Expand Down Expand Up @@ -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<FHIR_Bundle_Response<DiagnosticReport>>(`/DiagnosticReport${queryString}`, {
signal
})

return response
}

/**
*
* Retrieve the codeList from FHIR api either from expanding a code or fetching the roots of the valueSet
Expand Down
4 changes: 3 additions & 1 deletion src/services/aphp/serviceCohorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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 =
Expand All @@ -916,7 +918,7 @@ const servicesCohorts: IServiceCohorts = {
totalAllResults: totalAllImaging ?? 0,
totalPatients: totalPatientImaging ?? 0,
totalAllPatients: totalAllPatientsImaging ?? 0,
list: completeImagingList ?? []
list: imagingListWithDiagnosticReport ?? []
}
},

Expand Down
27 changes: 27 additions & 0 deletions src/services/aphp/serviceImaging.ts
Original file line number Diff line number Diff line change
@@ -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<CohortImaging[]> => {
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}`)
)
}))
}
4 changes: 3 additions & 1 deletion src/state/patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MedicationAdministration>
Expand Down Expand Up @@ -445,13 +446,14 @@ const fetchImaging = createAsyncThunk<FetchImagingReturn, FetchImagingParams, {
)

const imagingList = linkElementWithEncounter(imagingResponse.imagingList, hospits, deidentified)
const imagingListWithDiagnosticReport = await linkToDiagnosticReport(imagingList, signal)

return {
imaging: {
loading: false,
count: imagingResponse.imagingTotal,
total: patientState?.imaging?.total ? patientState?.imaging?.total : imagingResponse.imagingTotal,
list: imagingList,
list: imagingListWithDiagnosticReport,
page,
options
} as IPatientImaging<CohortImaging>
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Bundle,
Claim,
Condition,
DiagnosticReport,
DocumentReference,
Encounter,
Extension,
Expand Down Expand Up @@ -697,6 +698,7 @@ export type CohortImaging = ImagingStudy & {
serviceProvider?: string
NDA?: string
IPP?: string
diagnosticReport?: DiagnosticReport
}
export type IPatientImaging<T extends CohortImaging> = {
loading: boolean
Expand Down
Loading