From ac2a054c6d869e4c4c0927710a5ff8e0644c4ee9 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Thu, 26 Feb 2026 10:36:59 -0500 Subject: [PATCH] add supporting configs in rems admin for communincation forwarding --- .env | 3 +++ src/config.ts | 5 ++++- src/fhir/models.ts | 2 +- src/lib/communication.ts | 20 ++++++++++++++------ src/lib/etasu.ts | 9 ++++++++- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.env b/.env index 34a5e1b..45df726 100644 --- a/.env +++ b/.env @@ -13,6 +13,9 @@ WHITELIST = * SERVER_NAME = CodeX REMS Administrator Prototype FULL_RESOURCE_IN_APP_CONTEXT = false DOCKERED_EHR_CONTAINER_NAME = false +DOCKERED_INTERMEDIARY_CONTAINER_NAME = false +INTERMEDIARY_PORT=3003 +EHR_PORT=8080 #Frontend Vars FRONTEND_PORT=9090 diff --git a/src/config.ts b/src/config.ts index eedc332..1f3c872 100644 --- a/src/config.ts +++ b/src/config.ts @@ -42,7 +42,10 @@ export default { auth: { // This server's URI resourceServer: env.get('RESOURCE_SERVER').required().asUrlString(), - dockered_ehr_container_name: env.get('DOCKERED_EHR_CONTAINER_NAME').asString() + dockered_ehr_container_name: env.get('DOCKERED_EHR_CONTAINER_NAME').asString(), + dockered_interemediary_container_name: env.get('DOCKERED_INTERMEDIARY_CONTAINER_NAME').asString(), + dockered_ehr_port: env.get('EHR_PORT').asInt(), + dockered_intermediary_port: env.get('INTERMEDIARY_PORT').asInt() // // if you use this strategy, you need to add the corresponding env vars to docker-compose // diff --git a/src/fhir/models.ts b/src/fhir/models.ts index 218052e..70d6405 100644 --- a/src/fhir/models.ts +++ b/src/fhir/models.ts @@ -161,4 +161,4 @@ remsCaseCollectionSchema.index({ drugCode: 1 }); -export const remsCaseCollection = model('RemsCaseCollection', remsCaseCollectionSchema); +export const remsCaseCollection = model('RemsCaseCollection', remsCaseCollectionSchema); \ No newline at end of file diff --git a/src/lib/communication.ts b/src/lib/communication.ts index 2f7a62c..4b42d5c 100644 --- a/src/lib/communication.ts +++ b/src/lib/communication.ts @@ -19,7 +19,7 @@ export async function sendCommunicationToEHR( // Create patient object from REMS case const patient: Patient = { resourceType: 'Patient', - id: `${remsCase.patientFirstName}-${remsCase.patientLastName}`.replace(/\s+/g, '-'), + id: remsCase.remsPatientId, name: [ { given: [remsCase.patientFirstName], @@ -151,18 +151,26 @@ export async function sendCommunicationToEHR( return; } - if (config.fhirServerConfig.auth.dockered_ehr_container_name) { - const originalEhrEndpoint = ehrEndpoint; + const originalEhrEndpoint = ehrEndpoint.toString().replace(/\/$/, '') ; + logger.info(config.fhirServerConfig.auth); + if (config.fhirServerConfig.auth.dockered_ehr_container_name && originalEhrEndpoint.includes(config.fhirServerConfig.auth.dockered_ehr_port)) { ehrEndpoint = originalEhrEndpoint .replace(/localhost/g, config.fhirServerConfig.auth.dockered_ehr_container_name) .replace(/127\.0\.0\.1/g, config.fhirServerConfig.auth.dockered_ehr_container_name); logger.info( - `Running locally in Docker, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}` + `Running locally in Docker to ehr, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}` + ); + } else if (config.fhirServerConfig.auth.dockered_interemediary_container_name && originalEhrEndpoint.includes(config.fhirServerConfig.auth.dockered_intermediary_port)) { + ehrEndpoint = originalEhrEndpoint + .replace(/localhost/g, config.fhirServerConfig.auth.dockered_interemediary_container_name) + .replace(/127\.0\.0\.1/g, config.fhirServerConfig.auth.dockered_interemediary_container_name); + logger.info( + `Running locally in Docker to intermediary, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}` ); } // Send Communication to EHR - logger.info(`Sending Communication to EHR: ${ehrEndpoint}`); + logger.info(`Sending Communication to EHR: ${ehrEndpoint}/Communication`); const response = await axios.post(`${ehrEndpoint}/Communication`, communication, { headers: { @@ -179,4 +187,4 @@ export async function sendCommunicationToEHR( logger.error(`Failed to send Communication to EHR: ${error.message}`); throw error; } -} +} \ No newline at end of file diff --git a/src/lib/etasu.ts b/src/lib/etasu.ts index 341d91e..73dce2e 100644 --- a/src/lib/etasu.ts +++ b/src/lib/etasu.ts @@ -196,6 +196,11 @@ export const createNewRemsCaseFromCDSHook = async ( const patientLastName = patient.name?.[0].family || ''; const patientDOB = patient.birthDate || ''; const case_number = uid(); + + // Extract patientId from the patientReference (e.g., "Patient/pat017" -> "pat017") + const patientId = patientReference.includes('/') + ? patientReference.split('/').pop() || patientReference + : patientReference; // Fetch the full medication from database to get NDC code const fullMedication = await medicationCollection @@ -225,6 +230,7 @@ export const createNewRemsCaseFromCDSHook = async ( const remsRequest: Pick< RemsCase, | 'case_number' + | 'remsPatientId' | 'status' | 'dispenseStatus' | 'drugName' @@ -242,6 +248,7 @@ export const createNewRemsCaseFromCDSHook = async ( | 'metRequirements' > & { originatingFhirServer?: string } = { case_number: case_number, + remsPatientId: patientId, status: 'Pending', dispenseStatus: 'Pending', drugName: medicationData?.name, @@ -1013,4 +1020,4 @@ export const processQuestionnaireResponseSubmission = async (requestBody: Bundle export { getResource, getQuestionnaireResponse }; -export default router; +export default router; \ No newline at end of file