package thyyxxk.webserver.dao.his.zhuyuanyisheng;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.login.UserInfo;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
import java.math.BigDecimal;
import java.util.List;
/**
*
* 描述: 会诊申请
*
*
* @author xc
* @date 2021-05-07 11:01
*/
@Mapper
public interface HuiZhenShenQingDao {
/**
* 获取科室
*
* @return 返回科室
*/
@Select("select code,rtrim(name) name from zy_ward_code with(nolock) where " +
" (py_code like #{pyCode} or name like #{pyCode} or code like #{pyCode})")
List getZdUnitCode(String pyCode);
/**
* 获取会诊类别
*
* @return 返回科室
*/
@Select("select code,rtrim(name) name from ysh_zd_hz_level with(nolock)")
List getYshZdHzLevel();
/**
* 插入会诊申请
*
* @param param 要插入的实体类
*/
@Insert("INSERT INTO ysh_hz_record " +
"(inpatient_no, admiss_times, req_times, req_comment, input_id, input_date, req_date, dept_code, ward_code," +
" req_dept1, status_flag, hz_type, hz_level, hz_zd, hz_md, act_order_no , hz_doctor1,hz_id ) " +
"VALUES ( #{inpatientNo}, #{admissTimes}, #{reqTimes}, #{reqComment}, #{inputId}, #{inputDate}, #{reqDate}, " +
"#{deptCode}, #{wardCode}, #{reqDept1}, '1', #{hzType}, #{hzLevel}, #{hzZd}, #{hzMd}, #{actOrderNo} ,#{hzDoctor1},#{hzDoctor1})")
void chaRuHuiZhenShenQing(YshHzRecord param);
/**
* 插入一条医嘱
*
* @param param 参数
*/
@Insert("INSERT INTO yz_act_order ( order_code, order_name, frequ_code, infant_flag, order_time, physician, start_time, " +
"act_order_no, inpatient_no, admiss_times, drug_flag, enter_oper, enter_time, status_flag, self_buy, pay_self, " +
"serial, group_no, doctor_flag, exec_unit, dept_code, ward_code, reg_flag,confirm_time,signer,emergency_flag,yb_self_flag) " +
"VALUES ( #{orderCode}, #{orderName}, 'ONCE', '0', #{inputDate}, #{inputId}, #{inputDate}, " +
"#{actOrderNo}, #{inpatientNo}, #{admissTimes}, 'o', #{inputId}, #{inputDate}, '2', '0', '0', '00', '00', '1'," +
" #{reqDept1}, #{deptCode}, #{wardCode}, '',#{inputDate}, #{inputId},#{emergencyFlag},#{ybSelfFlag})")
void chaRuYiZhu(YshHzRecord param);
/**
* 获取到最大的 req_times 每次插入都要加一
*
* @param inpatientNo 住院号
* @param admissTimes 住院次数
* @return 返回最大的 req_times
*/
@Select("select isnull(max ( req_times ),0) from ysh_hz_record with(nolock) where inpatient_no = #{inpatientNo} and admiss_times =#{admissTimes} ")
Integer getMaxReqTimes(@Param("inpatientNo") String inpatientNo,
@Param("admissTimes") int admissTimes);
@Select("select code, emp_tit_code " +
"from a_employee_mi " +
"where dept_code = #{deptCode} " +
" and isnull(del_flag, 0) = 0 " +
" and emp_tit_code in ('001', '002', '003')")
List obtainDepartmentDoctor(String deptCode);
@Select("")
List chaKanHuiZhenShenQing(@Param("inpatientNo") String inpatientNo,
@Param("admissTimes") int admissTimes,
@Param("actOrderNo") BigDecimal actOrderNo);
/**
* 删除 会诊申请
*
* @param inpatientNo 住院号
* @param admissTimes 住院次数
* @param reqTimes 申请次数
*/
@Delete("delete ysh_hz_record where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and req_times = #{reqTimes}")
void shanChuShenQing(@Param("inpatientNo") String inpatientNo,
@Param("admissTimes") int admissTimes,
@Param("reqTimes") int reqTimes);
/**
* 删除医嘱
*
* @param actOrderNo 医嘱号
*/
@Delete("DELETE FROM yz_act_order WHERE act_order_no = #{actOrderNo} ")
void shanChuYiZhu(@Param("actOrderNo") BigDecimal actOrderNo);
@Select(" select code,name, " +
" dept_name = (select rtrim(name) from zd_unit_code where zd_unit_code.code = dept_code)," +
" emp_tit_name = (select rtrim(name) from zd_emp_title where zd_emp_title.code = emp_tit_code) " +
" from a_employee_mi with(nolock) where dept_code = #{deptCode} and emp_tit_code = #{hzType} and isnull(del_flag,0)=0")
List huiZhenYiSheng(@Param("deptCode") String deptCode,
@Param("hzType") String hzType);
@Select("select code, " +
" rtrim(name) as name, " +
" dept_code, " +
" dept_name = (select rtrim(name) from zd_unit_code where zd_unit_code.code = dept_code), " +
" emp_tit_code= right(emp_tit_code, 1), " +
" empTitName = (select rtrim(name) from zd_emp_title where zd_emp_title.code = emp_tit_code), " +
" code_rs " +
"from a_employee_mi " +
"where isnull(del_flag " +
" , 0) = 0 " +
" and emp_tit_code in ('001', '002', '003')" +
" and nullif(yb_code,'') is not null " +
" and (name like #{name} " +
" or py_code like #{name} " +
" or d_code like #{name})")
List getConsultingDoctorInfo(@Param("name") String name);
@Select("select data_element " +
"from emr_data_element " +
"where pat_no = #{patNo} " +
" and times = #{times}")
JSONObject getPatientEmrDiag(String patNo,
Integer times);
}