<?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.xinelu.manage.mapper.patientvisitouthospital.PatientVisitOutHospitalMapper">

    <resultMap type="PatientVisitOutHospital" id="PatientVisitOutHospitalResult">
            <result property="id" column="id"/>
            <result property="patientVisitRecordId" column="patient_visit_record_id"/>
            <result property="admissionDiagnosis" column="admission_diagnosis"/>
            <result property="admissionSituation" column="admission_situation"/>
            <result property="diagnosisTreatmentProcess" column="diagnosis_treatment_process"/>
            <result property="dischargeDiagnosis" column="discharge_diagnosis"/>
            <result property="dischargeStatus" column="discharge_status"/>
            <result property="dischargeOrder" column="discharge_order"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectPatientVisitOutHospitalVo">
        select id, patient_visit_record_id, admission_diagnosis, admission_situation, diagnosis_treatment_process, discharge_diagnosis, discharge_status, discharge_order, create_by, create_time, update_by, update_time from patient_visit_out_hospital
    </sql>

    <select id="selectPatientVisitOutHospitalList" parameterType="PatientVisitOutHospital" resultMap="PatientVisitOutHospitalResult">
        <include refid="selectPatientVisitOutHospitalVo"/>
        <where>
                        <if test="patientVisitRecordId != null ">
                            and patient_visit_record_id = #{patientVisitRecordId}
                        </if>
                        <if test="admissionDiagnosis != null  and admissionDiagnosis != ''">
                            and admission_diagnosis = #{admissionDiagnosis}
                        </if>
                        <if test="admissionSituation != null  and admissionSituation != ''">
                            and admission_situation = #{admissionSituation}
                        </if>
                        <if test="diagnosisTreatmentProcess != null  and diagnosisTreatmentProcess != ''">
                            and diagnosis_treatment_process = #{diagnosisTreatmentProcess}
                        </if>
                        <if test="dischargeDiagnosis != null  and dischargeDiagnosis != ''">
                            and discharge_diagnosis = #{dischargeDiagnosis}
                        </if>
                        <if test="dischargeStatus != null  and dischargeStatus != ''">
                            and discharge_status = #{dischargeStatus}
                        </if>
                        <if test="dischargeOrder != null  and dischargeOrder != ''">
                            and discharge_order = #{dischargeOrder}
                        </if>
        </where>
    </select>

    <select id="selectPatientVisitOutHospitalById" parameterType="Long"
            resultMap="PatientVisitOutHospitalResult">
            <include refid="selectPatientVisitOutHospitalVo"/>
            where id = #{id}
    </select>

    <insert id="insertPatientVisitOutHospital" parameterType="PatientVisitOutHospital" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_visit_out_hospital
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id,
                    </if>
                    <if test="admissionDiagnosis != null">admission_diagnosis,
                    </if>
                    <if test="admissionSituation != null">admission_situation,
                    </if>
                    <if test="diagnosisTreatmentProcess != null">diagnosis_treatment_process,
                    </if>
                    <if test="dischargeDiagnosis != null">discharge_diagnosis,
                    </if>
                    <if test="dischargeStatus != null">discharge_status,
                    </if>
                    <if test="dischargeOrder != null">discharge_order,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">#{patientVisitRecordId},
                    </if>
                    <if test="admissionDiagnosis != null">#{admissionDiagnosis},
                    </if>
                    <if test="admissionSituation != null">#{admissionSituation},
                    </if>
                    <if test="diagnosisTreatmentProcess != null">#{diagnosisTreatmentProcess},
                    </if>
                    <if test="dischargeDiagnosis != null">#{dischargeDiagnosis},
                    </if>
                    <if test="dischargeStatus != null">#{dischargeStatus},
                    </if>
                    <if test="dischargeOrder != null">#{dischargeOrder},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
        </trim>
    </insert>

    <update id="updatePatientVisitOutHospital" parameterType="PatientVisitOutHospital">
        update patient_visit_out_hospital
        <trim prefix="SET" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id =
                        #{patientVisitRecordId},
                    </if>
                    <if test="admissionDiagnosis != null">admission_diagnosis =
                        #{admissionDiagnosis},
                    </if>
                    <if test="admissionSituation != null">admission_situation =
                        #{admissionSituation},
                    </if>
                    <if test="diagnosisTreatmentProcess != null">diagnosis_treatment_process =
                        #{diagnosisTreatmentProcess},
                    </if>
                    <if test="dischargeDiagnosis != null">discharge_diagnosis =
                        #{dischargeDiagnosis},
                    </if>
                    <if test="dischargeStatus != null">discharge_status =
                        #{dischargeStatus},
                    </if>
                    <if test="dischargeOrder != null">discharge_order =
                        #{dischargeOrder},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePatientVisitOutHospitalById" parameterType="Long">
        delete from patient_visit_out_hospital where id = #{id}
    </delete>

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