Skip to main content

getRatingAppointmentInfo

getRatingAppointmentInfo

This method retrieves detailed appointment and agent information based on an encrypted token and verifies if the appointment is eligible for rating.

  1. Decrypt Token

    • Decrypt the input token using AES with a secret key.
    • Extract bookingId and appointmentId from the decrypted payload.
    • If either bookingId or appointmentId is missing, throw a BadRequestException indicating an invalid token.
  2. Determine Appointment Type

    • Check if bookingId starts with 'BKD' to identify if the appointment is internal.
    • Internal appointments will be queried from appointments table.
    • External appointments use appointments_ehr table.
  3. Fetch Completed Appointment

    • Query the appropriate repository (appointmentRepo or appointmentEhrRepo) for the appointment using:

      • appointmentId
      • Booking ID field name depending on internal/external type (bookingId or emrAppointmentId)
    • Use the helper method fetchCompletedAppointment with the appropriate parameters.

    • If no appointment is found, throw a NotFoundException.

  4. Check Rating Status

    • Query the ratingNotificationRepo for notifications linked to this appointment with status either:

      • RATED
      • CANCELLED
    • If any such notifications exist:

      • If any have status RATED, throw a BadRequestException indicating the appointment has already been reviewed.
      • Otherwise, throw a BadRequestException indicating the appointment can no longer be reviewed.
  5. Construct and Return Appointment Info

    • Return an object containing:

      • bookingId (from the appointment record, depending on appointment type)

      • startDatetime

      • customerId

      • agent object with:

        • id
        • name (concatenation of agent type name + first and last names)
        • imageUrl