<?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="org.diagbot.nlp.dao.mapper.InfoMapper">
	<!-- 映射定义列-->
	<resultMap type="org.diagbot.nlp.dao.model.Info" id="infoMap">
		<id property="id" column="id"/>
		<result property="rdn" column="rdn"/>
		<result property="sex" column="sex"/>
		<result property="age" column="age"/>
		<result property="resourceType" column="resource_type"/>
		<result property="deptCode" column="dept_code"/>
		<result property="deptName" column="dept_name"/>
		<result property="checkLabel" column="check_label"/>
		<result property="symptom" column="symptom"/>
		<result property="diag" column="diag"/>
		<result property="finalDiag" column="final_diag"/>
		<result property="chief" column="chief"/>
		<result property="present" column="present"/>
		<result property="vital" column="vital"/>
		<result property="lis" column="lis"/>
		<result property="pacs" column="pacs"/>
		<result property="past" column="past"/>
		<result property="family" column="family"/>
		<result property="person" column="person"/>
		<result property="allergic" column="allergic"/>
		<result property="dodate" column="dodate"/>
		<result property="treat" column="treat"/>
	</resultMap>

	<!-- 映射定义列-->
	<resultMap type="org.diagbot.nlp.dao.model.wrapper.InfoWrapper" id="infoWrapperMap">
		<id property="id" column="id"/>
		<result property="rdn" column="rdn"/>
		<result property="sex" column="sex"/>
		<result property="age" column="age"/>
		<result property="resourceType" column="resource_type"/>
		<result property="deptCode" column="dept_code"/>
		<result property="deptName" column="dept_name"/>
		<result property="checkLabel" column="check_label"/>
		<result property="symptom" column="symptom"/>
		<result property="diag" column="diag"/>
		<result property="finalDiag" column="final_diag"/>
		<result property="chief" column="chief"/>
		<result property="present" column="present"/>
		<result property="vital" column="vital"/>
		<result property="lis" column="lis"/>
		<result property="pacs" column="pacs"/>
		<result property="past" column="past"/>
		<result property="family" column="family"/>
		<result property="person" column="person"/>
		<result property="allergic" column="allergic"/>
		<result property="dodate" column="dodate"/>
		<result property="treat" column="treat"/>
	</resultMap>

	<!-- 通用查询结果列-->
	<sql id="Base_Column_List">
		 t.id,	 t.pk_dcpv as rdn,	 t.sex,	 t.age,	 t.resource_type, t.dept_code, t.dept_name, t.check_label, t.symptom, t.diag, t.final_diag, t.chief, t.present, t.vital, t.lis, t.pacs, t.past, t.family, t.person, t.allergic, t.dodate, t.treat
	</sql>

	<!-- 查询（根据主键ID查询） -->
	<select id="selectByPrimaryKey" resultMap="infoMap" parameterType="java.lang.Integer">
		 SELECT
		 <include refid="Base_Column_List" />
		 FROM doc_info t
		 WHERE t.id = #{id}
	</select>

	<!-- 查询（根据主键ID查询） -->
	<select id="selectWrapperByPrimaryKey" resultMap="infoWrapperMap" parameterType="java.lang.Integer">
		 SELECT
		 <include refid="Base_Column_List" />
		 FROM doc_info t
		 WHERE t.id = #{id}
	</select>

	<!-- 依据Map查询条件返回结果集-->
	<select id="selectList" resultMap="infoMap" parameterType="java.util.Map">
		SELECT 
		<include refid="Base_Column_List"/>
		FROM doc_info t WHERE 1=1
		<if test="id != null and id != ''">
				 and t.id = #{id}
		</if>
		<if test="rdn != null and rdn != ''">
				 and t.rdn = #{rdn}
		</if>
		<if test="sex != null and sex != ''">
				 and t.sex = #{sex}
		</if>
		<if test="age != null and age != ''">
				 and t.age = #{age}
		</if>
		<if test="precode != null and precode != ''">
				 and t.precode = #{precode}
		</if>
		<if test="checkLabel != null and checkLabel != ''">
			and t.check_label = #{checkLabel}
		</if>
		<if test="diag != null and diag != ''">
				 and t.diag = #{diag}
		</if>
		<if test="preDiag != null and preDiag != ''">
				 and t.pre_diag = #{preDiag}
		</if>
		<if test="resourceType != null and resourceType != ''">
			and t.resource_type = #{resourceType}
		</if>
	</select> 

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectListWrapper" resultMap="infoWrapperMap" parameterType="java.util.Map">
		SELECT 
		<include refid="Base_Column_List"/>
		FROM doc_info t WHERE 1=1 
		<if test="id != null and id != ''">
				 and t.id = #{id}
		</if>
		<if test="rdn != null and rdn != ''">
				 and t.rdn = #{rdn}
		</if>
		<if test="sex != null and sex != ''">
				 and t.sex = #{sex}
		</if>
		<if test="age != null and age != ''">
				 and t.age = #{age}
		</if>
		<if test="precode != null and precode != ''">
				 and t.precode = #{precode}
		</if>
		<if test="checkLabel != null and checkLabel != ''">
			and t.check_label = #{checkLabel}
		</if>
		<if test="diag != null and diag != ''">
				 and t.diag = #{diag}
		</if>
		<if test="preDiag != null and preDiag != ''">
				 and t.pre_diag = #{preDiag}
		</if>
		<if test="resourceType != null and resourceType != ''">
			and t.resource_type = #{resourceType}
		</if>
	</select>

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectFeatureList" resultMap="infoWrapperMap" parameterType="java.util.Map">
		SELECT
		id, pk_dcpv as rdn, sex, age, resource_type, check_label, symptom, diag, final_diag, present, vital, lis, pacs
		FROM doc_info t WHERE check_label = '1'
		<if test="resourceType != null and resourceType != ''">
			and t.resource_type = #{resourceType}
		</if>
		<if test="diag != null and diag != ''">
			and t.diag like concat('%', #{diag}, '%')
		</if>
		<if test="vital != null and vital != ''">
			and t.vital like concat('%', #{vital}, '%')
		</if>
	</select>

	<!-- 依据Map查询条件返回扩展属性结果集-->
	<select id="selectRdnList" resultMap="infoWrapperMap" parameterType="java.util.Map">
		SELECT
		id, pk_dcpv as rdn, sex, age, check_label
		FROM doc_info t WHERE check_label = '1' and resource_type = #{resourceType} and sex is not null and age is not null
		<if test="diag != null and diag != ''">
			and t.diag like concat('%', #{diag}, '%')
		</if>
		<if test="vital != null and vital != ''">
			and t.vital like concat('%', #{vital}, '%')
		</if>
	</select>

	<!--删除：根据主键ID删除-->
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		 DELETE FROM doc_info
		 WHERE id = #{id}
	</delete>

	<!-- 添加 -->
	<insert id="insert" parameterType="org.diagbot.nlp.dao.model.Info">
		 INSERT INTO doc_info
 		(id,rdn,sex,age,resource_type,check_label, precode,symptom,diag,pre_diag,final_diag,present)
		 VALUES 
 		(#{id},#{rdn},#{sex},#{age},#{resourceType},#{checkLabel},#{precode},#{symptom},#{diag},#{preDiag},#{finalDiag},#{present})
	</insert>

	<!-- 修 改-->
	<update id="updateByPrimaryKeySelective" parameterType="org.diagbot.nlp.dao.model.Info">
		 UPDATE doc_info
 		 <set> 
			<if test="diag != null">
				 diag = #{diag},
			</if>
 		 </set>
		 WHERE id = #{id}
	</update>

	<!-- 修 改-->
	<update id="updateByPrimaryKey" parameterType="org.diagbot.nlp.dao.model.Info">
		 UPDATE doc_info
		 SET 
			 rdn = #{rdn},
			 sex = #{sex},
			 age = #{age},
			 precode = #{precode},
			 diag = #{diag},
			 pre_diag = #{preDiag}
		 WHERE id = #{id}
	</update>
</mapper>