Skip to content

Commit

Permalink
Merge pull request #38 from jembi/feat-add-meta-profile-for-stub-patient
Browse files Browse the repository at this point in the history
Add patient profile to stubbed patient resource
  • Loading branch information
rcrichton authored Mar 6, 2024
2 parents 7bd980a + ae9eb8b commit 906954a
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "mpi-mediator",
"version": "v2.0.2",
"version": "v2.1.0",
"description": "An OpenHIM mediator to handle all interactions with an MPI component",
"main": "index.ts",
"scripts": {
"dev": "nodemon --config restart.json",
"start": "ts-node -r dotenv/config src/index.ts",
"format": "prettier --check --write '{src,tests}/**/*.ts'",
"lint": "eslint . --ext .ts,.js --fix",
"docker:build": "npm run build; docker build -t jembi/mpi-mediator:latest .",
"docker:build": "npm run build; docker build -t jembi/mpi-mediator:profile-fix .",
"build": "npm install; tsc -p tsconfig.build.json",
"test:unit": "LOG_LEVEL='fatal' MODE='testing' mocha -r ts-node/register 'tests/unit/*.ts' --timeout 15000",
"test:cucumber": "CUCUMBER_DEFAULT_TIMEOUT=20000 MODE='testing' cucumber-js 'tests/cucumber/features/**/*.feature' --no-color --exit --logLevel='error' --require 'tests/cucumber/step-definitions/*.ts' --require-module 'ts-node/register' --require-module 'dotenv/config' dotenv_config_path=.env.test --format-options \"{\\\"snippetInterface\\\": \\\"async-await\\\"}\" --format summary --format progress-bar",
Expand Down
1 change: 1 addition & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export const getConfig = () => {
process.env.ENABLE_JEMPI_GOLDEN_ID_UPDATE == 'true' ? true : false,
kafkaJempiAuditTopic: process.env.KAFKA_JEMPI_AUDIT_TOPIC ?? 'JeMPI-audit-trail',
bodySizeLimit: process.env.BODY_SIZE_LIMIT || '50mb',
patientProfileForStubPatient: process.env.PATIENT_PROFILE_FOR_STUB_PATIENT || '',
});
};
12 changes: 10 additions & 2 deletions src/utils/kafkaFhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ export const processBundle = async (bundle: Bundle): Promise<MpiMediatorResponse
);
} else {
const error = 'Patient entry in bundle is missing the "fullUrl"!';

logger.error(error);
return Promise.resolve(createHandlerResponseObject('Failed', {status: 400, body: {error}}));

return Promise.resolve(
createHandlerResponseObject('Failed', { status: 400, body: { error } })
);
}

return sendRequest(clientRegistryRequestDetails);
Expand Down Expand Up @@ -231,7 +235,11 @@ export const processBundle = async (bundle: Bundle): Promise<MpiMediatorResponse
});

// create a new bundle with stripped out patient and references to the MPI patient
const modifiedBundle: Bundle = modifyBundle(bundle, newPatientMap);
const modifiedBundle: Bundle = modifyBundle(
bundle,
newPatientMap,
config.patientProfileForStubPatient
);

Object.values(newPatientMap).forEach((patientData) => {
restorePatientResource(patientData);
Expand Down
13 changes: 11 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export const modifyBundle = (
mpiTransformResult?: MpiTransformResult;
mpiResponsePatient?: Patient;
};
} = {}
} = {},
patientProfileForStubPatient?: string
): Bundle => {
const modifiedBundle = Object.assign({}, bundle);

Expand All @@ -158,7 +159,7 @@ export const modifyBundle = (
throw new Error('ID in MPI response is missing');
}

return {
const stubPatient: BundleEntry<Patient> = {
fullUrl: entry.fullUrl,
resource: {
resourceType: 'Patient',
Expand All @@ -176,6 +177,14 @@ export const modifyBundle = (
url: `Patient/${newPatientId}`,
},
};

if (patientProfileForStubPatient && stubPatient.resource) {
stubPatient.resource.meta = {
profile: [patientProfileForStubPatient],
};
}

return stubPatient;
}

// Add request property to the bundle entries if missing, default to using upserts
Expand Down
116 changes: 116 additions & 0 deletions tests/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,122 @@ describe('Utils', (): void => {
expect(modifyBundle(bundle, newPatientIdMap)).to.be.deep.equal(expectedBundle);
});

it('should set a patient profile on the gutted patient resource if configured to do so', (): void => {
const bundle: Bundle = {
type: 'document',
resourceType: 'Bundle',
id: '12',
entry: [
{
fullUrl: 'Encounter/1234',
resource: {
resourceType: 'Encounter',
id: '1233',
subject: {
reference: 'Patient/1233',
},
status: 'planned',
},
},
{
fullUrl: 'Encounter/1111',
resource: {
resourceType: 'Encounter',
id: '1111',
subject: {
reference: 'Patient/1233',
},
status: 'planned',
},
},
{
fullUrl: 'Patient/1234',
resource: {
resourceType: 'Patient',
id: '1233',
name: [
{
given: ['John'],
family: 'Doe',
},
],
},
},
],
};
const expectedBundle: Bundle = {
resourceType: 'Bundle',
type: 'transaction',
id: '12',
entry: [
{
fullUrl: 'Encounter/1234',
resource: {
resourceType: 'Encounter',
id: '1233',
subject: {
reference: 'Patient/1233',
},
status: 'planned',
},
request: {
method: 'PUT',
url: 'Encounter/1233',
},
},
{
fullUrl: 'Encounter/1111',
resource: {
resourceType: 'Encounter',
id: '1111',
subject: {
reference: 'Patient/1233',
},
status: 'planned',
},
request: {
method: 'PUT',
url: 'Encounter/1111',
},
},
{
fullUrl: 'Patient/1234',
resource: {
meta: {
profile: ['http://example.com/patient-profile'],
},
resourceType: 'Patient',
link: [
{
type: 'refer',
other: {
reference: 'http://santedb-mpi:8080/fhir/Patient/xxx',
},
},
],
},
request: {
method: 'PUT',
url: 'Patient/xxx',
},
},
],
};

const newPatientIdMap: NewPatientMap = {
'Patient/1234': {
mpiResponsePatient: {
id: 'xxx',
resourceType: 'Patient',
},
},
};

expect(
modifyBundle(bundle, newPatientIdMap, 'http://example.com/patient-profile')
).to.be.deep.equal(expectedBundle);
});

it('should throw if MPI id is missing in response', (): void => {
const bundle: Bundle = {
type: 'document',
Expand Down

0 comments on commit 906954a

Please sign in to comment.