|
@ -0,0 +1,325 @@
|
|
|
package com.yihu.ehr.crawler.controller;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.yihu.core.constant.LogAttribute;
|
|
|
import com.yihu.core.util.log.BusinessLogger;
|
|
|
import com.yihu.core.util.log.DebugLogger;
|
|
|
import com.yihu.core.util.log.LogUtil;
|
|
|
import com.yihu.core.util.operator.DateUtil;
|
|
|
import com.yihu.ehr.mqhelper.ActiveMQHelper;
|
|
|
import com.yihu.ehr.vanguard.common.constant.*;
|
|
|
import com.yihu.ehr.vanguard.common.controller.BaseController;
|
|
|
import com.yihu.ehr.vanguard.crawler.DataCollectDispatcher;
|
|
|
import com.yihu.ehr.vanguard.crawler.service.patient.Patient;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 目前版本只需要采集,上传和注册病人档案就可了。
|
|
|
* <p>
|
|
|
* Created by Airhead on 2015/12/16.
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping(ApiVersionPrefix.CommonVersion + "/crawler")
|
|
|
@Api(protocols = "https", value = "CrawlerController", description = "档案采集接口", tags = {"采集"})
|
|
|
public class CrawlerController extends BaseController {
|
|
|
|
|
|
@RequestMapping(value = "/patient/fetch", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
|
|
|
public RestEcho fetch(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "patient", value = "病人索引信息", required = true)
|
|
|
@RequestParam(value = "patient", required = true) String patientInfo,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken,
|
|
|
HttpServletRequest request ) {
|
|
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
|
|
System.out.println(parameterMap);
|
|
|
boolean result = false;
|
|
|
RestEcho restEcho = new RestEcho();
|
|
|
try {
|
|
|
restEcho = tokenValid(userId, accessToken);
|
|
|
if (restEcho.getCode().asText().equals(Constants.OK)) {
|
|
|
Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
|
|
|
if (patient != null) {
|
|
|
boolean patientStore = DataCollectDispatcher.getInstance().isPatientStore(patient.getOrgCode(), patient.getPatientId(), patient.getEventNo());
|
|
|
if (patientStore && !LogicValues.LOGIC_TRUE.equals(patient.getReUploadFlg())) {//是否已传并不是为补传的病人
|
|
|
restEcho.failed(Constants.NO);
|
|
|
return restEcho;
|
|
|
}else {
|
|
|
result = DataCollectDispatcher.getInstance().collectData(patient);
|
|
|
}
|
|
|
}
|
|
|
if (!result) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
} else {
|
|
|
restEcho.success();
|
|
|
}
|
|
|
} else {
|
|
|
// token验证失败处理
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_COLLECT);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController采集异常", e);
|
|
|
}catch (Exception e) {
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_COLLECT);
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController采集异常", e);
|
|
|
}
|
|
|
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/query", method = RequestMethod.GET)
|
|
|
@ApiOperation(value = "查询病人健康档案", produces = "application/json", notes = "查询病人健康档案")
|
|
|
public RestEcho query(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "patient", value = "病人索引信息", required = true)
|
|
|
@RequestParam(value = "patient") String patient,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken) {
|
|
|
|
|
|
RestEcho restEcho = tokenValid(userId, accessToken);
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/check/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "检查病人是否已采集", produces = "application/json", notes = "检查病人是否已采集")
|
|
|
public RestEcho check(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "orgCode", value = "机构编码", required = true)
|
|
|
@PathVariable(value = "orgCode") String orgCode,
|
|
|
@ApiParam(name = "patientID", value = "病人ID", required = true)
|
|
|
@PathVariable(value = "patientID") String patientID,
|
|
|
@ApiParam(name = "eventNo", value = "事件号", required = true)
|
|
|
@PathVariable(value = "eventNo") String eventNo,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken) {
|
|
|
RestEcho restEcho = tokenValid(userId, accessToken);
|
|
|
boolean patientStore = DataCollectDispatcher.getInstance().isPatientStore(orgCode, patientID, eventNo);
|
|
|
if (patientStore) {
|
|
|
return restEcho.success();
|
|
|
}
|
|
|
|
|
|
return restEcho.failed(Constants.NO);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/transform/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "转换档案到标准格式", produces = "application/json", notes = "采集病人健康档案")
|
|
|
public String transform(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "orgCode", value = "机构编码", required = true)
|
|
|
@PathVariable(value = "orgCode") String orgCode,
|
|
|
@ApiParam(name = "patientID", value = "病人ID", required = true)
|
|
|
@PathVariable(value = "patientID") String patientID,
|
|
|
@ApiParam(name = "eventNo", value = "事件号", required = true)
|
|
|
@PathVariable(value = "eventNo") String eventNo,
|
|
|
@ApiParam(name = "content", value = "档案内容", required = true)
|
|
|
@PathVariable(value = "content") String content,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken) {
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/storage/{orgCode}/{patientID}/{eventNo}", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
|
|
|
public String storage(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "orgCode", value = "机构编码", required = true)
|
|
|
@PathVariable(value = "orgCode") String orgCode,
|
|
|
@ApiParam(name = "patientID", value = "病人ID", required = true)
|
|
|
@PathVariable(value = "patientID") String patientID,
|
|
|
@ApiParam(name = "eventNo", value = "事件号", required = true)
|
|
|
@PathVariable(value = "eventNo") String eventNo,
|
|
|
@ApiParam(name = "storageType", value = "保存类型", required = true)
|
|
|
@PathVariable(value = "storageType") String storageType,
|
|
|
@ApiParam(name = "content", value = "档案内容", required = true)
|
|
|
@PathVariable(value = "content") String content) {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/upload", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "向总支撑平台上传病人档案", produces = "application/json", notes = "向总支撑平台上传病人档案")
|
|
|
public RestEcho upload(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "patient", value = "病人索引信息", required = true)
|
|
|
@RequestParam(value = "patient", required = true) String patientInfo,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken,
|
|
|
HttpServletRequest request) {
|
|
|
RestEcho restEcho = tokenValid(userId, accessToken);
|
|
|
try {
|
|
|
if (restEcho.getCode().asText().equals(Constants.OK)) {
|
|
|
boolean result = false;
|
|
|
Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
|
|
|
if (patient != null) {
|
|
|
result = DataCollectDispatcher.getInstance().upload(patient);
|
|
|
}
|
|
|
if (!result) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
} else {
|
|
|
restEcho.success();
|
|
|
}
|
|
|
} else {
|
|
|
// token验证失败处理
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_UPLAOD);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.error(LogAttribute.MARK_EXCEPTION,request,LogAttribute.FAIL,"CrawlerController上传异常", e);
|
|
|
} catch (Exception e) {
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_UPLAOD);
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.fatal(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController上传异常", e);
|
|
|
}
|
|
|
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/register", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "向总支撑平台注册病人", produces = "application/json", notes = "向总支撑平台注册病人")
|
|
|
public RestEcho register(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "patient", value = "病人索引信息", required = true)
|
|
|
@RequestParam(value = "patient", required = true) String patientInfo,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken,
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
RestEcho restEcho = tokenValid(userId, accessToken);
|
|
|
try {
|
|
|
if (restEcho.getCode().asText().equals(Constants.OK)) {
|
|
|
boolean result = false;
|
|
|
Patient patient = DataCollectDispatcher.getInstance().parsePatient(patientInfo);
|
|
|
if (patient != null) {
|
|
|
result = DataCollectDispatcher.getInstance().register(patient);
|
|
|
}
|
|
|
if (!result) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
} else {
|
|
|
restEcho.success();
|
|
|
}
|
|
|
} else {
|
|
|
// token验证失败处理
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_REGISTER);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.error(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController注册异常", e);
|
|
|
} catch (Exception e) {
|
|
|
sendFailPatient(patientInfo, FlowType.AUTH_FAIL_REGISTER);
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.fatal(LogAttribute.MARK_EXCEPTION, request, LogAttribute.FAIL, "CrawlerController注册异常", e);
|
|
|
}
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/security/saveFail", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "安全认证失败病人保存", produces = "application/json", notes = "安全认证失败病人保存到队列")
|
|
|
public RestEcho saveAuthFail(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
@ApiParam(name = "patient", value = "病人索引信息", required = true)
|
|
|
@RequestParam(value = "patient", required = true) String patientInfo) {
|
|
|
RestEcho restEcho = new RestEcho();
|
|
|
DebugLogger.debug("saveAuthFail");
|
|
|
|
|
|
boolean succ= sendFailPatient(patientInfo, FlowType.AUTH_GEN_FAIL);
|
|
|
if (succ){
|
|
|
restEcho.success();
|
|
|
}else {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
}
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
|
|
|
public boolean sendFailPatient(String patientInfo, String failType) {
|
|
|
boolean result=false;
|
|
|
try {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
ObjectNode rootNode = objectMapper.readValue(patientInfo, ObjectNode.class);
|
|
|
rootNode.put(FlowType.AUTH_FAIL_TYPE, failType);
|
|
|
String patient = rootNode.toString();
|
|
|
ActiveMQHelper activeMQSender = new ActiveMQHelper();
|
|
|
activeMQSender.sendJSONMessage(FlowType.AUTH_FAIL_PATIENT, patient);
|
|
|
result=true;
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/patient/uploadLog", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "向总支撑平台上传日志文件", produces = "application/json", notes = "向总支撑平台上传日志文件")
|
|
|
public RestEcho uploadLog(
|
|
|
@ApiParam(name = "apiVersion", value = "API版本号", defaultValue = "v1.0")
|
|
|
@PathVariable(value = "apiVersion") String apiVersion,
|
|
|
// @ApiParam(name = "types", value = "日志类型", required = true)
|
|
|
// @RequestParam(value = "types", required = true) String[] types,
|
|
|
@ApiParam(name = "beginTime", value = "开始时间", required = true)
|
|
|
@RequestParam(value = "beginTime") String beginTime,
|
|
|
@ApiParam(name = "endTime", value = "结束时间", required = true)
|
|
|
@RequestParam(value = "endTime") String endTime,
|
|
|
@ApiParam(name = "userId", value = "用户ID", required = true)
|
|
|
@RequestParam(value = "userId") Integer userId,
|
|
|
@ApiParam(name = "accessToken", value = "数据令牌", required = true)
|
|
|
@RequestParam(value = "accessToken") String accessToken,
|
|
|
HttpServletRequest request) {
|
|
|
RestEcho restEcho = tokenValid(userId, accessToken);
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat(DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
|
|
|
try {
|
|
|
Date begin=sdf.parse(beginTime);
|
|
|
Date end=sdf.parse(endTime);
|
|
|
if (restEcho.getCode().asText().equals(Constants.OK)) {
|
|
|
boolean result = DataCollectDispatcher.getInstance().uploadLog(null,begin,end);
|
|
|
if (!result) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
} else {
|
|
|
restEcho.success();
|
|
|
}
|
|
|
} else {
|
|
|
System.out.println("---------------");
|
|
|
// TODO token验证失败处理
|
|
|
}
|
|
|
} catch (ParseException e) {
|
|
|
restEcho.failed(Constants.NO);
|
|
|
DebugLogger.fatal("CrawlerController日志上传异常", e);
|
|
|
}
|
|
|
|
|
|
return restEcho;
|
|
|
}
|
|
|
|
|
|
}
|