<?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.jlau.mapper.ReviewPrescriptionRecordsAppMapper">

    <select id="getReviewPrescriptionRecords" resultType="com.openhis.web.jlau.dto.ReviewPrescriptionRecordsDto">
        SELECT nrpr.ID AS review_id,
        nrpr.encounter_id,
        nrpr.prescription_no,
        nrpr.med_request_ids,
        nrpr.pass_flag,
        nrpr.reason_text,
        ap.NAME AS practitioner_name
        FROM nd_review_prescription_records AS nrpr
        LEFT JOIN adm_practitioner AS ap ON ap.ID = nrpr.practitioner_id
        AND ap.delete_flag = '0'
        WHERE nrpr.delete_flag = '0'
        <if test="prescriptionNo != null and prescriptionNo != ''">
            AND nrpr.prescription_no = #{prescriptionNo}
        </if>
        <if test="passFlag != null">
            AND nrpr.pass_flag = #{passFlag}
        </if>
        <if test="encounterId != null">
            AND nrpr.encounter_id = #{encounterId}
        </if>
    </select>

</mapper>