Spaces:
Runtime error
Runtime error
Commit
·
c1a2741
1
Parent(s):
cc9b10b
Upd patientfilter
Browse files- static/js/app.js +45 -41
static/js/app.js
CHANGED
|
@@ -903,18 +903,51 @@ How can I assist you today?`;
|
|
| 903 |
console.log('[DEBUG] loadPatient called');
|
| 904 |
const input = document.getElementById('patientIdInput');
|
| 905 |
const status = document.getElementById('patientStatus');
|
| 906 |
-
const
|
| 907 |
-
console.log('[DEBUG] Patient
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
|
|
|
| 911 |
return;
|
| 912 |
}
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
}
|
| 919 |
|
| 920 |
fetchAndRenderPatientSessions = async function () {
|
|
@@ -1032,37 +1065,8 @@ How can I assist you today?`;
|
|
| 1032 |
if (e.key === 'Enter') {
|
| 1033 |
const value = patientInput.value.trim();
|
| 1034 |
console.log('[DEBUG] Patient input Enter pressed with value:', value);
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
await this.loadPatient();
|
| 1038 |
-
hideSuggestions();
|
| 1039 |
-
} else {
|
| 1040 |
-
console.log('[DEBUG] Searching for patient by name/partial ID');
|
| 1041 |
-
try {
|
| 1042 |
-
const resp = await fetch(`/patients/search?q=${encodeURIComponent(value)}&limit=1`);
|
| 1043 |
-
console.log('[DEBUG] Search response status:', resp.status);
|
| 1044 |
-
if (resp.ok) {
|
| 1045 |
-
const data = await resp.json();
|
| 1046 |
-
console.log('[DEBUG] Search results for Enter:', data);
|
| 1047 |
-
const first = (data.results || [])[0];
|
| 1048 |
-
if (first) {
|
| 1049 |
-
console.log('[DEBUG] Found patient, setting as current:', first);
|
| 1050 |
-
this.currentPatientId = first.patient_id;
|
| 1051 |
-
this.savePatientId();
|
| 1052 |
-
patientInput.value = first.patient_id;
|
| 1053 |
-
hideSuggestions();
|
| 1054 |
-
const status = document.getElementById('patientStatus');
|
| 1055 |
-
if (status) { status.textContent = `Patient: ${first.patient_id}`; status.style.color = 'var(--text-secondary)'; }
|
| 1056 |
-
await this.fetchAndRenderPatientSessions();
|
| 1057 |
-
return;
|
| 1058 |
-
}
|
| 1059 |
-
}
|
| 1060 |
-
} catch (e) {
|
| 1061 |
-
console.error('[DEBUG] Search error on Enter:', e);
|
| 1062 |
-
}
|
| 1063 |
-
const status = document.getElementById('patientStatus');
|
| 1064 |
-
if (status) { status.textContent = 'No matching patient found'; status.style.color = 'var(--warning-color)'; }
|
| 1065 |
-
}
|
| 1066 |
}
|
| 1067 |
});
|
| 1068 |
document.addEventListener('click', (ev) => {
|
|
|
|
| 903 |
console.log('[DEBUG] loadPatient called');
|
| 904 |
const input = document.getElementById('patientIdInput');
|
| 905 |
const status = document.getElementById('patientStatus');
|
| 906 |
+
const value = (input?.value || '').trim();
|
| 907 |
+
console.log('[DEBUG] Patient input value:', value);
|
| 908 |
+
|
| 909 |
+
if (!value) {
|
| 910 |
+
console.log('[DEBUG] No input provided');
|
| 911 |
+
if (status) { status.textContent = 'Please enter patient ID or name.'; status.style.color = 'var(--warning-color)'; }
|
| 912 |
return;
|
| 913 |
}
|
| 914 |
+
|
| 915 |
+
// If it's a complete 8-digit ID, use it directly
|
| 916 |
+
if (/^\d{8}$/.test(value)) {
|
| 917 |
+
console.log('[DEBUG] Valid 8-digit ID provided');
|
| 918 |
+
this.currentPatientId = value;
|
| 919 |
+
this.savePatientId();
|
| 920 |
+
if (status) { status.textContent = `Patient: ${value}`; status.style.color = 'var(--text-secondary)'; }
|
| 921 |
+
await this.fetchAndRenderPatientSessions();
|
| 922 |
+
return;
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// Otherwise, search for patient by name or partial ID
|
| 926 |
+
console.log('[DEBUG] Searching for patient by name/partial ID');
|
| 927 |
+
try {
|
| 928 |
+
const resp = await fetch(`/patients/search?q=${encodeURIComponent(value)}&limit=1`);
|
| 929 |
+
console.log('[DEBUG] Search response status:', resp.status);
|
| 930 |
+
if (resp.ok) {
|
| 931 |
+
const data = await resp.json();
|
| 932 |
+
console.log('[DEBUG] Search results:', data);
|
| 933 |
+
const first = (data.results || [])[0];
|
| 934 |
+
if (first) {
|
| 935 |
+
console.log('[DEBUG] Found patient, setting as current:', first);
|
| 936 |
+
this.currentPatientId = first.patient_id;
|
| 937 |
+
this.savePatientId();
|
| 938 |
+
input.value = first.patient_id;
|
| 939 |
+
if (status) { status.textContent = `Patient: ${first.patient_id}`; status.style.color = 'var(--text-secondary)'; }
|
| 940 |
+
await this.fetchAndRenderPatientSessions();
|
| 941 |
+
return;
|
| 942 |
+
}
|
| 943 |
+
}
|
| 944 |
+
} catch (e) {
|
| 945 |
+
console.error('[DEBUG] Search error:', e);
|
| 946 |
+
}
|
| 947 |
+
|
| 948 |
+
// No patient found
|
| 949 |
+
console.log('[DEBUG] No patient found');
|
| 950 |
+
if (status) { status.textContent = 'No patient found. Try a different search.'; status.style.color = 'var(--warning-color)'; }
|
| 951 |
}
|
| 952 |
|
| 953 |
fetchAndRenderPatientSessions = async function () {
|
|
|
|
| 1065 |
if (e.key === 'Enter') {
|
| 1066 |
const value = patientInput.value.trim();
|
| 1067 |
console.log('[DEBUG] Patient input Enter pressed with value:', value);
|
| 1068 |
+
hideSuggestions();
|
| 1069 |
+
await this.loadPatient();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1070 |
}
|
| 1071 |
});
|
| 1072 |
document.addEventListener('click', (ev) => {
|