Spaces:
Sleeping
Sleeping
dylanglenister
commited on
Commit
·
1faabaf
1
Parent(s):
f24832a
Updating patient js file
Browse files- static/js/patient.js +11 -6
static/js/patient.js
CHANGED
|
@@ -15,9 +15,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 15 |
|
| 16 |
function getPatientIdFromUrl() {
|
| 17 |
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
| 18 |
const pidFromUrl = urlParams.get('patient_id');
|
| 19 |
-
|
| 20 |
-
return null;
|
| 21 |
}
|
| 22 |
|
| 23 |
async function loadPatientIntoForm(patientId) {
|
|
@@ -90,19 +90,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 90 |
});
|
| 91 |
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
| 92 |
const data = await resp.json();
|
| 93 |
-
const pid = data.
|
| 94 |
localStorage.setItem('medicalChatbotPatientId', pid);
|
| 95 |
|
| 96 |
// Add to localStorage for future suggestions
|
| 97 |
const existingPatients = JSON.parse(localStorage.getItem('medicalChatbotPatients') || '[]');
|
| 98 |
const newPatient = {
|
| 99 |
-
|
| 100 |
name: payload.name,
|
| 101 |
age: payload.age,
|
| 102 |
sex: payload.sex
|
| 103 |
};
|
| 104 |
// Check if patient already exists to avoid duplicates
|
| 105 |
-
const exists = existingPatients.some(p => p.
|
| 106 |
if (!exists) {
|
| 107 |
existingPatients.push(newPatient);
|
| 108 |
localStorage.setItem('medicalChatbotPatients', JSON.stringify(existingPatients));
|
|
@@ -125,7 +125,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 125 |
if (successEdit) successEdit.addEventListener('click', () => {
|
| 126 |
successModal.classList.remove('show');
|
| 127 |
const pid = createdIdEl?.textContent?.trim() || localStorage.getItem('medicalChatbotPatientId');
|
| 128 |
-
if (pid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
enableEditMode(pid);
|
| 130 |
loadPatientIntoForm(pid);
|
| 131 |
}
|
|
|
|
| 15 |
|
| 16 |
function getPatientIdFromUrl() {
|
| 17 |
const urlParams = new URLSearchParams(window.location.search);
|
| 18 |
+
// The API uses a generic string 'id', but we'll keep the client-side validation for now.
|
| 19 |
const pidFromUrl = urlParams.get('patient_id');
|
| 20 |
+
return pidFromUrl;
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
async function loadPatientIntoForm(patientId) {
|
|
|
|
| 90 |
});
|
| 91 |
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
| 92 |
const data = await resp.json();
|
| 93 |
+
const pid = data.id;
|
| 94 |
localStorage.setItem('medicalChatbotPatientId', pid);
|
| 95 |
|
| 96 |
// Add to localStorage for future suggestions
|
| 97 |
const existingPatients = JSON.parse(localStorage.getItem('medicalChatbotPatients') || '[]');
|
| 98 |
const newPatient = {
|
| 99 |
+
id: pid,
|
| 100 |
name: payload.name,
|
| 101 |
age: payload.age,
|
| 102 |
sex: payload.sex
|
| 103 |
};
|
| 104 |
// Check if patient already exists to avoid duplicates
|
| 105 |
+
const exists = existingPatients.some(p => p.id === pid);
|
| 106 |
if (!exists) {
|
| 107 |
existingPatients.push(newPatient);
|
| 108 |
localStorage.setItem('medicalChatbotPatients', JSON.stringify(existingPatients));
|
|
|
|
| 125 |
if (successEdit) successEdit.addEventListener('click', () => {
|
| 126 |
successModal.classList.remove('show');
|
| 127 |
const pid = createdIdEl?.textContent?.trim() || localStorage.getItem('medicalChatbotPatientId');
|
| 128 |
+
if (pid) {
|
| 129 |
+
// Update URL to reflect edit mode for clarity and reload safety
|
| 130 |
+
const newUrl = new URL(window.location.href);
|
| 131 |
+
newUrl.searchParams.set('patient_id', pid);
|
| 132 |
+
window.history.pushState({ path: newUrl.href }, '', newUrl.href);
|
| 133 |
+
|
| 134 |
enableEditMode(pid);
|
| 135 |
loadPatientIntoForm(pid);
|
| 136 |
}
|