140 lines
5.4 KiB
HTML
140 lines
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Test Health Info API</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 20px;
|
|
}
|
|
.message {
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
background-color: #f4f4f4;
|
|
border: 1px solid #ddd;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h2>Test Health Info API</h2>
|
|
|
|
<h3>Get Health Info</h3>
|
|
<label for="user_id_get">User ID:</label>
|
|
<input type="number" id="user_id_get" min="1" placeholder="Enter user ID">
|
|
<button onclick="getHealthInfo()">Get Health Info</button>
|
|
|
|
<div id="get-result" class="message"></div>
|
|
|
|
<h3>Update Health Info</h3>
|
|
<label for="user_id_post">User ID:</label>
|
|
<input type="number" id="user_id_post" min="1" placeholder="Enter user ID">
|
|
<br><br>
|
|
<label for="height">Height:</label>
|
|
<input type="number" id="height" placeholder="Enter height" step="0.01">
|
|
<br><br>
|
|
<label for="weight">Weight:</label>
|
|
<input type="number" id="weight" placeholder="Enter weight" step="0.01">
|
|
<br><br>
|
|
<label for="blood_type">Blood Type:</label>
|
|
<input type="text" id="blood_type" placeholder="Enter blood type">
|
|
<br><br>
|
|
<label for="medical_history">Medical History:</label>
|
|
<textarea id="medical_history" placeholder="Enter medical history"></textarea>
|
|
<br><br>
|
|
<label for="disability_status">Disability Status:</label>
|
|
<input type="checkbox" id="disability_status">
|
|
<br><br>
|
|
<label for="disability_category">Disability Category:</label>
|
|
<input type="text" id="disability_category" placeholder="Enter disability category">
|
|
<br><br>
|
|
<label for="disability_grade">Disability Grade:</label>
|
|
<input type="text" id="disability_grade" placeholder="Enter disability grade">
|
|
<br><br>
|
|
<button onclick="updateHealthInfo()">Update Health Info</button>
|
|
|
|
<div id="post-result" class="message"></div>
|
|
|
|
<script>
|
|
// Function to get health info via GET request
|
|
function getHealthInfo() {
|
|
const userId = document.getElementById('user_id_get').value;
|
|
const resultDiv = document.getElementById('get-result');
|
|
|
|
if (!userId) {
|
|
resultDiv.textContent = "Please enter a valid user ID.";
|
|
return;
|
|
}
|
|
|
|
fetch(`/ec_user/health_info/api/`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
|
|
},
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.error) {
|
|
resultDiv.textContent = `Error: ${data.error}`;
|
|
} else {
|
|
resultDiv.textContent = `Height: ${data.height}, Weight: ${data.weight}, Blood Type: ${data.blood_type}, Medical History: ${data.medical_history}, Disability Status: ${data.disability_status}, Disability Category: ${data.disability_category}, Disability Grade: ${data.disability_grade}`;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
resultDiv.textContent = `Error: ${error.message}`;
|
|
});
|
|
}
|
|
|
|
// Function to update health info via POST request
|
|
function updateHealthInfo() {
|
|
const userId = document.getElementById('user_id_post').value;
|
|
const height = document.getElementById('height').value;
|
|
const weight = document.getElementById('weight').value;
|
|
const bloodType = document.getElementById('blood_type').value;
|
|
const medicalHistory = document.getElementById('medical_history').value;
|
|
const disabilityStatus = document.getElementById('disability_status').checked;
|
|
const disabilityCategory = document.getElementById('disability_category').value;
|
|
const disabilityGrade = document.getElementById('disability_grade').value;
|
|
const resultDiv = document.getElementById('post-result');
|
|
|
|
if (!userId || !height || !weight || !bloodType) {
|
|
resultDiv.textContent = "Please fill out all required fields.";
|
|
return;
|
|
}
|
|
|
|
const postData = {
|
|
height: height,
|
|
weight: weight,
|
|
blood_type: bloodType,
|
|
medical_history: medicalHistory,
|
|
disability_status: disabilityStatus,
|
|
disability_category: disabilityCategory,
|
|
disability_grade: disabilityGrade
|
|
};
|
|
|
|
fetch(`/ec_user/health_info/api/`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
|
|
},
|
|
body: JSON.stringify(postData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.error) {
|
|
resultDiv.textContent = `Error: ${data.error}`;
|
|
} else {
|
|
resultDiv.textContent = data.message;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
resultDiv.textContent = `Error: ${error.message}`;
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|