<?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.emrCode.T_Herb_DiagMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrCode.T_Herb_Diag" >
    <result column="patient_id" property="patientId" jdbcType="VARCHAR" />
    <result column="herb_no" property="herbNo" jdbcType="SMALLINT" />
    <result column="herb_code" property="herbCode" jdbcType="VARCHAR" />
    <result column="herb_name" property="herbName" jdbcType="VARCHAR" />
    <result column="herb_type" property="herbType" jdbcType="VARCHAR" />
    <result column="herb_thing" property="herbThing" jdbcType="VARCHAR" />
    <result column="oper_code" property="operCode" jdbcType="VARCHAR" />
    <result column="oper_name" property="operName" jdbcType="VARCHAR" />
    <result column="oper_date" property="operDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <insert id="insert" parameterType="com.emr.entity.emrCode.T_Herb_Diag" >
    insert into t_herb_diag (patient_id, herb_no, herb_code, 
      herb_name, herb_type, herb_thing, 
      oper_code, oper_name, oper_date
      )
    values (#{patientId,jdbcType=VARCHAR}, #{herbNo,jdbcType=SMALLINT}, #{herbCode,jdbcType=VARCHAR}, 
      #{herbName,jdbcType=VARCHAR}, #{herbType,jdbcType=VARCHAR}, #{herbThing,jdbcType=VARCHAR}, 
      #{operCode,jdbcType=VARCHAR}, #{operName,jdbcType=VARCHAR}, #{operDate,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrCode.T_Herb_Diag" >
    insert into t_herb_diag
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        patient_id,
      </if>
      <if test="herbNo != null" >
        herb_no,
      </if>
      <if test="herbCode != null" >
        herb_code,
      </if>
      <if test="herbName != null" >
        herb_name,
      </if>
      <if test="herbType != null" >
        herb_type,
      </if>
      <if test="herbThing != null" >
        herb_thing,
      </if>
      <if test="operCode != null" >
        oper_code,
      </if>
      <if test="operName != null" >
        oper_name,
      </if>
      <if test="operDate != null" >
        oper_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        #{patientId,jdbcType=VARCHAR},
      </if>
      <if test="herbNo != null" >
        #{herbNo,jdbcType=SMALLINT},
      </if>
      <if test="herbCode != null" >
        #{herbCode,jdbcType=VARCHAR},
      </if>
      <if test="herbName != null" >
        #{herbName,jdbcType=VARCHAR},
      </if>
      <if test="herbType != null" >
        #{herbType,jdbcType=VARCHAR},
      </if>
      <if test="herbThing != null" >
        #{herbThing,jdbcType=VARCHAR},
      </if>
      <if test="operCode != null" >
        #{operCode,jdbcType=VARCHAR},
      </if>
      <if test="operName != null" >
        #{operName,jdbcType=VARCHAR},
      </if>
      <if test="operDate != null" >
        #{operDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrCode.T_Herb_Diag" >
    update t_herb_diag
    <set >
      <if test="herbNo != null" >
        herb_no = #{herbNo,jdbcType=SMALLINT},
      </if>
      <if test="herbCode != null" >
        herb_code = #{herbCode,jdbcType=VARCHAR},
      </if>
      <if test="herbName != null" >
        herb_name = #{herbName,jdbcType=VARCHAR},
      </if>
      <if test="herbType != null" >
        herb_type = #{herbType,jdbcType=VARCHAR},
      </if>
      <if test="herbThing != null" >
        herb_thing = #{herbThing,jdbcType=VARCHAR},
      </if>
      <if test="operCode != null" >
        oper_code = #{operCode,jdbcType=VARCHAR},
      </if>
      <if test="operName != null" >
        oper_name = #{operName,jdbcType=VARCHAR},
      </if>
      <if test="operDate != null" >
        oper_date = #{operDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where patient_id = #{patientId,jdbcType=VARCHAR} and  herb_no = #{currentHerbDiagNo,jdbcType=SMALLINT}
  </update>
  <!--根据patientId和诊断序号查询对象-->
  <select id="selectAllByPatientId" resultMap="BaseResultMap">
    SELECT
        herb_no,
        herb_code,
        herb_name,
        herb_type,
        herb_thing,
        oper_code,
        oper_name,
        oper_date
    FROM
        t_herb_diag
    WHERE
        patient_id = #{patientId}
        <if test="herbNo != null">
          AND herb_no = ${herbNo}
        </if>
    ORDER BY
        herb_no
  </select>
  <!--删除-->
  <delete id="deleteHerbDiagByPatientIdAndHerbNo" >
    delete from t_herb_diag
    where patient_id = #{patientId} and herb_no = ${herbNo}
  </delete>
</mapper>