forked from amrit03b/MedQ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
85 lines (61 loc) · 2.65 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
const diseases = {
Cold: ['fever', 'cough'],
Flu: ['fever', 'cough'],
Covid19: ['fever', 'cough', 'headache'],
Allergies: ['sneezing', 'itchy_eyes', 'runny_nose'],
Migraine: ['severe_headache', 'nausea', 'light_sensitivity']
};
document.getElementById('detect-btn').addEventListener('click', function () {
const selectedSymptoms = Array.from(document.querySelectorAll('input[name="symptom"]:checked'))
.map(checkbox => checkbox.value);
const matchedDiseases = matchDisease(selectedSymptoms);
displayDiseases(matchedDiseases);
});
function matchDisease(symptoms) {
const matchedDiseases = [];
for (const disease in diseases) {
const diseaseSymptoms = diseases[disease];
const allSymptomsMatched = diseaseSymptoms.every(symptom => symptoms.includes(symptom));
if (allSymptomsMatched) {
matchedDiseases.push(disease);
}
}
return matchedDiseases;
}
function displayDiseases(diseases) {
const diseaseList = document.getElementById('disease-list');
diseaseList.innerHTML = '';
if (diseases.length === 0) {
const listItem = document.createElement('li');
listItem.textContent = 'No matching diseases found.';
const consultLink = document.createElement('a');
consultLink.href = 'https://www.practo.com/kolkata/doctors';
consultLink.textContent = 'Consult Doctors';
listItem.appendChild(document.createElement('br'));
listItem.appendChild(document.createElement('br'));
listItem.appendChild(consultLink);
diseaseList.appendChild(listItem);
} else {
diseases.forEach(disease => {
const listItem = document.createElement('li');
const link = document.createElement('a');
link.href = "";
link.textContent = disease;
listItem.appendChild(link);
console.log("Hello");
if (disease === 'Cold') {
link.href = 'https://www.practo.com/kolkata/treatment-for-colds';
} else if (disease === 'Flu') {
link.href = 'https://www.practo.com/kolkata/treatment-for-flu';
} else if (disease === 'Covid19') {
link.href = 'https://www.practo.com/kolkata/doctors-for-coronavirus-symptoms-treatment';
} else if (disease === 'Allergies') {
link.href = 'https://www.lybrate.com/kolkata/treatment-for-allergy';
} else if (disease === 'Migraine') {
link.href = 'https://www.practo.com/kolkata/doctors-for-migraine-treatment';
}
diseaseList.appendChild(listItem);
});
}
document.getElementById('result-container').style.display = 'block';
}