<?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.chargemanage.mapper.OutpatientChargeAppMapper">

    <select id="selectEncounterPatientPage"
            resultType="com.openhis.web.chargemanage.dto.EncounterPatientPageDto">
        SELECT T3.encounter_id,
               T3.encounter_bus_no,
               T3.start_time,
               T3.patient_name,
               T3.patient_bus_no,
               T3.gender_enum,
               T3.birth_date,
               T3.id_card,
               T3.patient_py_str,
               T3.patient_wb_str
        FROM (
                 SELECT T1.id     AS encounter_id,
                        T1.bus_no AS encounter_bus_no,
                        T1.start_time,
                        T1.delete_flag,
                        T2."name" AS patient_name,
                        T2.bus_no AS patient_bus_no,
                        T2.gender_enum,
                        T2.birth_date,
                        T2.id_card,
                        T2.py_str AS patient_py_str,
                        T2.wb_str AS patient_wb_str
                 FROM adm_encounter AS T1
                    LEFT JOIN adm_patient AS T2
                        ON T1.patient_id = T2.id
                 WHERE T1.delete_flag = '0'
                 ORDER BY T1.encounter_bus_no DESC
             ) AS T3
        ${ew.customSqlSegment}
    </select>
</mapper>