Skip to content

Commit

Permalink
Add projection for the patient retrieval endpoint
Browse files Browse the repository at this point in the history
Setting the query parameter 'projection=partial' returns a partial patient (name, gender, birthDate and identifiers)
  • Loading branch information
bradsawadye committed May 8, 2024
1 parent 4336fcb commit 95e3ef8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { matchAsyncHandler } from './handlers/matchPatientAsync';
import { matchSyncHandler } from './handlers/matchPatientSync';
import { mpiMdmQueryLinksMiddleware } from '../middlewares/mpi-mdm-query-links';
import { validationMiddleware } from '../middlewares/validation';
import { buildOpenhimResponseObject, getData } from '../utils/utils';
import { buildOpenhimResponseObject, getData, patientProjector } from '../utils/utils';
import { fetchEverythingByRef } from './handlers/fetchPatientResources';
import { mpiMdmSummaryMiddleware } from '../middlewares/mpi-mdm-summary';
import { fetchPatientSummaryByRef } from './handlers/fetchPatientSummaries';
Expand Down Expand Up @@ -125,6 +125,9 @@ routes.get('/fhir/Patient/:patientId', async (req, res) => {
const patient = mpiResponse.body as Patient;

patient.id = requestedId;

if (req.query.projection === 'partial') mpiResponse.body = patientProjector(patient);

logger.debug(
`Mapped upstream ID ${upsteamId} to requested ID ${requestedId} in response body`
);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export const transformPatientResourceForMPI = (patient: Patient): MpiTransformRe
export const restorePatientResource = (patientData: PatientData) => {
patientData.restoredPatient = patientData.mpiResponsePatient;

// restore the source uuid of the patient
const id = Object.assign({id: ''}, patientData.mpiTransformResult?.patient).id;
patientData.restoredPatient = Object.assign({}, patientData.restoredPatient, {id});

if (patientData.mpiTransformResult?.extension?.length) {
patientData.restoredPatient = Object.assign({}, patientData.restoredPatient, {
extension: patientData.mpiTransformResult.extension,
Expand Down Expand Up @@ -312,3 +316,14 @@ export const mergeBundles = async (

return bundle;
};

export const patientProjector = (patient: Patient) : Patient => {
return {
resourceType: patient.resourceType,
id: patient.id,
identifier: patient.identifier,
name: patient.name,
birthDate: patient.birthDate,
gender: patient.gender
}
};

0 comments on commit 95e3ef8

Please sign in to comment.