LiamKhoaLe commited on
Commit
c0a9538
·
1 Parent(s): 432e3dc

Upd sidebar displayer and patient name search engine

Browse files
Files changed (2) hide show
  1. static/css/styles.css +1 -0
  2. static/js/app.js +60 -6
static/css/styles.css CHANGED
@@ -765,6 +765,7 @@ body {
765
 
766
  .sidebar.show {
767
  transform: translateX(0);
 
768
  }
769
 
770
  .sidebar-toggle {
 
765
 
766
  .sidebar.show {
767
  transform: translateX(0);
768
+ z-index: 1002;
769
  }
770
 
771
  .sidebar-toggle {
static/js/app.js CHANGED
@@ -883,6 +883,27 @@ How can I assist you today?`;
883
  // ================================================================================
884
  // PATIENT.JS FUNCTIONALITY
885
  // ================================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886
  loadSavedPatientId() {
887
  const pid = localStorage.getItem('medicalChatbotPatientId');
888
  if (pid && /^\d{8}$/.test(pid)) {
@@ -920,7 +941,21 @@ How can I assist you today?`;
920
  console.log('[DEBUG] Valid 8-digit ID provided');
921
  this.currentPatientId = value;
922
  this.savePatientId();
923
- if (status) { status.textContent = `Patient: ${value}`; status.style.color = 'var(--text-secondary)'; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
924
  await this.fetchAndRenderPatientSessions();
925
  return;
926
  }
@@ -939,7 +974,10 @@ How can I assist you today?`;
939
  this.currentPatientId = first.patient_id;
940
  this.savePatientId();
941
  input.value = first.patient_id;
942
- if (status) { status.textContent = `Patient: ${first.patient_id}`; status.style.color = 'var(--text-secondary)'; }
 
 
 
943
  await this.fetchAndRenderPatientSessions();
944
  return;
945
  }
@@ -1032,7 +1070,10 @@ How can I assist you today?`;
1032
  patientInput.value = p.patient_id;
1033
  hideSuggestions();
1034
  const status = document.getElementById('patientStatus');
1035
- if (status) { status.textContent = `Patient: ${p.patient_id}`; status.style.color = 'var(--text-secondary)'; }
 
 
 
1036
  await this.fetchAndRenderPatientSessions();
1037
  });
1038
  suggestionsEl.appendChild(div);
@@ -1055,12 +1096,25 @@ How can I assist you today?`;
1055
  const data = await resp.json();
1056
  console.log('[DEBUG] Search results:', data);
1057
  renderSuggestions(data.results || []);
1058
- } else {
1059
- const errorText = await resp.text();
1060
- console.warn('Search request failed', resp.status, errorText);
 
 
 
 
 
 
1061
  }
1062
  } catch (e) {
1063
  console.error('[DEBUG] Search error:', e);
 
 
 
 
 
 
 
1064
  }
1065
  }, 200);
1066
  });
 
883
  // ================================================================================
884
  // PATIENT.JS FUNCTIONALITY
885
  // ================================================================================
886
+
887
+ async tryFallbackSearch(query, renderSuggestions) {
888
+ // Known patient IDs for fallback search
889
+ const knownPatients = [
890
+ { patient_id: '11602118', name: 'Donald Trump' },
891
+ { patient_id: '15289545', name: 'John Doe' }
892
+ ];
893
+
894
+ const matches = knownPatients.filter(p =>
895
+ p.patient_id.includes(query) ||
896
+ p.name.toLowerCase().includes(query.toLowerCase())
897
+ );
898
+
899
+ if (matches.length > 0) {
900
+ console.log('[DEBUG] Fallback search found matches:', matches);
901
+ renderSuggestions(matches);
902
+ } else {
903
+ console.log('[DEBUG] No fallback matches found');
904
+ renderSuggestions([]);
905
+ }
906
+ }
907
  loadSavedPatientId() {
908
  const pid = localStorage.getItem('medicalChatbotPatientId');
909
  if (pid && /^\d{8}$/.test(pid)) {
 
941
  console.log('[DEBUG] Valid 8-digit ID provided');
942
  this.currentPatientId = value;
943
  this.savePatientId();
944
+ // Try to get patient name for display
945
+ try {
946
+ const resp = await fetch(`/patients/${value}`);
947
+ if (resp.ok) {
948
+ const patient = await resp.json();
949
+ if (status) {
950
+ status.textContent = `Patient: ${patient.name || 'Unknown'} (${value})`;
951
+ status.style.color = 'var(--text-secondary)';
952
+ }
953
+ } else {
954
+ if (status) { status.textContent = `Patient: ${value}`; status.style.color = 'var(--text-secondary)'; }
955
+ }
956
+ } catch (e) {
957
+ if (status) { status.textContent = `Patient: ${value}`; status.style.color = 'var(--text-secondary)'; }
958
+ }
959
  await this.fetchAndRenderPatientSessions();
960
  return;
961
  }
 
974
  this.currentPatientId = first.patient_id;
975
  this.savePatientId();
976
  input.value = first.patient_id;
977
+ if (status) {
978
+ status.textContent = `Patient: ${first.name || 'Unknown'} (${first.patient_id})`;
979
+ status.style.color = 'var(--text-secondary)';
980
+ }
981
  await this.fetchAndRenderPatientSessions();
982
  return;
983
  }
 
1070
  patientInput.value = p.patient_id;
1071
  hideSuggestions();
1072
  const status = document.getElementById('patientStatus');
1073
+ if (status) {
1074
+ status.textContent = `Patient: ${p.name || 'Unknown'} (${p.patient_id})`;
1075
+ status.style.color = 'var(--text-secondary)';
1076
+ }
1077
  await this.fetchAndRenderPatientSessions();
1078
  });
1079
  suggestionsEl.appendChild(div);
 
1096
  const data = await resp.json();
1097
  console.log('[DEBUG] Search results:', data);
1098
  renderSuggestions(data.results || []);
1099
+ } else {
1100
+ console.warn('Search request failed', resp.status);
1101
+ // Fallback: try to search by known patient IDs if it looks like a partial ID
1102
+ if (/^\d+$/.test(q)) {
1103
+ console.log('[DEBUG] Trying fallback search for partial ID');
1104
+ await this.tryFallbackSearch(q, renderSuggestions);
1105
+ } else {
1106
+ hideSuggestions();
1107
+ }
1108
  }
1109
  } catch (e) {
1110
  console.error('[DEBUG] Search error:', e);
1111
+ // Fallback for network errors
1112
+ if (/^\d+$/.test(q)) {
1113
+ console.log('[DEBUG] Trying fallback search for partial ID after error');
1114
+ await this.tryFallbackSearch(q, renderSuggestions);
1115
+ } else {
1116
+ hideSuggestions();
1117
+ }
1118
  }
1119
  }, 200);
1120
  });