Browse Source

科室收入统计中添加患者分类

xiaochan 2 years ago
parent
commit
0c0311a42f

+ 1 - 79
src/main/java/thyyxxk/webserver/dao/his/reports/KeShiShouRuDao.java

@@ -128,85 +128,6 @@ public interface KeShiShouRuDao {
                                                     @Param("codeRs") String codeRs,
                                                     @Param("reqDept") String reqDept);
 
-    /**
-     * 根据分类来查询
-     *
-     * @param page         分页
-     * @param execUnit     执行科室
-     * @param startTime    开始时间
-     * @param endTime      结束时间
-     * @param chargeCodeMx 项目编码
-     * @param code         人员编码
-     * @param codeRs       人事的人员编码
-     * @param reqDept      申请科室
-     * @param fenLei       分类的类型
-     * @return 返回分页数据
-     */
-    @Select("<script>" +
-            "select " +
-            "${fenLei}," +
-            "sum(charge_fee) charge_fee,sum(charge_amount) charge_amount,count(1) total,source = '住院' " +
-            "from zy_detail_charge a  " +
-            "where " +
-            "charge_date &gt;= #{startTime,jdbcType=TIMESTAMP} and charge_date &lt;= #{endTime,jdbcType=TIMESTAMP} and trans_flag_yb &lt;&gt; 2 " +
-            "<if test=\"list != null and list.size > 0 \">" +
-            "  and  a.exec_unit in " +
-            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
-            "#{item,jdbcType = CHAR}" +
-            "</foreach>" +
-            "</if>" +
-            "<if test=\"chargeCodeMx != null and chargeCodeMx != '' \">" +
-            "  and a.charge_code_mx = #{chargeCodeMx,jdbcType = CHAR}" +
-            "</if>" +
-            "<if test=\"code != null and code != '' \">" +
-            " and a.op_id_code in (#{code,jdbcType = CHAR},#{codeRs,jdbcType = CHAR}) " +
-            "</if>" +
-            "<if test=\"reqDept != null and reqDept != '' \">" +
-            " and a.ward_code = #{reqDept,jdbcType = CHAR} " +
-            "</if>" +
-            "group by " +
-            "<choose>" +
-            "<when test=\"fenLei == 'CONVERT(varchar(100), charge_date, 23) charge_date_string' \">" +
-            "CONVERT(varchar(100), charge_date, 23)" +
-            "</when>" +
-            "<otherwise>" +
-            "${fenLei}" +
-            "</otherwise>" +
-            "</choose>" +
-            "</script>")
-    List<KeShiFeiiYongTongJi> getZhuYuanFeiYongXiangMuFenLei(IPage<KeShiFeiiYongTongJi> page,
-                                                             @Param("list") List<String> execUnit,
-                                                             @Param("startTime") String startTime,
-                                                             @Param("endTime") String endTime,
-                                                             @Param("chargeCodeMx") String chargeCodeMx,
-                                                             @Param("code") String code,
-                                                             @Param("codeRs") String codeRs,
-                                                             @Param("reqDept") String reqDept,
-                                                             @Param("fenLei") String fenLei);
-
-
-    @Select("SELECT       rtrim(inpatient_no)    patient, " +
-            "             admiss_times           times, " +
-            "             rtrim(charge_code_mx)  charge_code_mx, " +
-            "             charge_date, " +
-            "             rtrim(op_id_code)      op_id_code, " +
-            "             rtrim(exec_unit)       exec_unit, " +
-            "             rtrim(ward_code)       ward_code, " +
-            "             convert(decimal(18, " +
-            "                 2), " +
-            "                     charge_fee)    charge_fee, " +
-            "             convert(decimal(18, " +
-            "                 2), " +
-            "                     charge_amount) charge_amount, " +
-            "    source = '住院' " +
-            "FROM zy_detail_charge a " +
-            "WHERE  trans_flag_yb <> 2 " +
-            " and ${ew.sqlSegment} " +
-            "  AND a.exec_unit IN (#{unit})")
-    XcPageHelp<KeShiFeiiYongTongJi> test(XcPageHelp<KeShiFeiiYongTongJi> pageHelp,
-                                         @Param(Constants.WRAPPER) QueryWrapper<?> qw,
-                                         @Param("unit") String unit);
-
     @Select("select ${fenLei} " +
             "sum(charge_fee) charge_fee," +
             "sum(charge_amount) charge_amount," +
@@ -217,6 +138,7 @@ public interface KeShiShouRuDao {
                                                                @Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper,
                                                                @Param("fenLei") String fenLei);
 
+
     /**
      * 这个是获取门诊费用的
      *

+ 77 - 0
src/main/java/thyyxxk/webserver/entity/excel/ToolExcel.java

@@ -0,0 +1,77 @@
+package thyyxxk.webserver.entity.excel;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.poi.excel.BigExcelWriter;
+import cn.hutool.poi.excel.StyleSet;
+import lombok.Data;
+import org.apache.poi.ss.usermodel.DataFormat;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ToolExcel {
+    private final List<Integer> widthIndex = new ArrayList<>();
+    private final BigExcelWriter writer = cn.hutool.poi.excel.ExcelUtil.getBigWriter();
+    private String format = "yyyy-mm-dd hh:mm:ss";
+
+    public ToolExcel() {
+
+    }
+
+
+    public ToolExcel addTitle(String name, String alias, int width) {
+        writer.addHeaderAlias(name, alias);
+        widthIndex.add(width);
+        return this;
+    }
+
+    public ToolExcel addTitle(String name, String alias) {
+        writer.addHeaderAlias(name, alias);
+        widthIndex.add(null);
+        return this;
+    }
+
+    public ToolExcel setDataFormat(String format) {
+        this.format = format;
+        return this;
+    }
+
+    public void exportExcel(Iterable<?> data, HttpServletResponse response) {
+
+        DataFormat dataFormat = writer.getWorkbook().createDataFormat();
+        short format = dataFormat.getFormat(this.format);
+        StyleSet styleSet = writer.getStyleSet();
+        styleSet.getCellStyleForDate()
+                .setDataFormat(format);
+
+        for (int i = 0; i < widthIndex.size(); i++) {
+            Integer width = widthIndex.get(i);
+            if (width != null) {
+                writer.setColumnWidth(i, width);
+            }
+        }
+
+        writer.setOnlyAlias(true);
+        writer.write(data, true);
+        ServletOutputStream out = null;
+        try {
+            response.setContentType("application/vnd.ms-excel;charset=utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=test.xls");
+
+            out = response.getOutputStream();
+            // 将Excel Workbook刷出到输出流
+            writer.flush(out, true);
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("文件写入失败!");
+        } finally {
+            //关闭流
+            writer.close();
+            IoUtil.close(out);
+        }
+    }
+
+}

+ 65 - 85
src/main/java/thyyxxk/webserver/service/reports/KeShiShouRuServer.java

@@ -1,5 +1,8 @@
 package thyyxxk.webserver.service.reports;
 
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.poi.excel.BigExcelWriter;
+import cn.hutool.poi.excel.ExcelWriter;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -9,13 +12,19 @@ import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.dao.his.reports.KeShiShouRuDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.excel.ToolExcel;
 import thyyxxk.webserver.entity.querydata.KeShiFeiiYongTongJi;
 import thyyxxk.webserver.entity.querydata.QueryDrugsAndProjects;
 import thyyxxk.webserver.entity.xc.XcPageHelp;
 import thyyxxk.webserver.service.PublicServer;
 import thyyxxk.webserver.utils.*;
 
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -128,6 +137,15 @@ public class KeShiShouRuServer {
                             "a.ward_code,wardCodeName = (select rtrim(name) from zd_unit_code where code = a.ward_code),"));
                     qp.setTotal(page.getTotal());
                     break;
+                case 5:
+                    qw.groupBy("a.inpatient_no,a.admiss_times");
+                    qp.setData(dao.getZhuYuanFeiYongXiangMuFenLeiV2(page,
+                            qw,
+                            "a.inpatient_no as patient," +
+                                    "(select rtrim(name) from a_patient_mi where a.inpatient_no = a_patient_mi.inpatient_no) as patient_name," +
+                                    "a.admiss_times as times,"));
+                    qp.setTotal(page.getTotal());
+                    break;
                 default:
 
                     break;
@@ -192,6 +210,15 @@ public class KeShiShouRuServer {
                             "warn_dept as wardCode,wardCodeName = (select rtrim(name) from zd_unit_code where code = warn_dept),"));
                     qp.setTotal(page.getTotal());
                     break;
+
+                case 5:
+                    qw.groupBy("patient_id,times,name");
+                    qp.setData(dao.getMenZhenFeiYongXiangMuFenLeiV2(
+                            page,
+                            qw,
+                            "rtrim(patient_id) as patient,times,rtrim(name) as patient_name,"));
+                    qp.setTotal(page.getTotal());
+                    break;
                 default:
 
                     break;
@@ -200,60 +227,6 @@ public class KeShiShouRuServer {
         return ResultVoUtil.success(qp);
     }
 
-
-    private void pingJieZiDuanMingChen(KeShiFeiiYongTongJi qp, String huanZheBiao) {
-        if (qp.getData() != null && !qp.getData().isEmpty()) {
-            Set<String> huanZheHaoSet = new HashSet<>();
-            Set<String> keShiSet = new HashSet<>();
-            Set<String> xiangMuSet = new HashSet<>();
-            Set<String> luRuRenSet = new HashSet<>();
-
-            qp.getData().forEach(item -> {
-                huanZheHaoSet.add(item.getPatient());
-                keShiSet.add(item.getExecUnit());
-                keShiSet.add(item.getWardCode());
-                xiangMuSet.add(item.getChargeCodeMx());
-                luRuRenSet.add(item.getOpIdCode());
-            });
-
-
-            Map<String, String> huanZheXingMingMap = dao.huanZheXingMing(huanZheHaoSet, huanZheBiao).stream().collect(Collectors.toMap(GetDropdownBox::getCode, GetDropdownBox::getName, (key1, key2) -> key1));
-            Map<String, String> xiangMuMingChenMap = dao.xiangMuMingChen(xiangMuSet).stream().collect(Collectors.toMap(GetDropdownBox::getCode, GetDropdownBox::getName, (key1, key2) -> key1));
-
-            Map<String, String> huoQuKeShiMap = dao.huoQuKeShiHuoRenYuan(keShiSet, "zd_unit_code").stream().collect(Collectors.toMap(GetDropdownBox::getCode, GetDropdownBox::getName, (key1, key2) -> key1));
-
-            // 获取人员信息
-            List<GetDropdownBox> RenYuan = dao.huoQuKeShiHuoRenYuan(luRuRenSet, "a_employee_mi");
-            // 第一次用 code 匹配
-            Map<String, String> luRuRenXingMingMap = RenYuan.stream().collect(Collectors.toMap(GetDropdownBox::getCode, GetDropdownBox::getName, (key1, key2) -> key1));
-
-            // 第二次用 code_rs 匹配
-            Map<String, String> luRuRenXingMingRenShiMap = RenYuan.stream().collect(Collectors.toMap(GetDropdownBox::getCodeRs, GetDropdownBox::getName, (key1, key2) -> key1));
-
-            qp.getData().forEach(item -> {
-                if (huanZheXingMingMap.containsKey(item.getPatient())) {
-                    item.setPatientName(huanZheXingMingMap.get(item.getPatient()));
-                }
-                if (xiangMuMingChenMap.containsKey(item.getChargeCodeMx())) {
-                    item.setChargeCodeName(xiangMuMingChenMap.get(item.getChargeCodeMx()));
-                }
-                if (huoQuKeShiMap.containsKey(item.getExecUnit())) {
-                    item.setExecUnitName(huoQuKeShiMap.get(item.getExecUnit()));
-                }
-                if (huoQuKeShiMap.containsKey(item.getWardCode())) {
-                    item.setWardCodeName(huoQuKeShiMap.get(item.getWardCode()));
-                }
-                if (luRuRenXingMingMap.containsKey(item.getOpIdCode())) {
-                    item.setOpName(luRuRenXingMingMap.get(item.getOpIdCode()));
-                } else if (luRuRenXingMingRenShiMap.containsKey(item.getOpIdCode())) {
-                    item.setOpName(luRuRenXingMingRenShiMap.get(item.getOpIdCode()));
-                } else {
-                    item.setOpName(item.getOpIdCode());
-                }
-            });
-        }
-    }
-
     public void exportExcel(HttpServletResponse response, QueryDrugsAndProjects param) {
         double pageSize = 1000;
         double currentPage = param.getTotal() / pageSize;
@@ -264,39 +237,46 @@ public class KeShiShouRuServer {
             param.setCurrentPage(i + 1);
             keShiFeiiYongTongJisList.addAll(getKeShouFei(param).getData().getData());
         }
+        ToolExcel excel = new ToolExcel();
 
-        String[] title;
-        if (param.getFenLei() == 3) {
-            title = new String[]{"患者姓名", "住院/门诊号", "次数", "项目编码", "项目名称", "收费日期", "录入人", "执行科室", "申请科室", "金额", "数量", "来源"};
-        } else {
-            title = new String[]{param.getFenLei() == 0 ? "日期" : param.getFenLei() == 1 ? "录入人" : "项目编码", "金额", "数量", "来源"};
-        }
-        String[][] content = new String[keShiFeiiYongTongJisList.size()][];
-        for (int i = 0; i < keShiFeiiYongTongJisList.size(); i++) {
-            content[i] = new String[title.length];
-            KeShiFeiiYongTongJi pojo = keShiFeiiYongTongJisList.get(i);
-            if (param.getFenLei() == 3) {
-                content[i][0] = pojo.getPatientName();
-                content[i][1] = pojo.getPatient();
-                content[i][2] = pojo.getTimes().toString();
-                content[i][3] = pojo.getChargeCodeMx();
-                content[i][4] = pojo.getChargeCodeName();
-                content[i][5] = DateUtil.formatDatetime(pojo.getChargeDate());
-                content[i][6] = pojo.getOpName();
-                content[i][7] = pojo.getExecUnitName();
-                content[i][8] = pojo.getWardCodeName();
-                content[i][9] = pojo.getChargeFee().toString();
-                content[i][10] = pojo.getChargeAmount().toString();
-                content[i][11] = pojo.getSource();
-            } else {
-                content[i][0] = param.getFenLei() == 0 ? pojo.getChargeDateString() : param.getFenLei() == 1 ? pojo.getOpName() : pojo.getChargeCodeName();
-                content[i][1] = pojo.getChargeFee().toString();
-                content[i][2] = pojo.getChargeAmount().toString();
-                content[i][3] = pojo.getSource();
-            }
+        switch (param.getFenLei()) {
+            case 0:
+                excel.addTitle("chargeDateString", "收费日期", 21);
+                break;
+            case 1:
+                excel.addTitle("opName", "录入人");
+                break;
+            case 2:
+                excel.addTitle("chargeCodeMx", "项目编码")
+                        .addTitle("chargeCodeName", "项目名称", 30);
+                break;
+            case 3:
+                excel.addTitle("patientName", "姓名")
+                        .addTitle("patient", "住院号")
+                        .addTitle("times", "次数")
+                        .addTitle("chargeCodeMx", "项目编码")
+                        .addTitle("chargeCodeName", "项目名称", 30)
+                        .addTitle("chargeDate", "执行日期", 21)
+                        .addTitle("chargeDateString", "收费日期", 21)
+                        .addTitle("opName", "录入人")
+                        .addTitle("execUnitName", "执行科室")
+                        .addTitle("wardCodeName", "申请科室");
+                break;
+            case 4:
+                excel.addTitle("wardCodeName", "申请科室");
+                break;
+            case 5:
+                excel.addTitle("patientName", "姓名")
+                        .addTitle("patient", "住院号")
+                        .addTitle("times", "次数");
+                break;
         }
-        ExcelUtil.exportExcel(response, title, content);
-    }
 
+        excel.addTitle("chargeFee", "金额")
+                .addTitle("chargeAmount", "数量")
+                .addTitle("source", "来源")
+                .exportExcel(keShiFeiiYongTongJisList, response);
+
+    }
 
 }