<?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.ruoyi.web.work.mapper.DiagnosisMapper">

    <select id="selectList" resultType="com.ruoyi.web.work.domain.Diagnosis">
        select * from tb_diagnosis
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="patId != null  and patId != ''"> and pat_id = #{patId}</if>
            <if test="visitId != null  and visitId != ''"> and visit_id = #{visitId}</if>
            <if test="doctor != null  and doctor != ''"> and doctor = #{doctor}</if>
            <if test="diagnosticCode != null  and diagnosticCode != ''"> and diagnostic_code = #{diagnosticCode}</if>
            <if test="diagnosticName != null  and diagnosticName != ''"> and diagnostic_name = #{diagnosticName}</if>
            <if test="diagnosisTime != null  and diagnosisTime != ''"> and diagnosis_time = #{diagnosisTime}</if>
            <if test="diagnosticType != null  and diagnosticType != ''"> and diagnostic_type = #{diagnosticType}</if>
            <if test="diagnosticCategoryCode != null  and diagnosticCategoryCode != ''"> and diagnostic_category_code = #{diagnosticCategoryCode}</if>
        </where>
    </select>

    <select id="getDiagnosisByCard" resultType="com.ruoyi.web.work.domain.Diagnosis">
        select * from tb_diagnosis where card_id=#{card}
    </select>

    <select id="getMedicalRecord" resultType="com.ruoyi.web.work.domain.dto.Pv1MedicalRecord">
        SELECT tb_diagnosis.diagnostic_name,tb_diagnosis.create_time,tb_visit.discharge_time,tb_visit.card_id
        FROM tb_diagnosis
                 JOIN tb_visit ON tb_diagnosis.pat_id=tb_visit.pat_id
        <where>
            <if test="patientId !=null and patientId!=''">
                and tb_diagnosis.pat_id=#{patId}
            </if>
            <if test="beginTime !=null and beginTime!='' and endTime!=null and endTime!=''">
                and  diagnosis_time BETWEEN #{beginTime} and #{endTime};
            </if>

        </where>

    </select>

    <select id="getDiagnosisByCardId" resultType="com.ruoyi.web.work.domain.Diagnosis">
        SELECT * from tb_diagnosis
        where tb_diagnosis.visit_id in (SELECT tb_visit.id from tb_visit WHERE tb_visit.card_id=#{cardId})
    </select>

    <select id="selectDiagnosisInfosByVisitId" resultType="com.ruoyi.web.work.domain.Diagnosis">
        SELECT * from tb_diagnosis
        where visit_id = #{visitId}
    </select>

</mapper>
