<?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.signpatientrecord.SignPatientRecordMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.manage.domain.signpatientrecord.SignPatientRecord">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="patientId" column="patient_id" jdbcType="BIGINT"/>
        <result property="patientName" column="patient_name" jdbcType="VARCHAR"/>
        <result property="patientPhone" column="patient_phone" jdbcType="VARCHAR"/>
        <result property="cardNo" column="card_no" jdbcType="VARCHAR"/>
	    <result property="sex" column="sex" jdbcType="VARCHAR"/>
	    <result property="birthDate" column="birth_date" jdbcType="DATE"/>
        <result property="signTime" column="sign_time" jdbcType="TIMESTAMP"/>
        <result property="hospitalAgencyId" column="hospital_agency_id" jdbcType="BIGINT"/>
        <result property="hospitalAgencyName" column="hospital_agency_name" jdbcType="VARCHAR"/>
        <result property="campusAgencyId" column="campus_agency_id" jdbcType="BIGINT"/>
        <result property="campusAgencyName" column="campus_agency_name" jdbcType="VARCHAR"/>
        <result property="departmentId" column="department_id" jdbcType="BIGINT"/>
        <result property="departmentName" column="department_name" jdbcType="VARCHAR"/>
        <result property="wardId" column="ward_id" jdbcType="BIGINT"/>
        <result property="wardName" column="ward_name" jdbcType="VARCHAR"/>
	    <result property="patientVisitRecordId" column="patient_visit_record_id" jdbcType="BIGINT"/>
        <result property="visitSerialNumber" column="visit_serial_number" jdbcType="VARCHAR"/>
        <result property="visitMethod" column="visit_method" jdbcType="VARCHAR"/>
	    <result property="inHospitalNumber" column="in_hospital_number" jdbcType="VARCHAR"/>
        <result property="signDiagnosis" column="sign_diagnosis" jdbcType="VARCHAR"/>
        <result property="reviewDiagnosis" column="review_diagnosis" jdbcType="VARCHAR"/>
        <result property="serviceStatus" column="service_status" jdbcType="VARCHAR"/>
        <result property="signStatus" column="sign_status" jdbcType="VARCHAR"/>
        <result property="intentionalSource" column="intentional_source" jdbcType="VARCHAR"/>
        <result property="intentionalTime" column="intentional_time" jdbcType="TIMESTAMP"/>
        <result property="billingDoctorId" column="billing_doctor_id" jdbcType="BIGINT"/>
        <result property="billingDoctorName" column="billing_doctor_name" jdbcType="VARCHAR"/>
        <result property="price" column="price" jdbcType="DECIMAL"/>
        <result property="paymentStatus" column="payment_status" jdbcType="VARCHAR"/>
	    <result property="healthManageId" column="health_manage_id" jdbcType="VARCHAR"/>
	    <result property="healthManageName" column="health_manage_name" jdbcType="VARCHAR"/>
	    <result property="portaitCheckStatus" column="portait_check_status" jdbcType="VARCHAR"/>
	    <result property="portaitCheckPerson" column="portait_check_person" jdbcType="VARCHAR"/>
	    <result property="portaitCheckDate" column="portait_check_date" jdbcType="TIMESTAMP"/>
	    <result property="routeCheckStatus" column="route_check_status" jdbcType="VARCHAR"/>
	    <result property="routeCheckPerson" column="route_check_person" jdbcType="VARCHAR"/>
	    <result property="routeCheckDate" column="route_check_date" jdbcType="TIMESTAMP"/>
	    <result property="routeCheckRemark" column="route_check_remark" jdbcType="VARCHAR"/>
	    <result property="delFlag" column="del_flag" jdbcType="TINYINT"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,patient_id,patient_name,
        patient_phone,card_no,sex,birth_date,sign_time,
        hospital_agency_id,hospital_agency_name,campus_agency_id,
        campus_agency_name,department_id,department_name,
        ward_id,ward_name,patient_visit_record_id,visit_serial_number,
        visit_method,in_hospital_number,sign_diagnosis,review_diagnosis,
        service_status,sign_status,intentional_source,
        intentional_time,billing_doctor_id,billing_doctor_name,
        price,payment_status,health_manage_id,health_manage_name,
	    portait_check_status,portait_check_person,portait_check_date,
        route_check_status,route_check_person,route_check_date,route_check_remark,
        del_flag,create_by,create_time,update_by,update_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from sign_patient_record
        where  id = #{id,jdbcType=BIGINT} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from sign_patient_record
        where  id = #{id,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.signpatientrecord.SignPatientRecord" useGeneratedKeys="true">
        insert into sign_patient_record
        ( id,patient_id,patient_name
        ,patient_phone,card_no,sex,birth_date,sign_time
        ,hospital_agency_id,hospital_agency_name,campus_agency_id
        ,campus_agency_name,department_id,department_name
        ,ward_id,ward_name,patient_visit_record_id,visit_serial_number
        ,visit_method,in_hospital_number,sign_diagnosis,review_diagnosis
        ,service_status,sign_status,intentional_source
        ,intentional_time,billing_doctor_id,billing_doctor_name
        ,price,payment_status,health_manage_id,health_manage_name
        ,portait_check_status,portait_check_person,portait_check_date
	    ,route_check_status,route_check_person,route_check_date,route_check_remark
        ,del_flag,create_by,create_time,update_by
        ,update_time)
        values (#{id,jdbcType=BIGINT},#{patientId,jdbcType=BIGINT},#{patientName,jdbcType=VARCHAR}
        ,#{patientPhone,jdbcType=VARCHAR},#{cardNo,jdbcType=VARCHAR},#{sex,jdbcType=VARCHAR},#{birthDate,jdbcType=DATE},#{signTime,jdbcType=TIMESTAMP}
        ,#{hospitalAgencyId,jdbcType=BIGINT},#{hospitalAgencyName,jdbcType=VARCHAR},#{campusAgencyId,jdbcType=BIGINT}
        ,#{campusAgencyName,jdbcType=VARCHAR},#{departmentId,jdbcType=BIGINT},#{departmentName,jdbcType=VARCHAR}
        ,#{wardId,jdbcType=BIGINT},#{wardName,jdbcType=VARCHAR},#{patientVisitRecordId,jdbcType=BIGINT},#{visitSerialNumber,jdbcType=VARCHAR}
        ,#{visitMethod,jdbcType=VARCHAR},#{inHospitalNumber,jdbcType=VARCHAR},#{signDiagnosis,jdbcType=VARCHAR},#{reviewDiagnosis,jdbcType=VARCHAR}
        ,#{serviceStatus,jdbcType=VARCHAR},#{signStatus,jdbcType=VARCHAR},#{intentionalSource,jdbcType=VARCHAR}
        ,#{intentionalTime,jdbcType=TIMESTAMP},#{billingDoctorId,jdbcType=BIGINT},#{billingDoctorName,jdbcType=VARCHAR}
        ,#{price,jdbcType=DECIMAL},#{paymentStatus,jdbcType=VARCHAR},#{healthManageId,jdbcType=BIGINT},#{healthManageName,jdbcType=VARCHAR}
	    ,#{portaitCheckStatus,jdbcType=VARCHAR},#{portaitCheckPerson,jdbcType=VARCHAR},#{portaitCheckDate,jdbcType=TIMESTAMP}
        ,#{routeCheckStatus,jdbcType=VARCHAR},#{routeCheckPerson,jdbcType=VARCHAR},#{routeCheckDate,jdbcType=TIMESTAMP},#{routeCheckRemark,jdbcType=VARCHAR}
        ,#{delFlag,jdbcType=TINYINT},#{createBy,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateBy,jdbcType=VARCHAR}
        ,#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.signpatientrecord.SignPatientRecord" useGeneratedKeys="true">
        insert into sign_patient_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="patientId != null">patient_id,</if>
                <if test="patientName != null">patient_name,</if>
                <if test="patientPhone != null">patient_phone,</if>
                <if test="cardNo != null">card_no,</if>
		        <if test="sex != null">sex,</if>
		        <if test="birthDate != null">birth_date,</if>
                <if test="signTime != null">sign_time,</if>
                <if test="hospitalAgencyId != null">hospital_agency_id,</if>
                <if test="hospitalAgencyName != null">hospital_agency_name,</if>
                <if test="campusAgencyId != null">campus_agency_id,</if>
                <if test="campusAgencyName != null">campus_agency_name,</if>
                <if test="departmentId != null">department_id,</if>
                <if test="departmentName != null">department_name,</if>
                <if test="wardId != null">ward_id,</if>
                <if test="wardName != null">ward_name,</if>
	        	<if test="patientVisitRecordId != null">patient_visit_record_id,</if>
                <if test="visitSerialNumber != null">visit_serial_number,</if>
                <if test="visitMethod != null">visit_method,</if>
	        	<if test="inHospitalNumber != null">in_hospital_number,</if>
                <if test="signDiagnosis != null">sign_diagnosis,</if>
                <if test="reviewDiagnosis != null">review_diagnosis,</if>
                <if test="serviceStatus != null">service_status,</if>
                <if test="signStatus != null">sign_status,</if>
                <if test="intentionalSource != null">intentional_source,</if>
                <if test="intentionalTime != null">intentional_time,</if>
                <if test="billingDoctorId != null">billing_doctor_id,</if>
                <if test="billingDoctorName != null">billing_doctor_name,</if>
                <if test="price != null">price,</if>
                <if test="paymentStatus != null">payment_status,</if>
		        <if test="healthManageId != null">health_manage_id,</if>
		        <if test="healthManageName != null">health_manage_name,</if>
		        <if test="portaitCheckStatus != null">portait_check_status,</if>
		        <if test="portaitCheckPerson != null">portait_check_person,</if>
		        <if test="portaitCheckDate != null">portait_check_date,</if>
		        <if test="routeCheckStatus != null">route_check_status,</if>
		        <if test="routeCheckPerson != null">route_check_person,</if>
		        <if test="routeCheckDate != null">route_check_date,</if>
		        <if test="routeCheckRemark != null">route_check_remark,</if>
                <if test="delFlag != null">del_flag,</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="id != null">#{id,jdbcType=BIGINT},</if>
                <if test="patientId != null">#{patientId,jdbcType=BIGINT},</if>
                <if test="patientName != null">#{patientName,jdbcType=VARCHAR},</if>
                <if test="patientPhone != null">#{patientPhone,jdbcType=VARCHAR},</if>
                <if test="cardNo != null">#{cardNo,jdbcType=VARCHAR},</if>
		        <if test="sex != null">#{sex,jdbcType=VARCHAR},</if>
		        <if test="birthDate != null">#{birthDate,jdbcType=DATE},</if>
                <if test="signTime != null">#{signTime,jdbcType=TIMESTAMP},</if>
                <if test="hospitalAgencyId != null">#{hospitalAgencyId,jdbcType=BIGINT},</if>
                <if test="hospitalAgencyName != null">#{hospitalAgencyName,jdbcType=VARCHAR},</if>
                <if test="campusAgencyId != null">#{campusAgencyId,jdbcType=BIGINT},</if>
                <if test="campusAgencyName != null">#{campusAgencyName,jdbcType=VARCHAR},</if>
                <if test="departmentId != null">#{departmentId,jdbcType=BIGINT},</if>
                <if test="departmentName != null">#{departmentName,jdbcType=VARCHAR},</if>
                <if test="wardId != null">#{wardId,jdbcType=BIGINT},</if>
                <if test="wardName != null">#{wardName,jdbcType=VARCHAR},</if>
	        	<if test="patientVisitRecordId != null">#{patientVisitRecordId,jdbcType=BIGINT},</if>
                <if test="visitSerialNumber != null">#{visitSerialNumber,jdbcType=VARCHAR},</if>
                <if test="visitMethod != null">#{visitMethod,jdbcType=VARCHAR},</if>
	        	<if test="inHospitalNumber != null">#{inHospitalNumber,jdbcType=VARCHAR},</if>
                <if test="signDiagnosis != null">#{signDiagnosis,jdbcType=VARCHAR},</if>
                <if test="reviewDiagnosis != null">#{reviewDiagnosis,jdbcType=VARCHAR},</if>
                <if test="serviceStatus != null">#{serviceStatus,jdbcType=VARCHAR},</if>
                <if test="signStatus != null">#{signStatus,jdbcType=VARCHAR},</if>
                <if test="intentionalSource != null">#{intentionalSource,jdbcType=VARCHAR},</if>
                <if test="intentionalTime != null">#{intentionalTime,jdbcType=TIMESTAMP},</if>
                <if test="billingDoctorId != null">#{billingDoctorId,jdbcType=BIGINT},</if>
                <if test="billingDoctorName != null">#{billingDoctorName,jdbcType=VARCHAR},</if>
                <if test="price != null">#{price,jdbcType=DECIMAL},</if>
                <if test="paymentStatus != null">#{paymentStatus,jdbcType=VARCHAR},</if>
		        <if test="healthManageId != null">#{healthManageId,jdbcType=BIGINT},</if>
		        <if test="healthManageName != null">#{healthManageName,jdbcType=VARCHAR},</if>
		        <if test="portaitCheckStatus != null">#{portaitCheckStatus,jdbcType=VARCHAR},</if>
		        <if test="portaitCheckPerson != null">#{portaitCheckPerson,jdbcType=VARCHAR},</if>
		        <if test="portaitCheckDate != null">#{portaitCheckDate,jdbcType=TIMESTAMP},</if>
		        <if test="routeCheckStatus != null">#{routeCheckStatus,jdbcType=VARCHAR},</if>
		        <if test="routeCheckPerson != null">#{routeCheckPerson,jdbcType=VARCHAR},</if>
		        <if test="routeCheckDate != null">#{routeCheckDate,jdbcType=TIMESTAMP},</if>
		        <if test="routeCheckRemark != null">#{routeCheckRemark,jdbcType=VARCHAR},</if>
                <if test="delFlag != null">#{delFlag,jdbcType=TINYINT},</if>
                <if test="createBy != null">#{createBy,jdbcType=VARCHAR},</if>
                <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
                <if test="updateBy != null">#{updateBy,jdbcType=VARCHAR},</if>
                <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xinelu.manage.domain.signpatientrecord.SignPatientRecord">
        update sign_patient_record
        <set>
                <if test="patientId != null">
                    patient_id = #{patientId,jdbcType=BIGINT},
                </if>
                <if test="patientName != null">
                    patient_name = #{patientName,jdbcType=VARCHAR},
                </if>
                <if test="patientPhone != null">
                    patient_phone = #{patientPhone,jdbcType=VARCHAR},
                </if>
                <if test="cardNo != null">
                    card_no = #{cardNo,jdbcType=VARCHAR},
                </if>
		        <if test="sex != null">
			        sex = #{sex,jdbcType=VARCHAR},
		        </if>
		        <if test="birthDate != null">
			        birth_date = #{birthDate,jdbcType=DATE},
		        </if>
                <if test="signTime != null">
                    sign_time = #{signTime,jdbcType=TIMESTAMP},
                </if>
                <if test="hospitalAgencyId != null">
                    hospital_agency_id = #{hospitalAgencyId,jdbcType=BIGINT},
                </if>
                <if test="hospitalAgencyName != null">
                    hospital_agency_name = #{hospitalAgencyName,jdbcType=VARCHAR},
                </if>
                <if test="campusAgencyId != null">
                    campus_agency_id = #{campusAgencyId,jdbcType=BIGINT},
                </if>
                <if test="campusAgencyName != null">
                    campus_agency_name = #{campusAgencyName,jdbcType=VARCHAR},
                </if>
                <if test="departmentId != null">
                    department_id = #{departmentId,jdbcType=BIGINT},
                </if>
                <if test="departmentName != null">
                    department_name = #{departmentName,jdbcType=VARCHAR},
                </if>
                <if test="wardId != null">
                    ward_id = #{wardId,jdbcType=BIGINT},
                </if>
                <if test="wardName != null">
                    ward_name = #{wardName,jdbcType=VARCHAR},
                </if>
		        <if test="patientVisitRecordId != null">
			        patient_visit_record_id = #{patientVisitRecordId,jdbcType=BIGINT},
		        </if>
                <if test="visitSerialNumber != null">
                    visit_serial_number = #{visitSerialNumber,jdbcType=VARCHAR},
                </if>
                <if test="visitMethod != null">
                    visit_method = #{visitMethod,jdbcType=VARCHAR},
                </if>
		        <if test="inHospitalNumber != null">
			        in_hospital_number = #{inHospitalNumber,jdbcType=VARCHAR},
		        </if>
                <if test="signDiagnosis != null">
                    sign_diagnosis = #{signDiagnosis,jdbcType=VARCHAR},
                </if>
                <if test="reviewDiagnosis != null">
                    review_diagnosis = #{reviewDiagnosis,jdbcType=VARCHAR},
                </if>
                <if test="serviceStatus != null">
                    service_status = #{serviceStatus,jdbcType=VARCHAR},
                </if>
                <if test="signStatus != null">
                    sign_status = #{signStatus,jdbcType=VARCHAR},
                </if>
                <if test="intentionalSource != null">
                    intentional_source = #{intentionalSource,jdbcType=VARCHAR},
                </if>
                <if test="intentionalTime != null">
                    intentional_time = #{intentionalTime,jdbcType=TIMESTAMP},
                </if>
                <if test="billingDoctorId != null">
                    billing_doctor_id = #{billingDoctorId,jdbcType=BIGINT},
                </if>
                <if test="billingDoctorName != null">
                    billing_doctor_name = #{billingDoctorName,jdbcType=VARCHAR},
                </if>
                <if test="price != null">
                    price = #{price,jdbcType=DECIMAL},
                </if>
                <if test="paymentStatus != null">
                    payment_status = #{paymentStatus,jdbcType=VARCHAR},
                </if>
		        <if test="healthManageId != null">
			        health_manage_id = #{healthManageId,jdbcType=BIGINT},
		        </if>
		        <if test="healthManageName != null">
			        health_manage_name = #{healthManageName,jdbcType=VARCHAR},
		        </if>
		        <if test="portaitCheckStatus != null">
			        portait_check_status = #{portaitCheckStatus,jdbcType=VARCHAR},
		        </if>
		        <if test="portaitCheckPerson != null">
			        portait_check_person = #{portaitCheckPerson,jdbcType=VARCHAR},
		        </if>
		        <if test="portaitCheckDate != null">
			        portait_check_date = #{portaitCheckDate,jdbcType=TIMESTAMP},
		        </if>
		        <if test="portaitCheckRemark != null">
			        portait_check_remark = #{portaitCheckRemark,jdbcType=VARCHAR},
		        </if>
		        <if test="routeCheckStatus != null">
			        route_check_status = #{routeCheckStatus,jdbcType=VARCHAR},
		        </if>
		        <if test="routeCheckPerson != null">
			        route_check_person = #{routeCheckPerson,jdbcType=VARCHAR},
		        </if>
		        <if test="routeCheckDate != null">
			        route_check_date = #{routeCheckDate,jdbcType=TIMESTAMP},
		        </if>
		        <if test="routeCheckRemark != null">
			        route_check_remark = #{routeCheckRemark,jdbcType=VARCHAR},
		        </if>
                <if test="delFlag != null">
                    del_flag = #{delFlag,jdbcType=TINYINT},
                </if>
                <if test="createBy != null">
                    create_by = #{createBy,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="updateBy != null">
                    update_by = #{updateBy,jdbcType=VARCHAR},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xinelu.manage.domain.signpatientrecord.SignPatientRecord">
        update sign_patient_record
        set 
            patient_id =  #{patientId,jdbcType=BIGINT},
            patient_name =  #{patientName,jdbcType=VARCHAR},
            patient_phone =  #{patientPhone,jdbcType=VARCHAR},
            card_no =  #{cardNo,jdbcType=VARCHAR},
            sex =  #{sex,jdbcType=VARCHAR},
	    	birth_date =  #{birthDate,jdbcType=DATE},
            sign_time =  #{signTime,jdbcType=TIMESTAMP},
            hospital_agency_id =  #{hospitalAgencyId,jdbcType=BIGINT},
            hospital_agency_name =  #{hospitalAgencyName,jdbcType=VARCHAR},
            campus_agency_id =  #{campusAgencyId,jdbcType=BIGINT},
            campus_agency_name =  #{campusAgencyName,jdbcType=VARCHAR},
            department_id =  #{departmentId,jdbcType=BIGINT},
            department_name =  #{departmentName,jdbcType=VARCHAR},
            ward_id =  #{wardId,jdbcType=BIGINT},
            ward_name =  #{wardName,jdbcType=VARCHAR},
		    patient_visit_record_id = #{patientVisitRecordId,jdbcType=BIGINT},
            visit_serial_number =  #{visitSerialNumber,jdbcType=VARCHAR},
            visit_method =  #{visitMethod,jdbcType=VARCHAR},
		    in_hospital_number = #{inHospitalNumber,jdbcType=VARCHAR},
            sign_diagnosis =  #{signDiagnosis,jdbcType=VARCHAR},
            review_diagnosis =  #{reviewDiagnosis,jdbcType=VARCHAR},
            service_status =  #{serviceStatus,jdbcType=VARCHAR},
            sign_status =  #{signStatus,jdbcType=VARCHAR},
            intentional_source =  #{intentionalSource,jdbcType=VARCHAR},
            intentional_time =  #{intentionalTime,jdbcType=TIMESTAMP},
            billing_doctor_id =  #{billingDoctorId,jdbcType=BIGINT},
            billing_doctor_name =  #{billingDoctorName,jdbcType=VARCHAR},
            price =  #{price,jdbcType=DECIMAL},
            payment_status =  #{paymentStatus,jdbcType=VARCHAR},
		    health_manage_id =  #{healthManageId,jdbcType=BIGINT},
		    health_manage_name =  #{healthManageName,jdbcType=VARCHAR},
		    portait_check_status =  #{portaitCheckStatus,jdbcType=VARCHAR},
		    portait_check_person =  #{portaitCheckPerson,jdbcType=VARCHAR},
		    portait_check_date =  #{portaitCheckDate,jdbcType=TIMESTAMP},
		    route_check_status =  #{routeCheckStatus,jdbcType=VARCHAR},
		    route_check_person =  #{routeCheckPerson,jdbcType=VARCHAR},
		    route_check_date =  #{routeCheckDate,jdbcType=TIMESTAMP},
		    route_check_remark =  #{routeCheckRemark,jdbcType=VARCHAR},
            del_flag =  #{delFlag,jdbcType=TINYINT},
            create_by =  #{createBy,jdbcType=VARCHAR},
            create_time =  #{createTime,jdbcType=TIMESTAMP},
            update_by =  #{updateBy,jdbcType=VARCHAR},
            update_time =  #{updateTime,jdbcType=TIMESTAMP}
        where   id = #{id,jdbcType=BIGINT} 
    </update>
	<select id="selectList" parameterType="com.xinelu.manage.dto.signpatientrecord.SignPatientListDto" resultType="com.xinelu.manage.vo.signpatientrecord.SignPatientListVo">
		select
		patient.service_status,patient.sign_status,
		sign.id,sign.patient_id,sign.patient_name,
		sign.patient_phone,sign.card_no,sign.sex,sign.birth_date, sign.sign_time,
		sign.hospital_agency_id,sign.hospital_agency_name,
		sign.campus_agency_id, sign.campus_agency_name,
		sign.department_id, sign.department_name,
		sign.ward_id,sign.ward_name,
		sign.visit_serial_number,sign.visit_method,sign.in_hospital_number,sign.sign_diagnosis,sign.review_diagnosis,
		sign.service_status,sign.sign_status,sign.intentional_source,
		sign.intentional_time,sign.billing_doctor_name,sign.payment_status,sign.price,sign.health_manage_id, sign.health_manage_name,
		sign.route_check_status,sign.portait_check_status,
		p.service_package_id, p.package_name, p.service_end_time, p.package_term, p.package_term_unit
		from patient_info patient
		    left join sign_patient_record sign on patient.sign_patient_record_id = sign.id
		    left join sign_patient_package p on sign.id = p.sign_patient_record_id
		<where>
			patient.del_flag = 0 and sign.del_flag = 0
			<if test="serviceStatus != null">
				and patient.service_status = #{serviceStatus}
			</if>
			<if test="patientName != null">
				and sign.patient_name like concat('%', #{patientName}, '%')
			</if>
			<if test="visitSerialNumber != null">
				and sign.visit_serial_number like concat('%', #{visitSerialNumber}, '%')
			</if>
			<if test="patientPhone != null">
				and sign.patient_phone like concat('%', #{patientPhone}, '%')
			</if>
			<if test="intentionalTimeStart != null">
				and date_format(sign.intentional_time, '%y%m%d') >= date_format(#{intentionalTimeStart}, '%y%m%d')
			</if>
			<if test="intentionalTimeEnd != null">
				and date_format(sign.intentional_time, '%y%m%d')  &lt;= date_format(#{intentionalTimeEnd}, '%y%m%d')
			</if>
			<if test="intentionalSource != null">
				and sign.intentional_source = #{intentionalSource}
			</if>
			<if test="signTimeStart != null">
				and date_format(sign.sign_time, '%y%m%d') >= date_format(#{signTimeStart}, '%y%m%d')
			</if>
			<if test="signTimeEnd != null">
				and date_format(sign.sign_time, '%y%m%d') &lt;= date_format(#{signTimeEnd}, '%y%m%d')
			</if>
			<if test="hospitalAgencyId != null ">
				and sign.hospital_agency_id = #{hospitalAgencyId}
			</if>
			<if test="campusAgencyId != null ">
				and sign.campus_agency_id = #{campusAgencyId}
			</if>
			<if test="departmentId != null ">
				and sign.department_id = #{departmentId}
			</if>
			<if test="wardId != null ">
				and sign.ward_id = #{wardId}
			</if>
			<if test="visitMethod != null ">
				and sign.visit_method = #{visitMethod}
			</if>
			<if test="signStatus != null ">
				and sign.sign_status = #{signStatus}
			</if>
			<choose>
				<when test="routeCheckStatus != null and routeCheckStatus == 'UNAUDITED'.toString()">
					and (sign.route_check_status is null or sign.portait_check_status is null)
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'AGREE'.toString()">
					and sign.route_check_status = #{routeCheckStatus} and sign.portait_check_status = #{routeCheckStatus}
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'DISAGREE'.toString()">
					and (sign.route_check_status = #{routeCheckStatus} or sign.portait_check_status = #{routeCheckStatus})
				</when>
			</choose>
			<if test="mainDiagnosis != null  and mainDiagnosis != ''">
				and patient.main_diagnosis like concat('%', #{mainDiagnosis}, '%')
			</if>
			<if test="dischargeTimeStart != null ">
				and date_format(patient.discharge_time,'%y%m%d') &gt;= date_format(#{dischargeTimeStart},'%y%m%d')
			</if>
			<if test="dischargeTimeEnd != null ">
				and date_format(patient.discharge_time,'%y%m%d') &lt;= date_format(#{dischargeTimeEnd},'%y%m%d')
			</if>
			<if test="patientSource != null ">
				and patient.patient_source like concat('%', #{patientSource}, '%')
			</if>
			<if test="serviceEndTimeStart != null">
				and date_format(p.service_end_time, '%y%m%d') >= date_format(#{serviceEndTimeStart}, '%y%m%d')
			</if>
			<if test="serviceEndTimeEnd != null">
				and date_format(p.service_end_time, '%y%m%d') &lt;= date_format(#{serviceEndTimeEnd}, '%y%m%d')
			</if>
			<!-- 数据范围过滤 -->
			${params.dataScope}
		</where>
		order by sign.id desc
	</select>
	<select id="getByRecordId" parameterType="java.lang.Long" resultType="com.xinelu.manage.vo.signpatientrecord.SignPatientInfoVo">
		select
		sign.id,sign.patient_id,sign.patient_name,
		sign.patient_phone,sign.card_no,sign.sex, sign.birth_date,sign.sign_time,
		sign.hospital_agency_id, sign.hospital_agency_name,
		sign.campus_agency_id, sign.campus_agency_name,
		sign.department_id, sign.department_name,
		sign.ward_id, sign.ward_name,
		sign.visit_serial_number, sign.visit_method,sign.in_hospital_number,sign.sign_diagnosis,sign.review_diagnosis,
		sign.service_status,sign.sign_status,sign.payment_status,sign.price,sign.health_manage_id,sign.health_manage_name,
		p.service_package_id, p.package_name, p.package_payment_status, p.package_price, p.service_start_time, p.service_end_time,
		p.package_term, p.package_term_unit, route.id as signPatientManageRouteId, route.route_id, route.route_name
		from sign_patient_record sign
	    left join sign_patient_package p on p.sign_patient_record_id = sign.id
	    left join sign_patient_manage_route route on route.sign_patient_record_id = sign.id
		<where>
			sign.del_flag = 0 and sign.id = #{id}
			and route.task_create_type = 'MANUAL_MATCHE'
		</where>
		LIMIT 1
	</select>

	<select id="getByPatient" parameterType="java.lang.Long" resultType="com.xinelu.manage.vo.signpatientrecord.SignPatientRecordVo">
		select
		sign.id,sign.patient_id,sign.patient_name,sign.sign_time,
		sign.service_status, p.package_name
		from sign_patient_record sign
		left join sign_patient_package p on p.sign_patient_record_id = sign.id
		<where>
			sign.del_flag = 0 and sign.patient_id = #{patientId} and sign.sign_status != 'SEPARATE_SIGN'
		</where>
 		order by sign.sign_time desc
	</select>
</mapper>
