<?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_DiagMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrCode.T_Diag" >
    <result column="patient_id" property="patientId" jdbcType="VARCHAR" />
    <result column="diag_no" property="diagNo" jdbcType="SMALLINT" />
    <result column="diag_code" property="diagCode" jdbcType="VARCHAR" />
    <result column="diag_name" property="diagName" jdbcType="VARCHAR" />
    <result column="diag_type" property="diagType" jdbcType="VARCHAR" />
    <result column="dis_thing" property="disThing" jdbcType="VARCHAR" />
    <result column="pathology_cut" property="pathologyCut" jdbcType="VARCHAR" />
    <result column="X_ray" property="xRay" 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" />
    <result column="singl" property="singl" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="pat_adm_condition" property="patAdmCondition" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="VARCHAR" />
    <result column="vid" property="vid" jdbcType="VARCHAR" />
    <result column="INHospStat" property="inhospstat" jdbcType="VARCHAR" />
  </resultMap>
  <insert id="insert" parameterType="com.emr.entity.emrCode.T_Diag" >
    insert into t_diag (patient_id, diag_no, diag_code, 
      diag_name, diag_type, dis_thing, 
      pathology_cut, X_ray, oper_code, 
      oper_name, oper_date, singl, 
      create_date, pat_adm_condition, pid, 
      vid, INHospStat)
    values (#{patientId,jdbcType=VARCHAR}, #{diagNo,jdbcType=SMALLINT}, #{diagCode,jdbcType=VARCHAR}, 
      #{diagName,jdbcType=VARCHAR}, #{diagType,jdbcType=VARCHAR}, #{disThing,jdbcType=VARCHAR}, 
      #{pathologyCut,jdbcType=VARCHAR}, #{xRay,jdbcType=VARCHAR}, #{operCode,jdbcType=VARCHAR}, 
      #{operName,jdbcType=VARCHAR}, #{operDate,jdbcType=TIMESTAMP}, #{singl,jdbcType=VARCHAR}, 
      #{createDate,jdbcType=TIMESTAMP}, #{patAdmCondition,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, 
      #{vid,jdbcType=VARCHAR}, #{inhospstat,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrCode.T_Diag" >
    insert into t_diag
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        patient_id,
      </if>
      <if test="diagNo != null" >
        diag_no,
      </if>
      <if test="diagCode != null" >
        diag_code,
      </if>
      <if test="diagName != null" >
        diag_name,
      </if>
      <if test="diagType != null" >
        diag_type,
      </if>
      <if test="disThing != null" >
        dis_thing,
      </if>
      <if test="pathologyCut != null" >
        pathology_cut,
      </if>
      <if test="xRay != null" >
        X_ray,
      </if>
      <if test="operCode != null" >
        oper_code,
      </if>
      <if test="operName != null" >
        oper_name,
      </if>
      <if test="operDate != null" >
        oper_date,
      </if>
      <if test="singl != null" >
        singl,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="patAdmCondition != null" >
        pat_adm_condition,
      </if>
      <if test="pid != null" >
        pid,
      </if>
      <if test="vid != null" >
        vid,
      </if>
      <if test="inhospstat != null" >
        INHospStat,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        #{patientId,jdbcType=VARCHAR},
      </if>
      <if test="diagNo != null" >
        #{diagNo,jdbcType=SMALLINT},
      </if>
      <if test="diagCode != null" >
        #{diagCode,jdbcType=VARCHAR},
      </if>
      <if test="diagName != null" >
        #{diagName,jdbcType=VARCHAR},
      </if>
      <if test="diagType != null" >
        #{diagType,jdbcType=VARCHAR},
      </if>
      <if test="disThing != null" >
        #{disThing,jdbcType=VARCHAR},
      </if>
      <if test="pathologyCut != null" >
        #{pathologyCut,jdbcType=VARCHAR},
      </if>
      <if test="xRay != null" >
        #{xRay,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>
      <if test="singl != null" >
        #{singl,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="patAdmCondition != null" >
        #{patAdmCondition,jdbcType=VARCHAR},
      </if>
      <if test="pid != null" >
        #{pid,jdbcType=VARCHAR},
      </if>
      <if test="vid != null" >
        #{vid,jdbcType=VARCHAR},
      </if>
      <if test="inhospstat != null" >
        #{inhospstat,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrCode.T_Diag" >
    update t_diag
    <set >
      <if test="diagNo != null" >
        diag_no = #{diagNo,jdbcType=SMALLINT},
      </if>
      <if test="diagCode != null" >
        diag_code = #{diagCode,jdbcType=VARCHAR},
      </if>
      <if test="diagName != null" >
        diag_name = #{diagName,jdbcType=VARCHAR},
      </if>
      <if test="diagType != null" >
        diag_type = #{diagType,jdbcType=VARCHAR},
      </if>
      <if test="disThing != null" >
        dis_thing = #{disThing,jdbcType=VARCHAR},
      </if>
      <if test="pathologyCut != null" >
        pathology_cut = #{pathologyCut,jdbcType=VARCHAR},
      </if>
      <if test="xRay != null" >
        X_ray = #{xRay,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>
      <if test="singl != null" >
        singl = #{singl,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="patAdmCondition != null" >
        pat_adm_condition = #{patAdmCondition,jdbcType=VARCHAR},
      </if>
      <if test="pid != null" >
        pid = #{pid,jdbcType=VARCHAR},
      </if>
      <if test="vid != null" >
        vid = #{vid,jdbcType=VARCHAR},
      </if>
      <if test="inhospstat != null" >
        INHospStat = #{inhospstat,jdbcType=VARCHAR}
      </if>
    </set>
    where patient_id = #{patientId,jdbcType=VARCHAR} and  diag_no = #{currentDiagNo,jdbcType=SMALLINT}
  </update>
  <!--根据patientId和诊断序号查询对象-->
  <select id="selectAllByPatientId" resultMap="BaseResultMap">
    SELECT
        diag_no,
        diag_code,
        diag_name,
        diag_type,
        dis_thing,
        pathology_cut,
        X_ray,
        oper_code,
        oper_name,
        oper_date,
        INHospStat
    FROM
        t_diag
    WHERE
        patient_id = #{patientId}
        <if test="diagNo != null">
          AND diag_no = ${diagNo}
        </if>
    ORDER BY
        diag_no
  </select>
  <!--删除-->
  <delete id="deleteDiagByPatientIdAndDiagNo" >
    delete from t_diag
    where patient_id = #{patientId} and diag_no in (${diagNos})
  </delete>
  <!--批量添加-->
  <insert id="SimpleInsert" parameterType="java.util.List">
      insert into t_diag(
        patient_id, diag_no, diag_code,
        diag_name, diag_type, dis_thing,
        pathology_cut, X_ray, oper_code,
        oper_name, oper_date, singl,
        create_date, pat_adm_condition, pid,
        vid, INHospStat
      )
      values
      <foreach collection="list" item="items" separator=",">
        (
          #{items.patientId,jdbcType=VARCHAR}, #{items.diagNo,jdbcType=SMALLINT}, #{items.diagCode,jdbcType=VARCHAR},
          #{items.diagName,jdbcType=VARCHAR}, #{items.diagType,jdbcType=VARCHAR}, #{items.disThing,jdbcType=VARCHAR},
          #{items.pathologyCut,jdbcType=VARCHAR}, #{items.xRay,jdbcType=VARCHAR}, #{items.operCode,jdbcType=VARCHAR},
          #{items.operName,jdbcType=VARCHAR}, #{items.operDate,jdbcType=TIMESTAMP}, #{items.singl,jdbcType=VARCHAR},
          #{items.createDate,jdbcType=TIMESTAMP}, #{items.patAdmCondition,jdbcType=VARCHAR}, #{items.pid,jdbcType=VARCHAR},
          #{items.vid,jdbcType=VARCHAR}, #{items.inhospstat,jdbcType=VARCHAR}
        )
      </foreach>
  </insert>

  <!--批量更新-->
  <update id="SimpleUpdate" parameterType="java.util.List">
    <foreach collection="list" item="items" separator=";">
        update t_diag
        <set>
          <if test="items.diagCode != null" >
            diag_code = #{items.diagCode,jdbcType=VARCHAR},
          </if>
          <if test="items.diagName != null" >
            diag_name = #{items.diagName,jdbcType=VARCHAR},
          </if>
          <if test="items.diagType != null" >
            diag_type = #{items.diagType,jdbcType=VARCHAR},
          </if>
          <if test="items.disThing != null" >
            dis_thing = #{items.disThing,jdbcType=VARCHAR},
          </if>
          <if test="items.pathologyCut != null" >
            pathology_cut = #{items.pathologyCut,jdbcType=VARCHAR},
          </if>
          <if test="items.xRay != null" >
            X_ray = #{items.xRay,jdbcType=VARCHAR},
          </if>
          <if test="items.operCode != null" >
            oper_code = #{items.operCode,jdbcType=VARCHAR},
          </if>
          <if test="items.operName != null" >
            oper_name = #{items.operName,jdbcType=VARCHAR},
          </if>
          <if test="items.operDate != null" >
            oper_date = #{items.operDate,jdbcType=TIMESTAMP},
          </if>
          <if test="items.singl != null" >
            singl = #{items.singl,jdbcType=VARCHAR},
          </if>
          <if test="items.createDate != null" >
            create_date = #{items.createDate,jdbcType=TIMESTAMP},
          </if>
          <if test="items.patAdmCondition != null" >
            pat_adm_condition = #{items.patAdmCondition,jdbcType=VARCHAR},
          </if>
          <if test="items.pid != null" >
            pid = #{items.pid,jdbcType=VARCHAR},
          </if>
          <if test="items.vid != null" >
            vid = #{items.vid,jdbcType=VARCHAR},
          </if>
          INHospStat = #{items.inhospstat,jdbcType=VARCHAR}
        </set>
        where patient_id = #{items.patientId} and diag_no = #{items.diagNo}
    </foreach>
  </update>
</mapper>