LiamKhoaLe commited on
Commit
daefea6
·
1 Parent(s): bc9985a

Fix doctor and patient search engine

Browse files
src/api/routes/chat.py CHANGED
@@ -27,7 +27,7 @@ async def chat_endpoint(
27
  start_time = time.time()
28
 
29
  try:
30
- logger.info(f"Chat request from user {request.user_id} in session {request.session_id}")
31
  logger.info(f"Message: {request.message[:100]}...") # Log first 100 chars of message
32
 
33
  # Get or create user profile (doctor as current user profile)
 
27
  start_time = time.time()
28
 
29
  try:
30
+ logger.info(f"POST /chat user={request.user_id} session={request.session_id} patient={request.patient_id} doctor={request.doctor_id}")
31
  logger.info(f"Message: {request.message[:100]}...") # Log first 100 chars of message
32
 
33
  # Get or create user profile (doctor as current user profile)
src/api/routes/session.py CHANGED
@@ -18,6 +18,7 @@ async def create_chat_session(
18
  ):
19
  """Create a new chat session (cache + Mongo)"""
20
  try:
 
21
  session_id = state.memory_system.create_session(request.user_id, request.title or "New Chat")
22
  # Also ensure in Mongo with patient/doctor
23
  ensure_session(session_id=session_id, patient_id=request.patient_id, doctor_id=request.doctor_id, title=request.title or "New Chat")
@@ -59,6 +60,7 @@ async def get_chat_session(
59
  async def list_sessions_for_patient(patient_id: str):
60
  """List sessions for a patient from Mongo"""
61
  try:
 
62
  return {"sessions": list_patient_sessions(patient_id)}
63
  except Exception as e:
64
  logger.error(f"Error listing sessions: {e}")
@@ -68,6 +70,7 @@ async def list_sessions_for_patient(patient_id: str):
68
  async def list_messages_for_session(session_id: str, limit: int | None = None):
69
  """List messages for a session from Mongo"""
70
  try:
 
71
  msgs = list_session_messages(session_id, limit=limit)
72
  # ensure JSON-friendly timestamps
73
  for m in msgs:
 
18
  ):
19
  """Create a new chat session (cache + Mongo)"""
20
  try:
21
+ logger.info(f"POST /sessions user_id={request.user_id} patient_id={request.patient_id} doctor_id={request.doctor_id}")
22
  session_id = state.memory_system.create_session(request.user_id, request.title or "New Chat")
23
  # Also ensure in Mongo with patient/doctor
24
  ensure_session(session_id=session_id, patient_id=request.patient_id, doctor_id=request.doctor_id, title=request.title or "New Chat")
 
60
  async def list_sessions_for_patient(patient_id: str):
61
  """List sessions for a patient from Mongo"""
62
  try:
63
+ logger.info(f"GET /patients/{patient_id}/sessions")
64
  return {"sessions": list_patient_sessions(patient_id)}
65
  except Exception as e:
66
  logger.error(f"Error listing sessions: {e}")
 
70
  async def list_messages_for_session(session_id: str, limit: int | None = None):
71
  """List messages for a session from Mongo"""
72
  try:
73
+ logger.info(f"GET /sessions/{session_id}/messages limit={limit}")
74
  msgs = list_session_messages(session_id, limit=limit)
75
  # ensure JSON-friendly timestamps
76
  for m in msgs:
src/api/routes/user.py CHANGED
@@ -83,6 +83,7 @@ class PatientCreateRequest(BaseModel):
83
  @router.get("/patients/{patient_id}")
84
  async def get_patient(patient_id: str):
85
  try:
 
86
  patient = get_patient_by_id(patient_id)
87
  if not patient:
88
  raise HTTPException(status_code=404, detail="Patient not found")
@@ -97,6 +98,7 @@ async def get_patient(patient_id: str):
97
  @router.post("/patients")
98
  async def create_patient_profile(req: PatientCreateRequest):
99
  try:
 
100
  patient = create_patient(
101
  name=req.name,
102
  age=req.age,
@@ -128,6 +130,7 @@ class PatientUpdateRequest(BaseModel):
128
  @router.patch("/patients/{patient_id}")
129
  async def update_patient(patient_id: str, req: PatientUpdateRequest):
130
  try:
 
131
  modified = update_patient_profile(patient_id, {k: v for k, v in req.model_dump().items() if v is not None})
132
  if modified == 0:
133
  return {"message": "No changes"}
@@ -139,6 +142,7 @@ async def update_patient(patient_id: str, req: PatientUpdateRequest):
139
  @router.get("/patients/search")
140
  async def search_patients_route(q: str, limit: int = 10):
141
  try:
 
142
  return {"results": search_patients(q, limit=limit)}
143
  except Exception as e:
144
  logger.error(f"Error searching patients: {e}")
 
83
  @router.get("/patients/{patient_id}")
84
  async def get_patient(patient_id: str):
85
  try:
86
+ logger.info(f"GET /patients/{patient_id}")
87
  patient = get_patient_by_id(patient_id)
88
  if not patient:
89
  raise HTTPException(status_code=404, detail="Patient not found")
 
98
  @router.post("/patients")
99
  async def create_patient_profile(req: PatientCreateRequest):
100
  try:
101
+ logger.info(f"POST /patients name={req.name}")
102
  patient = create_patient(
103
  name=req.name,
104
  age=req.age,
 
130
  @router.patch("/patients/{patient_id}")
131
  async def update_patient(patient_id: str, req: PatientUpdateRequest):
132
  try:
133
+ logger.info(f"PATCH /patients/{patient_id}")
134
  modified = update_patient_profile(patient_id, {k: v for k, v in req.model_dump().items() if v is not None})
135
  if modified == 0:
136
  return {"message": "No changes"}
 
142
  @router.get("/patients/search")
143
  async def search_patients_route(q: str, limit: int = 10):
144
  try:
145
+ logger.info(f"GET /patients/search q='{q}' limit={limit}")
146
  return {"results": search_patients(q, limit=limit)}
147
  except Exception as e:
148
  logger.error(f"Error searching patients: {e}")
static/css/styles.css CHANGED
@@ -80,6 +80,8 @@ body {
80
  height: 100vh;
81
  overflow: hidden;
82
  }
 
 
83
 
84
  /* Sidebar */
85
  .sidebar {
 
80
  height: 100vh;
81
  overflow: hidden;
82
  }
83
+ .app-overlay { position: fixed; inset:0; background: rgba(0,0,0,0.2); display:none; z-index: 900; }
84
+ .app-overlay.show { display:block; }
85
 
86
  /* Sidebar */
87
  .sidebar {
static/index.html CHANGED
@@ -10,6 +10,7 @@
10
  </head>
11
  <body>
12
  <div class="app-container">
 
13
  <!-- Sidebar -->
14
  <div class="sidebar" id="sidebar">
15
  <div class="sidebar-header">
 
10
  </head>
11
  <body>
12
  <div class="app-container">
13
+ <div class="app-overlay" id="appOverlay"></div>
14
  <!-- Sidebar -->
15
  <div class="sidebar" id="sidebar">
16
  <div class="sidebar-header">
static/js/app.js CHANGED
@@ -39,6 +39,11 @@ class MedicalChatbotApp {
39
  this.toggleSidebar();
40
  });
41
  // Click outside sidebar to close (mobile/overlay behavior)
 
 
 
 
 
42
  document.addEventListener('click', (e) => {
43
  const sidebar = document.getElementById('sidebar');
44
  const toggleBtn = document.getElementById('sidebarToggle');
@@ -46,7 +51,11 @@ class MedicalChatbotApp {
46
  const isOpen = sidebar.classList.contains('show');
47
  const clickInside = sidebar.contains(e.target) || (toggleBtn && toggleBtn.contains(e.target));
48
  if (isOpen && !clickInside) sidebar.classList.remove('show');
 
49
  });
 
 
 
50
 
51
  // New chat button
52
  document.getElementById('newChatBtn').addEventListener('click', () => {
@@ -975,6 +984,15 @@ How can I assist you today?`;
975
 
976
  showUserModal() {
977
  this.populateDoctorSelect();
 
 
 
 
 
 
 
 
 
978
  document.getElementById('profileRole').value = this.currentUser.role;
979
  document.getElementById('profileSpecialty').value = this.currentUser.specialty || '';
980
 
 
39
  this.toggleSidebar();
40
  });
41
  // Click outside sidebar to close (mobile/overlay behavior)
42
+ const overlay = document.getElementById('appOverlay');
43
+ const updateOverlay = () => {
44
+ const sidebar = document.getElementById('sidebar');
45
+ if (sidebar && overlay) overlay.classList.toggle('show', sidebar.classList.contains('show'));
46
+ };
47
  document.addEventListener('click', (e) => {
48
  const sidebar = document.getElementById('sidebar');
49
  const toggleBtn = document.getElementById('sidebarToggle');
 
51
  const isOpen = sidebar.classList.contains('show');
52
  const clickInside = sidebar.contains(e.target) || (toggleBtn && toggleBtn.contains(e.target));
53
  if (isOpen && !clickInside) sidebar.classList.remove('show');
54
+ updateOverlay();
55
  });
56
+ // Keep overlay synced when toggling
57
+ const origToggle = this.toggleSidebar.bind(this);
58
+ this.toggleSidebar = () => { origToggle(); updateOverlay(); };
59
 
60
  // New chat button
61
  document.getElementById('newChatBtn').addEventListener('click', () => {
 
984
 
985
  showUserModal() {
986
  this.populateDoctorSelect();
987
+ // Ensure the dropdown is visible immediately with options
988
+ const sel = document.getElementById('profileNameSelect');
989
+ if (sel && sel.options.length === 0) {
990
+ // Fallback in unlikely case populate didn't run
991
+ const createOpt = document.createElement('option');
992
+ createOpt.value = '__create__';
993
+ createOpt.textContent = 'Create doctor user...';
994
+ sel.appendChild(createOpt);
995
+ }
996
  document.getElementById('profileRole').value = this.currentUser.role;
997
  document.getElementById('profileSpecialty').value = this.currentUser.specialty || '';
998