-
Notifications
You must be signed in to change notification settings - Fork 0
/
endlessapi.js
166 lines (152 loc) · 4.91 KB
/
endlessapi.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
156
157
158
159
160
161
162
163
164
165
166
var request = require("request");
const axios = require("axios");
let sessionId = "";
let analysis = "";
async function initSession() {
var options = {
method: "GET",
url: "https://endlessmedicalapi1.p.rapidapi.com/InitSession",
headers: {
"x-rapidapi-host": "endlessmedicalapi1.p.rapidapi.com",
"x-rapidapi-key": "5812113f4bmshfa9aaa56fd6325cp1518c7jsn2e3209951355",
useQueryString: true,
},
};
await request(options, function (error, response, body) {
if (error) throw new Error(error);
sessionId = JSON.parse(body)["SessionID"];
console.log(sessionId);
return sessionId;
});
}
function acceptTermsOfUse() {
var options = {
method: "POST",
url: "https://endlessmedicalapi1.p.rapidapi.com/AcceptTermsOfUse",
qs: {
SessionID: sessionId,
passphrase:
"I have read, understood and I accept and agree to comply with the Terms of Use of EndlessMedicalAPI and Endless Medical services. The Terms of Use are available on endlessmedical.com",
},
headers: {
"x-rapidapi-host": "endlessmedicalapi1.p.rapidapi.com",
"x-rapidapi-key": "5812113f4bmshfa9aaa56fd6325cp1518c7jsn2e3209951355",
"content-type": "application/x-www-form-urlencoded",
useQueryString: true,
},
form: {},
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
return body["status"];
});
}
function updateFeature(feature, value) {
var options = {
method: "POST",
url: "https://endlessmedicalapi1.p.rapidapi.com/UpdateFeature",
qs: { SessionID: sessionId, name: feature, value: value },
headers: {
"x-rapidapi-host": "endlessmedicalapi1.p.rapidapi.com",
"x-rapidapi-key": "5812113f4bmshfa9aaa56fd6325cp1518c7jsn2e3209951355",
"content-type": "application/x-www-form-urlencoded",
useQueryString: true,
},
form: {},
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}
function deleteFeature(feature) {
var options = {
method: "POST",
url: "https://endlessmedicalapi1.p.rapidapi.com/DeleteFeature",
qs: { name: feature, SessionID: sessionId },
headers: {
"x-rapidapi-host": "endlessmedicalapi1.p.rapidapi.com",
"x-rapidapi-key": "5812113f4bmshfa9aaa56fd6325cp1518c7jsn2e3209951355",
"content-type": "application/x-www-form-urlencoded",
useQueryString: true,
},
form: {},
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}
async function analyze() {
axios({
method: "GET",
url: "https://endlessmedicalapi1.p.rapidapi.com/Analyze",
headers: {
"content-type": "application/octet-stream",
"x-rapidapi-host": "endlessmedicalapi1.p.rapidapi.com",
"x-rapidapi-key": "5812113f4bmshfa9aaa56fd6325cp1518c7jsn2e3209951355",
useQueryString: true,
},
params: {
SessionID: sessionId,
},
})
.then((response) => {
let count = 0;
display =
"<br /><div><button class='btn btn-block btn-light'>Probable Diseases:</button><br>";
response["data"]["Diseases"].forEach((element) => {
for (const k in element) {
if (element.hasOwnProperty(k)) {
const el = element[k];
display +=
"<div class='m-2 collapsible'>" +
k +
": " +
(el * 100).toFixed(2) +
"%</div><div class='progress progress-secondary' style='height: 2px;'><div class='progress-bar' role='progressbar' style='width: 25%;' aria-valuenow='" +
el * 100 +
" aria-valuemin='0' aria-valuemax='100'></div></div><div class='content'>";
response["data"]["VariableImportances"][count][k].forEach((i) => {
display +=
"<small><b>" +
i[0] +
"</b> </small><small class='mr-1'>(" +
(i[1] * 100).toFixed(2) +
"%)</small><br>";
});
display += "</div>";
count = count + 1;
}
}
});
display += "</div><script>collapser();</script>";
document.getElementById("analysis").innerHTML = display;
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
this.classList.toggle("active");
var content = this.nextElementSibling.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
})
.catch((error) => {
console.log(error);
});
}
module.exports = {
sessionId,
analysis,
initSession,
acceptTermsOfUse,
analyze,
updateFeature,
deleteFeature,
};