<?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.commomSearch.ScanPathMapper">
    <resultMap id="BaseResultMap" type="com.emr.vo.commomSearch.ScanPathVo">
        <result column="patient_id" property="patientId" jdbcType="VARCHAR"/>
        <result column="inpatient_no" property="inpatientNo" jdbcType="VARCHAR"/>
        <result column="assort_id" property="assortId" jdbcType="VARCHAR"/>
        <result column="scan_page" property="scanPage" jdbcType="VARCHAR"/>
        <result column="dis_date" property="disDate" jdbcType="VARCHAR"/>
        <result column="fileRealPath" property="fileRealPath" jdbcType="VARCHAR"/>
        <result column="assort_name" property="assortName" jdbcType="VARCHAR"/>
    </resultMap>
    <!--湛江、英德根据patientId集合查询图片路径-->
    <select id="selectScanFileByPatientIds" resultMap="BaseResultMap" parameterType="java.lang.String">
        SELECT
        dbo.t_scan_assort.assort_id,
        dbo.t_scan_assort.scan_page,
        (dbo.t_gdh_index.file_path+'\'+dbo.t_scan_assort.scan_page) fileRealPath
        FROM
        dbo.t_gdh_index
        LEFT OUTER JOIN
        dbo.t_scan_assort
        ON
        dbo.t_gdh_index.patient_id = dbo.t_scan_assort.patient_id
        <where>
            dbo.t_scan_assort.patient_id in (${patientIds})
            <if test="assortIds != null">
                AND dbo.t_scan_assort.assort_id in (${assortIds})
            </if>
        </where>
        ORDER BY
        dbo.t_scan_assort.assort_id
    </select>


    <!--脐血库、祈福根据patientId集合查询图片路径-->
    <select id="selectScanFileByBloodPatientIds" resultMap="BaseResultMap" parameterType="java.lang.String">
        SELECT
        commomtable.patient_id,
        commomtable.name,
        commomtable.inpatient_no,
        commomtable.dis_date,
        dbo.t_scan_assort.assort_id,
        dbo.t_scan_assort.scan_page,
        case
        when t_scan_assort.source = 1
        then convert(nvarchar(255),dbo.commomtable.${flag})+'\'+dbo.t_scan_assort.scan_page
        when t_scan_assort.source = 2
        then convert(nvarchar(255),dbo.commomtable.new_path)+'\'+dbo.t_scan_assort.scan_page
        end fileRealPath
        FROM
        dbo.commomtable
        LEFT OUTER JOIN
        dbo.t_scan_assort
        ON
        dbo.commomtable.patient_id = dbo.t_scan_assort.patient_id
        LEFT OUTER JOIN
        dbo.zd_assort
        ON
        dbo.zd_assort.assort_id = dbo.t_scan_assort.assort_id
        <where>
            dbo.commomtable.patient_id in (${patientIds})
            AND t_scan_assort.is_del != 1
            <if test="assortIds != null and assortIds != ''">
                AND dbo.t_scan_assort.scan_page in (${assortIds})
            </if>
        </where>
        ORDER BY
        dbo.zd_assort.assort_sort,t_scan_assort.scan_page
    </select>


    <!--脐血库、祈福根据patientId集合查询图片路径-->
    <select id="selectScanFileByBloodPatientIds1" resultMap="BaseResultMap" parameterType="java.lang.String">
        SELECT
        commomtable.patient_id,
        commomtable.name,
        commomtable.inpatient_no,
        commomtable.dis_date,
        dbo.t_scan_assort.assort_id,
        dbo.t_scan_assort.scan_page,
        dbo.zd_assort.assort_name,
        case
        when t_scan_assort.source = 1
        then convert(nvarchar(255),dbo.commomtable.${flag})+'\'+dbo.t_scan_assort.scan_page
        when t_scan_assort.source = 2
        then convert(nvarchar(255),dbo.commomtable.new_path)+'\'+dbo.t_scan_assort.scan_page
        end fileRealPath
        FROM
        dbo.commomtable
        LEFT OUTER JOIN
        dbo.t_scan_assort
        ON
        dbo.commomtable.patient_id = dbo.t_scan_assort.patient_id
        LEFT OUTER JOIN
        dbo.zd_assort
        ON
        dbo.zd_assort.assort_id = dbo.t_scan_assort.assort_id
        <where>
            dbo.commomtable.patient_id =#{patientIds}
            AND t_scan_assort.is_del != 1
            <if test="assortIds != null and assortIds != ''">
                AND dbo.t_scan_assort.scan_page in (${assortIds})
            </if>
        </where>
        ORDER BY
        dbo.zd_assort.assort_sort,t_scan_assort.scan_page
    </select>
    <update id="updateScanFileByPatientIdAndScanPage" parameterType="java.lang.String">
        ${sql}
    </update>

    <select id="selectCountPh" resultType="java.lang.Integer">
        select count(ph) from (SELECT distinct ph FROM dbo.t_gdh_index where ph is not null) temp
    </select>

    <select id="selectCountPdf" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM dbo.t_scan_assort
    </select>
    <select id="selectScanFileByBloodPatientId" resultType="com.emr.vo.commomSearch.ScanPathVo">
        SELECT
        commomtable.patient_id,
        commomtable.name,
        commomtable.inpatient_no,
        commomtable.dis_date,
        dbo.t_scan_assort.assort_id,
        dbo.t_scan_assort.scan_page
        FROM
        dbo.commomtable
        LEFT OUTER JOIN
        dbo.t_scan_assort
        ON
        dbo.commomtable.patient_id = dbo.t_scan_assort.patient_id
        LEFT OUTER JOIN
        dbo.zd_assort
        ON
        dbo.zd_assort.assort_id = dbo.t_scan_assort.assort_id
        <where>
            dbo.commomtable.patient_id =#{patientIds}
            AND t_scan_assort.is_del != 1
            <if test="assortIds != null and assortIds != ''">
                AND dbo.t_scan_assort.scan_page in (${assortIds})
            </if>
        </where>
        ORDER BY
        dbo.zd_assort.assort_sort,t_scan_assort.scan_page
    </select>
    <select id="selectFilaname" resultType="com.emr.vo.commomSearch.ScanPathVo">
        select * from  commomtable where    patient_id =#{patientIds}
    </select>
</mapper>