<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.openhis.web.doctorstation.mapper.ReservationRecordAppMapper">

    <select id="getReservationInfo" resultType="com.openhis.web.doctorstation.dto.ReservationRecordDto">
        SELECT ri.tenant_id,
               ri.id,
               ri.patient_name,
               ri.patient_tel,
               ri.chief_complaint,
               ri.reservation_time,
               ri.org_id,
               ri.org_name,
               ri.practitioner_id,
               ri.practitioner_name,
               ri.remark,
               ri.tooth_position
        from (SELECT crr.tenant_id,
                     crr.id,
                     crr.patient_name,
                     crr.patient_tel,
                     crr.chief_complaint,
                     crr.reservation_time,
                     crr.org_id,
                     ao.NAME AS org_name,
                     crr.practitioner_id,
                     ap.NAME AS practitioner_name,
                     crr.remark,
                     crr.tooth_position
              FROM cli_reservation_record AS crr
                       LEFT JOIN adm_organization AS ao ON ao.ID = crr.org_id
                  AND ao.delete_flag = '0'
                       LEFT JOIN adm_practitioner AS ap ON ap.ID = crr.practitioner_id
                  AND ap.delete_flag = '0'
              WHERE crr.delete_flag = '0'
              order by crr.reservation_time) AS ri
            ${ew.customSqlSegment}
    </select>

</mapper>