-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth_analysis.js
More file actions
99 lines (85 loc) · 3.32 KB
/
health_analysis.js
File metadata and controls
99 lines (85 loc) · 3.32 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
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
const addPatientButton = document.getElementById("addPatient");
const report = document.getElementById("report");
const btnSearch = document.getElementById('btnSearch');
const patients = [];
function addPatient() {
const name = document.getElementById("name").value;
const gender = document.querySelector('input[name="gender"]:checked');
const age = document.getElementById("age").value;
const condition = document.getElementById("condition").value;
if (name && gender && age && condition) {
patients.push({ name, gender: gender.value, age, condition });
resetForm();
generateReport();
}
}
function resetForm() {
document.getElementById("name").value = "";
document.querySelector('input[name="gender"]:checked').checked = false;
document.getElementById("age").value = "";
document.getElementById("condition").value = "";
}
function generateReport() {
const numPatients = patients.length;
const conditionsCount = {
Diabetes: 0,
Thyroid: 0,
"High Blood Pressure": 0,
};
const genderConditionsCount = {
Male: {
Diabetes: 0,
Thyroid: 0,
"High Blood Pressure": 0,
},
Female: {
Diabetes: 0,
Thyroid: 0,
"High Blood Pressure": 0,
},
};
for (const patient of patients) {
conditionsCount[patient.condition]++;
genderConditionsCount[patient.gender][patient.condition]++;
}
report.innerHTML = `Number of patients: ${numPatients}<br><br>`;
report.innerHTML += `Conditions Breakdown:<br>`;
for (const condition in conditionsCount) {
report.innerHTML += `${condition}: ${conditionsCount[condition]}<br>`;
}
report.innerHTML += `<br>Gender-Based Conditions:<br>`;
for (const gender in genderConditionsCount) {
report.innerHTML += `${gender}:<br>`;
for (const condition in genderConditionsCount[gender]) {
report.innerHTML += ` ${condition}: ${genderConditionsCount[gender][condition]}<br>`;
}
}
}
addPatientButton.addEventListener("click", addPatient);
function searchCondition() {
const input = document.getElementById('conditionInput').value.toLowerCase();
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
fetch('health_analysis.json')
.then(response => response.json())
.then(data => {
const condition = data.conditions.find(item => item.name.toLowerCase() === input);
if (condition) {
const symptoms = condition.symptoms.join(', ');
const prevention = condition.prevention.join(', ');
const treatment = condition.treatment;
resultDiv.innerHTML += `<h2>${condition.name}</h2>`;
resultDiv.innerHTML += `<img src="${condition.imagesrc}" alt="hjh">`;
resultDiv.innerHTML += `<p><strong>Symptoms:</strong> ${symptoms}</p>`;
resultDiv.innerHTML += `<p><strong>Prevention:</strong> ${prevention}</p>`;
resultDiv.innerHTML += `<p><strong>Treatment:</strong> ${treatment}</p>`;
} else {
resultDiv.innerHTML = 'Condition not found.';
}
})
.catch(error => {
console.error('Error:', error);
resultDiv.innerHTML = 'An error occurred while fetching data.';
});
}
btnSearch.addEventListener('click', searchCondition);