<?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.emr.dao.emrCodeType.Emr_Code_TypeMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrCodeType.Emr_Code_Type" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="type_flag" property="typeFlag" jdbcType="NVARCHAR" />
    <result column="type_name" property="typeName" jdbcType="NVARCHAR" />
    <result column="patient_id" property="patientId" jdbcType="NVARCHAR" />
    <result column="assort_id" property="assortId" jdbcType="NVARCHAR" />
    <result column="scan_page" property="scanPage" jdbcType="NVARCHAR" />
    <result column="effective" property="effective" jdbcType="INTEGER" />
    <result column="creater" property="creater" jdbcType="NVARCHAR" />
    <result column="create_time" property="createTime" jdbcType="NCHAR" />
    <result column="updater" property="updater" jdbcType="NVARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="NCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, type_flag, type_name, patient_id, assort_id, scan_page, effective, creater, create_time, 
    updater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_code_type
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_code_type
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.emrCodeType.Emr_Code_Type" >
    insert into emr_code_type (type_flag, type_name,
      patient_id, assort_id, scan_page, 
      effective, creater, create_time, 
      updater, update_time)
    values (#{typeFlag,jdbcType=NVARCHAR}, #{typeName,jdbcType=NVARCHAR},
      #{patientId,jdbcType=NVARCHAR}, #{assortId,jdbcType=NVARCHAR}, #{scanPage,jdbcType=NVARCHAR}, 
      #{effective,jdbcType=INTEGER}, #{creater,jdbcType=NVARCHAR}, #{createTime,jdbcType=NCHAR}, 
      #{updater,jdbcType=NVARCHAR}, #{updateTime,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrCodeType.Emr_Code_Type" >
    insert into emr_code_type
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="typeFlag != null" >
        type_flag,
      </if>
      <if test="typeName != null" >
        type_name,
      </if>
      <if test="patientId != null" >
        patient_id,
      </if>
      <if test="assortId != null" >
        assort_id,
      </if>
      <if test="scanPage != null" >
        scan_page,
      </if>
      <if test="effective != null" >
        effective,
      </if>
      <if test="creater != null" >
        creater,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updater != null" >
        updater,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="typeFlag != null" >
        #{typeFlag,jdbcType=NVARCHAR},
      </if>
      <if test="typeName != null" >
        #{typeName,jdbcType=NVARCHAR},
      </if>
      <if test="patientId != null" >
        #{patientId,jdbcType=NVARCHAR},
      </if>
      <if test="assortId != null" >
        #{assortId,jdbcType=NVARCHAR},
      </if>
      <if test="scanPage != null" >
        #{scanPage,jdbcType=NVARCHAR},
      </if>
      <if test="effective != null" >
        #{effective,jdbcType=INTEGER},
      </if>
      <if test="creater != null" >
        #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=NCHAR},
      </if>
      <if test="updater != null" >
        #{updater,jdbcType=NVARCHAR},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=NCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrCodeType.Emr_Code_Type" >
    update emr_code_type
    <set >
      <if test="typeFlag != null" >
        type_flag = #{typeFlag,jdbcType=NVARCHAR},
      </if>
      <if test="typeName != null" >
        type_name = #{typeName,jdbcType=NVARCHAR},
      </if>
      <if test="patientId != null" >
        patient_id = #{patientId,jdbcType=NVARCHAR},
      </if>
      <if test="assortId != null" >
        assort_id = #{assortId,jdbcType=NVARCHAR},
      </if>
      <if test="scanPage != null" >
        scan_page = #{scanPage,jdbcType=NVARCHAR},
      </if>
      <if test="effective != null" >
        effective = #{effective,jdbcType=INTEGER},
      </if>
      <if test="creater != null" >
        creater = #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=NCHAR},
      </if>
      <if test="updater != null" >
        updater = #{updater,jdbcType=NVARCHAR},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=NCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.emr.entity.emrCodeType.Emr_Code_Type" >
    update emr_code_type
    set type_flag = #{typeFlag,jdbcType=NVARCHAR},
      type_name = #{typeName,jdbcType=NVARCHAR},
      patient_id = #{patientId,jdbcType=NVARCHAR},
      assort_id = #{assortId,jdbcType=NVARCHAR},
      scan_page = #{scanPage,jdbcType=NVARCHAR},
      effective = #{effective,jdbcType=INTEGER},
      creater = #{creater,jdbcType=NVARCHAR},
      create_time = #{createTime,jdbcType=NCHAR},
      updater = #{updater,jdbcType=NVARCHAR},
      update_time = #{updateTime,jdbcType=NCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--根据patientId查询全部-->
  <select id="selectAllByPatientId" resultMap="BaseResultMap">
      SELECT
          id,
          type_flag,
          type_name,
          effective
      FROM
          emr_code_type
  </select>
  <!--验证标志或名称是否重复-->
  <select id="checkFlagAndNameIsExist" resultType="com.emr.entity.emrCodeType.Emr_Code_Type">
     SELECT
        id
     FROM
        emr_code_type
     WHERE
        effective = 1
        <if test="typeFlag != '' and typeFlag != null">
          AND type_flag = #{typeFlag}
        </if>
        <if test="typeName != '' and typeName != null">
          AND type_name = #{typeName}
        </if>
  </select>
</mapper>