Pārlūkot izejas kodu

优化门诊补录

lighter 2 gadi atpakaļ
vecāks
revīzija
db249979e3

+ 16 - 11
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/SiMzDao.java

@@ -62,6 +62,16 @@ public interface SiMzDao {
     @Select("select rtrim(name) from yp_zd_unit where code=#{code}")
     String selectDrugUnit(@Param("code") String code);
 
+    @Select("select receipt_no from t_mt_receipt where patient_id=#{patNo} and times=#{times} group by receipt_no")
+    List<Integer> selectGeneratedReceiptNos(@Param("patNo") String patNo, @Param("times") int times);
+
+    @Select("select count(1) from mz_charge_detail where patient_id=#{patNo} and times=#{times} " +
+            "and receipt_no=#{receiptNo} and pay_mark=0 and confirm_flag!=4")
+    int isReceiptPayed(@Param("patNo") String patNo, @Param("times") int times, @Param("receiptNo") int receiptNo);
+
+    @Delete("delete from t_mt_receipt where patient_id=#{patNo} and times=#{times} and receipt_no=#{receiptNo}")
+    void deleteCertainReceipt(@Param("patNo") String patNo, @Param("times") int times, @Param("receiptNo") int receiptNo);
+
     @Insert("insert into t_mt_receipt (patient_id, times, receipt_no, order_no, item_no, his_item_name, " +
             "his_item_code, fee_date, input_date, medi_item_type, charge_fee, price, quantity, drug_win, " +
             "input_staff, input_man, serial_no, yb_trans_flag, charge_type, bill_item_code) values (" +
@@ -78,12 +88,11 @@ public interface SiMzDao {
     void deleteAllReceipts(@Param("patNo") String patNo,
                            @Param("times") Integer times);
 
-    @Select("select *, " +
-            "chargeFee=(select sum(amount) from mz_deposit_file a where a.patient_id=patNo and a.times=temp.times and a.receipt_no=receiptNo), " +
-            "status=(select count(1) from t_mt_receipt a where a.patient_id=patNo and a.times=temp.times and a.receipt_no=receiptNo) " +
-            "from (SELECT rtrim(patient_id) patNo,times,rtrim(receipt_no) receiptNo,charge_date chargeDate FROM mz_deposit_file " +
-            "where patient_id=#{patNo} and charge_date>=#{start} and charge_date<=#{end} " +
-            " group by patient_id, times, receipt_no,charge_date) temp")
+    @Select("select patient_id as patNo,times,charge_date,receipt_no, " +
+            "chargeFee=(select cast(sum(isnull(unit_price,0.01)*isnull(drug_win,1)*isnull(quantity,1)) as decimal(16,2))), " +
+            "status=(select count(1) from t_mt_receipt d where d.patient_id=a.patient_id and d.times=a.times and d.receipt_no=a.receipt_no) " +
+            "from mz_charge_detail a where a.patient_id=#{patNo} and a.charge_date>=#{start} and a.charge_date<=#{end} " +
+            "and pay_mark=0 and confirm_flag!=4 group by patient_id, times, charge_date,receipt_no order by times")
     List<MzDepositFile> selectMzDepositFiles(@Param("patNo") String patNo, @Param("start") String start, @Param("end") String end);
 
     @Select("select patient_id,times,receipt_no,order_no,item_no,charge_item_code, " +
@@ -98,7 +107,7 @@ public interface SiMzDao {
             "(select national_code from zd_charge_item a where a.code=charge_item_code) else " +
             "(select max(national_code) from yp_zd_dict a where a.code=charge_item_code) end) " +
             "from mz_charge_detail where patient_id=#{patNo} and times=#{times} and " +
-            "receipt_no=#{receipt} and bill_item_code!='TC' and charge_item_code!='BILL99'")
+            "receipt_no=#{receipt} and pay_mark=0 and confirm_flag!=4 and bill_item_code!='TC' and charge_item_code!='BILL99'")
     List<MzReceipt> selectMzCharge(@Param("patNo") String patNo, @Param("times") int times, @Param("receipt") int receipt);
 
     @Select("select max(national_code) from ${table} where code=#{code}")
@@ -131,8 +140,4 @@ public interface SiMzDao {
             "values (#{patNo},#{times},#{ledgerSn},#{psnNo},#{psnCertType},#{insutype},#{insuplc},#{certno}," +
             "#{psnName},#{gend},#{naty},#{brdy},#{age},#{medType},#{psnIdetType},#{psnType},#{empName},getdate(),#{balc})")
     void insertSiMzInfoPsnNo(PsnBaseInfo psnBaseinfo);
-
-    @Select("select * from t_si_pat_info where pat_no=#{patNo} and times=#{times}")
-    SiPatInfo selectSiPatInfoForMz(@Param("patNo") String patNo,
-                                   @Param("times") int times);
 }

+ 8 - 0
src/main/java/thyyxxk/webserver/service/medicalinsurance/SiMzService.java

@@ -237,6 +237,14 @@ public class SiMzService {
         if (receipts.size() == 0) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "患者没有可以报销的项目!");
         }
+
+        MzReceipt receipt = receipts.get(0);
+        List<Integer> receiptNos = dao.selectGeneratedReceiptNos(receipt.getPatientId(), receipt.getTimes());
+        for (int receiptNo : receiptNos) {
+            if (dao.isReceiptPayed(receipt.getPatientId(), receipt.getTimes(), receiptNo) == 0) {
+                dao.deleteCertainReceipt(receipt.getPatientId(), receipt.getTimes(), receiptNo);
+            }
+        }
         receipts.forEach(dao::insertBatchedMtFeeInfo);
         return ResultVoUtil.success();
     }