from llm_engine import generate_response from tools import ( appointment_tool, hospital_policy_tool, doctor_search_tool, followup_tool ) from intent_detector import detect_intent doctor_waiting = False def healthcare_agent(phone, question): global doctor_waiting question = question.strip() intent = detect_intent(question) print("INTENT:", intent) # ================================== # DOCTOR DEPARTMENT SEARCH # MUST COME FIRST # ================================== if doctor_waiting or intent == "doctor_department": doctors = doctor_search_tool(question) if not doctors: doctor_waiting = False return ( "I couldn't find any doctors " "for this department." ) response = "Available doctors:\n\n" for doctor in doctors: response += ( f"{doctor['doctor_name']}\n" f"Specialization: " f"{doctor['specialization']}\n" f"Available Slots: " f"{doctor['available_slots']}\n\n" ) doctor_waiting = False return response # ================================== # DOCTOR SEARCH START # ================================== if intent == "doctor": doctor_waiting = True return ( "Sure, I can help you find a doctor.\n\n" "Please select a department:\n\n" "Cardiology\n" "Neurology\n" "Orthopedics\n" "Pediatrics\n" "Gynecology\n" "General Medicine" ) # ================================== # YOUR EXISTING APPOINTMENT CODE # ================================== if intent == "appointment": if not phone: return ( "Please provide your registered phone number " "so I can check your appointment." ) data = appointment_tool(phone) if not data: return ( "I couldn't find any appointment " "associated with this phone number." ) return generate_response( context=data, question=question ) # ================================== # FOLLOWUP LOOKUP # ================================== if intent == "followup": if not phone: return ( "Please provide your registered phone number " "so I can check your follow-up details." ) data = followup_tool(phone) print("FOLLOWUP RESULT:") print(data) if not data: return ( "I couldn't find any follow-up details " "for this phone number." ) return generate_response( context=data, question=""" The patient wants to know their follow-up details. Explain clearly. Include: - Follow-up date - Notes Do not show raw Python data. Do not mention database. """ ) # ================================== # YOUR EXISTING POLICY CODE # ================================== if intent == "policy": context = hospital_policy_tool(question) return generate_response( context=context, question=question ) # ================================== # GENERAL # ================================== return generate_response( context="", question=question )