<?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.mobile.mapper.appletpersoncenter.AppletPersonCenterMapper">

    <resultMap id="HealthRecordResult" type="com.xinelu.mobile.dto.appletpersoncenter.HealthRecordDTO">
        <result property="id" column="id"/>
        <result property="hospitalAgencyName" column="hospital_agency_name"/>
        <result property="departmentName" column="department_name"/>
        <result property="visitDate" column="visit_date"/>
    </resultMap>

    <resultMap id="HealthRecordInfo" type="com.xinelu.mobile.dto.appletpersoncenter.HealthRecordInfoDTO">
        <result property="id" column="id"/>
        <result property="age" column="age"/>
        <result property="birthDate" column="birth_date"/>
        <result property="patientName" column="patient_name"/>
        <result property="patientPhone" column="patient_phone"/>
        <result property="familyMemberPhone" column="family_member_phone"/>
        <result property="cardNo" column="card_no"/>
        <result property="signStatus" column="sign_status"/>
        <result property="attendingPhysicianName" column="attending_physician_name"/>
        <result property="hospitalAgencyName" column="hospital_agency_name"/>
        <result property="visitDate" column="visit_date"/>
        <result property="departmentName" column="department_name"/>
    </resultMap>


    <select id="getHealthRecordListByResidentId" parameterType="long" resultMap="HealthRecordResult">
        select id, hospital_agency_name, department_name, visit_date
        from patient_info
        where resident_id = #{residentId}
    </select>

    <select id="getHealthRecordInfoById" parameterType="long" resultMap="HealthRecordInfo">
        select id,
               TIMESTAMPDIFF(YEAR, birth_date, CURDATE()) AS age,
               birth_date,
               patient_name,
               patient_phone,
               family_member_phone,
               card_no,
               sign_status,
               sign_time,
               attending_physician_name,
               hospital_agency_name,
               visit_date,
               department_name
        from patient_info
        where id = #{id}
    </select>
</mapper>