Spaces:
Runtime error
Runtime error
Commit
·
94fccea
1
Parent(s):
fd44f08
Upd patient creator
Browse files- static/js/patient.js +8 -11
static/js/patient.js
CHANGED
|
@@ -13,12 +13,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 13 |
let isEditMode = false;
|
| 14 |
let currentPatientId = null;
|
| 15 |
|
| 16 |
-
function
|
| 17 |
const urlParams = new URLSearchParams(window.location.search);
|
| 18 |
const pidFromUrl = urlParams.get('patient_id');
|
| 19 |
if (pidFromUrl && /^\d{8}$/.test(pidFromUrl)) return pidFromUrl;
|
| 20 |
-
const pidFromStorage = localStorage.getItem('medicalChatbotPatientId');
|
| 21 |
-
if (pidFromStorage && /^\d{8}$/.test(pidFromStorage)) return pidFromStorage;
|
| 22 |
return null;
|
| 23 |
}
|
| 24 |
|
|
@@ -47,11 +45,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 47 |
if (titleEl) titleEl.textContent = 'Edit Patient';
|
| 48 |
}
|
| 49 |
|
| 50 |
-
// Initialize edit mode if patient_id is
|
| 51 |
-
const
|
| 52 |
-
if (
|
| 53 |
-
enableEditMode(
|
| 54 |
-
loadPatientIntoForm(
|
| 55 |
}
|
| 56 |
|
| 57 |
cancelBtn.addEventListener('click', () => {
|
|
@@ -92,11 +90,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 92 |
const data = await resp.json();
|
| 93 |
const pid = data.patient_id;
|
| 94 |
localStorage.setItem('medicalChatbotPatientId', pid);
|
| 95 |
-
// Show success modal
|
| 96 |
if (createdIdEl) createdIdEl.textContent = pid;
|
| 97 |
successModal.classList.add('show');
|
| 98 |
-
// Switch to edit mode automatically after creation
|
| 99 |
-
enableEditMode(pid);
|
| 100 |
}
|
| 101 |
} catch (err) {
|
| 102 |
console.error(err);
|
|
@@ -113,6 +109,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 113 |
const pid = createdIdEl?.textContent?.trim() || localStorage.getItem('medicalChatbotPatientId');
|
| 114 |
if (pid && /^\d{8}$/.test(pid)) {
|
| 115 |
enableEditMode(pid);
|
|
|
|
| 116 |
}
|
| 117 |
});
|
| 118 |
});
|
|
|
|
| 13 |
let isEditMode = false;
|
| 14 |
let currentPatientId = null;
|
| 15 |
|
| 16 |
+
function getPatientIdFromUrl() {
|
| 17 |
const urlParams = new URLSearchParams(window.location.search);
|
| 18 |
const pidFromUrl = urlParams.get('patient_id');
|
| 19 |
if (pidFromUrl && /^\d{8}$/.test(pidFromUrl)) return pidFromUrl;
|
|
|
|
|
|
|
| 20 |
return null;
|
| 21 |
}
|
| 22 |
|
|
|
|
| 45 |
if (titleEl) titleEl.textContent = 'Edit Patient';
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// Initialize: only enter edit mode if patient_id is explicitly in URL
|
| 49 |
+
const pidFromUrl = getPatientIdFromUrl();
|
| 50 |
+
if (pidFromUrl) {
|
| 51 |
+
enableEditMode(pidFromUrl);
|
| 52 |
+
loadPatientIntoForm(pidFromUrl);
|
| 53 |
}
|
| 54 |
|
| 55 |
cancelBtn.addEventListener('click', () => {
|
|
|
|
| 90 |
const data = await resp.json();
|
| 91 |
const pid = data.patient_id;
|
| 92 |
localStorage.setItem('medicalChatbotPatientId', pid);
|
| 93 |
+
// Show success modal (stay in create view until user opts to edit)
|
| 94 |
if (createdIdEl) createdIdEl.textContent = pid;
|
| 95 |
successModal.classList.add('show');
|
|
|
|
|
|
|
| 96 |
}
|
| 97 |
} catch (err) {
|
| 98 |
console.error(err);
|
|
|
|
| 109 |
const pid = createdIdEl?.textContent?.trim() || localStorage.getItem('medicalChatbotPatientId');
|
| 110 |
if (pid && /^\d{8}$/.test(pid)) {
|
| 111 |
enableEditMode(pid);
|
| 112 |
+
loadPatientIntoForm(pid);
|
| 113 |
}
|
| 114 |
});
|
| 115 |
});
|