Spaces:
Sleeping
Sleeping
File size: 4,727 Bytes
f5863be |
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Health Reports Processor</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 2rem;
max-width: 800px;
}
label {
display: block;
margin-top: 1rem;
font-weight: bold;
}
input, textarea, button {
width: 100%;
padding: 0.5rem;
margin-top: 0.25rem;
box-sizing: border-box;
font-size: 1rem;
}
button {
margin-top: 1rem;
cursor: pointer;
}
pre {
background: #f4f4f4;
padding: 1rem;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
border: 1px solid #ccc;
margin-top: 1rem;
}
.error {
color: red;
margin-top: 1rem;
}
</style>
</head>
<body>
<h1>Health Reports Processor</h1>
<!-- Upload form -->
<form id="uploadForm" enctype="multipart/form-data">
<label for="uploadPatientId">Patient ID:</label>
<input type="text" id="uploadPatientId" name="patient_id" required />
<label for="files">Upload Reports:</label>
<input type="file" id="files" name="files" multiple required />
<button type="submit">Upload Reports</button>
</form>
<div id="uploadResult"></div>
<hr />
<!-- Existing process reports form -->
<form id="reportForm">
<label for="patientId">Patient ID:</label>
<input type="text" id="patientId" name="patientId" required />
<label for="filenames">Filenames (comma-separated):</label>
<input type="text" id="filenames" name="filenames" placeholder="e.g. cbc.pdf, thyroid.pdf" required />
<button type="submit">Process Reports</button>
</form>
<div id="result"></div>
<script>
// Upload form
const uploadForm = document.getElementById('uploadForm');
const uploadResult = document.getElementById('uploadResult');
uploadForm.addEventListener('submit', async (e) => {
e.preventDefault();
uploadResult.innerHTML = '';
const patientId = document.getElementById('uploadPatientId').value.trim();
const filesInput = document.getElementById('files');
if (!patientId || filesInput.files.length === 0) {
uploadResult.innerHTML = '<p class="error">Please enter a Patient ID and select at least one file.</p>';
return;
}
const formData = new FormData();
formData.append('patient_id', patientId);
for (let f of filesInput.files) {
formData.append('files', f);
}
try {
const response = await fetch('/upload_reports', {
method: 'POST',
body: formData
});
if (!response.ok) {
const errData = await response.json();
uploadResult.innerHTML = `<p class="error">Error: ${errData.error || response.statusText}</p>`;
return;
}
const data = await response.json();
uploadResult.innerHTML = `<h2>Upload Result</h2><pre>${JSON.stringify(data, null, 2)}</pre>`;
} catch (err) {
uploadResult.innerHTML = `<p class="error">Upload failed: ${err.message}</p>`;
}
});
// Process form
const form = document.getElementById('reportForm');
const resultDiv = document.getElementById('result');
form.addEventListener('submit', async (e) => {
e.preventDefault();
resultDiv.innerHTML = '';
const patientId = form.patientId.value.trim();
const filenamesRaw = form.filenames.value.trim();
if (!patientId || !filenamesRaw) {
resultDiv.innerHTML = '<p class="error">Please enter both Patient ID and filenames.</p>';
return;
}
const filenames = filenamesRaw.split(',').map(f => f.trim()).filter(f => f.length > 0);
try {
const response = await fetch('/process_reports', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ patient_id: patientId, filenames: filenames })
});
if (!response.ok) {
const errorData = await response.json();
resultDiv.innerHTML = `<p class="error">Error: ${errorData.error || response.statusText}</p>`;
return;
}
const data = await response.json();
resultDiv.innerHTML = `<h2>Processed Result</h2><pre>${JSON.stringify(data, null, 2)}</pre>`;
} catch (err) {
resultDiv.innerHTML = `<p class="error">Request failed: ${err.message}</p>`;
}
});
</script>
</body>
</html>
|