Skip to content

Commit

Permalink
feat(imaging): add new diagnostic report linkage for doc ref (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang authored and aetchego committed Dec 11, 2024
1 parent dcd0426 commit 31dca18
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
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 @@ export 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
1 change: 1 addition & 0 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Binary,
Claim,
Condition,
DiagnosticReport,
DocumentReference,
Encounter,
ImagingStudy,
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 } from 'mappers/pmsi'
import { mapMedicationToOrderByCode } from 'mappers/medication'
import { linkToDiagnosticReport } from './serviceImaging'

export interface IServiceCohorts {
/**
Expand Down Expand Up @@ -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 =
Expand All @@ -917,7 +919,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 } 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 @@ -436,13 +437,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 @@ -696,6 +697,7 @@ export type CohortImaging = ImagingStudy & {
serviceProvider?: string
NDA?: string
IPP?: string
diagnosticReport?: DiagnosticReport
}
export type IPatientImaging<T extends CohortImaging> = {
loading: boolean
Expand Down

0 comments on commit 31dca18

Please sign in to comment.