<?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.fs.store.mapper.FsPrescribeMapper">
    
    <resultMap type="FsPrescribe" id="FsPrescribeResult">
        <result property="prescribeId"    column="prescribe_id"    />
        <result property="prescribeType"    column="prescribe_type"    />
        <result property="orderId"    column="order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="patientId"    column="patient_id"    />
        <result property="rpId"    column="rp_id"    />
        <result property="pharmacyCode"    column="pharmacy_code"    />
        <result property="pharmacyName"    column="pharmacy_name"    />
        <result property="chiefComplaint"    column="chief_complaint"    />
        <result property="nowIllness"    column="now_illness"    />
        <result property="historyIllness"    column="history_illness"    />
        <result property="patientAge"    column="patient_age"    />
        <result property="patientName"    column="patient_name"    />
        <result property="weight"    column="weight"    />
        <result property="isHistoryAllergic"    column="is_history_allergic"    />
        <result property="historyAllergic"    column="history_allergic"    />
        <result property="liverUnusual"    column="liver_unusual"    />
        <result property="renalUnusual"    column="renal_unusual"    />
        <result property="lactationFlag"    column="lactation_flag"    />
        <result property="patientTel"    column="patient_tel"    />
        <result property="patientGender"    column="patient_gender"    />
        <result property="recordPic"    column="record_pic"    />
        <result property="rpUrl"    column="rp_url"    />
        <result property="rpCreateTime"    column="rp_create_time"    />
        <result property="auditReason"    column="audit_reason"    />
        <result property="diagnose"    column="diagnose"    />
        <result property="drugs"    column="drugs"    />
        <result property="doctorName"    column="doctor_name"    />
        <result property="doctorId"    column="doctor_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectFsPrescribeVo">
        select prescribe_id, prescribe_type, order_id, user_id, patient_id, rp_id, pharmacy_code, pharmacy_name, chief_complaint, now_illness, history_illness, patient_age, patient_name, weight, is_history_allergic, history_allergic, liver_unusual, renal_unusual, lactation_flag, patient_tel, patient_gender, record_pic, rp_url, rp_create_time,audit_reason, diagnose, drugs, doctor_name, doctor_id, create_time,status from fs_prescribe
    </sql>

    <select id="selectFsPrescribeList" parameterType="FsPrescribe" resultMap="FsPrescribeResult">
        <include refid="selectFsPrescribeVo"/>
        <where>  
            <if test="prescribeType != null "> and prescribe_type = #{prescribeType}</if>
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="patientId != null "> and patient_id = #{patientId}</if>
            <if test="rpId != null  and rpId != ''"> and rp_id = #{rpId}</if>
            <if test="pharmacyCode != null  and pharmacyCode != ''"> and pharmacy_code = #{pharmacyCode}</if>
            <if test="pharmacyName != null  and pharmacyName != ''"> and pharmacy_name like concat('%', #{pharmacyName}, '%')</if>
            <if test="chiefComplaint != null  and chiefComplaint != ''"> and chief_complaint = #{chiefComplaint}</if>
            <if test="nowIllness != null  and nowIllness != ''"> and now_illness = #{nowIllness}</if>
            <if test="historyIllness != null  and historyIllness != ''"> and history_illness = #{historyIllness}</if>
            <if test="patientAge != null  and patientAge != ''"> and patient_age = #{patientAge}</if>
            <if test="patientName != null  and patientName != ''"> and patient_name like concat('%', #{patientName}, '%')</if>
            <if test="weight != null  and weight != ''"> and weight = #{weight}</if>
            <if test="isHistoryAllergic != null  and isHistoryAllergic != ''"> and is_history_allergic = #{isHistoryAllergic}</if>
            <if test="historyAllergic != null  and historyAllergic != ''"> and history_allergic = #{historyAllergic}</if>
            <if test="liverUnusual != null  and liverUnusual != ''"> and liver_unusual = #{liverUnusual}</if>
            <if test="renalUnusual != null  and renalUnusual != ''"> and renal_unusual = #{renalUnusual}</if>
            <if test="lactationFlag != null  and lactationFlag != ''"> and lactation_flag = #{lactationFlag}</if>
            <if test="patientTel != null  and patientTel != ''"> and patient_tel = #{patientTel}</if>
            <if test="patientGender != null  and patientGender != ''"> and patient_gender = #{patientGender}</if>
            <if test="recordPic != null  and recordPic != ''"> and record_pic = #{recordPic}</if>
            <if test="rpUrl != null  and rpUrl != ''"> and rp_url = #{rpUrl}</if>
            <if test="rpCreateTime != null "> and rp_create_time = #{rpCreateTime}</if>
            <if test="diagnose != null  and diagnose != ''"> and diagnose = #{diagnose}</if>
            <if test="drugs != null  and drugs != ''"> and drugs = #{drugs}</if>
            <if test="doctorName != null  and doctorName != ''"> and doctor_name like concat('%', #{doctorName}, '%')</if>
            <if test="doctorId != null  and doctorId != ''"> and doctor_id = #{doctorId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectFsPrescribeById" parameterType="Long" resultMap="FsPrescribeResult">
        <include refid="selectFsPrescribeVo"/>
        where prescribe_id = #{prescribeId}
    </select>
        
    <insert id="insertFsPrescribe" parameterType="FsPrescribe" useGeneratedKeys="true" keyProperty="prescribeId">
        insert into fs_prescribe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prescribeType != null">prescribe_type,</if>
            <if test="orderId != null">order_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="patientId != null">patient_id,</if>
            <if test="rpId != null">rp_id,</if>
            <if test="pharmacyCode != null">pharmacy_code,</if>
            <if test="pharmacyName != null">pharmacy_name,</if>
            <if test="chiefComplaint != null">chief_complaint,</if>
            <if test="nowIllness != null">now_illness,</if>
            <if test="historyIllness != null">history_illness,</if>
            <if test="patientAge != null">patient_age,</if>
            <if test="patientName != null">patient_name,</if>
            <if test="weight != null">weight,</if>
            <if test="isHistoryAllergic != null">is_history_allergic,</if>
            <if test="historyAllergic != null">history_allergic,</if>
            <if test="liverUnusual != null">liver_unusual,</if>
            <if test="renalUnusual != null">renal_unusual,</if>
            <if test="lactationFlag != null">lactation_flag,</if>
            <if test="patientTel != null">patient_tel,</if>
            <if test="patientGender != null">patient_gender,</if>
            <if test="recordPic != null">record_pic,</if>
            <if test="rpUrl != null">rp_url,</if>
            <if test="rpCreateTime != null">rp_create_time,</if>
            <if test="auditReason != null">audit_reason,</if>
            <if test="diagnose != null">diagnose,</if>
            <if test="drugs != null">drugs,</if>
            <if test="doctorName != null">doctor_name,</if>
            <if test="doctorId != null">doctor_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prescribeType != null">#{prescribeType},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="patientId != null">#{patientId},</if>
            <if test="rpId != null">#{rpId},</if>
            <if test="pharmacyCode != null">#{pharmacyCode},</if>
            <if test="pharmacyName != null">#{pharmacyName},</if>
            <if test="chiefComplaint != null">#{chiefComplaint},</if>
            <if test="nowIllness != null">#{nowIllness},</if>
            <if test="historyIllness != null">#{historyIllness},</if>
            <if test="patientAge != null">#{patientAge},</if>
            <if test="patientName != null">#{patientName},</if>
            <if test="weight != null">#{weight},</if>
            <if test="isHistoryAllergic != null">#{isHistoryAllergic},</if>
            <if test="historyAllergic != null">#{historyAllergic},</if>
            <if test="liverUnusual != null">#{liverUnusual},</if>
            <if test="renalUnusual != null">#{renalUnusual},</if>
            <if test="lactationFlag != null">#{lactationFlag},</if>
            <if test="patientTel != null">#{patientTel},</if>
            <if test="patientGender != null">#{patientGender},</if>
            <if test="recordPic != null">#{recordPic},</if>
            <if test="rpUrl != null">#{rpUrl},</if>
            <if test="rpCreateTime != null">#{rpCreateTime},</if>
            <if test="auditReason != null">#{auditReason},</if>
            <if test="diagnose != null">#{diagnose},</if>
            <if test="drugs != null">#{drugs},</if>
            <if test="doctorName != null">#{doctorName},</if>
            <if test="doctorId != null">#{doctorId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateFsPrescribe" parameterType="FsPrescribe">
        update fs_prescribe
        <trim prefix="SET" suffixOverrides=",">
            <if test="prescribeType != null">prescribe_type = #{prescribeType},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="patientId != null">patient_id = #{patientId},</if>
            <if test="rpId != null">rp_id = #{rpId},</if>
            <if test="pharmacyCode != null">pharmacy_code = #{pharmacyCode},</if>
            <if test="pharmacyName != null">pharmacy_name = #{pharmacyName},</if>
            <if test="chiefComplaint != null">chief_complaint = #{chiefComplaint},</if>
            <if test="nowIllness != null">now_illness = #{nowIllness},</if>
            <if test="historyIllness != null">history_illness = #{historyIllness},</if>
            <if test="patientAge != null">patient_age = #{patientAge},</if>
            <if test="patientName != null">patient_name = #{patientName},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="isHistoryAllergic != null">is_history_allergic = #{isHistoryAllergic},</if>
            <if test="historyAllergic != null">history_allergic = #{historyAllergic},</if>
            <if test="liverUnusual != null">liver_unusual = #{liverUnusual},</if>
            <if test="renalUnusual != null">renal_unusual = #{renalUnusual},</if>
            <if test="lactationFlag != null">lactation_flag = #{lactationFlag},</if>
            <if test="patientTel != null">patient_tel = #{patientTel},</if>
            <if test="patientGender != null">patient_gender = #{patientGender},</if>
            <if test="recordPic != null">record_pic = #{recordPic},</if>
            <if test="rpUrl != null">rp_url = #{rpUrl},</if>
            <if test="rpCreateTime != null">rp_create_time = #{rpCreateTime},</if>
            <if test="auditReason != null">audit_reason = #{auditReason},</if>
            <if test="diagnose != null">diagnose = #{diagnose},</if>
            <if test="drugs != null">drugs = #{drugs},</if>
            <if test="doctorName != null">doctor_name = #{doctorName},</if>
            <if test="doctorId != null">doctor_id = #{doctorId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where prescribe_id = #{prescribeId}
    </update>

    <delete id="deleteFsPrescribeById" parameterType="Long">
        delete from fs_prescribe where prescribe_id = #{prescribeId}
    </delete>

    <delete id="deleteFsPrescribeByIds" parameterType="String">
        delete from fs_prescribe where prescribe_id in 
        <foreach item="prescribeId" collection="array" open="(" separator="," close=")">
            #{prescribeId}
        </foreach>
    </delete>
    
</mapper>