Repository navigation
Expand file tree
/
Copy pathadmin.js
More file actions
47 lines (45 loc) · 1.8 KB
/
Copy pathadmin.js
File metadata and controls
47 lines (45 loc) · 1.8 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
document.addEventListener('DOMContentLoaded', function() {
fetch('http://localhost:8000/get_patients.php')
.then(response => response.json())
.then(data => {
if (Array.isArray(data)) {
const patientsList = document.getElementById('patients-list');
patientsList.innerHTML = '';
data.forEach(patient => {
const patientDiv = document.createElement('div');
patientDiv.innerHTML = `
<p>ID: ${patient.id}</p>
<p>Name: ${patient.name}</p>
<p>Code: ${patient.code}</p>
<p>Severity: ${patient.severity}</p>
<p>Status: ${patient.status}</p>
<p>Queue Time: ${new Date(patient.queue_time).toLocaleString()}</p>
<button onclick="updateStatus(${patient.id}, 'treated')">Mark as Treated</button>
<hr>
`;
patientsList.appendChild(patientDiv);
});
} else {
console.error('Unexpected response format:', data);
}
})
.catch(error => console.error('Error fetching patients:', error));
});
function updateStatus(id, status) {
fetch('http://localhost:8000/update_patients.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `id=${id}&status=${status}`
})
.then(response => response.json())
.then(data => {
if (data.message) {
alert(data.message);
location.reload();
} else {
alert('Error updating patient status.');
}
});
}