fix
This commit is contained in:
157
AssistantFnc.py
157
AssistantFnc.py
@@ -2139,164 +2139,7 @@ class AssistantFnc(llm.FunctionContext):
|
|||||||
"next_step": "retry_booking"
|
"next_step": "retry_booking"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @llm.ai_callable()
|
|
||||||
# async def saveAppointment(self,
|
|
||||||
# practitioner_id: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="ID of the practitioner to book with")
|
|
||||||
# ],
|
|
||||||
# patient_id: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="ID of the patient for the appointment")
|
|
||||||
# ],
|
|
||||||
# appointment_date: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="Date for the appointment in YYYY-MM-DD format or natural language")
|
|
||||||
# ],
|
|
||||||
# appointment_time: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="Time for the appointment in HH:MM AM/PM format")
|
|
||||||
# ],
|
|
||||||
# appointment_type: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="Type of appointment (e.g., 'Consultation', 'Follow-up', etc.)")
|
|
||||||
# ] = "Consultation",
|
|
||||||
# notes: Annotated[
|
|
||||||
# str, llm.TypeInfo(description="Any additional notes for the appointment")
|
|
||||||
# ] = ""
|
|
||||||
# ):
|
|
||||||
# """Book an appointment for a patient with a practitioner on base availablity."""
|
|
||||||
# try:
|
|
||||||
# logger.info(f"Booking appointment for patient {patient_id} with practitioner {practitioner_id} on {appointment_date} at {appointment_time}")
|
|
||||||
|
|
||||||
# # Parse the date if it's in natural language format
|
|
||||||
# parsed_date = self._parse_date_to_iso(appointment_date)
|
|
||||||
# if parsed_date:
|
|
||||||
# appointment_date = parsed_date
|
|
||||||
# logger.info(f"Parsed appointment date to: {appointment_date}")
|
|
||||||
|
|
||||||
# # First, check if the slot is available
|
|
||||||
# availability_result = await self.check_practitioner_availability(
|
|
||||||
# practitioner_id=practitioner_id,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# if availability_result.get("status") != "success":
|
|
||||||
# # If no slots available on the requested date, suggest alternative dates
|
|
||||||
# if availability_result.get("status") == "info" and availability_result.get("available_dates"):
|
|
||||||
# available_dates = availability_result.get("available_dates", {})
|
|
||||||
# date_suggestions = list(available_dates.keys())[:5] # Suggest up to 5 alternative dates
|
|
||||||
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": f"No available slots found on {appointment_date}",
|
|
||||||
# "suggested_dates": date_suggestions,
|
|
||||||
# "details": "Please try booking on one of the suggested dates"
|
|
||||||
# }
|
|
||||||
# else:
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": f"Failed to verify availability: {availability_result.get('message')}",
|
|
||||||
# "details": availability_result
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # Find the matching time slot
|
|
||||||
# available_slots = availability_result.get("available_slots", [])
|
|
||||||
# selected_slot = None
|
|
||||||
|
|
||||||
# # Normalize the input time for comparison
|
|
||||||
# try:
|
|
||||||
# # Try multiple time formats for flexibility
|
|
||||||
# time_formats = ["%I:%M %p", "%H:%M", "%I:%M%p", "%I.%M %p", "%I.%M%p"]
|
|
||||||
# input_time_obj = None
|
|
||||||
|
|
||||||
# for fmt in time_formats:
|
|
||||||
# try:
|
|
||||||
# input_time_obj = datetime.datetime.strptime(appointment_time, fmt)
|
|
||||||
# logger.info(f"Successfully parsed time with format: {fmt}")
|
|
||||||
# break
|
|
||||||
# except ValueError:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# if not input_time_obj:
|
|
||||||
# raise ValueError(f"Could not parse time: {appointment_time}")
|
|
||||||
|
|
||||||
# input_time_24h = input_time_obj.strftime("%H:%M")
|
|
||||||
# input_time_12h = input_time_obj.strftime("%I:%M %p")
|
|
||||||
# logger.info(f"Normalized appointment time: 24h={input_time_24h}, 12h={input_time_12h}")
|
|
||||||
|
|
||||||
# except ValueError:
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": f"Invalid time format: {appointment_time}. Please use format like '2:30 PM'.",
|
|
||||||
# "available_formats": ["1:30 PM", "13:30", "1:30PM", "1.30 PM"]
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # Find the matching slot
|
|
||||||
# for slot in available_slots:
|
|
||||||
# slot_datetime = slot.get("formatted_datetime", "")
|
|
||||||
# # Extract just the time portion from the formatted datetime (e.g., "2025-05-15 02:30 PM")
|
|
||||||
# if " " in slot_datetime:
|
|
||||||
# slot_date, slot_time = slot_datetime.split(" ", 1)
|
|
||||||
# if self._time_matches(slot_time, input_time_12h):
|
|
||||||
# selected_slot = slot
|
|
||||||
# logger.info(f"Found matching slot: {slot_datetime}")
|
|
||||||
# break
|
|
||||||
|
|
||||||
# if not selected_slot:
|
|
||||||
# # If no exact match found, suggest available times
|
|
||||||
# available_times = [slot.get("formatted_datetime").split(" ", 1)[1]
|
|
||||||
# for slot in available_slots if " " in slot.get("formatted_datetime", "")]
|
|
||||||
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": f"No available slot found at {appointment_time} on {appointment_date}",
|
|
||||||
# "available_times": available_times,
|
|
||||||
# "suggestion": "Please select from one of the available times"
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # Now book the appointment using the selected slot
|
|
||||||
# url = f"{Base_url}/api/assistant/book-appointment"
|
|
||||||
|
|
||||||
# if not self.accessToken:
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": "Authentication token not available."
|
|
||||||
# }
|
|
||||||
|
|
||||||
# headers = {
|
|
||||||
# "authorization": f"Bearer {self.accessToken}",
|
|
||||||
# "accesstoken": f"{self.accessToken}",
|
|
||||||
# "content-type": "application/json",
|
|
||||||
# "accept": "application/json"
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # Prepare the booking data
|
|
||||||
# booking_data = {
|
|
||||||
# "practitioner_id": practitioner_id,
|
|
||||||
# "patient_id": patient_id,
|
|
||||||
# "appointment_date": appointment_date,
|
|
||||||
# "start_time": selected_slot.get("start_time"), # Use the ISO format time from the slot
|
|
||||||
# "appointment_type": appointment_type,
|
|
||||||
# "notes": notes
|
|
||||||
# }
|
|
||||||
|
|
||||||
# logger.info(f"Sending booking request with data: {booking_data}")
|
|
||||||
# response = requests.post(url, headers=headers, json=booking_data)
|
|
||||||
# logger.info(f"Booking response status code: {response.status_code}")
|
|
||||||
|
|
||||||
# if response.status_code == 200:
|
|
||||||
# booking_result = response.json()
|
|
||||||
# return {
|
|
||||||
# "status": "success",
|
|
||||||
# "message": f"Successfully booked appointment on {appointment_date} at {appointment_time}",
|
|
||||||
# "appointment_details": booking_result.get("data", {}),
|
|
||||||
# "confirmation": f"Appointment confirmed for {appointment_date} at {appointment_time} with appointment type: {appointment_type}"
|
|
||||||
# }
|
|
||||||
# else:
|
|
||||||
# return {
|
|
||||||
# "status": "error",
|
|
||||||
# "message": f"Failed to book appointment. Status code: {response.status_code}",
|
|
||||||
# "details": response.text
|
|
||||||
# }
|
|
||||||
|
|
||||||
# except Exception as e:
|
|
||||||
# logger.error(f"Error booking appointment: {str(e)}")
|
|
||||||
# return {"status": "error", "message": f"Error booking appointment: {str(e)}"}
|
|
||||||
|
|
||||||
def _time_matches(self, slot_time, input_time):
|
def _time_matches(self, slot_time, input_time):
|
||||||
"""Helper function to compare if two time strings match, handling different formats"""
|
"""Helper function to compare if two time strings match, handling different formats"""
|
||||||
|
Reference in New Issue
Block a user