Skip to content

Commit a135a41

Browse files
authored
add supporting configs in rems admin for communincation forwarding (#185)
* add supporting configs in rems admin for communincation forwarding * fix the dockered ehr name * double // bug * run lint/prettier
1 parent c0f1f50 commit a135a41

4 files changed

Lines changed: 38 additions & 8 deletions

File tree

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ VSAC_API_KEY = changeMe
1212
WHITELIST = *
1313
SERVER_NAME = CodeX REMS Administrator Prototype
1414
FULL_RESOURCE_IN_APP_CONTEXT = false
15-
DOCKERED_EHR_CONTAINER_NAME = false
15+
INTERMEDIARY_PORT=3003
16+
EHR_PORT=8080
1617

1718
#Frontend Vars
1819
FRONTEND_PORT=9090

src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export default {
4242
auth: {
4343
// This server's URI
4444
resourceServer: env.get('RESOURCE_SERVER').required().asUrlString(),
45-
dockered_ehr_container_name: env.get('DOCKERED_EHR_CONTAINER_NAME').asString()
45+
dockered_ehr_container_name: env.get('DOCKERED_EHR_CONTAINER_NAME').asString(),
46+
dockered_interemediary_container_name: env
47+
.get('DOCKERED_INTERMEDIARY_CONTAINER_NAME')
48+
.asString(),
49+
dockered_ehr_port: env.get('EHR_PORT').asInt(),
50+
dockered_intermediary_port: env.get('INTERMEDIARY_PORT').asInt()
4651
//
4752
// if you use this strategy, you need to add the corresponding env vars to docker-compose
4853
//

src/lib/communication.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function sendCommunicationToEHR(
1919
// Create patient object from REMS case
2020
const patient: Patient = {
2121
resourceType: 'Patient',
22-
id: `${remsCase.patientFirstName}-${remsCase.patientLastName}`.replace(/\s+/g, '-'),
22+
id: remsCase.remsPatientId,
2323
name: [
2424
{
2525
given: [remsCase.patientFirstName],
@@ -151,20 +151,37 @@ export async function sendCommunicationToEHR(
151151
return;
152152
}
153153

154-
if (config.fhirServerConfig.auth.dockered_ehr_container_name) {
155-
const originalEhrEndpoint = ehrEndpoint;
154+
const originalEhrEndpoint = ehrEndpoint.toString().replace(/\/$/, '');
155+
logger.info(config.fhirServerConfig.auth);
156+
if (
157+
config.fhirServerConfig.auth.dockered_ehr_container_name &&
158+
originalEhrEndpoint.includes(config.fhirServerConfig.auth.dockered_ehr_port)
159+
) {
156160
ehrEndpoint = originalEhrEndpoint
157161
.replace(/localhost/g, config.fhirServerConfig.auth.dockered_ehr_container_name)
158162
.replace(/127\.0\.0\.1/g, config.fhirServerConfig.auth.dockered_ehr_container_name);
159163
logger.info(
160-
`Running locally in Docker, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}`
164+
`Running locally in Docker to ehr, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}`
165+
);
166+
} else if (
167+
config.fhirServerConfig.auth.dockered_interemediary_container_name &&
168+
originalEhrEndpoint.includes(config.fhirServerConfig.auth.dockered_intermediary_port)
169+
) {
170+
ehrEndpoint = originalEhrEndpoint
171+
.replace(/localhost/g, config.fhirServerConfig.auth.dockered_interemediary_container_name)
172+
.replace(
173+
/127\.0\.0\.1/g,
174+
config.fhirServerConfig.auth.dockered_interemediary_container_name
175+
);
176+
logger.info(
177+
`Running locally in Docker to intermediary, converting EHR url from ${originalEhrEndpoint} to ${ehrEndpoint}`
161178
);
162179
}
163180

164181
// Send Communication to EHR
165-
logger.info(`Sending Communication to EHR: ${ehrEndpoint}`);
182+
logger.info(`Sending Communication to EHR: ${ehrEndpoint}Communication`);
166183

167-
const response = await axios.post(`${ehrEndpoint}/Communication`, communication, {
184+
const response = await axios.post(`${ehrEndpoint}Communication`, communication, {
168185
headers: {
169186
'Content-Type': 'application/fhir+json'
170187
}

src/lib/etasu.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ export const createNewRemsCaseFromCDSHook = async (
197197
const patientDOB = patient.birthDate || '';
198198
const case_number = uid();
199199

200+
// Extract patientId from the patientReference (e.g., "Patient/pat017" -> "pat017")
201+
const patientId = patientReference.includes('/')
202+
? patientReference.split('/').pop() || patientReference
203+
: patientReference;
204+
200205
// Fetch the full medication from database to get NDC code
201206
const fullMedication = await medicationCollection
202207
.findOne({
@@ -225,6 +230,7 @@ export const createNewRemsCaseFromCDSHook = async (
225230
const remsRequest: Pick<
226231
RemsCase,
227232
| 'case_number'
233+
| 'remsPatientId'
228234
| 'status'
229235
| 'dispenseStatus'
230236
| 'drugName'
@@ -242,6 +248,7 @@ export const createNewRemsCaseFromCDSHook = async (
242248
| 'metRequirements'
243249
> & { originatingFhirServer?: string } = {
244250
case_number: case_number,
251+
remsPatientId: patientId,
245252
status: 'Pending',
246253
dispenseStatus: 'Pending',
247254
drugName: medicationData?.name,

0 commit comments

Comments
 (0)