|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package thyyxxk.webserver.service.zhuyuanyisheng;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import cn.hutool.core.util.StrUtil;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -11,6 +12,8 @@ import thyyxxk.webserver.entity.criticalValue.CriticalValue;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.entity.criticalValue.InspectionType;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.entity.criticalValue.PatientType;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.entity.criticalValue.SimpleEmployee;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.criticalValue.request.CriticalValueFromTest;
 | 
	
		
			
				|  |  | +import thyyxxk.webserver.entity.dictionary.CodeName;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.entity.socketmessage.SendUserList;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.service.externalhttp.WebSocketService;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.service.outpatient.wxapi.SendWxInfoService;
 | 
	
	
		
			
				|  | @@ -19,9 +22,7 @@ import thyyxxk.webserver.utils.ResultVoUtil;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.utils.SocketMsg;
 | 
	
		
			
				|  |  |  import thyyxxk.webserver.utils.StringUtil;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -52,7 +53,11 @@ public class PatientCriticalValuesService {
 | 
	
		
			
				|  |  |              return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有住院号或门诊号。");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          dao.insertCriticalValue(criticalValue);
 | 
	
		
			
				|  |  | +        sendMessageToDoctors(criticalValue);
 | 
	
		
			
				|  |  | +        return ResultVoUtil.success();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void sendMessageToDoctors(CriticalValue criticalValue) {
 | 
	
		
			
				|  |  |          List<SimpleEmployee> employeeList = getTargetEmployees(criticalValue);
 | 
	
		
			
				|  |  |          List<String> codeList = new ArrayList<>();
 | 
	
		
			
				|  |  |          StringBuilder codeRsBuilder = new StringBuilder();
 | 
	
	
		
			
				|  | @@ -61,7 +66,6 @@ public class PatientCriticalValuesService {
 | 
	
		
			
				|  |  |              codeRsBuilder.append("|").append(employee.getCodeRs());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          String touser = codeRsBuilder.substring(1);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          String wxMessage = criticalValue.getContent() +
 | 
	
		
			
				|  |  |                  "<a href=\"https://emr.hnthyy.cn/hospitalAppsApi/criticalValue/updateState?id=" +
 | 
	
		
			
				|  |  |                  criticalValue.getId() + "\">点击更新危急值状态</a>";
 | 
	
	
		
			
				|  | @@ -69,13 +73,11 @@ public class PatientCriticalValuesService {
 | 
	
		
			
				|  |  |          if (sendWxRes == 0) {
 | 
	
		
			
				|  |  |              dao.updateSentState(criticalValue.getId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          JSONObject socketMessage = new JSONObject();
 | 
	
		
			
				|  |  |          socketMessage.put("message", criticalValue.getContent());
 | 
	
		
			
				|  |  |          socketMessage.put("id", criticalValue.getId());
 | 
	
		
			
				|  |  |          String msg = SocketMsg.socketVo(Message.critical_value, socketMessage);
 | 
	
		
			
				|  |  |          socketService.sendUserListMessage(new SendUserList(codeList, msg));
 | 
	
		
			
				|  |  | -        return ResultVoUtil.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private CriticalValue makeEntityFromMessage(String message) {
 | 
	
	
		
			
				|  | @@ -130,7 +132,6 @@ public class PatientCriticalValuesService {
 | 
	
		
			
				|  |  |              List<SimpleEmployee> tempList = dao.selectEmployeesByDept(ward);
 | 
	
		
			
				|  |  |              employeeList.addAll(tempList);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          List<String> tempCodeList = new ArrayList<>();
 | 
	
		
			
				|  |  |          if (StringUtil.notBlank(referPhysician)) {
 | 
	
		
			
				|  |  |              tempCodeList.add(referPhysician);
 | 
	
	
		
			
				|  | @@ -147,4 +148,52 @@ public class PatientCriticalValuesService {
 | 
	
		
			
				|  |  |          employeeList = employeeList.stream().distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  |          return employeeList;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public CodeName getTargetDept(String patNo, int times, PatientType patientType) {
 | 
	
		
			
				|  |  | +        if (patientType == PatientType.INPATIENT) {
 | 
	
		
			
				|  |  | +            return dao.selectTargetDept(patNo);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return dao.selectTargetDept2(patNo, times);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public ResultVo<String> checkTheCriticalValue(CriticalValueFromTest value) {
 | 
	
		
			
				|  |  | +        if (null == value.getFlag()) {
 | 
	
		
			
				|  |  | +            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
 | 
	
		
			
				|  |  | +                    "flag 门诊住院标志不存在 1=住院 2=门诊");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        PatientType patientType = value.getFlag() == 1 ?
 | 
	
		
			
				|  |  | +                PatientType.INPATIENT : PatientType.OUTPATIENT;
 | 
	
		
			
				|  |  | +        CodeName targetDept = getTargetDept(value.getPatNo(), value.getTimes(), patientType);
 | 
	
		
			
				|  |  | +        if (null == targetDept) {
 | 
	
		
			
				|  |  | +            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有患者的就诊信息");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String label = patientType == PatientType.INPATIENT ? "住院号" : "门诊号";
 | 
	
		
			
				|  |  | +        if (StringUtil.isBlank(value.getBednum())) {
 | 
	
		
			
				|  |  | +            value.setBednum("无");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        String message = StrUtil.format("在【{}】就诊患者 【{}:{},姓名:{},性别:{},年龄:{},床号:{}】的【{}】检查结果出现危急值情况--【{}】。报告者:{},来自:【{}】。",
 | 
	
		
			
				|  |  | +                targetDept.getName(), label, value.getPatNo(), value.getPatientName(),
 | 
	
		
			
				|  |  | +                value.getPatientSex(), value.getPatientAge(), value.getBednum(),
 | 
	
		
			
				|  |  | +                value.getReqName(), value.getMessage(), value.getCommitman(),
 | 
	
		
			
				|  |  | +                value.getRoomcood());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String msgId = UUID.randomUUID().toString().replaceAll("-", "");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        CriticalValue criticalValue = new CriticalValue.Builder()
 | 
	
		
			
				|  |  | +                .patNo(value.getPatNo()).msgId(msgId)
 | 
	
		
			
				|  |  | +                .msgType("dept_critical_msg")
 | 
	
		
			
				|  |  | +                .sourceCode(value.getSentByDepartment())
 | 
	
		
			
				|  |  | +                .sourceName(value.getRoomcood())
 | 
	
		
			
				|  |  | +                .targetDeptCode(targetDept.getCode())
 | 
	
		
			
				|  |  | +                .targetDeptName(targetDept.getName())
 | 
	
		
			
				|  |  | +                .content(message).createTime(new Date())
 | 
	
		
			
				|  |  | +                .inspectionType(InspectionType.TEST)
 | 
	
		
			
				|  |  | +                .patientType(patientType).build();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        dao.insertCriticalValue(criticalValue);
 | 
	
		
			
				|  |  | +        sendMessageToDoctors(criticalValue);
 | 
	
		
			
				|  |  | +        return ResultVoUtil.success();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |