Browse Source

优化代码以及添加注释

xiaochan 3 years ago
parent
commit
1ed3a8e4ac

+ 0 - 6
src/main/java/thyyxxk/webserver/controller/zhuyuanyizheng/YizhuLuRuController.java

@@ -79,12 +79,6 @@ public class YizhuLuRuController {
         return server.huoQuGeiYaoFangShi(code);
     }
 
-    @GetMapping("/huoQuFuYiZhu")
-    public ResultVo<List<GetDropdownBox>> huoQuFuYiZhu(@RequestParam("patNo") String patNo,
-                                                       @RequestParam("times") Integer times) {
-        return server.huoQuFuYiZhu(patNo, times);
-    }
-
     @GetMapping("/huoQuZhiXinKeShi")
     public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
         return server.huoQuZhiXinKeShi(code);

+ 61 - 142
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -76,17 +76,17 @@ public interface YiZhuLuRuDao {
                                 @Param("admissTimes") Integer admissTimes,
                                 @Param("ledgerSn") Integer ledgerSn);
 
-    @Select("select rtrim(order_name) code, rtrim(order_name) name " +
+    @Select("select distinct rtrim(order_name) code, rtrim(order_name) name " +
             "from yz_act_order with (NOLOCK) " +
             "where inpatient_no = #{inpatientNo} " +
             "  and admiss_times = #{admissTimes} " +
-            "  and order_name like #{orderName}")
+            "  and (order_name like #{orderName} or order_code like #{orderName})")
     List<GetDropdownBox> huoQuYiZhuMingZi(@Param("inpatientNo") String inpatientNo,
                                           @Param("admissTimes") Integer admissTimes,
                                           @Param("orderName") String orderName);
 
     @Select("select     rtrim(frequ_code) code, " +
-            "    name = (select comm from yz_order_frequency where frequ_code = code) " +
+            "    name = (select rtrim(comm) from yz_order_frequency where frequ_code = code) " +
             "from yz_act_order with (NOLOCK) " +
             "where inpatient_no = #{patNo} " +
             "  and admiss_times = #{times} " +
@@ -110,10 +110,10 @@ public interface YiZhuLuRuDao {
             "       end_time, " +
             "       drug_specification, " +
             "       drug_quan, " +
-            "       drug_quan_name = (select name from yp_zd_unit where code = mini_unit)," +
+            "       drug_quan_name = (select name from yp_zd_unit with (NOLOCK) where code = mini_unit)," +
             "       supply_code, " +
             "       supply_code_name     = (select supply_name " +
-            "                               from yz_supply_type " +
+            "                               from yz_supply_type with (NOLOCK) " +
             "                               where yz_supply_type.supply_code = temp.supply_code)," +
             "       inpatient_no, " +
             "       admiss_times, " +
@@ -129,7 +129,7 @@ public interface YiZhuLuRuDao {
             "       self_buy, " +
             "       dose, " +
             "       dose_unit, " +
-            "       dose_unit_name       = (select name from yp_zd_unit where dose_unit = code)," +
+            "       dose_unit_name       = (select name from yp_zd_unit with (NOLOCK) where dose_unit = code)," +
             "       drug_occ, " +
             "       drug_volume, " +
             "       drug_vol_unit, " +
@@ -161,18 +161,17 @@ public interface YiZhuLuRuDao {
             "       refer_physician, " +
             "       consult_physician, " +
             "    /* 开这个医嘱的医生 */ " +
-            "       physician_name = (select  top(1) rtrim(name) from a_employee_mi where code = physician), " +
-            "       exec_unit_name = (select  top(1) rtrim(name) from zd_unit_code where code = exec_unit), " +
+            "       physician_name = (select  top(1) rtrim(name) from a_employee_mi with (NOLOCK) where code = physician), " +
+            "       exec_unit_name = (select  top(1) rtrim(name) from zd_unit_code with (NOLOCK) where code = exec_unit), " +
             "    /*管床医生*/ " +
-            "       refer_physician_name = (select rtrim(name) from a_employee_mi where code = refer_physician), " +
-            "       group_no_name = (select rtrim(group_name) from yp_zd_group_name where temp.group_no = group_no) " +
+            "       refer_physician_name = (select rtrim(name) from a_employee_mi with (NOLOCK) where code = refer_physician), " +
+            "       group_no_name = (select rtrim(group_name) from yp_zd_group_name with (NOLOCK) where temp.group_no = group_no) " +
             "from ( " +
             "         select top ${pageSize} * " +
             "         from (select row_number() over (order by act_order_no) rowIndex, * " +
             "               from yz_act_order a with (NOLOCK) " +
             "               where inpatient_no = #{patNo} " +
             "                 and admiss_times = #{times} " +
-            "                 and isnull(parent_no, '') = '' " +
             "<if test=\"orderName != null and orderName != '' \">" +
             " and order_name = #{orderName}" +
             "</if>" +
@@ -196,86 +195,10 @@ public interface YiZhuLuRuDao {
                                      @Param("orderName") String orderName);
 
 
-    @Select("select                     act_order_no, " +
-            "                           order_code, " +
-            "                           order_name, " +
-            "                           rtrim(frequ_code) frequ_code, " +
-            "                           instruction, " +
-            "                           discription, " +
-            "                           infant_flag, " +
-            "                           order_time, " +
-            "                           physician, " +
-            "                           start_time, " +
-            "                           end_time, " +
-            "                           drug_specification, " +
-            "                           drug_quan, " +
-            "    drug_quan_name       = (select name from yp_zd_unit where code = a.mini_unit), " +
-            "                           supply_code, " +
-            "    supply_code_name     = (select supply_name " +
-            "                            from yz_supply_type " +
-            "                            where yz_supply_type.supply_code = a.supply_code), " +
-            "                           inpatient_no, " +
-            "                           admiss_times, " +
-            "                           drug_flag, " +
-            "                           enter_oper, " +
-            "                           enter_time, " +
-            "                           mini_unit, " +
-            "                           drug_weight, " +
-            "                           drug_weight_unit, " +
-            "                           status_flag, " +
-            "                           status_time, " +
-            "                           parent_no, " +
-            "                           self_buy, " +
-            "                           dose, " +
-            "                           dose_unit, " +
-            "    dose_unit_name       = (select top (1) name from yp_zd_unit where dose_unit = yp_zd_unit.code), " +
-            "                           drug_occ, " +
-            "                           drug_volume, " +
-            "                           drug_vol_unit, " +
-            "                           exclu_back_time, " +
-            "                           exclu_act_order_no, " +
-            "                           pay_self, " +
-            "                           serial, " +
-            "                           group_no, " +
-            "                           signer, " +
-            "                           modifier, " +
-            "                           cl_code, " +
-            "                           doctor_flag, " +
-            "                           emergency_flag, " +
-            "    exclu_type='', " +
-            "    end_time_b=end_time, " +
-            "                           exec_unit, " +
-            "                           dept_code, " +
-            "                           ward_code, " +
-            "    new_flag='0', " +
-            "    order_no_pattern=0, " +
-            "    suprice_flag='', " +
-            "    self_flag            ='', " +
-            "    pack_size=0.0, " +
-            "    parent_no_c=           -1000, " +
-            "                           reg_flag, " +
-            "    parent_flag='', " +
-            "                           yb_self_flag, " +
-            "                           kf_flag, " +
-            "                           refer_physician, " +
-            "                           consult_physician, " +
-            "    /* 开这个医嘱的医生 */ " +
-            "    physician_name       = (select top (1) rtrim(name) from a_employee_mi where code = a.physician), " +
-            "    exec_unit_name       = (select top (1) rtrim(name) from zd_unit_code where code = a.exec_unit), " +
-            "    /*管床医生*/ " +
-            "    refer_physician_name = (select top (1) rtrim(name) from a_employee_mi where code = a.refer_physician), " +
-            "    group_no_name        = (select top (1) rtrim(group_name) from yp_zd_group_name where yp_zd_group_name.group_no = a.group_no) " +
-            "from yz_act_order a with (NOLOCK) " +
-            "where inpatient_no = #{patNo}   " +
-            "      and admiss_times = #{times}   " +
-            "      and isnull(parent_no, '') <> ''")
-    List<YzActOrder> ziYiZhu(@Param("patNo") String patNo,
-                             @Param("times") Integer times);
-
     @Select("<script>" +
             "select count(1) " +
             "from yz_act_order a with (NOLOCK) " +
-            "where inpatient_no = #{patNo} " +
+            "where  inpatient_no = #{patNo} " +
             "  and admiss_times = #{times} " +
             "  and isnull(parent_no, '') = '' " +
             "<if test=\"startTime != null and startTime != '' \"> " +
@@ -332,7 +255,7 @@ public interface YiZhuLuRuDao {
             "                yb_type, " +
             "                yb_flag_new," +
             "                father_flag, " +
-            "                manu_name=(select name from yp_zd_manufactory where code *= a.manu_code), " +
+            "                manu_name=(select name from yp_zd_manufactory with (NOLOCK) where code *= a.manu_code), " +
             "                stock_amount=a.stock_amount " +
             "FROM view_yp_zd_dict_base_yf a with (NOLOCK) " +
             "WHERE isnull(a.visible_flag_zy, '') <> '1' " +
@@ -377,15 +300,15 @@ public interface YiZhuLuRuDao {
 
     @Select("SELECT cast(rtrim(isnull(nullif(del_flag, ''), 0)) as int) del_flag, " +
             "       national_code national_code " +
-            "FROM yz_order_occurence a, " +
-            "     zd_charge_item b " +
+            "FROM yz_order_occurence a with (NOLOCK), " +
+            "     zd_charge_item b with (NOLOCK) " +
             "where a.order_code = #{code} " +
             "  and a.occ_code = b.code")
     XinZhenYzActOrder huoQuXiangMu(String code);
 
 
     @Select("select isnull(exclu_group_type, 0) " +
-            "from yz_order_item where order_code = #{code}")
+            "from yz_order_item with (NOLOCK) where order_code = #{code}")
     Integer shiFouPaiChiYiZhu(String code);
 
 
@@ -398,20 +321,20 @@ public interface YiZhuLuRuDao {
             "    weight,  " +
             "    /* 重量单位 */  " +
             "    weigh_unit,  " +
-            "    weigh_unit_name = (select name from yp_zd_unit where code = weigh_unit),  " +
+            "    weigh_unit_name = (select name from yp_zd_unit with (NOLOCK) where code = weigh_unit),  " +
             "    /*体积*/  " +
             "    volum,  " +
             "    /*体积单位*/  " +
             "    vol_unit,  " +
-            "    vol_unit_name   = (select name from yp_zd_unit where code = vol_unit),  " +
+            "    vol_unit_name   = (select name from yp_zd_unit with (NOLOCK) where code = vol_unit),  " +
             "    /*包装体积*/  " +
             "    pack_size,  " +
             "    /*包装单位*/  " +
             "    pack_unit,  " +
-            "    pack_unit_name  = (select name from yp_zd_unit where code = pack_unit),  " +
+            "    pack_unit_name  = (select name from yp_zd_unit with (NOLOCK) where code = pack_unit),  " +
             "    /*最小单位*/  " +
             "    mini_unit,  " +
-            "    mini_unit_name  = (select name from yp_zd_unit where code = mini_unit),  " +
+            "    mini_unit_name  = (select name from yp_zd_unit with (NOLOCK) where code = mini_unit),  " +
             "    /* 需要判断医生的权限 在 select doctor_xz_yp from a_employee_mi */  " +
             "    cast(isnull(NULLIF(yp_level, ''), 0) as int)  as yp_level, " +
             "    /*需要皮试*/  " +
@@ -421,46 +344,35 @@ public interface YiZhuLuRuDao {
             "   code as order_code,name as order_name ," +
             "   frequency as frequCode," +
             "   supply_type as supply_code " +
-            "from yp_zd_dict  " +
+            "from yp_zd_dict with (NOLOCK) " +
             "where  rtrim(code) + rtrim(serial) = #{code} " +
             "  and cast(isnull(NULLIF(del_flag, ''), 0) as int) = 0 ")
     YaoPinXinXi huoQuYaoPin(@Param("code") String code);
 
-    @Select("select cast(isnull(NULLIF(doctor_xz_yp, ''), 0) as int) from a_employee_mi where code = #{code}")
+    @Select("select cast(isnull(NULLIF(doctor_xz_yp, ''), 0) as int) from a_employee_mi with (NOLOCK) where code = #{code}")
     Integer huoQuYiShenDengJi(String code);
 
     @Select("select rtrim(supply_code) code,rtrim(supply_name) name " +
-            "from yz_supply_type " +
+            "from yz_supply_type with (NOLOCK) " +
             "where ps_flag in ('1', '0')")
     List<GetDropdownBox> piShiGeiYaoFangShi();
 
     @Select("select rtrim(code) code, rtrim(comm) name " +
-            "from yz_order_frequency " +
+            "from yz_order_frequency with (NOLOCK) " +
             "where (code like #{code} or comm like #{code})")
     List<GetDropdownBox> huoQuZhuYuanPinLv(String code);
 
 
     @Select("select rtrim(supply_code) code, rtrim(supply_name) name " +
-            "from yz_supply_type " +
+            "from yz_supply_type with (NOLOCK) " +
             "where (supply_code like #{code} or supply_name like #{code} or py_code like #{code} )")
     List<GetDropdownBox> huoQuGeiYaoFangShi(String code);
 
 
-    @Select("SELECT CONVERT(nvarchar(100), CAST(act_order_no AS decimal(11,0))) as code," +
-            "       rtrim(order_name) as name " +
-            "FROM yz_act_order " +
-            "WHERE (inpatient_no = #{patNo}) " +
-            "  AND (admiss_times = #{times}) " +
-            "  AND (isnull(parent_no, 0) = 0) " +
-            "  and status_flag <> '5' " +
-            "  and drug_flag = 'i'")
-    List<GetDropdownBox> huoQuFuYiZhu(@Param("patNo") String patNo,
-                                      @Param("times") Integer times);
-
     @Select("SELECT a.code code, " +
             "       a.name name " +
-            "FROM zd_unit_code a, " +
-            "     zd_dept_all b " +
+            "FROM zd_unit_code a with (NOLOCK), " +
+            "     zd_dept_all b with (NOLOCK) " +
             "where isnull(a.del_flag, '0') <> '1' " +
             "  and a.code = b.small_dept " +
             "  and (a.code like #{code} or a.name like #{code} or py_code like #{code}) " +
@@ -489,7 +401,7 @@ public interface YiZhuLuRuDao {
             "       cast(isnull(NULLIF(kjyw_flag, ''), 0) as int) as kjyw_flag," +
             "       cast(isnull(NULLIF(yp_level, ''), 0) as int)  as yp_level," +
             "       cast(isnull(NULLIF(del_flag, ''), 0) as int)  as del_flag  " +
-            "from yp_zd_dict " +
+            "from yp_zd_dict with (NOLOCK) " +
             "where rtrim(code) + rtrim(serial) in " +
             "<foreach collection='code' item='item' index='index' open='(' close=')' separator=','>" +
             "#{item}" +
@@ -504,9 +416,9 @@ public interface YiZhuLuRuDao {
             "       national_code, " +
             "       kjyw_flag = 0," +
             "       cast(rtrim(isnull(nullif(c.del_flag, ''), 0)) as int) del_flag " +
-            "from yz_order_item a, " +
-            "     yz_order_occurence b, " +
-            "     zd_charge_item c " +
+            "from yz_order_item a with (NOLOCK) , " +
+            "     yz_order_occurence b with (NOLOCK) , " +
+            "     zd_charge_item c with (NOLOCK)" +
             "where a.order_code in " +
             "<foreach collection='code' item='item' index='index' open='(' close=')' separator=','>" +
             "#{item}" +
@@ -522,7 +434,7 @@ public interface YiZhuLuRuDao {
             "       dept dept_code, " +
             "       zk_ward ward_code, " +
             "       refer_physician " +
-            "from zy_actpatient " +
+            "from zy_actpatient with (NOLOCK) " +
             "where inpatient_no = #{patNo} " +
             "  and admiss_times = #{times} ")
     XinZhenYiZhu huoQuHuanZheXinXi(@Param("patNo") String patNo,
@@ -563,7 +475,7 @@ public interface YiZhuLuRuDao {
             "                          ward_code /* 在院病人表中的 zk_ward*/, " +
             "                          reg_flag/* 0 */, " +
             "                          yb_self_flag/*医保自费标志*/,emergency_flag, " +
-            "                          kf_flag /*饭前饭后*/,parent_no, refer_physician/*患者的管床医生*/, confirm_time/*确认时间*/, signer/*确认人*/) " +
+            "                          kf_flag /*饭前饭后*/,parent_no, refer_physician/*患者的管床医生*/, confirm_time/*确认时间*/, signer/*确认人*/,end_time,modifier) " +
             "VALUES " +
             "<foreach collection='list' item='item' separator=','>" +
             "(#{item.orderCode}, #{item.orderName}, #{item.frequCode}, #{item.instruction}, #{item.discription}, #{infantFlag}, #{item.orderTime}, " +
@@ -625,7 +537,14 @@ public interface YiZhuLuRuDao {
             "<if test=\"item.parentNo == null \">" +
             "null," +
             "</if>" +
-            " #{referPhysician}, getdate(), #{inputCode})" +
+            " #{referPhysician}, getdate(), #{inputCode}," +
+            "<if test=\"item.endTime != null \">" +
+            "#{item.endTime},#{inputCode} " +
+            "</if>" +
+            "<if test=\"item.endTime == null\">" +
+            "null,null " +
+            "</if>" +
+            ")" +
             "</foreach>" +
             "</script>")
     void chaRuYiZhu(@Param("patNo") String patNo,
@@ -648,10 +567,10 @@ public interface YiZhuLuRuDao {
             "       input_date," +
             "       rtrim(input_type) input_type, " +
             "       sort_no," +
-            "       yiBeiShouCang = (select count(1) from yz_OrderPattern b where b.collect_code = a.pattern_code " +
+            "       yiBeiShouCang = (select count(1) from yz_OrderPattern b with (NOLOCK) where b.collect_code = a.pattern_code " +
             "                           and b.input_id = #{inputId})," +
             "       collect_code " +
-            "FROM yz_OrderPattern a " +
+            "FROM yz_OrderPattern a with (NOLOCK) " +
             "where 1=1 " +
             "<if test=\"code != null and code != '' \">" +
             "and (py_code like #{code} " +
@@ -683,7 +602,7 @@ public interface YiZhuLuRuDao {
 
     @Select("<script>" +
             "SELECT count(*) " +
-            "FROM yz_OrderPattern " +
+            "FROM yz_OrderPattern with (NOLOCK) " +
             "where 1=1 " +
             "<if test=\"code != null and code != '' \">" +
             "and (py_code like #{code} " +
@@ -717,17 +636,17 @@ public interface YiZhuLuRuDao {
             "                       rtrim(a.order_code) order_code, " +
             "                       a.frequ_code, " +
             "    frequ_code_name  = (select rtrim(comm) " +
-            "                        from yz_order_frequency " +
+            "                        from yz_order_frequency with (NOLOCK) " +
             "                        where yz_order_frequency.code = a.frequ_code), " +
             "                       a.drug_specification, " +
             "                       a.supply_code, " +
             "    supply_code_name = (select rtrim(supply_name) " +
-            "                        from yz_supply_type " +
+            "                        from yz_supply_type with (NOLOCK) " +
             "                        where yz_supply_type.supply_code = a.supply_code), " +
             "                       a.drug_quan, " +
             "                       a.instruction, " +
             "                       a.mini_unit, " +
-            "    mini_unit_name   = (select rtrim(name) from yp_zd_unit where code = mini_unit), " +
+            "    mini_unit_name   = (select rtrim(name) from yp_zd_unit with (NOLOCK) where code = mini_unit), " +
             "                       a.drug_weight, " +
             "                       a.drug_weight_unit, " +
             "                       a.parent_no, " +
@@ -735,7 +654,7 @@ public interface YiZhuLuRuDao {
             "                       a.drug_vol_unit, " +
             "                       a.dose, " +
             "                       a.dose_unit, " +
-            "    dose_unit_name   = (select rtrim(name) from yp_zd_unit where code = dose_unit), " +
+            "    dose_unit_name   = (select rtrim(name) from yp_zd_unit with (NOLOCK) where code = dose_unit), " +
             "                       a.exclu_act_order_no, " +
             "                       a.discription, " +
             "                       a.pattern_code, " +
@@ -748,9 +667,9 @@ public interface YiZhuLuRuDao {
             "    self_flag        ='', " +
             "    parent_flag='', " +
             "                       a.exec_unit, " +
-            "    exec_unit_name   = (select rtrim(name) from zd_unit_code where code = exec_unit) " +
-            "FROM yz_pattern_order a, " +
-            "     yz_order_item b " +
+            "    exec_unit_name   = (select rtrim(name) from zd_unit_code with (NOLOCK) where code = exec_unit) " +
+            "FROM yz_pattern_order a with (NOLOCK), " +
+            "     yz_order_item b with (NOLOCK) " +
             "WHERE a.pattern_code = #{code} " +
             "  and isnull(a.group_no, '00') = '00' " +
             "  and a.order_code = b.order_code " +
@@ -760,17 +679,17 @@ public interface YiZhuLuRuDao {
             "                       a.order_code, " +
             "                       a.frequ_code, " +
             "    frequ_code_name  = (select rtrim(comm) " +
-            "                        from yz_order_frequency " +
+            "                        from yz_order_frequency with (NOLOCK) " +
             "                        where yz_order_frequency.code = a.frequ_code), " +
             "                       a.drug_specification, " +
             "                       a.supply_code, " +
             "    supply_code_name = (select rtrim(supply_name) " +
-            "                        from yz_supply_type " +
+            "                        from yz_supply_type with (NOLOCK) " +
             "                        where yz_supply_type.supply_code = a.supply_code), " +
             "                       a.drug_quan, " +
             "                       a.instruction, " +
             "                       a.mini_unit, " +
-            "    mini_unit_name   = (select rtrim(name) from yp_zd_unit where code = mini_unit), " +
+            "    mini_unit_name   = (select rtrim(name) from yp_zd_unit with (NOLOCK) where code = mini_unit), " +
             "                       a.drug_weight, " +
             "                       a.drug_weight_unit, " +
             "                       a.parent_no, " +
@@ -778,7 +697,7 @@ public interface YiZhuLuRuDao {
             "                       a.drug_vol_unit, " +
             "                       a.dose, " +
             "                       a.dose_unit, " +
-            "    dose_unit_name   = (select rtrim(name) from yp_zd_unit where code = dose_unit), " +
+            "    dose_unit_name   = (select rtrim(name) from yp_zd_unit with (NOLOCK) where code = dose_unit), " +
             "                       a.exclu_act_order_no, " +
             "                       a.discription, " +
             "                       a.pattern_code, " +
@@ -791,9 +710,9 @@ public interface YiZhuLuRuDao {
             "    self_flag        =b.self_flag, " +
             "    parent_flag='', " +
             "                       a.exec_unit, " +
-            "    exec_unit_name   = (select rtrim(name) from zd_unit_code where code = exec_unit) " +
-            "FROM yz_pattern_order a, " +
-            "     view_yp_zd_dict_base_yf b " +
+            "    exec_unit_name   = (select rtrim(name) from zd_unit_code with (NOLOCK) where code = exec_unit) " +
+            "FROM yz_pattern_order a with (NOLOCK), " +
+            "     view_yp_zd_dict_base_yf b with (NOLOCK) " +
             "WHERE a.pattern_code = #{code} " +
             "  and a.group_no = b.group_no " +
             "  and a.order_code = b.code " +
@@ -804,7 +723,7 @@ public interface YiZhuLuRuDao {
 
     @Select("select pattern_code," +
             "       rtrim(input_type) input_type " +
-            "from yz_OrderPattern " +
+            "from yz_OrderPattern with (NOLOCK) " +
             "where pattern_name = #{patternName} " +
             "  and input_id = #{inputId}" +
             "  and input_type <> 4 ")
@@ -813,7 +732,7 @@ public interface YiZhuLuRuDao {
 
     @Select("select pattern_code," +
             "       rtrim(input_type) input_type " +
-            "from yz_OrderPattern " +
+            "from yz_OrderPattern with (NOLOCK) " +
             "where pattern_name = #{patternName} " +
             "and input_type not in ('3','4') ")
     yzOrderPattern gongGongMuBan(@Param("patternName") String patternName);
@@ -897,7 +816,7 @@ public interface YiZhuLuRuDao {
 
 
     @Select("select * " +
-            "from yz_OrderPattern " +
+            "from yz_OrderPattern with (NOLOCK) " +
             "where pattern_code = #{code}")
     yzOrderPattern huoQuMuBanXinXi(@Param("code") String code);
 
@@ -923,7 +842,7 @@ public interface YiZhuLuRuDao {
     void shanChuMuBan(@Param("patternCode") String patternCode);
 
     @Select("select collect_code " +
-            "from yz_OrderPattern " +
+            "from yz_OrderPattern with (NOLOCK) " +
             "where input_id = #{inputId} " +
             "  and collect_code = #{collectCode} ")
     String chongFuShouCang(@Param("inputId") String inputId,

+ 124 - 29
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -1,6 +1,5 @@
 package thyyxxk.webserver.service.zhuyuanyisheng;
 
-import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
@@ -46,6 +45,12 @@ public class YiZhuLuRuServer {
         this.publicServer = publicServer;
     }
 
+    /**
+     * 获取患者列表
+     *
+     * @param wardCode 根据病区来进行搜索
+     * @return 返回患者信息
+     */
     public ResultVo<List<ZyActpatient>> huoQuHuanZheLieBiao(String wardCode) {
         List<ZyActpatient> list = dao.huoQuHuanZheLieBiao(wardCode);
         if (ListUtil.isBlank(list)) {
@@ -55,6 +60,13 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(list);
     }
 
+    /**
+     * 获取患者的具体信息
+     * 同时要计算一些数据信息
+     *
+     * @param inpatientNo 住院号
+     * @return 返回
+     */
     public ResultVo<PatientTemp> huoQuHuanZheXinXi(String inpatientNo) {
         ResultVo<Patient> resPpatient = patientService.getPatientInfo(inpatientNo);
         if (resPpatient.getCode() != 200) {
@@ -79,8 +91,15 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(patient);
     }
 
+    /**
+     * 获取医嘱的名称 这里为什么不用 医嘱的code和医嘱号呢,是因为药品编码和项目编码有些一样而医嘱号,又每次只能查询一个
+     *
+     * @param inpatientNo 住院号
+     * @param admissTimes 住院次数
+     * @param orderName   前端搜索的医嘱名称
+     * @return 返回医嘱名称去重了
+     */
     public ResultVo<List<GetDropdownBox>> huoQuYiZhuMingCheng(String inpatientNo, Integer admissTimes, String orderName) {
-        log.info("查询这个患者医嘱名字住院号:{},住院次数:{},名称:{}", inpatientNo, admissTimes, orderName);
         return ResultVoUtil.success(dao.huoQuYiZhuMingZi(inpatientNo, admissTimes, StringUtil.isContainChinese(orderName)));
     }
 
@@ -89,12 +108,19 @@ public class YiZhuLuRuServer {
      *
      * @param patNo 住院号
      * @param times 住院次数
-     * @return 返回信息
+     * @return 返回自己的医嘱频率
      */
     public ResultVo<List<GetDropdownBox>> huoQuGeRenPinLv(String patNo, Integer times) {
         return ResultVoUtil.success(dao.huoQuGeRenPinLv(patNo, times));
     }
 
+    /**
+     * 获取医嘱的数据
+     * 可以根据,医嘱时间区间,执行频率,医嘱名
+     *
+     * @param param 查询条件
+     * @return 返回分页数据,同时做了树状图,这样会有一个问题,那就是开了套餐的数据查询不出来
+     */
     public ResultVo<IPage<YzActOrder>> huoQuYiZhuShuJu(YiZhuFeiYongChaXunTiaoJian param) {
         IPage<YzActOrder> page = new Page<>();
         if (param.getTotal() == 0) {
@@ -104,19 +130,22 @@ public class YiZhuLuRuServer {
             page.setTotal(param.getTotal());
         }
         List<YzActOrder> yiZhuList = dao.huoQuYiZhuShuJu(param.getCurrentPage(), param.getPageSize(), param.getPatNo(),
-                param.getTimes(), param.getStartTime(), param.getEndTime(), param.getFrequCode(), null);
-        // 获取副医嘱
-        yiZhuList.addAll(dao.ziYiZhu(param.getPatNo(), param.getTimes()));
+                param.getTimes(), param.getStartTime(), param.getEndTime(), param.getFrequCode(), param.getOrderName());
+
+        // 还有那些没有被匹配的子级医嘱
+        Map<BigDecimal, YzActOrder> wuFuJiYiZhu = yiZhuList.stream().collect(
+                Collectors.toMap(YzActOrder::getActOrderNo, a -> a, (k1, k2) -> k1));
+
         if (ListUtil.isBlank(yiZhuList)) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
         }
-        log.info("yizhu :{}", JSON.toJSONString(yiZhuList));
         // 做成树状图
         Map<BigDecimal, YzActOrder> map = new HashMap<>();
         List<YzActOrder> tree = new ArrayList<>();
         for (YzActOrder item : yiZhuList) {
             if (item.getParentNo() == null) {
                 tree.add(item);
+                wuFuJiYiZhu.remove(item.getActOrderNo());
             }
             map.put(item.getActOrderNo(), item);
             EntityStringTrim.beanAttributeValueTrim(item);
@@ -134,6 +163,7 @@ public class YiZhuLuRuServer {
         for (YzActOrder item : yiZhuList) {
             YzActOrder actOrder = map.get(item.getParentNo());
             if (actOrder != null) {
+                wuFuJiYiZhu.remove(item.getActOrderNo());
                 if (actOrder.getChildren() == null) {
                     actOrder.setChildren(new ArrayList<>());
                 }
@@ -141,11 +171,20 @@ public class YiZhuLuRuServer {
                 actOrder.getChildren().add(item);
             }
         }
+        if (!wuFuJiYiZhu.isEmpty()) {
+            tree.addAll(wuFuJiYiZhu.values());
+        }
+        EntityStringTrim.beanAttributeValueTrimList(tree);
         page.setRecords(tree);
-        log.info("树状图:{}", JSON.toJSONString(tree));
         return ResultVoUtil.success(page);
     }
 
+    /**
+     * 获取搜索的项目信息,如药品和项目
+     *
+     * @param code 拼音首字母,中文,编码来进行搜索
+     * @return 返回项目信息
+     */
     public ResultVo<List<YiZhuMingChen>> huoQuXiangMu(String code) {
         code = StringUtil.isContainChinese(code);
         List<YiZhuMingChen> list = dao.yiZhuMingChen1(code);
@@ -154,6 +193,13 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(list);
     }
 
+    /**
+     * 获取某一个费用的详细信息
+     *
+     * @param code   编码
+     * @param serial 00-项目 01-小包装的药品 99-大包装
+     * @return 返回该费用的一些详细信息,以及一些提示信息。
+     */
     public ResultVo<Map<String, Object>> huoQuFeiYongXinXi(String code, String serial) {
         Map<String, Object> map = new HashMap<>();
         if (serial.trim().equals("00")) {
@@ -178,7 +224,6 @@ public class YiZhuLuRuServer {
                         break;
                 }
             }
-            return ResultVoUtil.success(map);
         } else {
             YaoPinXinXi yp = dao.huoQuYaoPin(code.trim() + serial.trim());
             if (yp == null) {
@@ -202,29 +247,43 @@ public class YiZhuLuRuServer {
             }
             map.put("yaoPingJiLiang", yaoPingJiLiang);
             map.put("data", yp);
-            return ResultVoUtil.success(map);
         }
+        return ResultVoUtil.success(map);
     }
 
+    /**
+     * 获取频率
+     *
+     * @param code 五笔,拼音,中文,编码
+     * @return 返回对应的数据
+     */
     public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
         return ResultVoUtil.success(dao.huoQuZhuYuanPinLv(StringUtil.isContainChinese(code)));
     }
 
+    /**
+     * 获取给药方式
+     *
+     * @param code 五笔,拼音,中文,编码
+     * @return 返回对应的数据
+     */
     public ResultVo<List<GetDropdownBox>> huoQuGeiYaoFangShi(String code) {
         return ResultVoUtil.success(dao.huoQuGeiYaoFangShi(StringUtil.isContainChinese(code)));
     }
 
-    public ResultVo<List<GetDropdownBox>> huoQuFuYiZhu(String patNo, Integer times) {
-        return ResultVoUtil.success(dao.huoQuFuYiZhu(patNo, times));
-    }
-
+    /**
+     * 获取执行科室
+     *
+     * @param code 五笔,拼音,中文,编码
+     * @return 返回对应的数据
+     */
     public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
         return ResultVoUtil.success(dao.huoQuZhiXinKeShi(StringUtil.isContainChinese(code)));
     }
 
 
     /**
-     * 用来校验或者上传数据
+     * 用来校验数据 以及插入医嘱和插入抗菌药物以及,插入医嘱模板
      *
      * @param param 数据
      * @return 返回提示
@@ -234,6 +293,7 @@ public class YiZhuLuRuServer {
         if (ListUtil.isBlank(param.getList())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择数据");
         }
+
         Set<String> yaoPingCode = new HashSet<>();
         Set<String> xiangMuCode = new HashSet<>();
         StringBuilder cuoWuXinXi = new StringBuilder();
@@ -292,9 +352,9 @@ public class YiZhuLuRuServer {
                 if (StringUtil.isBlank(item.getDrugSpecification())) {
                     cuoWuXinXi.append(getCuoWuXinXi("药品规格不能为空", listSize, index));
                 }
-                if (item.getDrugQuan() == null || BigUtils.dengYu(item.getDrugQuan(), 0)) {
-                    cuoWuXinXi.append(getCuoWuXinXi("执行用量不能为空", listSize, index));
-                }
+//                if (item.getDrugQuan() == null || BigUtils.dengYu(item.getDrugQuan(), 0)) {
+//                    cuoWuXinXi.append(getCuoWuXinXi("执行用量不能为空", listSize, index));
+//                }
                 if (StringUtil.isBlank(item.getSupplyCode())) {
                     cuoWuXinXi.append(getCuoWuXinXi("给药方式不能为空", listSize, index));
                 }
@@ -308,10 +368,24 @@ public class YiZhuLuRuServer {
                     cuoWuXinXi.append(getCuoWuXinXi("包装大小不能为空", listSize, index));
                 }
                 // 插入模板就不需要 填写时间
-                if (item.getStartTime() == null) {
-                    cuoWuXinXi.append(getCuoWuXinXi("开始时间不能为空", listSize, index));
-                } else if (DateUtil.shiJianDaXiao(item.getStartTime(), item.getOrderTime(), "<")) {
-                    cuoWuXinXi.append(getCuoWuXinXi("开始时间不能在开医嘱之前", listSize, index));
+                if (!param.getChaRuMuBan()) {
+                    if (item.getOrderTime() == null) {
+                        cuoWuXinXi.append(getCuoWuXinXi("医嘱时间不能为空", listSize, index));
+                    } else if (item.getStartTime() == null) {
+                        cuoWuXinXi.append(getCuoWuXinXi("开始时间不能为空", listSize, index));
+                    } else if (DateUtil.shiJianDaXiao(item.getStartTime(), item.getOrderTime(), "<")) {
+                        cuoWuXinXi.append(getCuoWuXinXi("开始时间不能在开医嘱之前", listSize, index));
+                    }
+                    if (item.getEndTime() != null) {
+                        if (item.getFrequCode().trim().equals("ONCE")) {
+                            item.setEndTime(null);
+                        } else {
+                            if (DateUtil.shiJianDaXiao(item.getEndTime(), item.getStartTime(), "<")) {
+                                cuoWuXinXi.append(getCuoWuXinXi("结束时间不能在开始时间之前", listSize, index));
+                            }
+                        }
+
+                    }
                 }
             }
             XinZhenYzActOrder feiYongXinXi = yaoPingXinXi.get(item.getOrderCode().trim() + item.getSerial().trim());
@@ -356,11 +430,21 @@ public class YiZhuLuRuServer {
                 // 同时计算药品的执行用量 以及 领量
                 if (StringUtil.notBlank(feiYongXinXi.getDrugWeightUnit()) &&
                         item.getDoseUnit().trim().equals(feiYongXinXi.getDrugWeightUnit().trim())) {
-                    item.setDrugQuan(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight()));
-                    item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight(), 2));
+                    if (BigUtils.bigXiaoYu(item.getDose(), feiYongXinXi.getDrugWeight())) {
+                        item.setDrugQuan(BigDecimal.valueOf(1));
+                        item.setDrugOcc(BigDecimal.valueOf(1));
+                    } else {
+                        item.setDrugQuan(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight()));
+                        item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight(), 2));
+                    }
                 } else if (StringUtil.notBlank(feiYongXinXi.getDrugVolUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugVolUnit())) {
-                    item.setDrugQuan(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume()));
-                    item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume(), 2));
+                    if (BigUtils.bigXiaoYu(item.getDose(), feiYongXinXi.getDrugVolume())) {
+                        item.setDrugQuan(BigDecimal.valueOf(1));
+                        item.setDrugOcc(BigDecimal.valueOf(1));
+                    } else {
+                        item.setDrugQuan(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume()));
+                        item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume(), 2));
+                    }
                 } else if (StringUtil.notBlank(feiYongXinXi.getPackUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getPackUnit())) {
                     if (new BigDecimal(item.getDose().intValue()).compareTo(item.getDose()) != 0) {
                         cuoWuXinXi.append(getCuoWuXinXi("已经是最小单位了请不要带小数点。", listSize, index));
@@ -369,6 +453,7 @@ public class YiZhuLuRuServer {
                     item.setDrugOcc(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize(), 2));
                 }
                 try {
+                    // 这里把查询出来的一些信息 放到item 中 ,这个克隆不会影响已经有值的数据 这样就不用一个个set 了
                     EntityCopy.Copy(feiYongXinXi, item);
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -470,17 +555,23 @@ public class YiZhuLuRuServer {
 
     public ResultVo<List<YzActOrder>> huoQuMuBanShuJu(String code) {
         List<YzActOrder> muBanShuJu = dao.huoQuMuBanShuJu(code);
+
+        Map<BigDecimal, YzActOrder> wuFuJi = muBanShuJu.stream().collect(
+                Collectors.toMap(YzActOrder::getId, a -> a, (k1, k2) -> k1));
+
         Map<BigDecimal, YzActOrder> map = new HashMap<>();
         List<YzActOrder> tree = new ArrayList<>();
         for (YzActOrder item : muBanShuJu) {
             if (item.getParentNo() == null) {
                 tree.add(item);
+                wuFuJi.remove(item.getId());
             }
             map.put(item.getId(), item);
         }
         for (YzActOrder item : muBanShuJu) {
             YzActOrder yzActOrder = map.get(item.getParentNo());
             if (yzActOrder != null) {
+                wuFuJi.remove(item.getId());
                 item.setIsChildren(true);
                 if (yzActOrder.getChildren() == null) {
                     yzActOrder.setChildren(new ArrayList<>());
@@ -488,6 +579,10 @@ public class YiZhuLuRuServer {
                 yzActOrder.getChildren().add(item);
             }
         }
+        if (!wuFuJi.isEmpty()) {
+            log.info("剩下的:{}", wuFuJi.values());
+            tree.addAll(wuFuJi.values());
+        }
         return ResultVoUtil.success(tree);
     }
 
@@ -501,9 +596,9 @@ public class YiZhuLuRuServer {
         }
         List<Integer> role = publicServer.getRoleCode().getData();
         if (param.getInputType().equals("1") && publicServer.needRule(role, new int[]{38})) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限全院模板。");
-        } else if (!param.getInputType().equals("2") && publicServer.needRule(role, new int[]{38, 11})) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限科室模板。");
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限修改和删除全院模板。");
+        } else if (param.getInputType().equals("2") && publicServer.needRule(role, new int[]{38, 11})) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限修改和删除科室模板。");
         }
         String patternCode = yzOrderPattern.getPatternCode();
         if (StringUtil.notBlank(patternCode) && !param.getQingZhiTiHuan()) {