-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHack_doctors.java
More file actions
401 lines (277 loc) · 10.4 KB
/
Hack_doctors.java
File metadata and controls
401 lines (277 loc) · 10.4 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
package Tactio;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package hack_doctors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
public class Hack_doctors {
private static String TOKEN ;
//get last page
public static int getLastPage(JsonObject rootObject) {
JsonArray link = rootObject.get("link").getAsJsonArray();
JsonObject lastPageJsonObject= link.get(2).getAsJsonObject();
String lastPageUrl =lastPageJsonObject.get("url").getAsString();
String lastPage = lastPageUrl.substring(lastPageUrl.indexOf("page=")+5);
int lstPage = Integer.parseInt(lastPage);
return lstPage;
}
public static String getPatients() {
String id = "";
try {
String endpoint = "https://sandbox86.tactiorpm7000.com/tactio-clinician-api/1.1.4/patient";
String params = "";
String jsonOutput = endpointToJson(endpoint, params);
JsonElement jelement = new JsonParser().parse(jsonOutput);
JsonObject rootObject = jelement.getAsJsonObject();
//get last page
int lstPage =getLastPage( rootObject);
JsonArray entry = rootObject.get("entry").getAsJsonArray();
for(int page=1;page<lstPage;page++) {
for (int i = 0; i<entry.size(); i++) {
id = entry.get(i).getAsJsonObject().get("resource").getAsJsonObject().get("id").getAsString();
observation(id);
}
}
return id;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static void observation(String id) {
try {
String endpoint = "https://sandbox86.tactiorpm7000.com/tactio-clinician-api/1.1.4/observation";
String params = "subject="+id;
ArrayList<Double> gluc = new ArrayList<Double>();
ArrayList<Double> bmi = new ArrayList<Double>();
ArrayList<Double> gluc_post = new ArrayList<Double>();
ArrayList<Double> gluc_BT = new ArrayList<Double>();
ArrayList<Double> tgr = new ArrayList<Double>();
ArrayList<Double> hdl = new ArrayList<Double>();
ArrayList<Double> ldl = new ArrayList<Double>();
ArrayList<Double> wbc = new ArrayList<Double>();
ArrayList<Double> sys = new ArrayList<Double>();
ArrayList<Double> dias = new ArrayList<Double>();
ArrayList<Double> pr = new ArrayList<Double>();
ArrayList<Double> A1C = new ArrayList<Double>();
params = "subject="+id;
String jsonOutput = endpointToJson(endpoint, params);
JsonElement jelement = new JsonParser().parse(jsonOutput);
JsonObject rootObject = jelement.getAsJsonObject();
JsonArray entry = rootObject.get("entry").getAsJsonArray();
int lstPage =getLastPage( rootObject);
for (int page = 1; page<lstPage; page++) {
params = "subject="+id+"&count=5";
jsonOutput = endpointToJson(endpoint, params);
jelement = new JsonParser().parse(jsonOutput);
rootObject = jelement.getAsJsonObject();
entry = rootObject.get("entry").getAsJsonArray();
for (int i = 0; i<entry.size(); i++) {
String field_gluc =getValue("glucose", entry, i);
String field_bmi =getValue("bmi", entry, i);
String field_glucose_post_meal =getValue("glucose_post_meal", entry, i);
String field_glucose_bedtime =getValue("glucose_bedtime", entry, i);
String field_triglyceride =getValue("triglyceride", entry, i);
String field_hdl =getValue("hdl", entry, i);
String field_ldl =getValue("ldl", entry, i);
String field_whiteBloodCount =getValue("whiteBloodCount", entry, i);
String field_systolic =getValue("systolic", entry, i);
String field_diastolic =getValue("diastolic", entry, i);
String field_pulse_rate =getValue("pulse_rate", entry, i);
String field_A1C =getValue("A1C", entry, i);
//glucose
if(!field_gluc.equals("")) {
gluc.add(Double.parseDouble(field_gluc));
}
else if(!field_bmi.equals("")) {
//bmi
bmi.add(Double.parseDouble(field_bmi));
} else if(!field_glucose_post_meal.equals("")) {
//glucose_post_meal
gluc_post.add(Double.parseDouble(field_glucose_post_meal));
}
else if (!field_glucose_bedtime.equals("")) {
//gluc_bedtime
gluc_BT.add(Double.parseDouble(field_glucose_bedtime));
}
else if (!field_triglyceride.equals("")) {
//triglyceride
tgr.add(Double.parseDouble(field_triglyceride));
}
else if (!field_hdl.equals("")) {
//hdl
hdl.add(Double.parseDouble(field_hdl));
}
//ldl
else if(!field_ldl.equals("")) {
ldl.add(Double.parseDouble(field_ldl));
}
else if(!field_whiteBloodCount.equals("")) {
//whiteBloodCount
wbc.add(Double.parseDouble(field_whiteBloodCount));
}
else if(!field_systolic.equals("")) {
//systolic
sys.add(Double.parseDouble(field_systolic));
}
else if(!field_diastolic.equals("")) {
//diastolic
dias.add(Double.parseDouble(field_diastolic));
}
else if(!field_pulse_rate.equals("")) {
//pulse_rate
pr.add(Double.parseDouble(field_pulse_rate));
} else if(!field_A1C.equals("")) {
//A1C
A1C.add(Double.parseDouble(field_A1C));
}
}
}
//mean
double mean_gluc= mean_stDev(gluc)[0];
double mean_bmi= mean_stDev(bmi)[0];
double mean_gluc_post= mean_stDev(gluc_post)[0];
double mean_gluc_BT= mean_stDev(gluc_BT)[0];
double mean_tgr= mean_stDev(tgr)[0];
double mean_hdl= mean_stDev(hdl)[0];
double mean_ldl= mean_stDev(ldl)[0];
double mean_wbc= mean_stDev(wbc)[0];
double mean_sys= mean_stDev(sys)[0];
double mean_dias= mean_stDev(dias)[0];
double mean_pr= mean_stDev(pr)[0];
double mean_A1C= mean_stDev(A1C)[0];
//standard_dev
double stDev_gluc= mean_stDev(gluc)[1];
double stDev_gluc_post= mean_stDev(gluc_post)[1];
double stDev_gluc_BT= mean_stDev(gluc_BT)[1];
double stDev_tgr= mean_stDev(tgr)[1];
double stDev_hdl= mean_stDev(hdl)[1];
double stDev_ldl= mean_stDev(ldl)[1];
double stDev_wbc= mean_stDev(wbc)[1];
double stDev_sys= mean_stDev(sys)[1];
double stDev_dias= mean_stDev(dias)[1];
double stDev_pr= mean_stDev(pr)[1];
double stDev_A1C= mean_stDev(A1C)[1];
Patient p = new Patient(id, mean_bmi, mean_gluc, stDev_gluc, mean_gluc_post, stDev_gluc_post, mean_gluc_BT, stDev_gluc_BT, mean_A1C, stDev_A1C,
mean_sys, stDev_sys, mean_dias, stDev_dias, mean_pr, stDev_pr, mean_wbc, stDev_wbc, mean_tgr, stDev_tgr, mean_hdl, stDev_hdl, mean_ldl,
stDev_ldl);
p.hasInfection();
p.hasObesity();
p.hasDiabetesAndHyper();
p.hasDys();
} catch (Exception e) {
e.printStackTrace();
}
}
//create field string with jsonObject
public static String getValue(String input, JsonArray entry, int index) {
String value= "";
JsonObject x = (JsonObject) entry.get(index).getAsJsonObject();
JsonObject resource = (JsonObject) x.get("resource").getAsJsonObject();
JsonObject code = (JsonObject) resource.get("code").getAsJsonObject();
String text =code.get("text").getAsString();
if(text.equals(input)) {
JsonObject vQ = (JsonObject) resource.get("valueQuantity").getAsJsonObject();
value= vQ.get("value").getAsString();
return value;
}
return value;
}
//method to calculate the mean and standard deviation
public static double [] mean_stDev(ArrayList<Double> val) {
double average=0.0;
for(int i=0;i<val.size();i++) {
average += val.get(i);
}
average/=val.size();
double stDev=0.0;
for(int i=0;i<val.size();i++) {
stDev += (Math.pow((val.get(i)-average), 2.0));
}
stDev/=val.size();
stDev = Math.sqrt(stDev);
return new double [] {average, stDev};
}
private static String endpointToJson(String endpoint, String params) {
params = params.replace(' ', '+');
try {
String fullURL = endpoint;
if (params.isEmpty() == false) {
fullURL += "?" + params;
}
URL requestURL = new URL(fullURL);
HttpURLConnection connection = (HttpURLConnection) requestURL.openConnection();
String bearerAuth = "Bearer " + TOKEN;
connection.setRequestProperty("Authorization", bearerAuth);
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
String jsonOutput = "";
while ((inputLine = in.readLine()) != null) {
jsonOutput += inputLine;
}
in.close();
return jsonOutput;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
private static void accessToken() {
String token = "";
try {
String url = "https://sandbox86.tactiorpm7000.com/token.php";
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
// add header
post.setHeader("Content-Type", "application/json");
JSONObject rootObject = new JSONObject();
rootObject.put("grant_type", "password");
rootObject.put("client_id", "083e9a44a763473fbeb62fbf90b74551");
rootObject.put("client_secret", "ba09798f0921456e8b4e5e4588ea536d");
rootObject.put("username", "tactioClinician");
rootObject.put("password", "tactio");
StringEntity entity = new StringEntity(rootObject.toString(), "UTF8");
post.setEntity(entity);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
JsonElement jelement = new JsonParser().parse(result.toString());
JsonObject obj = jelement.getAsJsonObject();
token = obj.get("access_token").getAsString();
TOKEN = token;
} catch (Exception e) {
System.out.println("Something wrong here... make sure you set your Client ID and Client Secret properly!");
e.printStackTrace();
}
}
public static void main(String[] args) {
accessToken();
getPatients();
System.out.println(Patient.infection);
System.out.println(Patient.obese);
System.out.println(Patient.diaHyper);
System.out.println(Patient.dys);
}
}