<?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.patientinfo.PatientAllInfoViewMapper">

    <resultMap type="PatientAllInfoView" id="PatientAllInfoViewResult">
            <result property="patientId" column="patient_id"/>
            <result property="patientName" column="patient_name"/>
            <result property="patientPhone" column="patient_phone"/>
            <result property="familyMemberPhone" column="family_member_phone"/>
            <result property="birthDate" column="birth_date"/>
            <result property="cardNo" column="card_no"/>
            <result property="sex" column="sex"/>
            <result property="address" column="address"/>
            <result property="patientType" column="patient_type"/>
            <result property="patientVisitRecordId" column="patient_visit_record_id"/>
            <result property="visitMethod" column="visit_method"/>
            <result property="visitDate" column="visit_date"/>
	        <result property="hospitalAgencyId" column="hospital_agency_id"/>
            <result property="hospitalAgencyName" column="hospital_agency_name"/>
            <result property="campusAgencyName" column="campus_agency_name"/>
            <result property="departmentName" column="department_name"/>
            <result property="wardName" column="ward_name"/>
            <result property="attendingPhysicianName" column="attending_physician_name"/>
            <result property="mainDiagnosis" column="main_diagnosis"/>
            <result property="admissionTime" column="admission_time"/>
            <result property="dischargeTime" column="discharge_time"/>
            <result property="hospitalizationDays" column="hospitalization_days"/>
            <result property="inHospitalInfo" column="in_hospital_info"/>
            <result property="outHospitalInfo" column="out_hospital_info"/>
            <result property="visitSerialNumber" column="visit_serial_number"/>
            <result property="inHospitalNumber" column="in_hospital_number"/>
            <result property="responsibleNurse" column="responsible_nurse"/>
            <result property="surgicalName" column="surgical_name"/>
            <result property="surgicalRecord" column="surgical_record"/>
            <result property="signPatientRecordId" column="sign_patient_record_id"/>
            <result property="paymentStatus" column="payment_status"/>
            <result property="healthManageName" column="health_manage_name"/>
            <result property="serviceStatus" column="service_status"/>
            <result property="signStatus" column="sign_status"/>
            <result property="billingDoctorName" column="billing_doctor_name"/>
            <result property="signTime" column="sign_time"/>
            <result property="packageName" column="package_name"/>
            <result property="packagePaymentStatus" column="package_payment_status"/>
            <result property="packagePrice" column="package_price"/>
            <result property="serviceStartTime" column="service_start_time"/>
            <result property="serviceEndTime" column="service_end_time"/>
            <result property="packageTerm" column="package_term"/>
            <result property="packageTermUnit" column="package_term_unit"/>
    </resultMap>

    <sql id="selectPatientAllInfoViewVo">
        select patient_id, patient_name, patient_phone, family_member_phone, birth_date, card_no, sex, address, patient_type, patient_visit_record_id, visit_method, visit_date, hospital_agency_id, hospital_agency_name, campus_agency_name, department_name, ward_name, attending_physician_name, main_diagnosis, admission_time, discharge_time, hospitalization_days, in_hospital_info, out_hospital_info, visit_serial_number, in_hospital_number, responsible_nurse, surgical_name, surgical_record, sign_patient_record_id, payment_status, health_manage_name, service_status, sign_status, billing_doctor_name, sign_time, package_name, package_payment_status, package_price, service_start_time, service_end_time, package_term, package_term_unit from patient_all_info_view
    </sql>

    <select id="selectPatientAllInfoViewList" parameterType="PatientAllInfoView" resultMap="PatientAllInfoViewResult">
	    <include refid="selectPatientAllInfoViewVo" />
	    <where>
		    <if test="patientId != null ">
			    and patient_id = #{patientId}
		    </if>
		    <if test="patientVisitRecordId != null ">
			    and patient_visit_record_id = #{patientVisitRecordId}
		    </if>
		    <if test="signPatientRecordId != null ">
			    and sign_patient_record_id = #{signPatientRecordId}
		    </if>
		    <if test="hospitalAgencyId != null ">
			    and hospital_agency_id = #{hospitalAgencyId}
		    </if>
	    </where>
    </select>

	<select id="selectPatientAllInfoViewByPatientId" parameterType="Long" resultMap="PatientAllInfoViewResult">
		<include refid="selectPatientAllInfoViewVo" />
		where patient_id = #{patientId}
	</select>

    <select id="selectPatientAllInfoListViewByPatientId"
            resultType="com.xinelu.manage.domain.patientinfo.PatientAllInfoViewUppercase">
        select paiv.patient_id               PATIENTID,
               paiv.patient_name             PATIENTNAME,
               paiv.patient_phone            PATIENTPHONE,
               paiv.family_member_phone      FAMILYMEMBERPHONE,
               paiv.birth_date               BIRTHDATE,
               paiv.card_no                  CARDNO,
               paiv.sex                      SEX,
               paiv.address                  ADDRESS,
               paiv.patient_type             PATIENTTYPE,
               paiv.patient_visit_record_id  PATIENTVISITRECORDID,
               paiv.visit_method             VISITMETHOD,
               paiv.visit_date               VISITDATE,
               paiv.hospital_agency_name     HOSPITALAGENCYNAME,
               paiv.campus_agency_name       CAMPUSAGENCYNAME,
               paiv.department_name          DEPARTMENTNAME,
               paiv.ward_name                WARDNAME,
               paiv.attending_physician_name ATTENDINGPHYSICIANNAME,
               paiv.main_diagnosis           MAINDIAGNOSIS,
               paiv.admission_time           ADMISSIONTIME,
               paiv.discharge_time           DISCHARGETIME,
               paiv.hospitalization_days     HOSPITALIZATIONDAYS,
               paiv.in_hospital_info         INHOSPITALINFO,
               paiv.out_hospital_info        OUTHOSPITALINFO,
               paiv.visit_serial_number      VISITSERIALNUMBER,
               paiv.in_hospital_number       INHOSPITALNUMBER,
               paiv.responsible_nurse        RESPONSIBLENURSE,
               paiv.surgical_name            SURGICALNAME,
               paiv.surgical_record          SURGICALRECORD,
               paiv.sign_patient_record_id   SIGNPATIENTRECORDID,
               paiv.payment_status           PAYMENTSTATUS,
               paiv.health_manage_name       HEALTHMANAGENAME,
               paiv.service_status           SERVICESTATUS,
               paiv.sign_status              SIGNSTATUS,
               paiv.billing_doctor_name      BILLINGDOCTORNAME,
               paiv.sign_time                SIGNTIME,
               paiv.package_name             PACKAGENAME,
               paiv.package_payment_status   PACKAGEPAYMENTSTATUS,
               paiv.package_price            PACKAGEPRICE,
               paiv.service_start_time       SERVICESTARTTIME,
               paiv.service_end_time         SERVICEENDTIME,
               paiv.package_term             PACKAGETERM,
               paiv.package_term_unit        PACKAGETERMUNIT
        from patient_all_info_view paiv
                 left join patient_info pi ON pi.id = paiv.patient_id
        where paiv.patient_id = #{patientId}
        Order BY pi.update_time
    </select>
</mapper>