LiamKhoaLe commited on
Commit
bb7dc3e
·
1 Parent(s): c20f696

Upd 3 modal handlers for doctor, patient and settings

Browse files
Files changed (1) hide show
  1. static/js/app.js +62 -0
static/js/app.js CHANGED
@@ -1250,6 +1250,68 @@ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e)
1250
  });
1251
  })();
1252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1253
  // Doctor modal open/close wiring (from doctor.js)
1254
  document.addEventListener('DOMContentLoaded', () => {
1255
  const doctorCard = document.getElementById('userProfile');
 
1250
  });
1251
  })();
1252
 
1253
+ // Settings modal open/close wiring (from settings.js)
1254
+ document.addEventListener('DOMContentLoaded', () => {
1255
+ const settingsBtn = document.getElementById('settingsBtn');
1256
+ const modal = document.getElementById('settingsModal');
1257
+ const closeBtn = document.getElementById('settingsModalClose');
1258
+ const cancelBtn = document.getElementById('settingsModalCancel');
1259
+ if (settingsBtn && modal) settingsBtn.addEventListener('click', () => modal.classList.add('show'));
1260
+ if (closeBtn) closeBtn.addEventListener('click', () => modal.classList.remove('show'));
1261
+ if (cancelBtn) cancelBtn.addEventListener('click', () => modal.classList.remove('show'));
1262
+ if (modal) modal.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('show'); });
1263
+ });
1264
+
1265
+ // Patient modal open/close wiring (from patient.js)
1266
+ document.addEventListener('DOMContentLoaded', () => {
1267
+ const profileBtn = document.getElementById('patientMenuBtn');
1268
+ const modal = document.getElementById('patientModal');
1269
+ const closeBtn = document.getElementById('patientModalClose');
1270
+ const logoutBtn = document.getElementById('patientLogoutBtn');
1271
+ const createBtn = document.getElementById('patientCreateBtn');
1272
+ if (profileBtn && modal) {
1273
+ profileBtn.addEventListener('click', async () => {
1274
+ const pid = window.medicalChatbot?.currentPatientId;
1275
+ if (pid) {
1276
+ try {
1277
+ const resp = await fetch(`/patients/${pid}`);
1278
+ if (resp.ok) {
1279
+ const p = await resp.json();
1280
+ const name = p.name || 'Unknown';
1281
+ const age = typeof p.age === 'number' ? p.age : '-';
1282
+ const sex = p.sex || '-';
1283
+ const meds = Array.isArray(p.medications) && p.medications.length > 0 ? p.medications.join(', ') : '-';
1284
+ document.getElementById('patientSummary').textContent = `${name} — ${sex}, ${age}`;
1285
+ document.getElementById('patientMedications').textContent = meds;
1286
+ document.getElementById('patientAssessment').textContent = p.past_assessment_summary || '-';
1287
+ }
1288
+ } catch (e) {
1289
+ console.error('Failed to load patient profile', e);
1290
+ }
1291
+ }
1292
+ modal.classList.add('show');
1293
+ });
1294
+ }
1295
+ if (closeBtn && modal) {
1296
+ closeBtn.addEventListener('click', () => modal.classList.remove('show'));
1297
+ modal.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('show'); });
1298
+ }
1299
+ if (logoutBtn) {
1300
+ logoutBtn.addEventListener('click', () => {
1301
+ if (confirm('Log out current patient?')) {
1302
+ window.medicalChatbot.currentPatientId = null;
1303
+ localStorage.removeItem('medicalChatbotPatientId');
1304
+ const status = document.getElementById('patientStatus');
1305
+ if (status) { status.textContent = 'No patient selected'; status.style.color = 'var(--text-secondary)'; }
1306
+ const input = document.getElementById('patientIdInput');
1307
+ if (input) input.value = '';
1308
+ modal.classList.remove('show');
1309
+ }
1310
+ });
1311
+ }
1312
+ if (createBtn) createBtn.addEventListener('click', () => modal.classList.remove('show'));
1313
+ });
1314
+
1315
  // Doctor modal open/close wiring (from doctor.js)
1316
  document.addEventListener('DOMContentLoaded', () => {
1317
  const doctorCard = document.getElementById('userProfile');