Here's a step-by-step guide to building an illness diagnosis website using HTML, CSS, JavaScript, and Node.js/Express:
1. Project Structure
illness-diagnosis/
├── public/
│ ├── css/
│ │ └── style.css
│ ├── js/
│ │ └── app.js
│ └── index.html
├── server.js
└── illnesses.json
2. Frontend Implementation (HTML/CSS/JS)
index.html
<!DOCTYPE html>
<html>
<head>
<title>Symptom Checker</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="quiz-container">
<!-- First question displayed by default -->
<div class="question active" id="q1">
<p>Do you have a fever?</p>
<label><input type="radio" name="fever" value="yes"> Yes</label>
<label><input type="radio" name="fever" value="no"> No</label>
<button onclick="nextQuestion()">Next</button>
</div>
<!-- Subsequent questions hidden initially -->
<div class="question" id="q2">
<p>Do you have a cough?</p>
<label><input type="radio" name="cough" value="yes"> Yes</label>
<label><input type="radio" name="cough" value="no"> No</label>
<button onclick="nextQuestion()">Next</button>
<button onclick="prevQuestion()">Previous</button>
</div>
<!-- Add more questions similarly -->
<!-- ... -->
<div class="question" id="q10">
<!-- Final question -->
</div>
<div class="result" id="result" style="display: none;">
<h2>Diagnosis:</h2>
<div id="diagnosis-output"></div>
<h3>Suggested Treatment:</h3>
<div id="treatment-output"></div>
</div>
</div>
<script src="js/app.js"></script>
</body>
</html>
style.css
.question {
display: none;
padding: 20px;
border: 1px solid #ccc;
margin: 10px 0;
}
.active {
display: block;
}
.result {
padding: 20px;
border: 1px solid #00ff00;
}
app.js
let currentQuestion = 1;
function nextQuestion() {
document.getElementById(`q${currentQuestion}`).classList.remove('active');
currentQuestion++;
document.getElementById(`q${currentQuestion}`).classList.add('active');
if (currentQuestion === 10) {
document.getElementById('submit').style.display = 'block';
}
}
function prevQuestion() {
document.getElementById(`q${currentQuestion}`).classList.remove('active');
currentQuestion--;
document.getElementById(`q${currentQuestion}`).classList.add('active');
}
document.querySelector('form').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const symptoms = Object.fromEntries(formData.entries());
const response = await fetch('/diagnosis', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(symptoms)
});
const result = await response.json();
document.getElementById('diagnosis-output').textContent = result.name;
document.getElementById('treatment-output').textContent = result.treatment;
document.getElementById('result').style.display = 'block';
});
3. Backend Implementation (Node.js/Express)
server.js
const express = require('express');
const app = express();
const fs = require('fs');
const port = 3000;
app.use(express.json());
app.use(express.static('public'));
// Load illness data
const illnesses = JSON.parse(fs.readFileSync('illnesses.json'));
app.post('/diagnosis', (req, res) => {
let bestMatch = null;
let maxScore = 0;
illnesses.forEach(illness => {
let score = 0;
Object.entries(illness.symptoms).forEach(([symptom, weight]) => {
if (req.body[symptom] === 'yes') {
score += weight;
}
});
if (score > maxScore) {
maxScore = score;
bestMatch = illness;
}
});
res.json(bestMatch);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
illnesses.json
{
"illnesses": [
{
"name": "Common Cold",
"symptoms": {
"fever": 1,
"cough": 3,
"soreThroat": 2,
"headache": 1,
"runnyNose": 4
},
"treatment": "Rest, hydration, over-the-counter cold medication..."
},
{
"name": "Flu",
"symptoms": {
"fever": 3,
"cough": 2,
"bodyAches": 4,
"fatigue": 3,
"headache": 2
},
"treatment": "Bed rest, antiviral medication if caught early..."
},
// Add more illnesses...
]
}
4. Key Considerations
5. Testing & Deployment
- Test symptom combinations to ensure accurate diagnosis
- Deploy using services like Vercel or Heroku
- Consider adding more questions and illnesses for better accuracy
- Implement error handling for incomplete submissions
This implementation provides a basic framework. For production use, consider:
- Adding more sophisticated medical logic
- Implementing a database for dynamic data
- Including a wider range of symptoms and illnesses
- Adding user authentication for personalized tracking
The system uses a simple scoring algorithm, but you could enhance it with machine learning or integrate with medical APIs for better accuracy. Always include clear disclaimers about not replacing professional medical advice.