<?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.regdoctorstation.mapper.RequestFormManageAppMapper">

    <select id="getRequestForm" resultType="com.openhis.web.regdoctorstation.dto.RequestFormQueryDto">
        SELECT drf.id  AS request_form_id,
               drf.encounter_id,
               drf.prescription_no,
               drf.NAME,
               drf.desc_json,
               drf.requester_id,
               drf.create_time,
               ap.NAME AS patient_name
        FROM doc_request_form AS drf
                 LEFT JOIN adm_encounter AS ae ON ae.ID = drf.encounter_id
            AND ae.delete_flag = '0'
                 LEFT JOIN adm_patient AS ap ON ap.ID = ae.patient_id
            AND ap.delete_flag = '0'
        WHERE drf.delete_flag = '0'
          AND drf.encounter_id = #{encounterId}
          AND drf.type_code = #{typeCode}
    </select>

    <select id="getRequestFormDetail" resultType="com.openhis.web.regdoctorstation.dto.RequestFormDetailQueryDto">
        SELECT wsr.quantity,
               wsr.unit_code,
               wad.NAME AS advice_name,
               aci.total_price
        FROM wor_service_request AS wsr
                 LEFT JOIN wor_activity_definition AS wad ON wad.ID = wsr.activity_id
            AND wad.delete_flag = '0'
                 LEFT JOIN adm_charge_item AS aci ON aci.service_id = wsr.ID
            AND aci.delete_flag = '0'
        WHERE wsr.delete_flag = '0'
          AND wsr.prescription_no = #{prescriptionNo}
    </select>

</mapper>