-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (95 loc) · 3.56 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<style>
table, table tr td{
border: 1px solid black;
}
.ca-na{
background-color: #ff0000;
}
.ca-a{
background-color: #008000;
color: #ffffff;
}
.dropdownContainer{
padding: 2rem 0;
}
</style>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script>
var districtId = '';
var statusInterval;
function setDistrict(){
districtId = $('#districtList').val();
if(districtId !== ''){
statusInterval = setInterval(() => {
getStatus(districtId);
}, 2000);
}else{
clearInterval(statusInterval);
}
}
async function getStatus(selectedDistrict){
let bodyHtml = '';
let karnatakaDistrictIDs = [294, 276, 265];
let otherDistrictIDs = [selectedDistrict];
let queryDistrictIds;
if(selectedDistrict === '294'){
queryDistrictIds = karnatakaDistrictIDs;
}else{
queryDistrictIds = otherDistrictIDs;
}
let todayDate = `${new Date().getDate()}-${new Date().getMonth()+1}-${new Date().getFullYear()}`;
let requests = queryDistrictIds.map(districtCode => fetch("https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id="+districtCode+"&date="+todayDate+""));
let promiseResponse = await Promise.all(requests).then(responses => Promise.all(responses.map(r => r.json())));
promiseResponse.map(result => {
result.centers.map(sessions=>{
sessions.sessions.map(sessionsAge => {
if(sessionsAge.min_age_limit < 45){
var capacityStatus = 'ca-na';
if(sessionsAge.available_capacity > 0){
capacityStatus = 'ca-a';
}
bodyHtml += '<tr><td>'+sessions.name+'</td><td>'+sessions.pincode+'</td><td>'+sessionsAge.vaccine+'</td><td>'+sessionsAge.min_age_limit+'</td><td>'+sessionsAge.date+'</td><td class="'+capacityStatus+'"">'+sessionsAge.available_capacity+'</td></tr>';
}
})
})
$('#bodyContent').html(bodyHtml);
});
}
</script>
</head>
<body>
<div class="dropdownContainer">
<label for="">Select State</label>
<select onchange="setDistrict()" name="districtList" id="districtList">
<option value="">Select one District</option>
<option value="45">Tinsikua (ASSAM)</option>
<option value="294">BBMP (Karnataka)</option>
<option value="69">Karimganj (ASSAM)</option>
</select>
</div>
<table>
<thead>
<tr>
<td>Hospital</td>
<td>Pincode</td>
<td>Vaccine Name</td>
<td>Age</td>
<td>Date</td>
<td>Availability</td>
</tr>
</thead>
<tbody id="bodyContent">
</tbody>
</table>
</body>
</html>