<?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_OperateMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrCode.T_Operate" >
    <result column="patient_id" property="patientId" jdbcType="VARCHAR" />
    <result column="operate_no" property="operateNo" jdbcType="SMALLINT" />
    <result column="operate_code" property="operateCode" jdbcType="VARCHAR" />
    <result column="operate_name" property="operateName" jdbcType="NVARCHAR" />
    <result column="operate_date" property="operateDate" jdbcType="TIMESTAMP" />
    <result column="operator" property="operator" jdbcType="VARCHAR" />
    <result column="assistant_1" property="assistant1" jdbcType="VARCHAR" />
    <result column="assistant_2" property="assistant2" jdbcType="VARCHAR" />
    <result column="assistant_3" property="assistant3" jdbcType="VARCHAR" />
    <result column="anaesthesia_type" property="anaesthesiaType" jdbcType="VARCHAR" />
    <result column="cut" property="cut" jdbcType="VARCHAR" />
    <result column="anaesthesia_name" property="anaesthesiaName" 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="operate_class" property="operateClass" jdbcType="VARCHAR" />
    <result column="OPERATION_SCALE" property="operationScale" jdbcType="VARCHAR" />
    <result column="ChosSurg" property="chossurg" jdbcType="NCHAR" />
    <result column="OperDegr" property="operdegr" jdbcType="NCHAR" />
  </resultMap>
  <insert id="insert" parameterType="com.emr.entity.emrCode.T_Operate" >
    insert into t_operate (patient_id, operate_no, operate_code, 
      operate_name, operate_date, operator, 
      assistant_1, assistant_2, assistant_3, 
      anaesthesia_type, cut, anaesthesia_name, 
      oper_code, oper_name, oper_date, 
      operate_class, OPERATION_SCALE, ChosSurg, 
      OperDegr)
    values (#{patientId,jdbcType=VARCHAR}, #{operateNo,jdbcType=SMALLINT}, #{operateCode,jdbcType=VARCHAR}, 
      #{operateName,jdbcType=NVARCHAR}, #{operateDate,jdbcType=TIMESTAMP}, #{operator,jdbcType=VARCHAR}, 
      #{assistant1,jdbcType=VARCHAR}, #{assistant2,jdbcType=VARCHAR}, #{assistant3,jdbcType=VARCHAR}, 
      #{anaesthesiaType,jdbcType=VARCHAR}, #{cut,jdbcType=VARCHAR}, #{anaesthesiaName,jdbcType=VARCHAR}, 
      #{operCode,jdbcType=VARCHAR}, #{operName,jdbcType=VARCHAR}, #{operDate,jdbcType=TIMESTAMP}, 
      #{operateClass,jdbcType=VARCHAR}, #{operationScale,jdbcType=VARCHAR}, #{chossurg,jdbcType=NCHAR}, 
      #{operdegr,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrCode.T_Operate" >
    insert into t_operate
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        patient_id,
      </if>
      <if test="operateNo != null" >
        operate_no,
      </if>
      <if test="operateCode != null" >
        operate_code,
      </if>
      <if test="operateName != null" >
        operate_name,
      </if>
      <if test="operateDate != null" >
        operate_date,
      </if>
      <if test="operator != null" >
        operator,
      </if>
      <if test="assistant1 != null" >
        assistant_1,
      </if>
      <if test="assistant2 != null" >
        assistant_2,
      </if>
      <if test="assistant3 != null" >
        assistant_3,
      </if>
      <if test="anaesthesiaType != null" >
        anaesthesia_type,
      </if>
      <if test="cut != null" >
        cut,
      </if>
      <if test="anaesthesiaName != null" >
        anaesthesia_name,
      </if>
      <if test="operCode != null" >
        oper_code,
      </if>
      <if test="operName != null" >
        oper_name,
      </if>
      <if test="operDate != null" >
        oper_date,
      </if>
      <if test="operateClass != null" >
        operate_class,
      </if>
      <if test="operationScale != null" >
        OPERATION_SCALE,
      </if>
      <if test="chossurg != null" >
        ChosSurg,
      </if>
      <if test="operdegr != null" >
        OperDegr,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="patientId != null" >
        #{patientId,jdbcType=VARCHAR},
      </if>
      <if test="operateNo != null" >
        #{operateNo,jdbcType=SMALLINT},
      </if>
      <if test="operateCode != null" >
        #{operateCode,jdbcType=VARCHAR},
      </if>
      <if test="operateName != null" >
        #{operateName,jdbcType=NVARCHAR},
      </if>
      <if test="operateDate != null" >
        #{operateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null" >
        #{operator,jdbcType=VARCHAR},
      </if>
      <if test="assistant1 != null" >
        #{assistant1,jdbcType=VARCHAR},
      </if>
      <if test="assistant2 != null" >
        #{assistant2,jdbcType=VARCHAR},
      </if>
      <if test="assistant3 != null" >
        #{assistant3,jdbcType=VARCHAR},
      </if>
      <if test="anaesthesiaType != null" >
        #{anaesthesiaType,jdbcType=VARCHAR},
      </if>
      <if test="cut != null" >
        #{cut,jdbcType=VARCHAR},
      </if>
      <if test="anaesthesiaName != null" >
        #{anaesthesiaName,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="operateClass != null" >
        #{operateClass,jdbcType=VARCHAR},
      </if>
      <if test="operationScale != null" >
        #{operationScale,jdbcType=VARCHAR},
      </if>
      <if test="chossurg != null" >
        #{chossurg,jdbcType=NCHAR},
      </if>
      <if test="operdegr != null" >
        #{operdegr,jdbcType=NCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrCode.T_Operate" >
    update t_operate
    <set >
      <if test="operateNo != null" >
        operate_no = #{operateNo,jdbcType=SMALLINT},
      </if>
      <if test="operateCode != null" >
        operate_code = #{operateCode,jdbcType=VARCHAR},
      </if>
      <if test="operateName != null" >
        operate_name = #{operateName,jdbcType=NVARCHAR},
      </if>
      <if test="operateDate != null" >
        operate_date = #{operateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null" >
        operator = #{operator,jdbcType=VARCHAR},
      </if>
      <if test="assistant1 != null" >
        assistant_1 = #{assistant1,jdbcType=VARCHAR},
      </if>
      <if test="assistant2 != null" >
        assistant_2 = #{assistant2,jdbcType=VARCHAR},
      </if>
      <if test="assistant3 != null" >
        assistant_3 = #{assistant3,jdbcType=VARCHAR},
      </if>
      <if test="anaesthesiaType != null" >
        anaesthesia_type = #{anaesthesiaType,jdbcType=VARCHAR},
      </if>
      <if test="cut != null" >
        cut = #{cut,jdbcType=VARCHAR},
      </if>
      <if test="anaesthesiaName != null" >
        anaesthesia_name = #{anaesthesiaName,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="operateClass != null" >
        operate_class = #{operateClass,jdbcType=VARCHAR},
      </if>
      <if test="operationScale != null" >
        OPERATION_SCALE = #{operationScale,jdbcType=VARCHAR},
      </if>
      <if test="chossurg != null" >
        ChosSurg = #{chossurg,jdbcType=NCHAR},
      </if>
      <if test="operdegr != null" >
        OperDegr = #{operdegr,jdbcType=NCHAR},
      </if>
    </set>
    where patient_id = #{patientId,jdbcType=VARCHAR} and  operate_no = #{currentOperateNo,jdbcType=SMALLINT}
  </update>
  <!--根据patientId和手术序号查询手术信息对象-->
  <select id="selectAllByPatientId" resultMap="BaseResultMap">
      SELECT
          operate_no,
          operate_code,
          operate_name,
          operate_date,
          operator,
          assistant_1,
          assistant_2,
          assistant_3,
          anaesthesia_type,
          cut,
          anaesthesia_name,
          oper_code,
          oper_name,
          oper_date,
          operate_class,
          ChosSurg
      FROM
          t_operate
      WHERE
          patient_id = #{patientId}
          <if test="operateNo != null">
              AND operate_no = ${operateNo}
          </if>
      ORDER BY
          operate_no
  </select>
  <!--删除-->
  <delete id="deleteOperCodeByPatientIdAndOperNo" >
    delete from t_operate
    where patient_id = #{patientId} and operate_no in(${operateNo})
  </delete>

  <!--批量添加-->
  <insert id="SimpleInsert" parameterType="java.util.List">
    insert into t_operate(
      patient_id, operate_no, operate_code,
      operate_name, operate_date, operator,
      assistant_1, assistant_2, assistant_3,
      anaesthesia_type, cut, anaesthesia_name,
      oper_code, oper_name, oper_date,
      operate_class, OPERATION_SCALE, ChosSurg,
      OperDegr
    )
    values
    <foreach collection="list" item="items" separator=",">
      (
        #{items.patientId,jdbcType=VARCHAR}, #{items.operateNo,jdbcType=SMALLINT}, #{items.operateCode,jdbcType=VARCHAR},
        #{items.operateName,jdbcType=NVARCHAR}, #{items.operateDate,jdbcType=TIMESTAMP}, #{items.operator,jdbcType=VARCHAR},
        #{items.assistant1,jdbcType=VARCHAR}, #{items.assistant2,jdbcType=VARCHAR}, #{items.assistant3,jdbcType=VARCHAR},
        #{items.anaesthesiaType,jdbcType=VARCHAR}, #{items.cut,jdbcType=VARCHAR}, #{items.anaesthesiaName,jdbcType=VARCHAR},
        #{items.operCode,jdbcType=VARCHAR}, #{items.operName,jdbcType=VARCHAR}, #{items.operDate,jdbcType=TIMESTAMP},
        #{items.operateClass,jdbcType=VARCHAR}, #{items.operationScale,jdbcType=VARCHAR}, #{items.chossurg,jdbcType=NCHAR},
        #{items.operdegr,jdbcType=NCHAR}
      )
    </foreach>
  </insert>

  <!--批量更新-->
  <update id="SimpleUpdate" parameterType="java.util.List">
    <foreach collection="list" item="items" separator=";">
      update t_operate
      <set>
        <if test="items.operateCode != null" >
          operate_code = #{items.operateCode,jdbcType=VARCHAR},
        </if>
        <if test="items.operateName != null" >
          operate_name = #{items.operateName,jdbcType=NVARCHAR},
        </if>
        <if test="items.operateDate != null" >
          operate_date = #{items.operateDate,jdbcType=TIMESTAMP},
        </if>
          operator = #{items.operator,jdbcType=VARCHAR},
          assistant_1 = #{items.assistant1,jdbcType=VARCHAR},
          assistant_2 = #{items.assistant2,jdbcType=VARCHAR},
          anaesthesia_type = #{items.anaesthesiaType,jdbcType=VARCHAR},
          cut = #{items.cut,jdbcType=VARCHAR},
          anaesthesia_name = #{items.anaesthesiaName,jdbcType=VARCHAR},
          operate_class = #{items.operateClass,jdbcType=VARCHAR},
          ChosSurg = #{items.chossurg,jdbcType=NCHAR},
      </set>
      where patient_id = #{items.patientId} and operate_no = #{items.operateNo}
    </foreach>
  </update>
</mapper>