<?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.emr.dao.quality.QualityMapper" >
    <insert id="addPh">
        insert into ph (ph
        )
        values (#{ph}
               )
    </insert>

    <select id="getPhNum" resultType="java.lang.Integer">
    SELECT  COUNT(distinct ph) FROM commomtable
        <where> 1=1
            <if test="startRange != null and startRange != ''">
                and  ph >= #{startRange,jdbcType=NVARCHAR}
            </if>
            <if test="endRange != null and endRange != ''">
                and  ph &lt;= #{endRange,jdbcType=NVARCHAR}
            </if>
        </where>
    </select>
    <select id="getFileNum" resultType="java.lang.Integer">
        SELECT
            COUNT(t.patient_id)
        FROM
            commomtable c
                LEFT JOIN t_scan_assort t on c.patient_id=t.patient_id
        <where> t.is_del!=1
<!--            <if test="startRange != null and startRange != '' and endRange != null and endRange != ''">-->
<!--                and  ph >= #{startRange,jdbcType=NVARCHAR}-->
<!--            </if>-->
<!--            <if test="startRange != null and startRange != '' and endRange != null and endRange != ''">-->
<!--                and  ph &lt;= #{endRange,jdbcType=NVARCHAR}-->
<!--            </if>-->
<!--            <if test="startRange != null and startRange != '' and endRange = null and endRange = ''">-->
<!--                and  ph = #{startRange,jdbcType=NVARCHAR}-->
<!--            </if>-->
<!--            <if test="startRange = null and startRange = '' and endRange != null and endRange != ''">-->
<!--                and  ph = #{endRange,jdbcType=NVARCHAR}-->
<!--            </if>-->
            <if test="startRange != null and startRange != '' ">
                and  ph >= #{startRange,jdbcType=NVARCHAR}
            </if>
            <if test="endRange != null and endRange != ''">
                and  ph &lt;= #{endRange,jdbcType=NVARCHAR}
            </if>
        </where>
    </select>
    <select id="getFliePath" resultType="java.lang.String">
        SELECT
            c.file_path+'\'+t.scan_page as fliePath
        FROM
            commomtable c
                LEFT JOIN t_scan_assort t on c.patient_id=t.patient_id
        where t.is_del!=1 and c.ph=#{ph,jdbcType=NVARCHAR}
    </select>
    <select id="getPh" resultType="java.lang.String">
        SELECT  distinct ph FROM commomtable
        <where> 1=1
            <if test="startRange != null and startRange != '' ">
                and  ph >= #{startRange,jdbcType=NVARCHAR}
            </if>
            <if test="endRange != null and endRange != ''">
                and  ph &lt;= #{endRange,jdbcType=NVARCHAR}
            </if>
        </where>
    </select>
</mapper>