<?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.TemplateInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.TemplateInfo">
        <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="name" property="name" />
        <result column="doctor_id" property="doctorId" />
        <result column="hospital_dept_id" property="hospitalDeptId" />
        <result column="hospital_id" property="hospitalId" />
        <result column="sex" property="sex" />
        <result column="type" property="type" />
        <result column="preview" property="preview" />
        <result column="data_json" property="dataJson" />
        <result column="remark" property="remark" />
    </resultMap>
    <!--根据医生id查询该医生保存的病历模板 -->
	<select id="findByDoctorIdTemplate" resultType="com.diagbot.dto.TemplateInfoDTO">
	SELECT
		id AS id,
		gmt_create AS gmtCreate,
		creator AS creator,
		NAME AS modeName,
		doctor_id AS doctorId,
		hospital_id AS hospitalId,
		hospital_dept_id As hospitalDeptId,
		TYPE AS modeType,
		preview AS preview,
		data_json AS dataJson,
		remark AS remark
	FROM
		icss_template_info WHERE is_deleted = "N"
		<if test="id != null and id != ''">
			and id = #{id}
		</if>
		<if test="name != null and name != ''">
			and name = #{name}
		</if>
	    <if test="hospitalDeptId != null and hospitalDeptId != ''">
			and hospital_dept_id = #{hospitalDeptId}
		</if>
		<if test="doctorId != null and doctorId != ''">
			and doctor_id = #{doctorId}
		</if>
		<if test="hospitalId != null and hospitalId != ''">
			and hospital_id = #{hospitalId}
		</if>
		<if test="type != null and type != ''">
			and type = #{type}
		</if>
		ORDER BY gmt_create DESC

	</select>
</mapper>
