|
@@ -0,0 +1,191 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.diagbot.dto.MedicalRecordDTO;
|
|
|
+import com.diagbot.entity.MedBehospitalType;
|
|
|
+import com.diagbot.entity.MedCheckWork;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.impl.MedBehospitalTypeServiceImpl;
|
|
|
+import com.diagbot.service.impl.MedCheckWorkServiceImpl;
|
|
|
+import com.diagbot.service.impl.MedicalRecordServiceImpl;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.SysUserUtils;
|
|
|
+import com.diagbot.vo.MedCheckWorkAddVO;
|
|
|
+import com.diagbot.vo.RecordContentVO;
|
|
|
+import com.diagbot.vo.RecordTypeVO;
|
|
|
+import com.diagbot.vo.TaskVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author songxl
|
|
|
+ * @since 2021-05-11
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class MedCheckWorkFacade extends MedCheckWorkServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ private MedCheckWorkServiceImpl medCheckWorkServiceImpl;
|
|
|
+ @Autowired
|
|
|
+ private MedBehospitalTypeServiceImpl medBehospitalTypeServiceImpl;
|
|
|
+ @Autowired
|
|
|
+ private MedicalRecordServiceImpl medicalRecordServiceImpl;
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 批量插入任务
|
|
|
+ * @Date 2021/5/11
|
|
|
+ * @Param [medCheckWorkVOList]
|
|
|
+ * @Return java.lang.Boolean
|
|
|
+ * @MethodName addCheck
|
|
|
+ */
|
|
|
+ public Boolean addCheck(ArrayList<MedCheckWorkAddVO> medCheckWorkVOList) {
|
|
|
+
|
|
|
+ Long hospitalId = Long.parseLong(SysUserUtils.getCurrentHospitalID());
|
|
|
+ String create = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ List<MedCheckWork> checkWorkList = new ArrayList<>();
|
|
|
+ for(MedCheckWorkAddVO medCheckWorkAddVO:medCheckWorkVOList)
|
|
|
+ {
|
|
|
+ //入参验证
|
|
|
+ if (StringUtil.isBlank(medCheckWorkAddVO.getBehospitalCode())
|
|
|
+ ||StringUtil.isBlank(medCheckWorkAddVO.getWorkType())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "病历id或任务类型不能为空!");
|
|
|
+ }
|
|
|
+ MedCheckWork medCheckWork = new MedCheckWork();
|
|
|
+ medCheckWork.setHospitalId(hospitalId);
|
|
|
+ medCheckWork.setCreator(create);
|
|
|
+ medCheckWork.setGmtCreate(DateUtil.now());
|
|
|
+ medCheckWork.setBehospitalCode(medCheckWorkAddVO.getBehospitalCode());
|
|
|
+ medCheckWork.setWorkType(medCheckWorkAddVO.getWorkType());
|
|
|
+
|
|
|
+ medCheckWork.setId(Long.valueOf(medCheckWorkAddVO.getBehospitalCode()));
|
|
|
+ checkWorkList.add(medCheckWork);
|
|
|
+ }
|
|
|
+ return medCheckWorkServiceImpl.saveBatch(checkWorkList,10);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 获取每日住院患者的类型(出院、病危、抢救。。。)
|
|
|
+ * @Date 2021/5/11
|
|
|
+ * @Param [param]
|
|
|
+ * @Return void
|
|
|
+ * @MethodName execute
|
|
|
+ */
|
|
|
+ public void execute(String param) {
|
|
|
+ JSONObject paramJson = JSONObject.parseObject(param);
|
|
|
+ Long hospiatlId = paramJson.getLong("hospital");
|
|
|
+ JSONObject typeValue = paramJson.getJSONObject("typeVal");
|
|
|
+ JSONObject typeName = paramJson.getJSONObject("typeName");
|
|
|
+ int searchSize = paramJson.getInteger("searchSize");
|
|
|
+ int batchSize = paramJson.getInteger("batchSize");
|
|
|
+
|
|
|
+
|
|
|
+ //定义批量插入的集合
|
|
|
+ HashMap<String,MedBehospitalType> medBehospitalTypeMap = null;
|
|
|
+ //1.判断患者类型表是否有记录
|
|
|
+ int count = medBehospitalTypeServiceImpl.count();
|
|
|
+ if(count>0)
|
|
|
+ {
|
|
|
+ medBehospitalTypeMap = new HashMap<>();
|
|
|
+ //2.1获取最近指定归档时间间隔的患者
|
|
|
+ RecordTypeVO recordContentVO = new RecordTypeVO();
|
|
|
+ recordContentVO.setHospitalId(hospiatlId);
|
|
|
+ recordContentVO.setModeList(new ArrayList<String>(typeValue.keySet()));
|
|
|
+ recordContentVO.setIsPlacefile(1l);//获取已归档的患者
|
|
|
+ recordContentVO.setStartTime(DateUtil.formatDateTime(DateUtil.addMinutes(DateUtil.now(),-30)));
|
|
|
+ recordContentVO.setEndTime(DateUtil.formatDateTime(DateUtil.now()));
|
|
|
+ getPatientRecordType(medBehospitalTypeMap,
|
|
|
+ medicalRecordServiceImpl.getMedicalRecord(recordContentVO),typeValue,typeName,hospiatlId);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //2.2添加今天之前所有患者的类型
|
|
|
+ //2.2.1获取所有数据数量
|
|
|
+ medBehospitalTypeMap = new HashMap<>();
|
|
|
+ RecordTypeVO recordContentVO = new RecordTypeVO();
|
|
|
+ recordContentVO.setHospitalId(hospiatlId);
|
|
|
+ recordContentVO.setModeList(new ArrayList<String>(typeValue.keySet()));
|
|
|
+ recordContentVO.setIsPlacefile(1l);//获取已归档的患者
|
|
|
+ int num = medicalRecordServiceImpl.getRecordCount(recordContentVO);
|
|
|
+ if(num>0)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(num<searchSize)
|
|
|
+ {
|
|
|
+ //执行一次
|
|
|
+ recordContentVO.setStart(0L);
|
|
|
+ recordContentVO.setEnd(num+0L);
|
|
|
+ getPatientRecordType(medBehospitalTypeMap,
|
|
|
+ medicalRecordServiceImpl.getMedicalRecord(recordContentVO),typeValue,typeName,hospiatlId);
|
|
|
+ }
|
|
|
+ int i = num/searchSize+1;
|
|
|
+ for(int j=0;j<i;j++)
|
|
|
+ {
|
|
|
+ //5000个一次循环添加
|
|
|
+ recordContentVO.setStart(j*searchSize*1L);
|
|
|
+ recordContentVO.setEnd(searchSize*1L);
|
|
|
+ getPatientRecordType(medBehospitalTypeMap,
|
|
|
+ medicalRecordServiceImpl.getMedicalRecord(recordContentVO),typeValue,typeName,hospiatlId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.批量执行插入操作
|
|
|
+ if(medBehospitalTypeMap.size()>0)
|
|
|
+ {
|
|
|
+ List<MedBehospitalType> medBehospitalTypeList = new ArrayList<>(medBehospitalTypeMap.values());
|
|
|
+ medBehospitalTypeServiceImpl.saveBatch(medBehospitalTypeList,batchSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Author songxl
|
|
|
+ * @Description 获取患者类型存入批量插入map
|
|
|
+ * @Date 2021/5/11
|
|
|
+ * @Param [medBehospitalTypeMap, medicalRecordList, typeValue, typeName, hospiatlId]
|
|
|
+ * @Return void
|
|
|
+ * @MethodName getPatientRecordType
|
|
|
+ */
|
|
|
+ private void getPatientRecordType(HashMap<String,MedBehospitalType> medBehospitalTypeMap,
|
|
|
+ List<MedicalRecordDTO> medicalRecordList,
|
|
|
+ JSONObject typeValue,
|
|
|
+ JSONObject typeName,Long hospiatlId) {
|
|
|
+
|
|
|
+ if(medicalRecordList==null || medicalRecordList.isEmpty()){return;}
|
|
|
+ //1.遍历查询出来的结果
|
|
|
+ for(MedicalRecordDTO medicalRecordDTO:medicalRecordList)
|
|
|
+ {
|
|
|
+ //2.判断批量插入map中有没有这个患者
|
|
|
+ if(medBehospitalTypeMap.containsKey(medicalRecordDTO.getBehospitalCode()))
|
|
|
+ {
|
|
|
+ //3.比较这两次的分值大小
|
|
|
+ int lval = medBehospitalTypeMap.get(medicalRecordDTO.getBehospitalCode()).getValue();
|
|
|
+ int nval = typeValue.getInteger(medicalRecordDTO.getModeId()+"");
|
|
|
+ if(nval>lval)
|
|
|
+ {
|
|
|
+ medBehospitalTypeMap.get(medicalRecordDTO.getBehospitalCode()).setValue(nval);
|
|
|
+ medBehospitalTypeMap.get(medicalRecordDTO.getBehospitalCode())
|
|
|
+ .setBehospitalType(typeName.getString(medicalRecordDTO.getModeId()+""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //4.获取分值记录这个患者
|
|
|
+ MedBehospitalType medBehospitalType = new MedBehospitalType();
|
|
|
+ medBehospitalType.setBehospitalCode(medicalRecordDTO.getBehospitalCode());
|
|
|
+ medBehospitalType.setBehospitalType(typeName.getString(medicalRecordDTO.getModeId()+""));
|
|
|
+ medBehospitalType.setValue(typeValue.getInteger(medicalRecordDTO.getModeId()+""));
|
|
|
+ medBehospitalType.setCreateTime(DateUtil.now());
|
|
|
+ medBehospitalType.setHospitalId(hospiatlId);
|
|
|
+ medBehospitalTypeMap.put(medicalRecordDTO.getBehospitalCode(),medBehospitalType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|