<?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.framework.system.mapper.DiagnosisUpdatesMapper">
    
    <resultMap type="DiagnosisUpdates" id="DiagnosisUpdatesResult">
        <result property="UpdateID"    column="UpdateID"    />
        <result property="PatientID"    column="PatientID"    />
        <result property="UpdateDate"    column="UpdateDate"    />
        <result property="Diagnosis"    column="Diagnosis"    />
        <result property="NewSymptoms"    column="NewSymptoms"    />
        <result property="ChangedSymptoms"    column="ChangedSymptoms"    />
        <result property="VitalSignsChanges"    column="VitalSignsChanges"    />
        <result property="LabResultsChanges"    column="LabResultsChanges"    />
        <result property="TreatmentChanges"    column="TreatmentChanges"    />
        <result property="Notes"    column="Notes"    />
        <result property="UpdatedBy"    column="UpdatedBy"    />
        <result property="UpdatedAt"    column="UpdatedAt"    />
    </resultMap>

    <sql id="selectDiagnosisUpdatesVo">
        select UpdateID, PatientID, UpdateDate, Diagnosis, NewSymptoms, ChangedSymptoms, VitalSignsChanges, LabResultsChanges, TreatmentChanges, Notes, UpdatedBy, UpdatedAt from DiagnosisUpdates
    </sql>

    <select id="selectDiagnosisUpdatesList" parameterType="DiagnosisUpdates" resultMap="DiagnosisUpdatesResult">
        <include refid="selectDiagnosisUpdatesVo"/>
        <where>  
            <if test="PatientID != null "> and PatientID = #{PatientID}</if>
            <if test="UpdateDate != null "> and UpdateDate = #{UpdateDate}</if>
            <if test="Diagnosis != null  and Diagnosis != ''"> and Diagnosis = #{Diagnosis}</if>
            <if test="NewSymptoms != null  and NewSymptoms != ''"> and NewSymptoms = #{NewSymptoms}</if>
            <if test="ChangedSymptoms != null  and ChangedSymptoms != ''"> and ChangedSymptoms = #{ChangedSymptoms}</if>
            <if test="VitalSignsChanges != null  and VitalSignsChanges != ''"> and VitalSignsChanges = #{VitalSignsChanges}</if>
            <if test="LabResultsChanges != null  and LabResultsChanges != ''"> and LabResultsChanges = #{LabResultsChanges}</if>
            <if test="TreatmentChanges != null  and TreatmentChanges != ''"> and TreatmentChanges = #{TreatmentChanges}</if>
            <if test="Notes != null  and Notes != ''"> and Notes = #{Notes}</if>
            <if test="UpdatedBy != null  and UpdatedBy != ''"> and UpdatedBy = #{UpdatedBy}</if>
            <if test="UpdatedAt != null "> and UpdatedAt = #{UpdatedAt}</if>
        </where>
    </select>
    
    <select id="selectDiagnosisUpdatesByUpdateID" parameterType="Long" resultMap="DiagnosisUpdatesResult">
        <include refid="selectDiagnosisUpdatesVo"/>
        where UpdateID = #{UpdateID}
    </select>

    <insert id="insertDiagnosisUpdates" parameterType="DiagnosisUpdates" useGeneratedKeys="true" keyProperty="UpdateID">
        insert into DiagnosisUpdates
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">PatientID,</if>
            <if test="UpdateDate != null">UpdateDate,</if>
            <if test="Diagnosis != null">Diagnosis,</if>
            <if test="NewSymptoms != null">NewSymptoms,</if>
            <if test="ChangedSymptoms != null">ChangedSymptoms,</if>
            <if test="VitalSignsChanges != null">VitalSignsChanges,</if>
            <if test="LabResultsChanges != null">LabResultsChanges,</if>
            <if test="TreatmentChanges != null">TreatmentChanges,</if>
            <if test="Notes != null">Notes,</if>
            <if test="UpdatedBy != null">UpdatedBy,</if>
            <if test="UpdatedAt != null">UpdatedAt,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">#{PatientID},</if>
            <if test="UpdateDate != null">#{UpdateDate},</if>
            <if test="Diagnosis != null">#{Diagnosis},</if>
            <if test="NewSymptoms != null">#{NewSymptoms},</if>
            <if test="ChangedSymptoms != null">#{ChangedSymptoms},</if>
            <if test="VitalSignsChanges != null">#{VitalSignsChanges},</if>
            <if test="LabResultsChanges != null">#{LabResultsChanges},</if>
            <if test="TreatmentChanges != null">#{TreatmentChanges},</if>
            <if test="Notes != null">#{Notes},</if>
            <if test="UpdatedBy != null">#{UpdatedBy},</if>
            <if test="UpdatedAt != null">#{UpdatedAt},</if>
         </trim>
    </insert>

    <update id="updateDiagnosisUpdates" parameterType="DiagnosisUpdates">
        update DiagnosisUpdates
        <trim prefix="SET" suffixOverrides=",">
            <if test="PatientID != null">PatientID = #{PatientID},</if>
            <if test="UpdateDate != null">UpdateDate = #{UpdateDate},</if>
            <if test="Diagnosis != null">Diagnosis = #{Diagnosis},</if>
            <if test="NewSymptoms != null">NewSymptoms = #{NewSymptoms},</if>
            <if test="ChangedSymptoms != null">ChangedSymptoms = #{ChangedSymptoms},</if>
            <if test="VitalSignsChanges != null">VitalSignsChanges = #{VitalSignsChanges},</if>
            <if test="LabResultsChanges != null">LabResultsChanges = #{LabResultsChanges},</if>
            <if test="TreatmentChanges != null">TreatmentChanges = #{TreatmentChanges},</if>
            <if test="Notes != null">Notes = #{Notes},</if>
            <if test="UpdatedBy != null">UpdatedBy = #{UpdatedBy},</if>
            <if test="UpdatedAt != null">UpdatedAt = #{UpdatedAt},</if>
        </trim>
        where UpdateID = #{UpdateID}
    </update>

    <delete id="deleteDiagnosisUpdatesByUpdateID" parameterType="Long">
        delete from DiagnosisUpdates where UpdateID = #{UpdateID}
    </delete>

    <delete id="deleteDiagnosisUpdatesByUpdateIDs" parameterType="String">
        delete from DiagnosisUpdates where UpdateID in 
        <foreach item="UpdateID" collection="array" open="(" separator="," close=")">
            #{UpdateID}
        </foreach>
    </delete>
</mapper>