-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
277 lines (219 loc) · 9.26 KB
/
script.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
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
const jsonData = require('./sample1.json');
const jsonData2 = require('./sample2.json');
const jsonData3 = require('./sample3.json');
// Get references to the input field and search button
const searchName = document.getElementById('filter1');
const searchDate = document.getElementById('filter2');
const searchButton = document.getElementById('searchButton');
// Function to handle the search
function handleSearch() {
const table = document.getElementById('actions-log');
const table3 = document.getElementById('admin-log');
const cards = document.getElementsByClassName('card');
console.log(cards);
// console.log("reached");
// delete rows after refresh
while (table.rows.length > 1) {
table.deleteRow(1);
}
while (table3.rows.length > 1) {
table3.deleteRow(1);
}
// refresh colors
for (let i = 0; i < cards.length; i++) {
// console.log(person2.status);
cards[i].style.backgroundColor = '#fff';
}
// console.log(searchName);
const index = jsonData.findIndex(obj => obj.name === searchName.value);
const index2 = jsonData2.findIndex(obj => obj.name === searchName.value);
const index3 = jsonData3.findIndex(obj => obj.name === searchName.value);
// console.log(index);
const person = jsonData[index];
const person2 = jsonData2[index2];
const person3 = jsonData3[index3];
// console.log(person);
const length = person.timestamps.length;
for (let i = 0; i < length; i++) {
const newRow = table.insertRow();
const name = person.name;
const timestamp = person.timestamps[i];
// console.log(timestamp);
const [datePart, timePart] = timestamp.split(' ');
const cell0 = newRow.insertCell(0);
const cell1 = newRow.insertCell(1);
const cell2 = newRow.insertCell(2);
cell0.textContent = name;
cell1.textContent = datePart;
cell2.textContent = timePart;
}
const newRow3 = table3.insertRow();
const name3 = person3.name;
console.log(name3);
const pres = person3.prescriptions;
const nur = person3.nurses;
const cell03 = newRow3.insertCell(0);
const cell13 = newRow3.insertCell(1);
const cell23 = newRow3.insertCell(2);
console.log(pres);
cell03.textContent = name3;
cell13.textContent = pres;
cell23.textContent = nur;
console.log(index2);
for (let i = 0; i < cards.length; i++) {
// console.log(person2.status);
if (person2.status[i] == 1) {
// console.log(cards[i]);
switch (i) {
case 0:
cards[i].style.backgroundColor = '#575959';
break;
case 1:
cards[i].style.backgroundColor = '#ff7526';
break;
case 2:
cards[i].style.backgroundColor = 'orange';
break;
case 3:
cards[i].style.backgroundColor = '#eee152';
break;
case 4:
cards[i].style.backgroundColor = '#32fd1d';
break;
case 5:
cards[i].style.backgroundColor = '#4155A0';
break;
case 6:
cards[i].style.backgroundColor = '#575959';
break;
default:
cards[i].style.backgroundColor = 'white';
}
}
}
}
// Add a click event listener to the search button
searchButton.addEventListener('click', handleSearch);
// const {MongoClient} = require('mongodb');
// async function main() {
// // we'll add code here soon
// const uri = "mongodb://localhost:27017/hackduke";
// const client = new MongoClient(uri);
// try {
// // Connect to the MongoDB cluster
// await client.connect();
// // Make the appropriate DB calls
// await listDatabases(client);
// } catch (e) {
// console.error(e);
// } finally {
// await client.close();
// }
// }
// main().catch(console.error);
// var MongoClient = require('mongodb').MongoClient;
// const username = encodeURIComponent('annabelle');
// const password = encodeURIComponent('lwy9Ao3mpoDAVEeN');
// const uri = `mongodb+srv://${username}:${password}@hackduke.hasnibk.mongodb.net/?retryWrites=true&w=majority`;
// // Get references to the input field and search button
// const searchName = document.getElementById('filter1');
// const searchDate = document.getElementById('filter2');
// const searchButton = document.getElementById('searchButton');
// async function connectToMongoDB() {
// const client = new MongoClient(uri);
// try {
// await client.connect();
// console.log('Connected to MongoDB!');
// const db = client.db('pillbox'); // Replace with your database name
// const collection = db.collection('box_status'); // Replace with your collection name
// const cursor = collection.find();
// // console.log(cursor);
// await listDatabases(client);
// // Now, you can query the collection to access data
// const documents = await collection.find({}).toArray();
// console.log('Retrieved documents:', documents);
// const table = document.getElementById('actions-log');
// console.log(table.rows.length);
// while (table.rows.length > 1) {
// table.deleteRow(1);
// }
// // console.log(searchName);
// const index = documents.findIndex(obj => obj.name === searchName.value);
// console.log(index);
// const person = documents[index];
// // console.log(person);
// const length = person.timestamps.length;
// for (let i = 0; i < length; i++) {
// const newRow = table.insertRow();
// const name = person.name;
// const timestamp = person.timestamps[i];
// // console.log(timestamp);
// const [datePart, timePart] = timestamp.split(' ');
// const cell0 = newRow.insertCell(0);
// const cell1 = newRow.insertCell(1);
// const cell2 = newRow.insertCell(2);
// cell0.textContent = name;
// cell1.textContent = datePart;
// cell2.textContent = timePart;
// }
// } catch (e) {
// console.error('Error:', e);
// } finally {
// await client.close();
// }
// }
// async function listDatabases(client){
// databasesList = await client.db().admin().listDatabases();
// console.log("Databases:");
// databasesList.databases.forEach(db => console.log(` - ${db.name}`));
// };
// // Add a click event listener to the search button
// searchButton.addEventListener('click', connectToMongoDB);
// var { MongoClient } = require('mongodb');
// var username = encodeURIComponent('annabelle');
// var password = encodeURIComponent('lwy9Ao3mpoDAVEeN');
// var uri = 'mongodb+srv://' + username + ':' + password + '@hackduke.hasnibk.mongodb.net/?retryWrites=true&w=majority';
// function connectToMongoDB() {
// var client = new MongoClient(uri);
// client.connect()
// .then(function () {
// console.log('Connected to MongoDB!');
// var db = client.db('pillbox'); // Replace with your database name
// var collection = db.collection('box_status'); // Replace with your collection name
// // Query the collection to access data
// return collection.find({}).toArray();
// })
// .then(function (documents) {
// console.log('Retrieved documents:', documents);
// var table = document.getElementById('actions-log');
// // Clear existing rows
// while (table.rows.length > 1) {
// table.deleteRow(1);
// }
// documents.forEach(function (person) {
// var length = person.timestamps.length;
// for (var i = 0; i < length; i++) {
// var newRow = table.insertRow();
// var name = person.name;
// var timestamp = person.timestamps[i];
// var datePartTimePart = timestamp.split(' ');
// var cell0 = newRow.insertCell(0);
// var cell1 = newRow.insertCell(1);
// var cell2 = newRow.insertCell(2);
// cell0.textContent = name;
// cell1.textContent = datePartTimePart[0];
// cell2.textContent = datePartTimePart[1];
// }
// });
// })
// .catch(function (error) {
// console.error('Error:', error);
// })
// .finally(function () {
// client.close();
// });
// }
// // Call the connectToMongoDB function
// connectToMongoDB();
// Add a click event listener to the search button
// searchButton.addEventListener('click', connectToMongoDB);