<?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.FollowUpRemindersMapper">
    
    <resultMap type="FollowUpReminders" id="FollowUpRemindersResult">
        <result property="ReminderID"    column="ReminderID"    />
        <result property="PatientID"    column="PatientID"    />
        <result property="ReminderDate"    column="ReminderDate"    />
        <result property="ReminderType"    column="ReminderType"    />
        <result property="ReminderMessage"    column="ReminderMessage"    />
        <result property="Status"    column="Status"    />
        <result property="SentBy"    column="SentBy"    />
        <result property="SentAt"    column="SentAt"    />
        <result property="Notes"    column="Notes"    />
    </resultMap>

    <sql id="selectFollowUpRemindersVo">
        select ReminderID, PatientID, ReminderDate, ReminderType, ReminderMessage, Status, SentBy, SentAt, Notes from FollowUpReminders
    </sql>

    <select id="selectFollowUpRemindersList" parameterType="FollowUpReminders" resultMap="FollowUpRemindersResult">
        <include refid="selectFollowUpRemindersVo"/>
        <where>  
            <if test="PatientID != null "> and PatientID = #{PatientID}</if>
            <if test="ReminderDate != null "> and ReminderDate = #{ReminderDate}</if>
            <if test="ReminderType != null  and ReminderType != ''"> and ReminderType = #{ReminderType}</if>
            <if test="ReminderMessage != null  and ReminderMessage != ''"> and ReminderMessage = #{ReminderMessage}</if>
            <if test="Status != null  and Status != ''"> and Status = #{Status}</if>
            <if test="SentBy != null  and SentBy != ''"> and SentBy = #{SentBy}</if>
            <if test="SentAt != null "> and SentAt = #{SentAt}</if>
            <if test="Notes != null  and Notes != ''"> and Notes = #{Notes}</if>
        </where>
    </select>
    
    <select id="selectFollowUpRemindersByReminderID" parameterType="Long" resultMap="FollowUpRemindersResult">
        <include refid="selectFollowUpRemindersVo"/>
        where ReminderID = #{ReminderID}
    </select>

    <insert id="insertFollowUpReminders" parameterType="FollowUpReminders" useGeneratedKeys="true" keyProperty="ReminderID">
        insert into FollowUpReminders
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">PatientID,</if>
            <if test="ReminderDate != null">ReminderDate,</if>
            <if test="ReminderType != null and ReminderType != ''">ReminderType,</if>
            <if test="ReminderMessage != null">ReminderMessage,</if>
            <if test="Status != null and Status != ''">Status,</if>
            <if test="SentBy != null">SentBy,</if>
            <if test="SentAt != null">SentAt,</if>
            <if test="Notes != null">Notes,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="PatientID != null">#{PatientID},</if>
            <if test="ReminderDate != null">#{ReminderDate},</if>
            <if test="ReminderType != null and ReminderType != ''">#{ReminderType},</if>
            <if test="ReminderMessage != null">#{ReminderMessage},</if>
            <if test="Status != null and Status != ''">#{Status},</if>
            <if test="SentBy != null">#{SentBy},</if>
            <if test="SentAt != null">#{SentAt},</if>
            <if test="Notes != null">#{Notes},</if>
         </trim>
    </insert>

    <update id="updateFollowUpReminders" parameterType="FollowUpReminders">
        update FollowUpReminders
        <trim prefix="SET" suffixOverrides=",">
            <if test="PatientID != null">PatientID = #{PatientID},</if>
            <if test="ReminderDate != null">ReminderDate = #{ReminderDate},</if>
            <if test="ReminderType != null and ReminderType != ''">ReminderType = #{ReminderType},</if>
            <if test="ReminderMessage != null">ReminderMessage = #{ReminderMessage},</if>
            <if test="Status != null and Status != ''">Status = #{Status},</if>
            <if test="SentBy != null">SentBy = #{SentBy},</if>
            <if test="SentAt != null">SentAt = #{SentAt},</if>
            <if test="Notes != null">Notes = #{Notes},</if>
        </trim>
        where ReminderID = #{ReminderID}
    </update>

    <delete id="deleteFollowUpRemindersByReminderID" parameterType="Long">
        delete from FollowUpReminders where ReminderID = #{ReminderID}
    </delete>

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