-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionMetadata.SetRequestHeaders.js
64 lines (57 loc) · 1.82 KB
/
ConnectionMetadata.SetRequestHeaders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This script reads a mocked (hard-coded, thanks APIGEE...) Custom Attribute which
* in the non-sandbox environments comes from an APIGEE app. These are sent to the API
* as the `NHSD-Connection-Metadata` header.
*
* The Http Header 'NHSD-End-User-Organisation-ODS' is expected.
*/
//---- CHANGE AVAILABLE POINTER TYPES FOR EACH ORGANISATION HERE ----//
const nrlPointers = {
// This one is needed for Smoke Tests
"RJ11": [
"http://snomed.info/sct|736253001",
"http://snomed.info/sct|736253002"
],
// These ones are needed for the Seed data
"Y05868": [
"http://snomed.info/sct|736253002",
"http://snomed.info/sct|887701000000100",
"http://snomed.info/sct|1363501000000100",
"http://snomed.info/sct|861421000000109"
],
"8J008": [
"http://snomed.info/sct|1363501000000100"
],
"RY26A": [
"http://snomed.info/sct|861421000000109"
],
"RM559":[
"http://snomed.info/sct|736253002"
]
};
//-------------------------------------------------------------------//
(function () {
var odsCode = context.getVariable(
"request.header.NHSD-End-User-Organisation-ODS"
);
if (!odsCode || odsCode.trim().length === 0) {
//This will trigger RaiseFault.400MissingODSHeader.xml - see proxies/default.xml in the DefaultFaultRules
return;
}
var nrlPointerTypes = nrlPointers[odsCode];
if (!nrlPointerTypes) {
//This will trigger RaiseFault.400NoPointers.xml - see targets/target.xml
return;
}
var odsCodeExtension = context.getVariable(
"request.header.NHSD-End-User-Organisation"
);
var connectionMetadata = {
"nrl.ods-code": odsCode,
"nrl.ods-code-extension": odsCodeExtension,
"nrl.pointer-types": nrlPointerTypes,
"nrl.app-id": "NRL-SANDBOX-APP"
};
context.targetRequest.headers["NHSD-Connection-Metadata"] =
connectionMetadata;
})();