From fb191b5d549c018afbc8579bd519b783d7e383bf Mon Sep 17 00:00:00 2001 From: Ryan Crichton Date: Wed, 6 Mar 2024 15:17:32 +0200 Subject: [PATCH 1/2] Add patient profile to stubbed patient resource --- src/config/config.ts | 1 + src/utils/kafkaFhir.ts | 12 ++++- src/utils/utils.ts | 13 ++++- tests/unit/utils.ts | 116 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 4 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 0058308..fd9d918 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -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 || '', }); }; diff --git a/src/utils/kafkaFhir.ts b/src/utils/kafkaFhir.ts index 8487e2b..c14a89b 100644 --- a/src/utils/kafkaFhir.ts +++ b/src/utils/kafkaFhir.ts @@ -189,8 +189,12 @@ export const processBundle = async (bundle: Bundle): Promise { restorePatientResource(patientData); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index cc60f14..bab600d 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -135,7 +135,8 @@ export const modifyBundle = ( mpiTransformResult?: MpiTransformResult; mpiResponsePatient?: Patient; }; - } = {} + } = {}, + patientProfileForStubPatient?: string ): Bundle => { const modifiedBundle = Object.assign({}, bundle); @@ -158,7 +159,7 @@ export const modifyBundle = ( throw new Error('ID in MPI response is missing'); } - return { + const stubPatient: BundleEntry = { fullUrl: entry.fullUrl, resource: { resourceType: 'Patient', @@ -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 diff --git a/tests/unit/utils.ts b/tests/unit/utils.ts index 1c582fb..3601838 100644 --- a/tests/unit/utils.ts +++ b/tests/unit/utils.ts @@ -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', From ae9eb8bffb852dd6c2287e47a6f7c56ab5c117ce Mon Sep 17 00:00:00 2001 From: Ryan Crichton Date: Wed, 6 Mar 2024 15:26:03 +0200 Subject: [PATCH 2/2] Bump version --- package-lock.json | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index cea1724..f866e2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mpi-mediator", - "version": "v2.0.2", + "version": "v2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mpi-mediator", - "version": "v2.0.2", + "version": "v2.1.0", "license": "ISC", "dependencies": { "@types/sinon": "^10.0.13", diff --git a/package.json b/package.json index e83c68b..ded4b38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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": { @@ -8,7 +8,7 @@ "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",