Created
November 30, 2016 23:31
-
-
Save tobalsgithub/57d4a4205768888852f63f386fb477a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var async = require('async'); | |
var apiKey = process.env.API_KEY; | |
var destinationIds = process.env.DEST_IDS.split(','); | |
var concurrent = !!process.env.CONCURRENT; | |
var deviceDataModel = getDeviceDataModel(); | |
var schedulingDataModel = getSchedulingDataModel(); | |
var subscriptions = {}; | |
var token; | |
run(); | |
function run () { | |
authenticate(apiKey, (err, accessToken) => { | |
token = accessToken; | |
console.log(`token ${token}`); | |
var fn = concurrent ? async.parallel : async.series; | |
var recurring = function () { | |
fn([ | |
async.apply(sendRequest, token, destinationIds[0]), | |
async.apply(sendRequest, token, destinationIds[1]), | |
], (err) => { | |
if (err) { | |
throw err; | |
} | |
process.nextTick(recurring); | |
}); | |
}; | |
recurring(); | |
}); | |
} | |
function sendRequest (accessToken, destinationId, cb) { | |
console.log('Sending request to ' + destinationId + ' with accessToken ' + accessToken); | |
var dataModelJSON = destinationId === destinationIds[0] ? schedulingDataModel : deviceDataModel; | |
dataModelJSON.Meta.Destinations[0].ID = destinationId; | |
var options = { | |
url: 'http://localhost:1337/endpoint', | |
headers: { | |
Authorization: 'Bearer ' + accessToken | |
}, | |
body: dataModelJSON, | |
json: true | |
}; | |
request.post(options, (err, res) => { | |
if (err) { | |
throw err; | |
} | |
setTimeout(cb, 5000); | |
}); | |
} | |
function authenticate (apiKey, cb) { | |
var options = { | |
url: 'http://localhost:1337/auth/authenticate', | |
body: { | |
apiKey: apiKey, | |
secret: 'asdfasdf' | |
}, | |
json: true | |
}; | |
request.post(options, (err, res) => { | |
console.log(err); | |
cb(null, res.body.accessToken); | |
}); | |
} | |
function getDeviceDataModel () { | |
return { | |
"Meta": { | |
"DataModel": "Device", | |
"EventType": "New", | |
"EventDateTime": "2016-11-01T15:03:19.440Z", | |
"Destinations": [ | |
{ | |
"ID": "" | |
} | |
] | |
}, | |
"Patient": { | |
"Identifiers": [ | |
{ | |
"ID": "0000000001", | |
"IDType": "MR" | |
}, | |
{ | |
"ID": "a1d4ee8aba494ca^^^&1.3.6.1.4.1.21367.2005.13.20.1000&ISO", | |
"IDType": "NIST" | |
} | |
], | |
"Demographics": { | |
"FirstName": "Timothy", | |
"MiddleName": "Paul", | |
"LastName": "Bixby", | |
"DOB": "2008-01-06", | |
"SSN": "101-01-0001", | |
"Sex": "Male", | |
"Race": "Asian", | |
"IsHispanic": null, | |
"MaritalStatus": "Single", | |
"IsDeceased": null, | |
"DeathDateTime": null, | |
"PhoneNumber": { | |
"Home": "+18088675301", | |
"Office": null, | |
"Mobile": null | |
}, | |
"EmailAddresses": [], | |
"Language": "en", | |
"Citizenship": [], | |
"Address": { | |
"StreetAddress": "4762 Hickory Street", | |
"City": "Monroe", | |
"State": "WI", | |
"ZIP": "53566", | |
"County": "Green", | |
"Country": "US" | |
} | |
}, | |
"Notes": [] | |
}, | |
"Visit": { | |
"VisitNumber": "1234", | |
"Location": { | |
"Type": null, | |
"Facility": null, | |
"Department": null, | |
"Room": null, | |
"Bed": null | |
} | |
}, | |
"Device": { | |
"ID": "dev28701" | |
}, | |
"Observations": [ | |
{ | |
"DateTime": "2015-08-13T21:08:57.581Z", | |
"Code": "Systolic", | |
"Value": "110.00", | |
"ValueType": "Numeric", | |
"Units": "mmHg" | |
}, | |
{ | |
"DateTime": "2015-08-13T21:08:57.581Z", | |
"Code": "Diastolic", | |
"Value": "90.00", | |
"ValueType": "Numeric", | |
"Units": "mmHg" | |
}, | |
{ | |
"DateTime": "2015-08-13T21:08:57.581Z", | |
"Code": "Heart Rate", | |
"Value": "55", | |
"ValueType": "Numeric", | |
"Units": "beats/min" | |
} | |
] | |
}; | |
} | |
function getSchedulingDataModel () { | |
return { | |
"Meta": { | |
"DataModel": "Scheduling", | |
"EventType": "New", | |
"EventDateTime": "2016-11-29T21:26:51.060Z", | |
"Test": true, | |
"Source": { | |
"ID": "7ce6f387-c33c-417d-8682-81e83628cbd9", | |
"Name": "Redox Dev Tools" | |
}, | |
"Destinations": [ | |
{ | |
"ID": "" | |
} | |
], | |
"Message": { | |
"ID": 5565 | |
}, | |
"Transmission": { | |
"ID": 12414 | |
}, | |
"FacilityCode": null | |
}, | |
"Patient": { | |
"Identifiers": [ | |
{ | |
"ID": "0000000001", | |
"IDType": "MR" | |
}, | |
{ | |
"ID": "e167267c-16c9-4fe3-96ae-9cff5703e90a", | |
"IDType": "REDOX" | |
}, | |
{ | |
"ID": "a1d4ee8aba494ca^^^&1.3.6.1.4.1.21367.2005.13.20.1000&ISO", | |
"IDType": "NIST" | |
} | |
], | |
"Demographics": { | |
"FirstName": "Timothy", | |
"MiddleName": "Paul", | |
"LastName": "Bixby", | |
"DOB": "2008-01-06", | |
"SSN": "101-01-0001", | |
"Sex": "Male", | |
"Race": "Asian", | |
"IsHispanic": null, | |
"MaritalStatus": "Single", | |
"IsDeceased": null, | |
"DeathDateTime": null, | |
"PhoneNumber": { | |
"Home": "+18088675301", | |
"Office": null, | |
"Mobile": null | |
}, | |
"EmailAddresses": [], | |
"Language": "en", | |
"Citizenship": [], | |
"Address": { | |
"StreetAddress": "4762 Hickory Street", | |
"City": "Monroe", | |
"State": "WI", | |
"ZIP": "53566", | |
"County": "Green", | |
"Country": "US" | |
} | |
}, | |
"Notes": [] | |
}, | |
"Visit": { | |
"VisitNumber": "1234", | |
"VisitDateTime": "2016-11-29T21:41:14.934Z", | |
"PatientClass": null, | |
"Status": null, | |
"Duration": 15, | |
"Reason": "Check up", | |
"Instructions": null, | |
"AttendingProvider": { | |
"ID": 4356789876, | |
"IDType": "NPI", | |
"FirstName": "Pat", | |
"LastName": "Granite", | |
"Credentials": [ | |
"MD" | |
], | |
"Address": { | |
"StreetAddress": "123 Main St.", | |
"City": "Madison", | |
"State": "WI", | |
"ZIP": "53703", | |
"County": "Dane", | |
"Country": "USA" | |
}, | |
"Location": { | |
"Type": null, | |
"Facility": null, | |
"Department": null | |
}, | |
"PhoneNumber": { | |
"Office": null | |
} | |
}, | |
"ConsultingProvider": { | |
"ID": null, | |
"IDType": null, | |
"FirstName": null, | |
"LastName": null, | |
"Credentials": [], | |
"Address": { | |
"StreetAddress": null, | |
"City": null, | |
"State": null, | |
"ZIP": null, | |
"County": null, | |
"Country": null | |
}, | |
"Location": { | |
"Type": null, | |
"Facility": null, | |
"Department": null | |
}, | |
"PhoneNumber": { | |
"Office": null | |
} | |
}, | |
"ReferringProvider": { | |
"ID": null, | |
"IDType": null, | |
"FirstName": null, | |
"LastName": null, | |
"Credentials": [], | |
"Address": { | |
"StreetAddress": null, | |
"City": null, | |
"State": null, | |
"ZIP": null, | |
"County": null, | |
"Country": null | |
}, | |
"Location": { | |
"Type": null, | |
"Facility": null, | |
"Department": null | |
}, | |
"PhoneNumber": { | |
"Office": null | |
} | |
}, | |
"Location": { | |
"Type": "Inpatient", | |
"Facility": "RES General Hospital", | |
"Department": "3N" | |
}, | |
"Diagnoses": [ | |
{ | |
"Code": "R07.0", | |
"Codeset": "ICD-10", | |
"Name": "Pain in throat", | |
"Type": null | |
} | |
] | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment