Explorar el Código

add
添加临床信息导出excel功能

18339543638 hace 1 año
padre
commit
9b0a716294

+ 19 - 0
nb-core/src/main/java/com/nb/core/enums/ExportType.java

@@ -0,0 +1,19 @@
+package com.nb.core.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Enum : ExportType
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年09月25日
+ */
+@AllArgsConstructor
+@Getter
+public enum ExportType {
+    DOCX(".docx"),
+    EXCEL(".xlsx");
+    @Getter
+    private String suffix;
+}

+ 37 - 0
nb-core/src/main/java/com/nb/core/result/ExportResult.java

@@ -0,0 +1,37 @@
+package com.nb.core.result;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.nb.core.enums.ExportType;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @ClassName : ExportResult
+ * @Description : 文件导出结果
+ * @Author : LF
+ * @Date: 2023年06月15日
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ExportResult {
+    private String fileName;
+    private String base64;
+    private ExportType type;
+    public String getFileName() {
+        if(CollectionUtil.size(StrUtil.split(fileName,"."))>2){
+            return fileName;
+        }
+        return fileName+type.getSuffix();
+    }
+
+    public static ExportResult of(String fileName,String base64){
+        return new ExportResult(fileName,base64,ExportType.EXCEL);
+    }
+
+    public static ExportResult of(String fileName,String base64,ExportType type){
+        return new ExportResult(fileName,base64,type);
+    }
+}

+ 9 - 2
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/BusClinicController.java

@@ -4,9 +4,12 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.annotation.SaMode;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.nb.core.enums.ExportType;
+import com.nb.core.result.ExportResult;
 import com.nb.web.api.entity.*;
 import com.nb.web.service.bus.controller.vo.ClinicExportVo;
 import com.nb.web.service.bus.controller.vo.ClinicStatsVo;
@@ -20,6 +23,7 @@ import com.nb.core.entity.GenericEntity;
 import com.nb.core.exception.CustomException;
 import com.nb.core.result.R;
 import com.nb.web.service.bus.utils.AnalExportUtils;
+import com.nb.web.service.bus.utils.ExportExcelUtils;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -27,6 +31,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -266,7 +271,9 @@ public class BusClinicController {
         return result;
     }
 
-    public R exportExcel(Collection<String> clinicId){
-        return null;
+    @PostMapping("/export/excel")
+    @ApiOperation(value = "导出所选临床数据的excel",notes = "导出所选临床数据的excel,权限【无】")
+    public R<ExportResult> exportExcel(@RequestBody Collection<String> clinicId) throws IOException {
+        return R.success(ExportResult.of("驼人镇痛泵手术(评价)信息列表",clinicService.exportExcelSourceListBase64(clinicId), ExportType.EXCEL));
     }
 }

+ 230 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/vo/BusClinicExcelVO.java

@@ -0,0 +1,230 @@
+package com.nb.web.service.bus.controller.vo;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.nb.core.enums.SexEnum;
+import com.nb.web.api.bean.FormulaDrugDetailDomain;
+import com.nb.web.api.bean.FormulaDrugDomain;
+import com.nb.web.api.entity.BusEvaluationEntity;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @ClassName : BusClinicExcelVO
+ * @Description : 手术信息导出excel实体
+ * @Author : LF
+ * @Date: 2024年10月11日
+ */
+@Data
+public class BusClinicExcelVO {
+
+    private String id;
+
+    @ExcelProperty("住院号")
+    private String patientCode;
+
+    @ExcelProperty(value = "患者姓名")
+    private String patientName;
+
+    @ExcelProperty(value = "患者性别")
+    private String patientGender;
+
+    @ExcelProperty(value = "患者年龄")
+    private Integer patientAge;
+
+    @ExcelProperty(value = "手术开始时间",format = DatePattern.NORM_DATETIME_PATTERN)
+    private Date startTime;
+
+    @ExcelProperty(value = "病区")
+    private String ward;
+
+    @ExcelProperty(value = "病床号")
+    private String bedNo;
+
+    @ExcelProperty(value = "体重")
+    private String weight;
+
+    @ExcelProperty(value = "身高")
+    private String height;
+
+    @ExcelProperty("手术名称")
+    private String surgeryName;
+
+    @ExcelProperty(value = "麻醉医生")
+    private String anaDoctor;
+
+    @ExcelProperty(value = "麻醉方式")
+    private String anaType;
+
+    @ExcelProperty(value = "备注")
+    private String remark;
+
+    @ExcelProperty(value = "镇痛方式")
+    private String analType;
+
+    @ExcelProperty(value = "手术医生")
+    private String surgeryDoctor;
+
+    @ExcelProperty(value = "配置人员")
+    private String configPerson;
+
+    @ExcelProperty(value = "配方")
+    private FormulaDrugDomain formula;
+
+    private String formulas;
+
+    @ExcelProperty(value = "ASA")
+    private String asa;
+
+    @ExcelProperty(value = "医嘱")
+    private String entrust;
+
+
+    /*************评价部分********************/
+
+    @ExcelProperty(value = "疼痛静止评分")
+    private Integer statics;
+
+    @ExcelProperty(value = "疼痛活动评分")
+    private Integer activity;
+
+    @ExcelProperty(value = "镇静评分")
+    private Integer calm;
+
+    @ExcelProperty(value = "左上肢")
+    private Integer leftArm;
+
+    @ExcelProperty(value = "左下肢")
+    private Integer leftLeg;
+
+    @ExcelProperty(value = "右上肢")
+    private Integer rightArm;
+
+    @ExcelProperty(value = "右下肢")
+    private Integer rightLeg;
+
+    @ExcelProperty(value = "恶心呕吐")
+    private Integer nauseaVomit;
+
+    @ExcelProperty(value = "瘙痒")
+    private Integer itch;
+
+    @ExcelProperty(value = "眩晕")
+    private Integer vertigo;
+
+    @ExcelProperty(value = "咽喉疼痛")
+    private Integer soreThroat;
+
+    @ExcelProperty(value = "尿潴留")
+    private Integer uroschesis;
+
+    @ExcelProperty(value = "呼吸抑制")
+    private Integer breathDepression;
+
+    @ExcelProperty(value = "声音嘶哑")
+    private Integer hoarseness;
+
+    @ExcelProperty(value = "认知障碍")
+    private Integer cognitionObstacle;
+
+    @ExcelProperty(value = "其他")
+    private String other;
+
+    @ExcelProperty(value = "满意度")
+    private Integer satisfaction;
+
+    @ExcelProperty(value = "收缩压")
+    private BigDecimal shrinkPressure;
+
+    @ExcelProperty(value = "舒张压")
+    private BigDecimal diastensPressure;
+
+    @ExcelProperty(value = "心率")
+    private BigDecimal heartRate;
+
+    @ExcelProperty(value = "胎心")
+    private BigDecimal fetalHeartRate;
+
+    @ExcelProperty(value = "呼吸频率")
+    private BigDecimal breathRate;
+
+    @ExcelProperty(value = "血氧饱和度")
+    private BigDecimal bloodOxygenSaturation;
+
+    @ExcelProperty(value = "评价时间")
+    private Date evaluateTime;
+
+    @ExcelProperty(value = "评价人")
+    private String evaluator;
+
+    @ExcelProperty(value = "备注")
+    private String evalRemark;
+
+    public void setPatientGender(String patientGender) {
+        if(ObjectUtil.isNotNull(patientGender)){
+            SexEnum sexEnum = SexEnum.valueOf(patientGender);
+            if(ObjectUtil.isNull(sexEnum)){
+                this.patientGender = SexEnum.UNKNOW.getText();
+            }else {
+                this.patientGender = sexEnum.getText();
+            }
+        }
+    }
+
+
+
+    public String getFormulas() {
+        String content="";
+        if(ObjectUtil.isNotNull(this.formula)&& CollectionUtil.isNotEmpty(this.formula.getDetail())){
+            List<FormulaDrugDetailDomain> detail = this.formula.getDetail();
+            for (int i = 0; i < detail.size(); i++) {
+                FormulaDrugDetailDomain formulaDrugDetailDomain = CollectionUtil.get(detail, i);
+                content=content+formulaDrugDetailDomain.getName()+formulaDrugDetailDomain.getDose()+formulaDrugDetailDomain.getUnit();
+                if(i!=(detail.size()-1)){
+                    content=content+1;
+                }
+            }
+        }
+        return content;
+    }
+
+
+    public void parseEval(BusEvaluationEntity eval){
+        if(ObjectUtil.isNull(eval)){
+            return;
+        }
+        this.statics=eval.getStatics();
+        this.activity=eval.getActivity();
+        this.calm=eval.getCalm();
+        this.leftArm=eval.getLeftArm();
+        this.leftLeg=eval.getLeftLeg();
+        this.rightArm=eval.getRightArm();
+        this.rightLeg=eval.getRightLeg();
+        this.nauseaVomit=eval.getNauseaVomit();
+        this.itch=eval.getItch();
+        this.vertigo=eval.getVertigo();
+        this.soreThroat=eval.getSoreThroat();
+        this.uroschesis=eval.getUroschesis();
+        this.breathDepression=eval.getBreathDepression();
+        this.hoarseness=eval.getHoarseness();
+        this.cognitionObstacle=eval.getCognitionObstacle();
+        this.other=eval.getOther();
+        this.satisfaction=eval.getSatisfaction();
+        this.shrinkPressure=eval.getShrinkPressure();
+        this.diastensPressure=eval.getDiastensPressure();
+        this.heartRate=eval.getHeartRate();
+        this.fetalHeartRate=eval.getFetalHeartRate();
+        this.breathRate=eval.getBreathRate();
+        this.bloodOxygenSaturation=eval.getBloodOxygenSaturation();
+        this.evaluateTime=eval.getEvaluateTime();
+        this.evaluator=eval.getEvaluator();
+        this.evalRemark=eval.getRemark();
+
+
+    }
+}

+ 42 - 1
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusClinicService.java

@@ -1,5 +1,6 @@
 package com.nb.web.service.bus.service;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONUtil;
@@ -12,6 +13,7 @@ import com.nb.web.api.enums.ClinicManageEnum;
 import com.nb.web.api.event.ClinicFinishedEvent;
 import com.nb.web.api.event.ClinicRestartEvent;
 import com.nb.web.api.event.PatientInfoEvent;
+import com.nb.web.service.bus.controller.vo.BusClinicExcelVO;
 import com.nb.web.service.bus.controller.vo.ClinicStatsVo;
 import com.nb.web.api.entity.BusClinicEntity;
 import com.nb.web.api.entity.BusInfusionHistoryEntity;
@@ -24,16 +26,17 @@ import com.nb.web.service.bus.registry.patient.PatientRegistry;
 import com.nb.web.service.bus.service.dto.ClinicQuery;
 import com.nb.web.service.bus.service.dto.ClinicResult;
 import com.nb.web.service.bus.service.dto.ClinicStatsReturnResult;
+import com.nb.web.service.bus.utils.ExportExcelUtils;
 import com.nb.web.service.bus.utils.WsPublishUtils;
 import com.nb.common.crud.BaseService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.EmbeddedValueResolverAware;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
+import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -317,4 +320,42 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
     public IPage<ClinicResult> latestQueryPage(ClinicQuery query){
         return this.baseMapper.latestQueryPage(query.getPage(),query);
     }
+
+    /**
+     * 获取导出临床excel所需的数据
+     * @param clinicIds
+     * @return
+     */
+    public String  exportExcelSourceListBase64(Collection<String> clinicIds) throws IOException {
+        if(CollectionUtil.isEmpty(clinicIds)){
+            return ExportExcelUtils.exportClinicExcelBase64(new ArrayList<>());
+        }
+        List<BusClinicEntity> clinicList = this.baseMapper.selectList(new LambdaQueryWrapper<BusClinicEntity>()
+                .in(BusClinicEntity::getId, clinicIds));
+        if(CollectionUtil.isEmpty(clinicList)){
+            return ExportExcelUtils.exportClinicExcelBase64(new ArrayList<>());
+        }
+        List<BusClinicExcelVO> result =new ArrayList<>();
+        List<BusEvaluationEntity> evals = evaluationMapper.selectList(new LambdaQueryWrapper<BusEvaluationEntity>()
+                .in(BusEvaluationEntity::getClinicId, clinicIds)
+                .orderByDesc(BusEvaluationEntity::getEvaluateTime));
+        Map<String, List<BusEvaluationEntity>> clinicMap = evals.stream()
+                .collect(Collectors.groupingBy(BusEvaluationEntity::getClinicId));
+
+        for (BusClinicEntity clinicEntity : clinicList) {
+            List<BusEvaluationEntity> excelEvals = clinicMap.get(clinicEntity.getId());
+            if (CollectionUtil.isNotEmpty(excelEvals)) {
+                for (BusEvaluationEntity excelEval : excelEvals) {
+                    BusClinicExcelVO clinicExcel = BeanUtil.copyProperties(clinicEntity, BusClinicExcelVO.class);
+                    clinicExcel.parseEval(excelEval);
+                    result.add(clinicExcel);
+                }
+            }else {
+                BusClinicExcelVO clinicExcel = BeanUtil.copyProperties(clinicEntity, BusClinicExcelVO.class);
+                result.add(clinicExcel);
+            }
+        }
+
+      return ExportExcelUtils.exportClinicExcelBase64(result);
+    }
 }

+ 66 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/utils/ClinicExcelMergeWriteHandler.java

@@ -0,0 +1,66 @@
+package com.nb.web.service.bus.utils;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.write.handler.RowWriteHandler;
+import com.alibaba.excel.write.handler.SheetWriteHandler;
+import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
+import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext;
+import com.nb.web.service.bus.controller.vo.BusClinicExcelVO;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import java.util.List;
+
+/**
+ * @ClassName : ClinicExcelMergeWriteHandler
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年10月11日
+ */
+
+public class ClinicExcelMergeWriteHandler implements RowWriteHandler {
+    private int minRowIndex=4;
+    //最大的合并列数
+    private int maxColumnIndex=18;
+
+    private List<BusClinicExcelVO> source;
+
+    public ClinicExcelMergeWriteHandler(List<BusClinicExcelVO> source) {
+        this.source = source;
+    }
+
+    @Override
+    public void afterRowDispose(RowWriteHandlerContext context) {
+        Integer rowIndex = context.getRowIndex();
+        if(rowIndex!=CollectionUtil.size(source)+3){
+            return;
+        }
+        Integer lastRowIndex =rowIndex;
+        int lastMergeIndex=lastRowIndex;
+        int currentIndex=lastRowIndex;
+        while (currentIndex>=4){
+            int preIndex=currentIndex-1;
+            preIndex=preIndex>4?preIndex:4;
+            BusClinicExcelVO curSource = CollectionUtil.get(source, currentIndex-4);
+            BusClinicExcelVO preSource = CollectionUtil.get(source, preIndex-4);
+            if(!StrUtil.equals(curSource.getId(),preSource.getId())||currentIndex==4){
+                for (int i = 0; i <= maxColumnIndex; i++) {
+                    mergeCell(context.getWriteSheetHolder().getSheet(),currentIndex,lastMergeIndex,i,i);
+                }
+                lastMergeIndex=preIndex;
+            }
+            currentIndex--;
+        }
+    }
+
+    private void mergeCell(Sheet sheet,int startRowIndex, int endRowIndex, int startColumnIndex, int endColumnIndex){
+        //开始和结束行数一样
+        if(startRowIndex==endRowIndex){
+            return;
+        }
+        CellRangeAddress cellRangeAddress = new CellRangeAddress(startRowIndex, endRowIndex, startColumnIndex, endColumnIndex);
+        sheet.addMergedRegion(cellRangeAddress);
+    }
+
+}

+ 36 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/utils/ExportExcelUtils.java

@@ -0,0 +1,36 @@
+package com.nb.web.service.bus.utils;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.io.resource.ResourceUtil;
+import com.alibaba.excel.EasyExcel;
+import com.nb.web.service.bus.controller.vo.BusClinicExcelVO;
+import org.springframework.util.Base64Utils;
+import java.io.*;
+import java.util.*;
+/**
+ * @ClassName : ExportExcelUtils
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年10月11日
+ */
+public class ExportExcelUtils {
+    public static final byte[] clinic_pattern= IoUtil.readBytes(ResourceUtil.getStream("classpath:"+ File.separator+"export"+File.separator+"clinicExcel.xlsx"));
+
+    public static String exportClinicExcelBase64( List<BusClinicExcelVO> source)  {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        EasyExcel
+                .write(outputStream)
+                .withTemplate(IoUtil.toStream(clinic_pattern))
+                .registerWriteHandler(new ClinicExcelMergeWriteHandler(source))
+                .sheet().doFill(source);
+        try {
+            return bytesToBase64(outputStream.toByteArray());
+        }finally {
+            IoUtil.close(outputStream);
+        }
+    }
+
+    public static String bytesToBase64(byte[] bytes){
+        return "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"+Base64Utils.encodeToString(bytes);
+    }
+}

BIN
nb-service/web-service/src/main/resources/export/clinicExcel.xlsx