保存提交时间

master
wyb 2 years ago
parent aa3746705d
commit f50fcd9ade

@ -0,0 +1,6 @@
[
{
"method": "WS_RECORD_SUBMIT",
"collectorIds": ["1","2"]
}
]

@ -0,0 +1,17 @@
package com.docus.server.message.api;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.message.api.dto.CompensateTaskDTO;
/**
* @author wyb
*/
public interface CollectTaskService {
/**
*,
* @param dto
* @return
*/
CommonResult<String> compensateTask(CompensateTaskDTO dto);
}

@ -0,0 +1,43 @@
package com.docus.server.message.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
*
*
* @author wyb
*/
@Data
@ApiModel("任务补偿下发参数")
public class CompensateTaskDTO {
/**
*
*/
@ApiModelProperty(value = "病案主键",required = true)
@NotNull(message = "病案主键不能为空")
@Size(min = 1,message = "病案主键不能为空")
private List<String> patientIds;
/**
*
*/
@ApiModelProperty(value = "采集器id",required = true)
@NotNull(message = "采集采集器id不能为空")
@Size(min = 1,message = "采集采集器id不能为空")
private List<String> collectorIds;
/**
*
*/
@NotNull(message = "队列优先级不能为空")
@Min(value = 1,message = "队列优先级不能小于1")
@Max(value = 10,message = "队列优先级不能大于10")
@ApiModelProperty(value = "队列优先级",required = true)
private Integer priority;
}

@ -0,0 +1,37 @@
package com.docus.server.message.api.impl;
import cn.hutool.http.HttpUtil;
import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.message.api.CollectTaskService;
import com.docus.server.message.api.dto.CompensateTaskDTO;
import com.docus.server.message.config.UrlConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author wyb
*/
@Service
public class CollectTaskServiceImpl implements CollectTaskService {
private UrlConfig urlConfig;
@Autowired
public void setUrlConfig(UrlConfig urlConfig) {
this.urlConfig = urlConfig;
}
@Override
public CommonResult<String> compensateTask(CompensateTaskDTO dto) {
String response = HttpUtil.post(urlConfig.getCompensateTaskUrl(), Func.toJson(dto));
CommonResult commonResult = Func.readJson(response, CommonResult.class);
Object data = commonResult.getData();
CommonResult<String> result = new CommonResult<>();
result.setCode(commonResult.getCode());
result.setMsgCode(commonResult.getMsgCode());
result.setMsg(commonResult.getMsg());
result.setData(data==null?null:String.valueOf(data));
return result;
}
}

@ -0,0 +1,13 @@
package com.docus.server.message.busservice;
import com.docus.server.message.dto.Message;
import com.docus.server.message.dto.MessageResponse;
public interface SdBusinessService {
/**
*
* @param message
* @return
*/
MessageResponse recordSubmitHandle(Message message);
}

@ -0,0 +1,207 @@
package com.docus.server.message.busservice.impl;
import com.docus.core.util.DateUtil;
import com.docus.core.util.Func;
import com.docus.infrastructure.core.exception.BaseException;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.infrastructure.web.api.ResultCode;
import com.docus.server.message.api.CollectTaskService;
import com.docus.server.message.api.dto.CompensateTaskDTO;
import com.docus.server.message.busservice.SdBusinessService;
import com.docus.server.message.config.CollectTaskConfig;
import com.docus.server.message.dto.Message;
import com.docus.server.message.dto.MessageResponse;
import com.docus.server.message.mapper.TBasicMapper;
import com.docus.server.message.util.XmlUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class SdBusinessServiceImpl implements SdBusinessService {
private CollectTaskService collectTaskService;
private TBasicMapper tBasicMapper;
@Autowired
public void setCollectTaskService(CollectTaskService collectTaskService) {
this.collectTaskService = collectTaskService;
}
@Autowired
public void settBasicMapper(TBasicMapper tBasicMapper) {
this.tBasicMapper = tBasicMapper;
}
@Override
public MessageResponse recordSubmitHandle(Message message) {
try {
CollectTaskConfig.TaskConfig taskConfig = CollectTaskConfig.getTaskConfig("WS_RECORD_SUBMIT");
if (taskConfig == null || Func.isEmpty(taskConfig.getCollectorIds())) {
throw new RuntimeException("任务配置未配置采集器id,WS_RECORD_SUBMIT");
}
RecordSubmitDTO recordSubmitDto = convert(message.getMessage());
verifyRecordSubmitDTO(recordSubmitDto);
List<String> patientIds = tBasicMapper.getPatientIdsByInpatientNoAndTimes(recordSubmitDto.getInHospIndexNo(), recordSubmitDto.getVisitNo());
verifyPatientIds(patientIds);
tBasicMapper.insertOrUpdateSubmitTime(patientIds.get(0),recordSubmitDto.getSubmitTime());
compensateTask(patientIds, taskConfig.getCollectorIds());
return new MessageResponse(ResultCode.SUCCESS.getCode(), success());
} catch (BaseException baseException) {
log.error(baseException.getMessage(), baseException);
// 业务异常,不希望重试,直接消息返回错误
MessageResponse response = new MessageResponse(ResultCode.FAILED.getCode(), fail(baseException.getMessage()));
response.setRetry(0);
return response;
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
// 不可知的错误,希望重试
MessageResponse response = new MessageResponse(ResultCode.FAILED.getCode(), fail("系统错误"));
response.setRetry(1);
return response;
}
}
private void verifyRecordSubmitDTO(RecordSubmitDTO recordSubmitDto) {
if (Func.isBlank(recordSubmitDto.getInHospIndexNo())) {
throw new BaseException("住院号不能为空!");
}
if (Func.isEmpty(recordSubmitDto.getVisitNo())) {
throw new BaseException("住院次数不能为空!");
}
if (Func.isEmpty(recordSubmitDto.getSubmitTime())) {
throw new BaseException("提交时间不能为空!");
}
if (Func.isEmpty(recordSubmitDto.getInHospState())) {
throw new BaseException("住院状态不能为空!");
}
if (recordSubmitDto.getInHospState() != 1) {
throw new BaseException("住院状态需要为已出院!");
}
}
private void compensateTask(List<String> patientIds, List<String> collectorIds) {
CompensateTaskDTO dto = new CompensateTaskDTO();
dto.setPatientIds(patientIds);
dto.setCollectorIds(collectorIds);
dto.setPriority(4);
log.info("补偿电子病历任务 数据:{}", dto);
CommonResult<String> task = collectTaskService.compensateTask(dto);
if (ResultCode.FAILED.getCode().equals(task.getCode())) {
throw new RuntimeException("补偿失败!");
}
}
private void verifyPatientIds(List<String> patientIds) {
if (Func.isEmpty(patientIds)) {
throw new BaseException("住院号+住院次数 ,系统无此患者!");
}
if (patientIds.size() > 1) {
throw new BaseException("住院号+住院次数 ,系统中患者有多个!");
}
}
private RecordSubmitDTO convert(String str) {
String inHospNo=null;
String inHospIndexNo=null;
Integer visitNo=null;
String name=null;
Date submitTime=null;
Integer inHospState=null;
XmlUtil xmlUtil = XmlUtil.of(str);
try {
// 住院状态 住院状态 0在院 1出院
Node inHospStateNode = xmlUtil.getNode("/Request/Msg/INHOSP_STATE");
inHospState=Integer.parseInt(inHospStateNode.getTextContent());
}catch (Exception ex){
throw new BaseException("解析住院状态出错!");
}
try {
// 住院流水号
Node inHospNoNode = xmlUtil.getNode("/Request/Msg/INHOSP_NO");
inHospNo=inHospNoNode.getTextContent();
} catch (Exception ex) {
throw new BaseException("解析 住院流水号 出错!");
}
try {
// 住院号
Node inHospIndexNoNode = xmlUtil.getNode("/Request/Msg/INHOSP_INDEX_NO");
inHospIndexNo=inHospIndexNoNode.getTextContent();
} catch (Exception ex) {
throw new BaseException("解析 住院号 出错!");
}
try {
// 住院次数
Node visitNoNode = xmlUtil.getNode("/Request/Msg/VISIT_NO");
visitNo=Integer.parseInt(visitNoNode.getTextContent());
} catch (Exception ex) {
throw new BaseException("解析 住院次数 出错!");
}
try {
// 患者姓名
Node nameNode = xmlUtil.getNode("/Request/Msg/NAME");
name=nameNode.getTextContent();
} catch (Exception ex) {
throw new BaseException("解析 出错!");
}
try {
// 提交时间
Node submitTimeNode = xmlUtil.getNode("/Request/Msg/SUBMIT_TIME");
submitTime= DateUtil.parse(submitTimeNode.getTextContent(), DateUtil.PATTERN_DATETIME);
} catch (Exception ex) {
throw new BaseException("解析 提交时间 出错!");
}
RecordSubmitDTO recordSubmitDTO = new RecordSubmitDTO();
recordSubmitDTO.setInHospNo(inHospNo);
recordSubmitDTO.setVisitNo(visitNo);
recordSubmitDTO.setInHospState(inHospState);
recordSubmitDTO.setName(name);
recordSubmitDTO.setInHospIndexNo(inHospIndexNo);
recordSubmitDTO.setSubmitTime(submitTime);
return recordSubmitDTO;
}
private String success() {
return "<Response>" +
"<RetInfo>" +
"<RetCode>0</RetCode>" +
"<RetCon>成功</RetCon>" +
"</RetInfo>" +
"</Response>";
}
private String fail(String message) {
return "<Response>" +
"<RetInfo>" +
"<RetCode>1</RetCode>" +
"<RetCon>" + message + "</RetCon>" +
"</RetInfo>" +
"</Response>";
}
@Data
private static class RecordSubmitDTO {
// 住院流水号
private String inHospNo;
// 住院号
private String inHospIndexNo;
// 住院次数
private Integer visitNo;
// 患者姓名
private String name;
// 提交时间
private Date submitTime;
// 住院状态0在院 1出院
private Integer inHospState;
}
}

@ -0,0 +1,41 @@
package com.docus.server.message.config;
import com.docus.core.util.Func;
import com.docus.server.message.util.TableJsonRead;
import lombok.Data;
import java.util.List;
import java.util.Objects;
/**
* @author wyb
*/
public class CollectTaskConfig {
private final static String CONFIG_FILE_PATH = "data-config";
private final static String CONFIG_FILE_NAME = "collect-task-config.json";
public static TaskConfig getTaskConfig(String method) {
Objects.requireNonNull(method);
TableJsonRead jsonReader = new TableJsonRead();
String taskConfigJson = jsonReader.ReadContent(CONFIG_FILE_PATH, CONFIG_FILE_NAME);
if (taskConfigJson == null) {
return null;
}
List<TaskConfig> taskConfigList = Func.parseJsonArray(taskConfigJson, TaskConfig.class);
if (Func.isEmpty(taskConfigList)) {
return null;
}
for (TaskConfig taskConfig : taskConfigList) {
if (method.equals(taskConfig.getMethod())) {
return taskConfig;
}
}
return null;
}
@Data
public static class TaskConfig {
private String method;
private List<String> collectorIds;
}
}

@ -9,10 +9,11 @@ import org.springframework.stereotype.Component;
*
* @author wyb
*/
@Component
@Getter
@Setter
@ConfigurationProperties(prefix = "docus.url")
@Component
public class UrlConfig {
/**
*

@ -1,11 +1,12 @@
package com.docus.server.message.controller;
import com.docus.infrastructure.web.api.ResultCode;
import com.docus.server.message.busservice.SdBusinessService;
import com.docus.server.message.dto.Message;
import com.docus.server.message.dto.MessageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -22,11 +23,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/message/receive")
public class MessageReceiveController {
private SdBusinessService sdBusinessService;
@Autowired
public void setSdBusinessService(SdBusinessService sdBusinessService){
this.sdBusinessService=sdBusinessService;
}
@PostMapping("/wsRecordSubmit/do")
@ApiOperation("消息接收测试")
public MessageResponse receiveMessage(@RequestBody Message message) {
System.out.println("wsRecordSubmit" + message);
return new MessageResponse(ResultCode.SUCCESS.getCode(), "成功接收到了!");
return sdBusinessService.recordSubmitHandle(message);
}
}

@ -9,8 +9,16 @@ import lombok.Setter;
@Getter
@Setter
public class MessageResponse {
/**
* @see com.docus.infrastructure.web.api.ResultCode#SUCCESS
* @see com.docus.infrastructure.web.api.ResultCode#FAILED
*/
private Integer respCode;
private String respMessage;
/**
* 0 1
*/
private int retry;
public MessageResponse(Integer respCode, String respMessage) {
this.respCode = respCode;

@ -0,0 +1,13 @@
package com.docus.server.message.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
public interface TBasicMapper{
List<String> getPatientIdsByInpatientNoAndTimes(@Param("inpatientNo")String inHospIndexNo, @Param("admissTimes") Integer visitNo);
int insertOrUpdateSubmitTime(@Param("patientId") String patientId, @Param("submitTime") Date submitTime);
}

@ -76,6 +76,11 @@ public class UnifyMessageServiceImpl implements UnifyMessageService {
}
private String verifyMessageResponseAndGetReturnMessage(List<MessageResponse> responseLis) {
for (MessageResponse response : responseLis) {
if (response.getRetry()==1) {
throw new RuntimeException("需要重试!");
}
}
responseLis = responseLis.stream().filter(item -> Func.isNotEmpty(item.getRespCode())).collect(Collectors.toList());
if (Func.isEmpty(responseLis)) {
throw new RuntimeException("未收到成功和失败的返回结果!");

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.docus.server.message.mapper.TBasicMapper">
<insert id="insertOrUpdateSubmitTime">
insert into `docus_medicalrecord`.`t_basic_extend` (patient_id,doctor_submit_time) values (#{patientId},#{submitTime})
ON DUPLICATE KEY UPDATE doctor_submit_time=#{submitTime}
</insert>
<select id="getPatientIdsByInpatientNoAndTimes" resultType="java.lang.String">
SELECT patient_id
FROM `docus_medicalrecord`.t_basic tb
WHERE tb.inpatient_no=#{inpatientNo} and tb.admiss_times=#{admissTimes}
</select>
</mapper>
Loading…
Cancel
Save