<?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.diagbot.mapper.InquiryInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.InquiryInfo">
        <id column="id" property="id" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
        <result column="hospital_id" property="hospitalId" />
        <result column="hospital_dept_id" property="hospitalDeptId" />
        <result column="doctor_id" property="doctorId" />
        <result column="patient_id" property="patientId" />
        <result column="inquiry_code" property="inquiryCode" />
        <result column="reg_visited_state" property="regVisitedState" />
        <result column="type" property="type" />
        <result column="diagnose" property="diagnose" />
        <result column="sign" property="sign" />
        <result column="data_json" property="dataJson" />
        <result column="remark" property="remark" />
    </resultMap>
    
    <select id="getPatientLast" parameterType="map" resultMap="BaseResultMap">
    	SELECT
		a.*
		FROM icss_inquiry_info a JOIN icss_inquiry_detail b 
		on a.id=b.inquiry_id
		where a.hospital_id=#{hospitalId} and a.patient_id=#{patientId}
		and a.sign=0 and b.type=3 and a.is_deleted='N' 
		and b.is_deleted='N' 
		group by a.id
		ORDER BY a.gmt_create desc
		limit 0,1
    </select>

</mapper>
