|
|
|
|
package com.ann.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.ann.entity.constant.AliasName;
|
|
|
|
|
import com.ann.entity.constant.InterfaceName;
|
|
|
|
|
import com.ann.entity.filing.ArchiveDetail;
|
|
|
|
|
import com.ann.entity.filing.MessageSubordinate;
|
|
|
|
|
import com.ann.entity.filing.dto.MessageDto;
|
|
|
|
|
import com.ann.entity.interfaceEntity.ArchiveMaster;
|
|
|
|
|
import com.ann.entity.interfaceEntity.InterfaceHisCache;
|
|
|
|
|
import com.ann.entity.interfaceEntity.MessageLog;
|
|
|
|
|
import com.ann.entity.interfaceEntity.ScanningFile;
|
|
|
|
|
import com.ann.service.*;
|
|
|
|
|
import com.ann.utils.*;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author: LeiJiaXin
|
|
|
|
|
* @Date: 2019/7/11 22:00
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class QueueService {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(QueueService.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
InterfaceHisCacheService interfaceHisCacheService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
MessageSubordinateService messageSubordinateService;
|
|
|
|
|
@Autowired
|
|
|
|
|
ArchiveMasterService archiveMasterService;
|
|
|
|
|
@Autowired
|
|
|
|
|
ArchiveDetailService archiveDetailService;
|
|
|
|
|
@Autowired
|
|
|
|
|
MessageService messageService;
|
|
|
|
|
|
|
|
|
|
//---------------------定时器
|
|
|
|
|
public void doSomething(List<MessageSubordinate> all) throws Exception {
|
|
|
|
|
if (all.size() > 0) {
|
|
|
|
|
for (MessageSubordinate messageSubordinate : all) {
|
|
|
|
|
Integer status = 2;
|
|
|
|
|
ArchiveDetail archiveDetail = null;
|
|
|
|
|
try {
|
|
|
|
|
// 解析内容
|
|
|
|
|
MessageLog messageLog = JSON.parseObject(messageSubordinate.getContentJson(), MessageLog.class);
|
|
|
|
|
if (messageLog != null) {
|
|
|
|
|
String outJson = messageLog.getOutJson();
|
|
|
|
|
if (outJson != null) {
|
|
|
|
|
MessageDto messageDto = JSON.parseObject(outJson, MessageDto.class);
|
|
|
|
|
if (messageDto.getSource().equals(InterfaceName.NURSE_DATA) && (messageDto.getReportAddress().endsWith(".jpg")
|
|
|
|
|
|| messageDto.getReportAddress().endsWith(".JPG") )){
|
|
|
|
|
messageSubordinate.setRemark("住院号:" + messageDto.getInpNo() + "pdf路径为空(可能出现下载问题)。。。");
|
|
|
|
|
} else {
|
|
|
|
|
ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(messageDto.getInpNo(), messageDto.getVisitId());
|
|
|
|
|
if (archiveMaster != null) {
|
|
|
|
|
if(!Objects.equals(messageDto.getType(),AliasName.PATHOLOGY_REPORT)){
|
|
|
|
|
if(archiveMaster.getArchiveState().equals("初审") || archiveMaster.getArchiveState().equals("已归档")){
|
|
|
|
|
messageSubordinate.setStatus(3);
|
|
|
|
|
messageSubordinateService.save(messageSubordinate);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String address = messageDto.getReportAddress();
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
if (address != null && (!address.equals(""))) {
|
|
|
|
|
// 如果是老数据
|
|
|
|
|
if(Objects.equals(messageDto.getIsOld(),"0")){
|
|
|
|
|
archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),messageDto.getDetailType(),1);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
}else{
|
|
|
|
|
// 查询库中是否存在 如果存在就更新
|
|
|
|
|
archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId());
|
|
|
|
|
if (archiveDetail == null) {
|
|
|
|
|
archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),
|
|
|
|
|
messageDto.getDetailType(),1);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
}else{
|
|
|
|
|
//更新时间
|
|
|
|
|
archiveDetail.setUpLoadDateTime(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
String pdfPath = null;
|
|
|
|
|
String emrPath = "";
|
|
|
|
|
|
|
|
|
|
if(messageDto.getSource().equals(InterfaceName.NURSE_DATA)){
|
|
|
|
|
//医生 护理单独做处理
|
|
|
|
|
if(archiveMaster.getEmrNurseCmt() == null){
|
|
|
|
|
archiveMaster.setEmrNurseCmt("提交");
|
|
|
|
|
archiveMasterService.save(archiveMaster);
|
|
|
|
|
}
|
|
|
|
|
String a = "";
|
|
|
|
|
if(messageDto.getApplyId().lastIndexOf("_") != -1){
|
|
|
|
|
a = messageDto.getApplyId().substring(0, messageDto.getApplyId().indexOf(".pdf"));
|
|
|
|
|
}else{
|
|
|
|
|
a = address.substring(0, address.lastIndexOf("_"));
|
|
|
|
|
}
|
|
|
|
|
emrPath = messageDto.getType() + "~" + (a.substring(a.lastIndexOf("_") + 1, a.length())) + "~";
|
|
|
|
|
|
|
|
|
|
} else if(messageDto.getSource().equals(InterfaceName.DOCTOR_DATA)){
|
|
|
|
|
//护士 护理单独做处理
|
|
|
|
|
if(archiveMaster.getEmrDoctorCmt() == null){
|
|
|
|
|
archiveMaster.setEmrDoctorCmt("提交");
|
|
|
|
|
archiveMasterService.save(archiveMaster);
|
|
|
|
|
}
|
|
|
|
|
emrPath = messageDto.getType() + "~" + messageDto.getCaptionDateTime() + "~";
|
|
|
|
|
}else{
|
|
|
|
|
// 20200518 给重症系统的文件排序
|
|
|
|
|
if(messageDto.getType().equals(AliasName.ICU_REPORT)){
|
|
|
|
|
//重症如果是pdf
|
|
|
|
|
emrPath = messageDto.getDetailType() + "~" + messageDto.getCaptionDateTime() + "~";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), emrPath);
|
|
|
|
|
if (pdfFile != null) {
|
|
|
|
|
if (address.endsWith(".pdf") || address.endsWith(".PDF")) {
|
|
|
|
|
String path = DownloadUtils.downLoadPdfFile(pdfFile, address, messageDto.getType());
|
|
|
|
|
if (path != null) {
|
|
|
|
|
pdfPath = path;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Objects.equals(messageDto.getType(), AliasName.ICU_REPORT)) {
|
|
|
|
|
File file = pdfFile;
|
|
|
|
|
if(address.indexOf(".png") != -1){
|
|
|
|
|
file = FileUtils.createDir("images", messageDto.getInpNo(), messageDto.getVisitId());
|
|
|
|
|
}
|
|
|
|
|
String fileNames = DownloadUtils.downloadImageFiles(address, file.getParent());
|
|
|
|
|
if(fileNames != null){
|
|
|
|
|
if(address.indexOf(".png") != -1) {
|
|
|
|
|
// 多个图片那么转成pdf
|
|
|
|
|
pdfPath = PdfUtils.imageDirToPdf(fileNames, pdfFile);
|
|
|
|
|
} else{
|
|
|
|
|
if(fileNames.indexOf(";") != -1){
|
|
|
|
|
fileNames = fileNames.substring(0,fileNames.length()-1);
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(new File(fileNames).renameTo(file)){
|
|
|
|
|
pdfPath = file.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 一张图片转成pdf
|
|
|
|
|
File imageFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), emrPath);
|
|
|
|
|
if (DownloadUtils.downloadImageFile(address, messageDto.getType(), imageFile)) {
|
|
|
|
|
pdfPath = PdfUtils.imagesToPdf(imageFile, pdfFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//存入pdf地址
|
|
|
|
|
if (pdfPath != null) {
|
|
|
|
|
// 转成格式
|
|
|
|
|
archiveDetail.setPdfPath(pdfPath);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
|
|
|
|
|
//更新messageLog的最后执行时间
|
|
|
|
|
Date xmlCreateTime = messageLog.getXmlCreateTime();
|
|
|
|
|
long beginTime = xmlCreateTime.getTime();
|
|
|
|
|
long endTime = date.getTime();
|
|
|
|
|
messageLog.setXmlExecutionTime(endTime - beginTime);
|
|
|
|
|
|
|
|
|
|
messageService.save(messageLog);
|
|
|
|
|
// 成功
|
|
|
|
|
status = 1;
|
|
|
|
|
} else {
|
|
|
|
|
status = 2;
|
|
|
|
|
messageSubordinate.setRemark("住院号:" + messageDto.getInpNo() + "pdf路径为空(可能出现下载问题)。。。");
|
|
|
|
|
if (archiveDetail.getId() != null) {
|
|
|
|
|
archiveDetailService.delete(archiveDetail.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 判断是否是扫描文件
|
|
|
|
|
if(messageDto.getType().equals(AliasName.SCANNING_FILE)){
|
|
|
|
|
String outContent = this.handlePdfFile(messageDto, archiveMaster.getId());
|
|
|
|
|
if(outContent == null){
|
|
|
|
|
status = 1;
|
|
|
|
|
//更新messageLog的最后执行时间
|
|
|
|
|
Date xmlCreateTime = messageLog.getXmlCreateTime();
|
|
|
|
|
long beginTime = xmlCreateTime.getTime();
|
|
|
|
|
long endTime = date.getTime();
|
|
|
|
|
messageLog.setXmlExecutionTime(endTime - beginTime);
|
|
|
|
|
|
|
|
|
|
messageService.save(messageLog);
|
|
|
|
|
}else{
|
|
|
|
|
messageSubordinate.setRemark(outContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
messageSubordinate.setRemark("地址为空。。。。");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
messageSubordinate.setRemark("住院号为:" + messageDto.getInpNo() + "的ArchiveMaster为空。。。。");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 设置参数
|
|
|
|
|
messageSubordinate.setRemark(e + "");
|
|
|
|
|
// 报错删掉患者报告详情信息
|
|
|
|
|
if (archiveDetail != null) {
|
|
|
|
|
if (archiveDetail.getId() != null) {
|
|
|
|
|
archiveDetailService.delete(archiveDetail.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
messageSubordinate.setStatus(status);
|
|
|
|
|
|
|
|
|
|
// 判断次数等于多少
|
|
|
|
|
if (messageSubordinate.getRuns() < 6 && messageSubordinate.getStatus() == 2) {
|
|
|
|
|
Integer runs = messageSubordinate.getRuns();
|
|
|
|
|
messageSubordinate.setRuns(runs + 1);
|
|
|
|
|
}
|
|
|
|
|
messageSubordinateService.save(messageSubordinate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定时器:根据第一次 没有成功的消息 重新尝试
|
|
|
|
|
public void doSomethingByError(List<MessageSubordinate> all) throws Exception {
|
|
|
|
|
if (all.size() > 0) {
|
|
|
|
|
for (MessageSubordinate messageSubordinate : all) {
|
|
|
|
|
messageSubordinate.setStatus(0);
|
|
|
|
|
messageSubordinateService.save(messageSubordinate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String handlePdfFile(MessageDto messageDto,String masterId) throws Exception {
|
|
|
|
|
try {
|
|
|
|
|
ScanningFile scanningFile = JSON.parseObject(messageDto.getObject().toString(), ScanningFile.class);
|
|
|
|
|
if (scanningFile == null) {
|
|
|
|
|
return "扫描文件解析实体错误。。。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object[] objects = WebServiceUtils.connect(scanningFile.getPath() + "\\" + scanningFile.getFileName());
|
|
|
|
|
if (objects == null) {
|
|
|
|
|
return "扫描文件下载图片出错了。。。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] bytes = (byte[]) objects[0];
|
|
|
|
|
String path = (scanningFile.getApplyId() != null ? scanningFile.getApplyId() : "") + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : "");
|
|
|
|
|
// 给临时图片填充内容
|
|
|
|
|
File imageTempFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(), path);
|
|
|
|
|
File imageFile = FileUtils.getImageFileByByteArray(bytes, imageTempFile);
|
|
|
|
|
if (imageFile == null) {
|
|
|
|
|
return "扫描文件填充临时图片出错了。。。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), path);
|
|
|
|
|
String pdfPath = PdfUtils.imagesToPdf(imageFile, pdfFile);
|
|
|
|
|
//存入pdf地址
|
|
|
|
|
if (pdfPath == null) {
|
|
|
|
|
return "扫描文件image转成pdf出错了。。。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果存在 那就更新
|
|
|
|
|
ArchiveDetail archiveDetail = archiveDetailService.isExit(masterId, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId() + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : ""));
|
|
|
|
|
if (archiveDetail == null) {
|
|
|
|
|
archiveDetail = new ArchiveDetail(masterId, new Date(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId() + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : ""), pdfPath);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return e + "";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void doSomethingByHIS() {
|
|
|
|
|
try {
|
|
|
|
|
//循环开始处理 所有未处理的
|
|
|
|
|
List<InterfaceHisCache> interfaceHisCaches = interfaceHisCacheService.findInterfaceHisCacheByState();
|
|
|
|
|
for (InterfaceHisCache interfaceHisCache: interfaceHisCaches) {
|
|
|
|
|
String type = null,remark = null,title = null,pdfPath = null,state = "2";
|
|
|
|
|
ArchiveDetail archiveDetail = null;
|
|
|
|
|
try{
|
|
|
|
|
ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId());
|
|
|
|
|
if(archiveMaster != null){
|
|
|
|
|
if(interfaceHisCache.getType() != null){
|
|
|
|
|
//给type 属性赋值
|
|
|
|
|
if(Objects.equals(interfaceHisCache.getType(),"0")){
|
|
|
|
|
type = AliasName.SOS;
|
|
|
|
|
title = "临时医嘱";
|
|
|
|
|
}else if(Objects.equals(interfaceHisCache.getType(),"1")){
|
|
|
|
|
type = AliasName.PRN;
|
|
|
|
|
title = "长期医嘱";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询库中是否存在 如果存在就更新
|
|
|
|
|
archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), interfaceHisCache.getType(), "HIS系统", "");
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
if (archiveDetail == null) {
|
|
|
|
|
archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, type, "HIS系统", "",
|
|
|
|
|
title ,1);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
}else{
|
|
|
|
|
//更新时间
|
|
|
|
|
archiveDetail.setUpLoadDateTime(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始下载
|
|
|
|
|
File pdfFile = FileUtils.createFile("pdfs", interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId(), archiveDetail.getId(), "");
|
|
|
|
|
if (pdfFile != null) {
|
|
|
|
|
if (interfaceHisCache.getPdfPath().endsWith(".pdf") || interfaceHisCache.getPdfPath().endsWith(".PDF")) {
|
|
|
|
|
pdfPath = DownloadUtils.downLoadPdfFile(pdfFile, interfaceHisCache.getPdfPath(), type);
|
|
|
|
|
if (pdfPath != null) {
|
|
|
|
|
// 转成格式
|
|
|
|
|
archiveDetail.setPdfPath(pdfPath);
|
|
|
|
|
archiveDetailService.save(archiveDetail);
|
|
|
|
|
//删除FTP文件
|
|
|
|
|
if(FTPUtil.deleteFile(interfaceHisCache.getPdfPath())){
|
|
|
|
|
// 成功
|
|
|
|
|
state = "1";
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
remark = "下载失败";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
remark = "文件创建失败";
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
remark = "类型为空";
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
remark = "没有入院信息";
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
remark = e.getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(remark != null){
|
|
|
|
|
// 报错删掉患者报告详情信息
|
|
|
|
|
if (archiveDetail != null) {
|
|
|
|
|
archiveDetailService.delete(archiveDetail.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//赋值
|
|
|
|
|
interfaceHisCache.setValue(state,remark,new Date());
|
|
|
|
|
interfaceHisCacheService.save(interfaceHisCache);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|