forked from electron/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunity.js
156 lines (139 loc) · 5.26 KB
/
unity.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var request = require('request');
// replace with your own appname, serviceusername, and servicepassword!
var ff = {
"appname": 'HealthReactor.NeauxClick.TestApp',
"serviceusername": 'Healt-ce66-NeauxClick-test',
"servicepassword": 'H%fLthR9@Ct0Rn%7^xCc#C5t%st8pp'
}
var Url = 'http://tw115ga-azure.unitysandbox.com';
var Svc_username = ff.serviceusername;
var Svc_password = ff.servicepassword;
var Appname = ff.appname;
var Ehr_username = 'jmedici';
var Ehr_password = 'password01';
// create the shitty unity JSON bundle //
var _buildJSON = (action, appname, ehruserid, patientid, unitytoken,
param1, param2, param3, param4, param5, param6, data) =>
{
return {
'Action': action,
'Appname': appname,
'AppUserID': ehruserid,
'PatientID': patientid,
'Token': unitytoken,
'Parameter1': param1 || '', 'Parameter2': param2 || '',
'Parameter3': param3 || '', 'Parameter4': param4 || '',
'Parameter5': param5 || '', 'Parameter6': param6 || '',
'Data': data || ''
};
};
// post JSON to endpoint //
var _unityAction = (json, callback) => {
console.log('sending: ', json);
request.post({
url: Url + '/Unity/UnityService.svc/json/MagicJson',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(json)
}, (err, res, body) => {
callback(err, body);
});
}
// build Magic action JSON string
module.exports = {
buildJSON: _buildJSON,
unityAction: _unityAction,
getToken: (callback) => {
request.post({
url: Url + '/Unity/UnityService.svc/json/GetToken',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify( { 'Username': Svc_username, 'Password': Svc_password } )
}, (err, res, body) => {
if(err) {
callback(err);
return;
}
if(body.indexOf('Error') != -1) {
_token = null;
callback(body);
return;
}
callback(null, _token = body);
});
},
authEHR: (callback) => {
var json = _buildJSON('GetUserAuthentication', Appname, Ehr_username, '', _token, Ehr_password);
_unityAction(json, (err, body) => {
if(err) {
callback(err);
return;
}
var bodyJson = JSON.parse(body);
var valid_user = bodyJson[0]['getuserauthenticationinfo'][0]['ValidUser'];
if(valid_user == 'YES') {
callback(null);
} else {
callback('EHR user is invalid: ' + body[0]['getuserauthenticationinfo'][0]['ErrorMessage']);
}
});
},
getServerInfo: (callback) => {
var json = _buildJSON('GetServerInfo', Appname, Ehr_username, '', _token);
_unityAction(json, callback);
},
getUserDetails: (callback) => {
var json = _buildJSON('GetUserDetails', Appname, Ehr_username, '', _token);
_unityAction(json, callback);
},
// callback is invoked with: { status: [success/error], data: [data] }
saveVital: (patientId, data, callback) => {
var xml =
'<savevitalsdatarequest>'
+ '<savevitalsdata fieldid=\"' + data.type + '\" value1=\"' + data.value + '\"';
if(data.value2 != null) {
xml += ' value2=\"' + data.value2 + '\"';
}
if(data.units != null) {
xml += ' units=\"' + data.units + '\"';
}
xml += ' />' + '</savevitalsdatarequest>';
var json = _buildJSON('SaveVitalsData', Appname, Ehr_username, patientId, _token, xml);
_unityAction(json, callback);
},
saveProblemsData: (patientId, data, callback) => {
var xml =
"<saveproblemsdatarequest>"
+ "<saveproblemsdata setid=\"" + data.id + "\" fieldid=\"problem\" attributeid=\"title\" value1=\"" + data.title + "\"/>"
+ "<saveproblemsdata setid=\"" + data.id + "\" fieldid=\"problem\" attributeid=\"code\" value1=\"" + data.code + "\" />"
+ "<saveproblemsdata setid=\"" + data.id + "\" fieldid=\"problem\" attributeid=\"source\" value1=\"" + data.source + "\"/>"
+ "<saveproblemsdata setid=\"" + data.id + "\" fieldid=\"status\" value1=\"" + data.status + "\"/>"
+ "<saveproblemsdata setid=\"" + data.id + "\" fieldid=\"severity\" value1=\"" + data.severity + "\"/>"
+ "</saveproblemsdatarequest>";
var json = _buildJSON('SaveProblemsData', Appname, Ehr_username, patientId, _token, xml);
_unityAction(json, callback);
}
}
/*var getPatients = function(){
console.log('GetPatients:');
var stdin = process.openStdin();
console.log('Enter a Patient ID to display (e.g., 324): ');
stdin.addListener("data", function(d) {
// note: d is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then substring()
var data=d.toString().trim();
console.log("you entered: [" + data + "]");
if (!data) {
console.log('No patient ID specified; exiting.');
emitter.emit('CleanUp');
}
else {
// Call GetPatient Magic action; Parameter1-6 and data not used in this example
var json = buildJSON('GetPatient', Appname, Ehr_username, data, token);
unityAction(json, function(body) {
console.log('Output from GetPatient: ');
console.log(JSON.stringify(body));
emitter.emit('CleanUp');
});
}
});
};*/