<?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.patientvisitinhospital.PatientVisitInHospitalMapper">

    <resultMap type="PatientVisitInHospital" id="PatientVisitInHospitalResult">
            <result property="id" column="id"/>
            <result property="patientVisitRecordId" column="patient_visit_record_id"/>
            <result property="chiefComplaint" column="chief_complaint"/>
            <result property="presentIllnessHistory" column="present_illness_history"/>
            <result property="pastHistory" column="past_history"/>
            <result property="personalHistory" column="personal_history"/>
            <result property="maritalHistory" column="marital_history"/>
            <result property="menstrualFertilityHistory" column="menstrual_fertility_history"/>
            <result property="familyHistory" column="family_history"/>
            <result property="patientsSignature" column="patients_signature"/>
            <result property="confirmedSignature" column="confirmed_signature"/>
            <result property="signatureDate" column="signature_date"/>
            <result property="physicalExamination" column="physical_examination"/>
            <result property="specialityExamination" column="speciality_examination"/>
            <result property="assistantExamination" column="assistant_examination"/>
            <result property="primaryDiagnosis" column="primary_diagnosis"/>
            <result property="physicianSignature" column="physician_signature"/>
            <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="selectPatientVisitInHospitalVo">
        select id, patient_visit_record_id, chief_complaint, present_illness_history, past_history, personal_history, marital_history, menstrual_fertility_history, family_history, patients_signature, confirmed_signature, signature_date, physical_examination, speciality_examination, assistant_examination, primary_diagnosis, physician_signature, create_by, create_time, update_by, update_time from patient_visit_in_hospital
    </sql>

    <select id="selectPatientVisitInHospitalList" parameterType="PatientVisitInHospital" resultMap="PatientVisitInHospitalResult">
        <include refid="selectPatientVisitInHospitalVo"/>
        <where>
                        <if test="patientVisitRecordId != null ">
                            and patient_visit_record_id = #{patientVisitRecordId}
                        </if>
                        <if test="chiefComplaint != null  and chiefComplaint != ''">
                            and chief_complaint = #{chiefComplaint}
                        </if>
                        <if test="presentIllnessHistory != null  and presentIllnessHistory != ''">
                            and present_illness_history = #{presentIllnessHistory}
                        </if>
                        <if test="pastHistory != null  and pastHistory != ''">
                            and past_history = #{pastHistory}
                        </if>
                        <if test="personalHistory != null  and personalHistory != ''">
                            and personal_history = #{personalHistory}
                        </if>
                        <if test="maritalHistory != null  and maritalHistory != ''">
                            and marital_history = #{maritalHistory}
                        </if>
                        <if test="menstrualFertilityHistory != null  and menstrualFertilityHistory != ''">
                            and menstrual_fertility_history = #{menstrualFertilityHistory}
                        </if>
                        <if test="familyHistory != null  and familyHistory != ''">
                            and family_history = #{familyHistory}
                        </if>
                        <if test="patientsSignature != null  and patientsSignature != ''">
                            and patients_signature = #{patientsSignature}
                        </if>
                        <if test="confirmedSignature != null  and confirmedSignature != ''">
                            and confirmed_signature = #{confirmedSignature}
                        </if>
                        <if test="signatureDate != null ">
                            and signature_date = #{signatureDate}
                        </if>
                        <if test="physicalExamination != null  and physicalExamination != ''">
                            and physical_examination = #{physicalExamination}
                        </if>
                        <if test="specialityExamination != null  and specialityExamination != ''">
                            and speciality_examination = #{specialityExamination}
                        </if>
                        <if test="assistantExamination != null  and assistantExamination != ''">
                            and assistant_examination = #{assistantExamination}
                        </if>
                        <if test="primaryDiagnosis != null  and primaryDiagnosis != ''">
                            and primary_diagnosis = #{primaryDiagnosis}
                        </if>
                        <if test="physicianSignature != null  and physicianSignature != ''">
                            and physician_signature = #{physicianSignature}
                        </if>
        </where>
    </select>

    <select id="selectPatientVisitInHospitalById" parameterType="Long"
            resultMap="PatientVisitInHospitalResult">
            <include refid="selectPatientVisitInHospitalVo"/>
            where id = #{id}
    </select>

    <insert id="insertPatientVisitInHospital" parameterType="PatientVisitInHospital" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_visit_in_hospital
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id,
                    </if>
                    <if test="chiefComplaint != null">chief_complaint,
                    </if>
                    <if test="presentIllnessHistory != null">present_illness_history,
                    </if>
                    <if test="pastHistory != null">past_history,
                    </if>
                    <if test="personalHistory != null">personal_history,
                    </if>
                    <if test="maritalHistory != null">marital_history,
                    </if>
                    <if test="menstrualFertilityHistory != null">menstrual_fertility_history,
                    </if>
                    <if test="familyHistory != null">family_history,
                    </if>
                    <if test="patientsSignature != null">patients_signature,
                    </if>
                    <if test="confirmedSignature != null">confirmed_signature,
                    </if>
                    <if test="signatureDate != null">signature_date,
                    </if>
                    <if test="physicalExamination != null">physical_examination,
                    </if>
                    <if test="specialityExamination != null">speciality_examination,
                    </if>
                    <if test="assistantExamination != null">assistant_examination,
                    </if>
                    <if test="primaryDiagnosis != null">primary_diagnosis,
                    </if>
                    <if test="physicianSignature != null">physician_signature,
                    </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="chiefComplaint != null">#{chiefComplaint},
                    </if>
                    <if test="presentIllnessHistory != null">#{presentIllnessHistory},
                    </if>
                    <if test="pastHistory != null">#{pastHistory},
                    </if>
                    <if test="personalHistory != null">#{personalHistory},
                    </if>
                    <if test="maritalHistory != null">#{maritalHistory},
                    </if>
                    <if test="menstrualFertilityHistory != null">#{menstrualFertilityHistory},
                    </if>
                    <if test="familyHistory != null">#{familyHistory},
                    </if>
                    <if test="patientsSignature != null">#{patientsSignature},
                    </if>
                    <if test="confirmedSignature != null">#{confirmedSignature},
                    </if>
                    <if test="signatureDate != null">#{signatureDate},
                    </if>
                    <if test="physicalExamination != null">#{physicalExamination},
                    </if>
                    <if test="specialityExamination != null">#{specialityExamination},
                    </if>
                    <if test="assistantExamination != null">#{assistantExamination},
                    </if>
                    <if test="primaryDiagnosis != null">#{primaryDiagnosis},
                    </if>
                    <if test="physicianSignature != null">#{physicianSignature},
                    </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="updatePatientVisitInHospital" parameterType="PatientVisitInHospital">
        update patient_visit_in_hospital
        <trim prefix="SET" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id =
                        #{patientVisitRecordId},
                    </if>
                    <if test="chiefComplaint != null">chief_complaint =
                        #{chiefComplaint},
                    </if>
                    <if test="presentIllnessHistory != null">present_illness_history =
                        #{presentIllnessHistory},
                    </if>
                    <if test="pastHistory != null">past_history =
                        #{pastHistory},
                    </if>
                    <if test="personalHistory != null">personal_history =
                        #{personalHistory},
                    </if>
                    <if test="maritalHistory != null">marital_history =
                        #{maritalHistory},
                    </if>
                    <if test="menstrualFertilityHistory != null">menstrual_fertility_history =
                        #{menstrualFertilityHistory},
                    </if>
                    <if test="familyHistory != null">family_history =
                        #{familyHistory},
                    </if>
                    <if test="patientsSignature != null">patients_signature =
                        #{patientsSignature},
                    </if>
                    <if test="confirmedSignature != null">confirmed_signature =
                        #{confirmedSignature},
                    </if>
                    <if test="signatureDate != null">signature_date =
                        #{signatureDate},
                    </if>
                    <if test="physicalExamination != null">physical_examination =
                        #{physicalExamination},
                    </if>
                    <if test="specialityExamination != null">speciality_examination =
                        #{specialityExamination},
                    </if>
                    <if test="assistantExamination != null">assistant_examination =
                        #{assistantExamination},
                    </if>
                    <if test="primaryDiagnosis != null">primary_diagnosis =
                        #{primaryDiagnosis},
                    </if>
                    <if test="physicianSignature != null">physician_signature =
                        #{physicianSignature},
                    </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="deletePatientVisitInHospitalById" parameterType="Long">
        delete from patient_visit_in_hospital where id = #{id}
    </delete>

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