-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
65 lines (52 loc) · 1.95 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
const workerURL = "https://health-worker.mari-hirota97.workers.dev"
document.getElementById('health-form').addEventListener('submit', async function(e) {
e.preventDefault();
const formData = {
name: document.getElementById('name').value,
age: document.getElementById('age').value,
symptoms: document.getElementById('symptoms').value,
duration: document.getElementById('duration').value,
severity: document.getElementById('severity').value
};
try {
const response = await fetch(`${workerURL}/predict`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
const data = await response.json();
document.getElementById('result').classList.remove('hidden');
document.getElementById('prediction').innerText = `Prediction: ${data.prediction}`;
if (data.serious) {
document.getElementById('schedule-btn').classList.remove('hidden');
} else {
document.getElementById('schedule-btn').classList.add('hidden');
}
} catch (error) {
alert('Error: ' + error.message);
}
});
document.getElementById('schedule-btn').addEventListener('click', async function() {
const formData = {
name: document.getElementById('name').value,
age: document.getElementById('age').value,
symptoms: document.getElementById('symptoms').value,
duration: document.getElementById('duration').value,
severity: document.getElementById('severity').value
};
try {
const response = await fetch(`${workerURL}/schedule`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
const data = await response.json();
alert(`Appointment scheduled for: ${data.time}`);
} catch (error) {
alert('Error: ' + error.message);
}
});