Skip to content

Commit e2974e2

Browse files
committed
fix the context issue
1 parent 96e00d0 commit e2974e2

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ VITE_USER = alice
2626
VITE_HOOK_TO_SEND = patient-view
2727
VITE_URL_FILTER = http://localhost:3000/*
2828
VITE_USE_INTERMEDIARY = false
29+
VITE_USE_PHARMACY_IN_PREFETCH = true
2930
VITE_INTERMEDIARY = http://localhost:3003
3031
VITE_DISABLE_MEDICATION_STATUS = false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Following are a list of modifiable paths:
134134
| VITE_URL | `http://localhost:3000` | The base url of this app. Should be modified if the port or domain change. |
135135
| VITE_USER | `alice` | The default user to login as when opening the app. |
136136
| VITE_USE_INTERMEDIARY | false | When true, the app will send all CDS Hooks and REMS ETASU check calls to the intermediary defined in VITE_INTERMEDIARY. |
137+
| VITE_USE_PHARMACY_IN_PREFETCH | true | When true, the app will send pharmacy information to the rems admin in the CDS Hooks prefetch |
137138
| VITE_INTERMEDIARY | `http://localhost:3030` | The base url of the intermediary. |
138139

139140
# Data Rights

src/PrefetchTemplate.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Prefetch Template Source:
22
// https://build.fhir.org/ig/HL7/davinci-crd/hooks.html#prefetch
33
export class PrefetchTemplate {
4-
static generatePrefetchMap() {
4+
static generatePrefetchMap(includePharmacy = true, pharmacyId = 'pharm0111') {
55
const prefetchMap = new Map();
66

77
const PRACTITIONER_PREFETCH = new PrefetchTemplate('{{context.userId}}');
@@ -11,20 +11,21 @@ export class PrefetchTemplate {
1111
);
1212
const PATIENT_PREFETCH = new PrefetchTemplate('{{context.patientId}}');
1313

14-
const PHARMACY_PREFETCH = new PrefetchTemplate('HealthcareService/{{context.pharmacyId}}');
15-
1614
const ALL_REQUESTS_PREFETCH = new PrefetchTemplate(
1715
'MedicationRequest?subject={{context.patientId}}&_include=MedicationRequest:medication'
1816
);
1917

20-
// prefetchMap.set("Coverage", COVERAGE_PREFETCH_QUERY);
18+
// Core prefetch items (always included)
2119
prefetchMap.set('request', REQUEST_PREFETCH);
2220
prefetchMap.set('practitioner', PRACTITIONER_PREFETCH);
2321
prefetchMap.set('patient', PATIENT_PREFETCH);
24-
prefetchMap.set('pharmacy', PHARMACY_PREFETCH);
2522
prefetchMap.set('medicationRequests', ALL_REQUESTS_PREFETCH);
26-
// prefetchMap.set("ServiceRequest", SERVICE_REQUEST_BUNDLE);
27-
// prefetchMap.set("Encounter", ENCOUNTER_BUNDLE);
23+
24+
// Optional pharmacy prefetch (only if explicitly requested and pharmacyId provided)
25+
if (includePharmacy && pharmacyId) {
26+
const PHARMACY_PREFETCH = new PrefetchTemplate(`HealthcareService/${pharmacyId}`);
27+
prefetchMap.set('pharmacy', PHARMACY_PREFETCH);
28+
}
2829

2930
return prefetchMap;
3031
}
@@ -47,8 +48,6 @@ export class PrefetchTemplate {
4748
paramElementMap.set('context.draftOrders.context.appointments.Appointment.id', ['id']);
4849
paramElementMap.set('context.draftOrders.context.encounterId', ['id']);
4950
paramElementMap.set('context.patientId', ['subject', 'reference']);
50-
paramElementMap.set('context.pharmacyId', ['id']);
51-
5251
return paramElementMap;
5352
}
5453

@@ -60,26 +59,24 @@ export class PrefetchTemplate {
6059
// Regex source: https://regexland.com/all-between-specified-characters/
6160
var parametersToFill = query.match(/(?<={{).*?(?=}})/gs);
6261
var resolvedQuery = query.slice();
62+
if (parametersToFill) {
6363
for (var j = 0; j < parametersToFill.length; j++) {
6464
var unresolvedParameter = parametersToFill[j];
6565
var resolvedParameter;
6666
if (requestBundle) {
67-
if (unresolvedParameter === 'context.pharmacyId') {
68-
resolvedParameter = pharmacyId;
69-
} else {
7067
resolvedParameter = PrefetchTemplate.resolveParameter(unresolvedParameter, requestBundle);
71-
}
7268
} else {
7369
if (unresolvedParameter === 'context.patientId') {
7470
resolvedParameter = patientReference;
7571
} else if (unresolvedParameter === 'context.userId') {
7672
resolvedParameter = userReference;
77-
} else if (unresolvedParameter === 'context.pharmacyId') {
78-
resolvedParameter = pharmacyId;
79-
}
73+
}
74+
}
75+
if (resolvedParameter) {
76+
resolvedQuery = resolvedQuery.replace('{{' + unresolvedParameter + '}}', resolvedParameter);
8077
}
81-
resolvedQuery = resolvedQuery.replace('{{' + unresolvedParameter + '}}', resolvedParameter);
8278
}
79+
}
8380
resolvedQueries.set(prefetchKey, resolvedQuery);
8481
}
8582
return resolvedQueries;

src/util/data.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import env from 'env-var';
22

33
const headerDefinitions = {
4+
includePharmacyInPreFetch: {
5+
display: 'Include Pharmacy in Prefetch',
6+
type: 'check',
7+
default: env.get('VITE_USE_PHARMACY_IN_PREFETCH').asBool()
8+
},
49
useIntermediary: {
510
display: 'Use Intermediary',
611
type: 'check',

0 commit comments

Comments
 (0)