-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path042023_project_v2.html
294 lines (223 loc) · 8.53 KB
/
042023_project_v2.html
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
<!DOCTYPE html>
<html>
<head>
<title>Patient Query Page</title>
<!-- load the jQuery library -->
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<!-- CSS -->
<style>
/* asterisk below selects all elements, use it for styles that aren't inherited, like box-sizing */
/* box-sizing: border-box allows setting sizes for element content, padding, and border */
* {
box-sizing: border-box;
}
/* body selects the body element */
/* styles set here are inherited into some subelements of the body, unless overridden */
body {
font: 20px Arial;
}
/* input elements inside a form do not inherit the body font */
/* sets styles for input buttons */
input {
border: 1px solid transparent;
background-color: #f1f1f1; /* slightly gray */
padding: 10px;
font-size: 20px;
}
/* sets style for the submit button */
button {
background-color: DodgerBlue;
color: #fff; /* white; */
}
/* sets styles for a select element dropdown option */
select {
font-size: 16px;
width: 200px;
}
/* sets styles for a table, table header cell (th), and a table data cell (td) */
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 15px;
}
/* sets width for the entire table */
table {
width: 400px;
}
/* sets text alignment for a table header cell */
th {
text-align: left;
}
/* sets text alignment for a table data cell */
td {
text-align: left;
}
/* overrides default background color for every other table row (tr) */
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>DECAMP2 Patient Query </h1>
<h2>Welcome to the DECAMP2 Patient Query! </h2>
<p>
Select from the options below whether you would like to perform a single patient query or query of the entire database.
</p>
<h3 margin = 100>Single Patient Query</h3>
Enter a patient ID (example:xxxx):
<input type="text" id="id">
<button type="button" id="singlePt_button">Submit</button>
<div id="single-query-div"></div>
<div id="single_download_button"></div>
<h3>Whole Database Search</h3>
Select one of the options here to search the entire database:
<label for="opt"> </label>
<select id="opt">
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
</select>
<button type="button" id="multiplePt_button">Submit</button>
<div id= "multi-query-div"></div>
<h3>Download Entire Dataset</h3>
<button type="button" id="download_button">Download Dataset</button><br><br>
<script>
$(document).ready(function() {
$("#singlePt_button").click(function() {
$("#single-query-div").empty();
var id = $("#id").val();
if (CheckID(id) == 0) {
$.get("https://bioed.bu.edu/cgi-bin/students_23/Team_G/041923_Project_AJAX.py",
{
id: id,
query: "singlePatientSearch"
},
function(data) {
if (data["error"] == 0) {
submitSingleQuery(data["table_data"], id);
//createButton();
} else {
$("#single-query-div").append(data["message"]);
}
},
"json"
);
}
else {
alert(CheckID(id))
}
});
$("#multiplePt_button").click(function() {
$("#multi-query-div").empty();
var opt=$("#opt").val();
// TODO: not working
$.get("https://bioed.bu.edu/cgi-bin/students_23/Team_G/042023_Project_AJAX.py",
{
opt: opt,
query: "wholePatientSearch"
},
function(data) {
if (data["error"] == 0) {
submitMultipleQuery(data["table_data"], opt);
} else {
$("#multi-query-div").append(data["message"]);
}
},
"json"
);
alert(check(opt))
});
});
function downloadDataset() {
// TODO: code to download entire dataset
}
function CheckID(id) {
errorMessage = ""
if (id == 0) {
return "You didnt enter data "
}
return errorMessage
}
function check(opt) {
errorMessage = ""
return opt
return errorMessage
}
function SingleTableTitle(id) {
return `Data table for patient id ${id}`
}
function submitSingleQuery(data,id) {
var id = document.getElementById("id").value;
let tableTitle = SingleTableTitle(id)
let table_body_contents = "";
let rowData = "";
$("#single-query-div").empty();
if (data != "") {
// TODO: add relevant data and change column headings
for (let row = 0; row < data.length; row++) {
rowData = data[row];
a = rowData[0]
b = rowData[1]
c = rowData[2]
d = rowData[3]
table_body_contents += `<tr><td> ${a}</td><td> ${b}</td><td> ${c}</td><td> ${d}</td></tr>`;
}
let table_template = `<table class="table table-hover"><thead><tr><th>a</th><th>b</th><th>c</th><th>d</th></tr></thead><tbody>${table_body_contents}</tbody></table>`;
$("#single-query-div").append(tableTitle);
//put the final table in the table div
$("#single-query-div").append(table_template);
// add button to download table as text file
let downloadBtn = document.createElement("button");
downloadBtn.innerHTML = "click here to download this data as a .txt file";
downloadBtn.onclick = function() {
let tableData = "";
let rows = document.querySelectorAll("table tr");
// loop through table rows and columns to build table data
for (let i = 0; i < rows.length; i++) {
let cols = rows[i].querySelectorAll("td");
for (let j = 0; j < cols.length; j++) {
tableData += cols[j].innerText + "\t";
}
tableData += "\n";
}
// create a blob with the table data
let blob = new Blob([tableData], { type: "text/plain;charset=utf-8" });
// create a download link and trigger click event to download file
let downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = "singlePtTable.txt";
downloadLink.click();
};
$("#single-query-div").append(downloadBtn);
} //if
} //funct
function downloadTable() {
//TODO
}
function submitMultipleQuery(data,opt) {
var opt = document.getElementById("opt").value;
// TODO: (eventually) make this more specific
let tableTitle = 'Whole Database Query'
let table_body_contents = "";
let rowData = "";
$("#multi-query-div").empty();
if (data != "") {
// TODO: add relevant data and change column headings
for (let row = 0; row < data.length; row++) {
rowData = data[row];
a = rowData[0]
b = rowData[1]
c = rowData[2]
d = rowData[3]
table_body_contents += `<tr><td> ${a}</td><td> ${b}</td><td> ${c}</td><td> ${d}</td></tr>`;
} //for
let table_template = `<table class="table table-hover"><thead><tr><th>a</th><th>b</th><th>c</th><th>d</th></tr></thead><tbody>${table_body_contents}</tbody></table>`;
$("#multi-query-div").append(tableTitle);
//put the final table in the table div
$("#multi-query-div").append(table_template);
} //if
} // function
</script>
</body>
</html>