<?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.FollowUpRecordsMapper">
    
    <resultMap type="FollowUpRecords" id="FollowUpRecordsResult">
        <result property="RecordID"    column="RecordID"    />
        <result property="PatientID"    column="PatientID"    />
        <result property="FollowUpDate"    column="FollowUpDate"    />
        <result property="Symptoms"    column="Symptoms"    />
        <result property="Diagnosis"    column="Diagnosis"    />
        <result property="TreatmentPlan"    column="TreatmentPlan"    />
        <result property="MedicationsPrescribed"    column="MedicationsPrescribed"    />
        <result property="VitalSigns"    column="VitalSigns"    />
        <result property="LabResults"    column="LabResults"    />
        <result property="Notes"    column="Notes"    />
        <result property="CreatedBy"    column="CreatedBy"    />
        <result property="CreatedAt"    column="CreatedAt"    />
    </resultMap>

    <sql id="selectFollowUpRecordsVo">
        select RecordID, PatientID, FollowUpDate, Symptoms, Diagnosis, TreatmentPlan, MedicationsPrescribed, VitalSigns, LabResults, Notes, CreatedBy, CreatedAt from FollowUpRecords
    </sql>

    <select id="selectFollowUpRecordsList" parameterType="FollowUpRecords" resultMap="FollowUpRecordsResult">
        <include refid="selectFollowUpRecordsVo"/>
        <where>  
            <if test="PatientID != null "> and PatientID = #{PatientID}</if>
            <if test="FollowUpDate != null "> and FollowUpDate = #{FollowUpDate}</if>
            <if test="Symptoms != null  and Symptoms != ''"> and Symptoms = #{Symptoms}</if>
            <if test="Diagnosis != null  and Diagnosis != ''"> and Diagnosis = #{Diagnosis}</if>
            <if test="TreatmentPlan != null  and TreatmentPlan != ''"> and TreatmentPlan = #{TreatmentPlan}</if>
            <if test="MedicationsPrescribed != null  and MedicationsPrescribed != ''"> and MedicationsPrescribed = #{MedicationsPrescribed}</if>
            <if test="VitalSigns != null  and VitalSigns != ''"> and VitalSigns = #{VitalSigns}</if>
            <if test="LabResults != null  and LabResults != ''"> and LabResults = #{LabResults}</if>
            <if test="Notes != null  and Notes != ''"> and Notes = #{Notes}</if>
            <if test="CreatedBy != null  and CreatedBy != ''"> and CreatedBy = #{CreatedBy}</if>
            <if test="CreatedAt != null "> and CreatedAt = #{CreatedAt}</if>
        </where>
    </select>
    
    <select id="selectFollowUpRecordsByRecordID" parameterType="Long" resultMap="FollowUpRecordsResult">
        <include refid="selectFollowUpRecordsVo"/>
        where RecordID = #{RecordID}
    </select>

    <insert id="insertFollowUpRecords" parameterType="FollowUpRecords" useGeneratedKeys="true" keyProperty="RecordID">
        insert into FollowUpRecords
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">PatientID,</if>
            <if test="FollowUpDate != null">FollowUpDate,</if>
            <if test="Symptoms != null">Symptoms,</if>
            <if test="Diagnosis != null">Diagnosis,</if>
            <if test="TreatmentPlan != null">TreatmentPlan,</if>
            <if test="MedicationsPrescribed != null">MedicationsPrescribed,</if>
            <if test="VitalSigns != null">VitalSigns,</if>
            <if test="LabResults != null">LabResults,</if>
            <if test="Notes != null">Notes,</if>
            <if test="CreatedBy != null">CreatedBy,</if>
            <if test="CreatedAt != null">CreatedAt,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">#{PatientID},</if>
            <if test="FollowUpDate != null">#{FollowUpDate},</if>
            <if test="Symptoms != null">#{Symptoms},</if>
            <if test="Diagnosis != null">#{Diagnosis},</if>
            <if test="TreatmentPlan != null">#{TreatmentPlan},</if>
            <if test="MedicationsPrescribed != null">#{MedicationsPrescribed},</if>
            <if test="VitalSigns != null">#{VitalSigns},</if>
            <if test="LabResults != null">#{LabResults},</if>
            <if test="Notes != null">#{Notes},</if>
            <if test="CreatedBy != null">#{CreatedBy},</if>
            <if test="CreatedAt != null">#{CreatedAt},</if>
         </trim>
    </insert>

    <update id="updateFollowUpRecords" parameterType="FollowUpRecords">
        update FollowUpRecords
        <trim prefix="SET" suffixOverrides=",">
            <if test="PatientID != null">PatientID = #{PatientID},</if>
            <if test="FollowUpDate != null">FollowUpDate = #{FollowUpDate},</if>
            <if test="Symptoms != null">Symptoms = #{Symptoms},</if>
            <if test="Diagnosis != null">Diagnosis = #{Diagnosis},</if>
            <if test="TreatmentPlan != null">TreatmentPlan = #{TreatmentPlan},</if>
            <if test="MedicationsPrescribed != null">MedicationsPrescribed = #{MedicationsPrescribed},</if>
            <if test="VitalSigns != null">VitalSigns = #{VitalSigns},</if>
            <if test="LabResults != null">LabResults = #{LabResults},</if>
            <if test="Notes != null">Notes = #{Notes},</if>
            <if test="CreatedBy != null">CreatedBy = #{CreatedBy},</if>
            <if test="CreatedAt != null">CreatedAt = #{CreatedAt},</if>
        </trim>
        where RecordID = #{RecordID}
    </update>

    <delete id="deleteFollowUpRecordsByRecordID" parameterType="Long">
        delete from FollowUpRecords where RecordID = #{RecordID}
    </delete>

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