From 8475aafdc29b90a4c6eef023faae634d6d093a5c Mon Sep 17 00:00:00 2001
From: leijx <1477272687@qq.com>
Date: Mon, 14 Dec 2020 19:53:28 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EMessageLog=20masterId,webserv?=
=?UTF-8?q?iceInfo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
EMRInterface.iml | 4 +
pom.xml | 25 +++
.../ann/demo/controller/TestController.java | 3 +-
.../ann/demo/entity/constant/AliasName.java | 105 ++++-----
.../ann/demo/entity/filing/ArchiveDetail.java | 13 ++
.../demo/entity/filing/dto/MessageDto.java | 2 +
.../entity/interfaceEntity/ArchiveMaster.java | 9 +
.../demo/interfaces/HomepageDictionary.java | 2 +
.../impl/HomepageDictionaryImpl.java | 31 ++-
.../com/ann/demo/service/AnalysisService.java | 40 ++++
.../demo/service/ArchiveDetailService.java | 2 +
.../demo/service/ArchiveMasterService.java | 15 ++
.../impl/ArchiveDetailServiceImpl.java | 5 +
.../impl/ArchiveMasterServiceImpl.java | 28 +++
.../com/ann/demo/utils/DownloadUtils.java | 136 ++++++++++++
src/main/java/com/ann/demo/utils/FTPUtil.java | 181 +++++++++++++++
.../java/com/ann/demo/utils/FileUtils.java | 210 ++++++++++++++++++
.../java/com/ann/demo/utils/PdfUtils.java | 64 ++++++
.../java/com/ann/demo/utils/XMLUtils.java | 13 ++
src/main/resources/application.yml | 5 +-
src/main/resources/templates/demo.html | 2 +
21 files changed, 839 insertions(+), 56 deletions(-)
create mode 100644 src/main/java/com/ann/demo/service/ArchiveMasterService.java
create mode 100644 src/main/java/com/ann/demo/service/impl/ArchiveMasterServiceImpl.java
create mode 100644 src/main/java/com/ann/demo/utils/DownloadUtils.java
create mode 100644 src/main/java/com/ann/demo/utils/FTPUtil.java
create mode 100644 src/main/java/com/ann/demo/utils/FileUtils.java
create mode 100644 src/main/java/com/ann/demo/utils/PdfUtils.java
diff --git a/EMRInterface.iml b/EMRInterface.iml
index 46b386c..f106d9c 100644
--- a/EMRInterface.iml
+++ b/EMRInterface.iml
@@ -150,5 +150,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d2ffd23..8f817e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,6 +100,31 @@
org.springframework.boot
spring-boot-starter-quartz
+
+
+
+ commons-net
+ commons-net
+ 3.6
+
+
+
+ commons-io
+ commons-io
+ 2.4
+
+
+ org.apache.commons
+ commons-lang3
+ 3.8
+
+
+
+
+ com.itextpdf
+ itextpdf
+ 5.5.11
+
diff --git a/src/main/java/com/ann/demo/controller/TestController.java b/src/main/java/com/ann/demo/controller/TestController.java
index 2a58c19..1b6233a 100644
--- a/src/main/java/com/ann/demo/controller/TestController.java
+++ b/src/main/java/com/ann/demo/controller/TestController.java
@@ -46,7 +46,8 @@ public class TestController {
Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.ICU_REPORT) ||
Objects.equals(interfaceForm.getInterfaceName(), InterfaceName.BLOODAPPLY_REPORT) ||
Objects.equals(interfaceForm.getInterfaceName(), "DoctorData") ||
- Objects.equals(interfaceForm.getInterfaceName(), "NurseData")) {
+ Objects.equals(interfaceForm.getInterfaceName(), "NurseData") ||
+ Objects.equals(interfaceForm.getInterfaceName(), "ScanningFile")) {
objects = client.invoke(interfaceForm.getInterfaceName(), interfaceForm.getContent());
} else {
objects = client.invoke(interfaceForm.getInterfaceName(), interfaceForm.getParameter(), interfaceForm.getContent());
diff --git a/src/main/java/com/ann/demo/entity/constant/AliasName.java b/src/main/java/com/ann/demo/entity/constant/AliasName.java
index d9d8143..15b3315 100644
--- a/src/main/java/com/ann/demo/entity/constant/AliasName.java
+++ b/src/main/java/com/ann/demo/entity/constant/AliasName.java
@@ -10,59 +10,60 @@ import java.util.Map;
*/
public class AliasName {
- public static final String USER = "用户字典";
-
- public static final String DEPARTMENT = "科室字典";
-
- // 超声报告
- public static final String ULTRASONIC_REPORT = "57";
-
- // 病理检查报告单
- public static final String PATHOLOGY_REPORT = "52";
-
- // 放射诊断报告单 54
- public static final String RADIATION_REPORT = "54";
-
- // 心电图报告单 59
- public static final String EKG_REPORT = "59";
-
- // 入院记录
- public static final String ADMISSION_RECORD = "9";
-
- // 出院记录
- public static final String DISCHARGE_RECORD = "113";
-
- // 转科记录
- public static final String TRANSFER_RECORD = "114";
-
- // 取消入院
- public static final String CANCELLATION_DISCHARGE = "115";
-
- // 手麻
- public static final String HANDNUMBNESS_REPORT = "117";
-
- // ICU报告
- public static final String ICU_REPORT = "121";
-
- // 其他类型 目前来说 是手麻系统的其他三个
+// public static final String USER = "用户字典";
+//
+// public static final String DEPARTMENT = "科室字典";
+//
+// // 超声报告
+// public static final String ULTRASONIC_REPORT = "57";
+//
+// // 病理检查报告单
+// public static final String PATHOLOGY_REPORT = "52";
+//
+// // 放射诊断报告单 54
+// public static final String RADIATION_REPORT = "54";
+//
+// // 心电图报告单 59
+// public static final String EKG_REPORT = "59";
+//
+// // 入院记录
+// public static final String ADMISSION_RECORD = "9";
+//
+// // 出院记录
+// public static final String DISCHARGE_RECORD = "113";
+//
+// // 转科记录
+// public static final String TRANSFER_RECORD = "114";
+//
+// // 取消入院
+// public static final String CANCELLATION_DISCHARGE = "115";
+//
+// // 手麻
+// public static final String HANDNUMBNESS_REPORT = "117";
+//
+// // ICU报告
+// public static final String ICU_REPORT = "121";
+//
+// // 其他类型 目前来说 是手麻系统的其他三个
public static final String OTHER = "18";
- // 检查申请单
- public static final String PARAMETER_EXAMAPPLY = "119";
-
- // 输血单
- public static final String BLOODAPPLY_REPORT = "120";
-
- // PET/CT报告单
- public static final String PETCT_REPORT = "60";
-
- // 检验申请单
- //public static final String PARAMETER_EXAMAPPLY = "118";
-
- // 检验报告
- public static final String INSPECTION_REPORT = "10";
-
- // 扫描文件
+//
+// // 检查申请单
+// public static final String PARAMETER_EXAMAPPLY = "119";
+//
+// // 输血单
+// public static final String BLOODAPPLY_REPORT = "120";
+//
+// // PET/CT报告单
+// public static final String PETCT_REPORT = "60";
+//
+// // 检验申请单
+// //public static final String PARAMETER_EXAMAPPLY = "118";
+//
+// // 检验报告
+// public static final String INSPECTION_REPORT = "10";
+//
+// // 扫描文件
public static final String SCANNING_FILE = "30";
// 护理、医生
@@ -70,7 +71,7 @@ public class AliasName {
public static final Map NURSE_MAP;
// 病案首页
- public static final String MEDICAL_RECORD_HOMEPAGE = "3";
+// public static final String MEDICAL_RECORD_HOMEPAGE = "3";
static {
diff --git a/src/main/java/com/ann/demo/entity/filing/ArchiveDetail.java b/src/main/java/com/ann/demo/entity/filing/ArchiveDetail.java
index efd22df..b8d1630 100644
--- a/src/main/java/com/ann/demo/entity/filing/ArchiveDetail.java
+++ b/src/main/java/com/ann/demo/entity/filing/ArchiveDetail.java
@@ -51,6 +51,9 @@ public class ArchiveDetail {
*/
private String applyId;
+ @Column(name = "page_number")
+ private Integer number;
+
public ArchiveDetail() {
}
@@ -60,4 +63,14 @@ public class ArchiveDetail {
this.assortID = assortID;
this.source = source;
}
+
+ public ArchiveDetail(String masterID, Date upLoadDateTime, String assortID, String source, String applyId, String pdfPath,Integer number) {
+ this.masterID = masterID;
+ this.upLoadDateTime = upLoadDateTime;
+ this.assortID = assortID;
+ this.source = source;
+ this.applyId = applyId;
+ this.pdfPath = pdfPath;
+ this.number = number;
+ }
}
diff --git a/src/main/java/com/ann/demo/entity/filing/dto/MessageDto.java b/src/main/java/com/ann/demo/entity/filing/dto/MessageDto.java
index 34fd137..0182cc3 100644
--- a/src/main/java/com/ann/demo/entity/filing/dto/MessageDto.java
+++ b/src/main/java/com/ann/demo/entity/filing/dto/MessageDto.java
@@ -61,6 +61,8 @@ public class MessageDto {
//20200609 0是老数据 1是新数据
private String isOld;
+ private String pageNum;
+
public MessageDto() {
}
diff --git a/src/main/java/com/ann/demo/entity/interfaceEntity/ArchiveMaster.java b/src/main/java/com/ann/demo/entity/interfaceEntity/ArchiveMaster.java
index 7a45ee9..da377bf 100644
--- a/src/main/java/com/ann/demo/entity/interfaceEntity/ArchiveMaster.java
+++ b/src/main/java/com/ann/demo/entity/interfaceEntity/ArchiveMaster.java
@@ -133,4 +133,13 @@ public class ArchiveMaster {
* 2019-7-30
*/
private String transferDept;
+
+ /**
+ * 是否扫描
+ * 2020-12-14
+ */
+ @Column(name = "isscaned")
+ private String isScaned;
+
+
}
diff --git a/src/main/java/com/ann/demo/interfaces/HomepageDictionary.java b/src/main/java/com/ann/demo/interfaces/HomepageDictionary.java
index 8e8a4ea..87762a2 100644
--- a/src/main/java/com/ann/demo/interfaces/HomepageDictionary.java
+++ b/src/main/java/com/ann/demo/interfaces/HomepageDictionary.java
@@ -13,5 +13,7 @@ public interface HomepageDictionary {
@WebMethod
String DoctorData(@WebParam(name = "xmlStr") String xmlStr);
+ @WebMethod
+ String ScanningFile(@WebParam(name = "xmlStr") String xmlStr);
}
diff --git a/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java b/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java
index 0ea7fcf..a8ed08d 100644
--- a/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java
+++ b/src/main/java/com/ann/demo/interfaces/impl/HomepageDictionaryImpl.java
@@ -47,6 +47,9 @@ public class HomepageDictionaryImpl implements HomepageDictionary {
@Autowired
private ArchiveMasterRepository archiveMasterRepository;
+ @Autowired
+ private AnalysisService analysisService;
+
@Override
public String NurseData(String xmlStr) {
String outContent = "失败";
@@ -194,14 +197,16 @@ public class HomepageDictionaryImpl implements HomepageDictionary {
if(! (archiveMaster.getArchiveState().equals("初审") || archiveMaster.getArchiveState().equals("已归档") )){
String addFlag = messageDto.getAddFlag();
- if(Objects.equals(addFlag,"delete") || Objects.equals(addFlag,"update") || Objects.equals(addFlag,"insert")){
+ if(Objects.equals(addFlag,"delete") || Objects.equals(addFlag,"update")
+ || Objects.equals(addFlag,"insert") || Objects.equals(addFlag,"")){
if(Objects.equals(messageDto.getIsOld(),"0")){
messageDto.setApplyId(messageDto.getInpNo() + "-" + messageDto.getVisitId()+"-doctor-"+messageDto.getCommitTime());
remark = archiveDetailService.updateAllFlag(messageDto.getApplyId(), messageDto.getSource());
}else if(Objects.equals(messageDto.getIsOld(),"1")){
ArchiveDetail archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId());
- if(archiveDetail == null && !Objects.equals(addFlag,"insert")){
+
+ if(archiveDetail == null && !Objects.equals(addFlag,"insert") ){
remark = messageDto.getSubType()+"没有生成对应的文件不能"+addFlag;
}else{
if(Objects.equals(addFlag,"delete")){
@@ -274,4 +279,26 @@ public class HomepageDictionaryImpl implements HomepageDictionary {
}
return outContent;
}
+
+ @Override
+ public String ScanningFile(String xmlStr) {
+ String outContent = "失败";
+ try {
+ boolean flag = false;
+ String remark = null;
+ MessageDto messageDto = XMLUtils.xpathToBean(xmlStr, EMRData.class, InterfaceName.SCANNING_FILE);
+ if (messageDto != null) {
+ remark = analysisService.handlePdfFile(messageDto);
+ if(remark == null){
+ flag = true;
+ }
+ } else {
+ remark = "传过来的消息无法解析。。";
+ }
+ outContent = AnalysisService.getReturnResult(flag, remark);
+ }catch (Exception e){
+ logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]);
+ }
+ return outContent;
+ }
}
diff --git a/src/main/java/com/ann/demo/service/AnalysisService.java b/src/main/java/com/ann/demo/service/AnalysisService.java
index 59b7471..6dfc6ce 100644
--- a/src/main/java/com/ann/demo/service/AnalysisService.java
+++ b/src/main/java/com/ann/demo/service/AnalysisService.java
@@ -1,11 +1,21 @@
package com.ann.demo.service;
+import com.ann.demo.entity.filing.ArchiveDetail;
+import com.ann.demo.entity.filing.dto.MessageDto;
+import com.ann.demo.entity.interfaceEntity.ArchiveMaster;
import com.ann.demo.entity.normalEntity.OutPara;
+import com.ann.demo.utils.DownloadUtils;
+import com.ann.demo.utils.FileUtils;
+import com.ann.demo.utils.PdfUtils;
import com.ann.demo.utils.XMLUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.io.File;
+import java.util.Date;
+
/**
* 解析逻辑
*
@@ -14,6 +24,10 @@ import org.springframework.stereotype.Component;
*/
@Component
public class AnalysisService {
+ @Autowired
+ private ArchiveMasterService archiveMasterService;
+ @Autowired
+ private ArchiveDetailService archiveDetailService;
public static String getReturnResult(boolean resultCode,String content) throws Exception {
OutPara outPara = new OutPara();
@@ -28,4 +42,30 @@ public class AnalysisService {
}
+ public String handlePdfFile(MessageDto messageDto) throws Exception{
+ String pdfPath = "";
+ ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(messageDto.getInpNo(),messageDto.getVisitId());
+ if(archiveMaster == null){
+ return "没有患者信息";
+ }
+ File imageFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(),"");
+ if(DownloadUtils.downloadImageFile(messageDto.getReportAddress(), imageFile) == null){
+ return "下载图像出错";
+ }
+ File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), messageDto.getApplyId());
+ //存入pdf地址
+ pdfPath = PdfUtils.imagesToPdf(imageFile, pdfFile);
+ if (pdfPath == null) {
+ return "image转成pdf出错了。。。";
+ }
+ ArchiveDetail archiveDetail = new ArchiveDetail(archiveMaster.getId(), new Date(), messageDto.getType(), "嘉时扫描系统", messageDto.getApplyId(), pdfPath,Integer.valueOf(messageDto.getPageNum()));
+ archiveDetail.setTitle(messageDto.getDetailType());
+ archiveDetailService.save(archiveDetail);
+ if(archiveDetail.getId() != null){
+ archiveMaster.setIsScaned("1");
+ archiveMasterService.save(archiveMaster);
+ return null;
+ }
+ return "出错了";
+ }
}
diff --git a/src/main/java/com/ann/demo/service/ArchiveDetailService.java b/src/main/java/com/ann/demo/service/ArchiveDetailService.java
index b885013..bf7cb07 100644
--- a/src/main/java/com/ann/demo/service/ArchiveDetailService.java
+++ b/src/main/java/com/ann/demo/service/ArchiveDetailService.java
@@ -15,4 +15,6 @@ public interface ArchiveDetailService {
ArchiveDetail isExit(String id, String type, String source, String applyId);
boolean delete(String id);
+
+ void save(ArchiveDetail archiveDetail);
}
diff --git a/src/main/java/com/ann/demo/service/ArchiveMasterService.java b/src/main/java/com/ann/demo/service/ArchiveMasterService.java
new file mode 100644
index 0000000..96e01a9
--- /dev/null
+++ b/src/main/java/com/ann/demo/service/ArchiveMasterService.java
@@ -0,0 +1,15 @@
+package com.ann.demo.service;
+
+
+import com.ann.demo.entity.interfaceEntity.ArchiveMaster;
+
+/**
+ * @Author: LeiJiaXin
+ * @Date: 2019/7/11 20:53
+ */
+public interface ArchiveMasterService {
+
+ public void save(ArchiveMaster archiveMaster);
+
+ public ArchiveMaster findByInpNoAndVisitIdAndIsValid(String inpNo, String visitId) throws Exception;
+}
diff --git a/src/main/java/com/ann/demo/service/impl/ArchiveDetailServiceImpl.java b/src/main/java/com/ann/demo/service/impl/ArchiveDetailServiceImpl.java
index 1a278ba..7b77f26 100644
--- a/src/main/java/com/ann/demo/service/impl/ArchiveDetailServiceImpl.java
+++ b/src/main/java/com/ann/demo/service/impl/ArchiveDetailServiceImpl.java
@@ -84,4 +84,9 @@ public class ArchiveDetailServiceImpl implements ArchiveDetailService {
return true;
return false;
}
+
+ @Override
+ public void save(ArchiveDetail archiveDetail) {
+ archiveDetailRepository.save(archiveDetail);
+ }
}
diff --git a/src/main/java/com/ann/demo/service/impl/ArchiveMasterServiceImpl.java b/src/main/java/com/ann/demo/service/impl/ArchiveMasterServiceImpl.java
new file mode 100644
index 0000000..3029188
--- /dev/null
+++ b/src/main/java/com/ann/demo/service/impl/ArchiveMasterServiceImpl.java
@@ -0,0 +1,28 @@
+package com.ann.demo.service.impl;
+
+import com.ann.demo.entity.interfaceEntity.ArchiveMaster;
+import com.ann.demo.repository.ArchiveMasterRepository;
+import com.ann.demo.service.ArchiveMasterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author: LeiJiaXin
+ * @Date: 2019/7/11 20:53
+ */
+@Service
+public class ArchiveMasterServiceImpl implements ArchiveMasterService {
+
+ @Autowired
+ private ArchiveMasterRepository archiveMasterRepository;
+
+ @Override
+ public void save(ArchiveMaster archiveMaster) {
+ archiveMasterRepository.save(archiveMaster);
+ }
+
+ @Override
+ public ArchiveMaster findByInpNoAndVisitIdAndIsValid(String inpNo, String visitId) throws Exception {
+ return archiveMasterRepository.findByInpNoAndVisitIdAndIsValid(inpNo, visitId, 0);
+ }
+}
diff --git a/src/main/java/com/ann/demo/utils/DownloadUtils.java b/src/main/java/com/ann/demo/utils/DownloadUtils.java
new file mode 100644
index 0000000..12b88c9
--- /dev/null
+++ b/src/main/java/com/ann/demo/utils/DownloadUtils.java
@@ -0,0 +1,136 @@
+package com.ann.demo.utils;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @Description 下载工具
+ * @Date 2019/7/2 16:56
+ * @Created by ljx
+ */
+public class DownloadUtils {
+
+ static final Logger logger = LoggerFactory.getLogger(DownloadUtils.class);
+
+
+ /**
+ * 从网络Url中下载文件
+ *
+ * @param urlStr
+ * @param fileName
+ * @param savePath
+ * @throws IOException
+ */
+ public static void downLoadByUrl(String urlStr, String fileName, String savePath) throws IOException {
+ URL url = new URL(urlStr);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ //设置超时间为5秒
+ conn.setConnectTimeout(5 * 1000);
+ //防止屏蔽程序抓取而返回403错误
+ conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+ //得到输入流
+ InputStream inputStream = conn.getInputStream();
+ //获取自己数组
+ byte[] getData = readInputStream(inputStream);
+ //文件保存位置
+ File saveDir = new File(savePath);
+ if (!saveDir.exists()) {
+ saveDir.mkdir();
+ }
+ File file = new File(saveDir + File.separator + fileName);
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(getData);
+ if (fos != null) {
+ fos.close();
+ }
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ System.out.println("info:" + url + " download success");
+ }
+
+
+ /**
+ * 从输入流中获取字节数组
+ *
+ * @param inputStream
+ * @return
+ * @throws IOException
+ */
+ public static byte[] readInputStream(InputStream inputStream) throws IOException {
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ while ((len = inputStream.read(buffer)) != -1) {
+ bos.write(buffer, 0, len);
+ }
+ bos.close();
+ return bos.toByteArray();
+ }
+
+ //从共享目录下载文件
+ public static boolean cmdFile(String path, File imageFile) {
+ boolean result = false;
+ BufferedInputStream in = null;
+ BufferedOutputStream out = null;
+ try {
+ Runtime.getRuntime().exec("net use \\10.6.0.74 his /user:his");
+ in = new BufferedInputStream(new FileInputStream(path));
+ out = new BufferedOutputStream(new FileOutputStream(imageFile));
+
+ byte[] buffer = new byte[1024];
+ while (in.read(buffer) != -1) {
+ out.write(buffer);
+ buffer = new byte[1024];
+ }
+ out.flush();
+ result = true;
+ } catch (IOException e) {
+ // FileUtils.deleteImageFile(imageFile);
+ logger.error("出错咯!错误信息:" + e);
+ } finally {
+ try {
+ if (out != null) {
+ out.close();
+ }
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ // FileUtils.deleteImageFile(imageFile);
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ public static String downloadImageFile(String address, File imageFile) throws Exception {
+ String url = "";
+ String path = "";
+ Integer port = 21;
+
+ address = address.substring(address.indexOf("/") + 2, address.length());
+ path = address.substring(address.indexOf("/"), address.length());
+ //处理url 以及端口 如果有端口 截取 否则默认端口
+ if (address.indexOf(":") != -1 && address.indexOf("/") != -1) {
+ port = Integer.parseInt(address.substring(address.indexOf(":") + 1, address.indexOf("/")));
+ url = address.substring(0, address.indexOf(":"));
+ }
+ String userName = "common";
+ String password = "common";
+
+ FTPClient ftpClient = FTPUtil.connectFtpServer(url, port, userName, password);
+ if (FTPUtil.downloadFtp(path, ftpClient, imageFile)) {
+ return imageFile.getAbsolutePath();
+ }
+ return null;
+
+// return imageFile.getAbsolutePath();
+ }
+
+}
diff --git a/src/main/java/com/ann/demo/utils/FTPUtil.java b/src/main/java/com/ann/demo/utils/FTPUtil.java
new file mode 100644
index 0000000..6110883
--- /dev/null
+++ b/src/main/java/com/ann/demo/utils/FTPUtil.java
@@ -0,0 +1,181 @@
+package com.ann.demo.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPReply;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @Author: LeiJiaXin
+ * @Date: 2019/8/22 9:17
+ */
+public class FTPUtil {
+
+ static final Logger logger = LoggerFactory.getLogger(FTPUtil.class);
+
+ /**
+ * 连接 FTP 服务器
+ *
+ * @param addr FTP 服务器 IP 地址
+ * @param port FTP 服务器端口号
+ * @param username 登录用户名
+ * @param password 登录密码
+ * @return
+ * @throws Exception
+ */
+ public static FTPClient connectFtpServer(String addr, int port, String username, String password) throws Exception {
+ FTPClient ftpClient = new FTPClient();
+ try {
+ ftpClient.setControlEncoding("UTF-8");
+ ftpClient.setAutodetectUTF8(true);
+// ftpClient.setControlEncoding("UTF-8"); // 设置组件工作字符集为UTF-8
+
+ ftpClient.connect(addr, port);
+ /**登录 FTP 服务器
+ * 1)如果传入的账号为空,则使用匿名登录,此时账号使用 "Anonymous",密码为空即可*/
+ if (StringUtils.isBlank(username)) {
+ ftpClient.login("Anonymous", "");
+ } else {
+ ftpClient.login(username, password);
+ }
+
+ /** 设置传输的文件类型
+ * BINARY_FILE_TYPE:二进制文件类型
+ * ASCII_FILE_TYPE:ASCII传输方式,这是默认的方式
+ * ....
+ */
+ ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
+
+ /**
+ * 确认应答状态码是否正确完成响应
+ * 凡是 2开头的 isPositiveCompletion 都会返回 true,因为它底层判断是:
+ * return (reply >= 200 && reply < 300);
+ */
+ int reply = ftpClient.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply)) {
+ /**
+ * 如果 FTP 服务器响应错误 中断传输、断开连接
+ * abort:中断文件正在进行的文件传输,成功时返回 true,否则返回 false
+ * disconnect:断开与服务器的连接,并恢复默认参数值
+ */
+ ftpClient.abort();
+ ftpClient.disconnect();
+ }
+ } catch (IOException e) {
+ throw e;
+ }
+ return ftpClient;
+ }
+
+ /**
+ * 使用完毕,应该及时关闭连接
+ * 终止 ftp 传输
+ * 断开 ftp 连接
+ *
+ * @param ftpClient
+ * @return
+ */
+ public static FTPClient closeFTPConnect(FTPClient ftpClient) throws Exception {
+ try {
+ if (ftpClient != null && ftpClient.isConnected()) {
+ ftpClient.abort();
+ ftpClient.disconnect();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return ftpClient;
+ }
+
+
+ public static boolean downloadFtp(String path, FTPClient ftp, File file) throws Exception {
+ InputStream is = null;
+ FileOutputStream fos = null;
+ boolean result = false;
+ try {
+ is = ftp.retrieveFileStream(path);
+ if(is != null){
+ byte[] bytes = new byte[1024];
+ int i;
+ fos = new FileOutputStream(file);
+ while ((i = is.read(bytes)) != -1) {
+ fos.write(bytes, 0, i);
+ }
+ closeFTPConnect(ftp);
+ }
+ if(file.length() == 0){
+ FileUtils.deleteImageFile(file);
+ }else{
+ result = true;
+ }
+ } catch (Exception e) {
+ FileUtils.deleteImageFile(file);
+ throw e;
+ } finally {
+ try {
+ if (fos != null) {
+ fos.close();
+ }
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException e) {
+ FileUtils.deleteImageFile(file);
+ throw e;
+ }
+ }
+ return result;
+ }
+
+ public static boolean deleteFile(String address) throws Exception {
+ boolean flag = false;
+ FTPClient ftpClient = null;
+ try {
+ String url = "";
+ String path = "";
+ Integer port = 21;
+ // 处理 “/”
+ if (address.indexOf("/") == -1) {
+ address = address.replace("\\", "/");
+ }
+ address = address.substring(address.indexOf("/") + 2, address.length());
+ path = address.substring(address.indexOf("/"), address.length());
+ url = address.substring(0, address.indexOf("/"));
+
+ ftpClient = connectFtpServer(url, port, "his", "his_docus");
+ // 切换FTP目录
+ ftpClient.changeWorkingDirectory("/");
+ int dele = ftpClient.dele(path);
+ logger.error("删除FTP文件为:{}",address);
+ flag = true;
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ if (ftpClient != null && ftpClient.isConnected()) {
+ try {
+ ftpClient.disconnect();// 断开连接,如果想连续删除就得把finally块注掉
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return flag;
+ }
+
+
+ public static void main(String[] args) throws Exception {
+ /* String address = "ftp://10.6.0.241/02019-08-29.png;ftp://10.6.0.241/12019-08-29.png";
+ File imageFile = FileUtils.createFile("images","2019","0827", "阿雷小猴子" );
+ File pdfFile = FileUtils.createFile("pdfs","2019","0827", "阿雷小猴子" );
+ String s = DownloadUtils.downloadImageFiles(address, imageFile.getParent());
+ // 图片那么转成pdf
+ String pdfPath = PdfUtils.imageDirToPdf(s,pdfFile);
+ System.out.println(pdfPath);*/
+ }
+}
diff --git a/src/main/java/com/ann/demo/utils/FileUtils.java b/src/main/java/com/ann/demo/utils/FileUtils.java
new file mode 100644
index 0000000..0347d0b
--- /dev/null
+++ b/src/main/java/com/ann/demo/utils/FileUtils.java
@@ -0,0 +1,210 @@
+package com.ann.demo.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.*;
+import java.time.LocalDate;
+import java.util.Objects;
+
+/**
+ * @Author: LeiJiaXin
+ * @Date: 2019/7/24 16:42
+ */
+@Component
+public class FileUtils {
+
+ static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
+
+ // pdf地址
+ public static String pdfPath;
+
+ @Value("${file.pdfPath}")
+ public void setPdfPath(String pdfPath) {
+ FileUtils.pdfPath = pdfPath;
+ }
+
+ public static String getPdfPath() {
+ return pdfPath;
+ }
+
+ // image地址
+ public static String imagePath;
+
+ @Value("${file.imagePath}")
+ public void setImagePath(String imagePath) {
+ FileUtils.imagePath = imagePath;
+ }
+
+ public static String getImagePath() {
+ return imagePath;
+ }
+
+
+ public static File createFile(String fileType, String inpNo, String visitId, String path) throws IOException {
+ File localFile = null;
+ try {
+ //生成图片地址
+ // ---------------------------此处写死 年月需改善
+ LocalDate date = LocalDate.now();
+ String fileDirName = null;
+ if (Objects.equals(fileType, "images")) {
+ fileDirName = imagePath+ date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId;
+ } else if (Objects.equals(fileType, "pdfs")) {
+ fileDirName = pdfPath + "/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId;
+ }
+
+ //判断是否有该文件夹 否则创建
+ File fileDir = new File(fileDirName);
+ if (!fileDir.exists()) {
+ fileDir.mkdirs();
+ }
+
+ String fileName = null;
+ if (Objects.equals(fileType, "images")) {
+ fileName = fileDir + "/" + path + ".jpg";
+ } else if (Objects.equals(fileType, "pdfs")) {
+ fileName = fileDir + "/" + path + ".pdf";
+ }
+
+ localFile = new File(fileName);
+ if (!localFile.exists()) {
+ localFile.createNewFile();
+ }
+
+ } catch (IOException e) {
+ logger.error("出错咯!错误信息:" + e);
+ throw e;
+ }
+ return localFile;
+ }
+
+
+ public static void deleteImageFile(File file) {
+ if (!file.exists()) {
+ System.out.println(file.getAbsolutePath() + "文件不存在");
+ } else {
+ if (file.length() == 0) {
+ // 当前文件 大小为0
+ File fileParent = new File(file.getParent());
+ File[] fileParents = fileParent.listFiles();
+ // 如果文件个数大于1 那么已经有其他的报告 只删除本身 否则就删除当前文件以及父级目录
+ if (fileParents.length > 1) {
+ // -----------------------------改成log 形式
+ file.delete();
+ System.out.println("删除文件为:" + file.getAbsolutePath());
+ } else {
+ file.delete();
+ fileParent.delete();
+ System.out.println("删除文件为:" + file.getAbsolutePath() + ",以及父文件:" + fileParent.getName());
+ }
+ }
+ }
+ }
+
+
+ public static int deleteImageFile1(File file, int i) {
+ if (!file.exists()) {
+ System.out.println(file.getAbsolutePath() + "文件不存在");
+ return i;
+ } else {
+ // 当前文件 大小为0
+ File fileParent = new File(file.getParent());
+ File[] fileParents = fileParent.listFiles();
+ // 如果文件个数大于1 那么已经有其他的报告 只删除本身 否则就删除当前文件以及父级目录
+ if (fileParents.length > 1) {
+ // -----------------------------改成log 形式
+ file.delete();
+ System.out.println("删除文件为:" + file.getAbsolutePath());
+ } else {
+ file.delete();
+ fileParent.delete();
+ System.out.println("删除文件为:" + file.getAbsolutePath() + ",以及父文件:" + fileParent.getName());
+ }
+ return i++;
+ }
+ }
+
+ public static File getImageFileByByteArray(Object[] objects, File file) throws Exception {
+ OutputStream out = null;
+ InputStream is = null;
+ try {
+ out = new FileOutputStream(file);
+ is = new ByteArrayInputStream((byte[])objects[0]);
+ byte[] buff = new byte[1024];
+ int len = 0;
+ while((len=is.read(buff))!=-1){
+ out.write(buff, 0, len);
+ }
+ return file;
+ } catch (Exception e) {
+ FileUtils.deleteImageFile(file);
+ logger.error("出错咯!错误信息:" + e);
+ throw e;
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e1) {
+ FileUtils.deleteImageFile(file);
+ logger.error("出错咯!错误信息:" + e1);
+ throw e1;
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e1) {
+ FileUtils.deleteImageFile(file);
+ logger.error("出错咯!错误信息:" + e1);
+ throw e1;
+ }
+ }
+ }
+ }
+
+ public static String haha(String path,byte[] bytes){
+ int n = 1024;
+ FileOutputStream os = null;
+ try {
+ // 创建文件输出流对象
+ File file = new File(path);
+ os= new FileOutputStream(file);
+ // 写入输出流
+ int length = bytes.length;
+ int start = 0;
+ while(length>start+n){
+ os.write(bytes, start, n);
+ start= start+n;
+ }
+
+ if(length != start+n){
+ n = length-start;
+ os.write(bytes, start, n);
+ }
+ return path;
+ } catch (IOException e) {
+ return null;
+ }finally{
+ // 关闭输出流
+ try {
+ if(os !=null){
+ os.close();
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+ }
+
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ String address = "ftp://10.6.0.155/2019-10-21/000581031700_1_000581031700_0_1_JHR06.00.02_34_2_0.pdf";
+ String a = address.substring(0, address.indexOf(".pdf"));
+ String emrPath = a.substring(a.lastIndexOf("_") + 1, a.length());
+
+ System.out.println(emrPath);
+ }
+}
diff --git a/src/main/java/com/ann/demo/utils/PdfUtils.java b/src/main/java/com/ann/demo/utils/PdfUtils.java
new file mode 100644
index 0000000..7fd1e64
--- /dev/null
+++ b/src/main/java/com/ann/demo/utils/PdfUtils.java
@@ -0,0 +1,64 @@
+package com.ann.demo.utils;
+
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.Image;
+import com.itextpdf.text.Rectangle;
+import com.itextpdf.text.pdf.PdfWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @Author: LeiJiaXin
+ * @Date: 2019/7/11 22:32
+ */
+public class PdfUtils {
+
+ static final Logger logger = LoggerFactory.getLogger(PdfUtils.class);
+
+ /**
+ * 生成pdf文件
+ *
+ * @param imageFile
+ * @param pdfFile 需要转换的图片路径的数组
+ */
+ public static String imagesToPdf(File imageFile, File pdfFile) throws IOException, DocumentException {
+ String fileName = null;
+ try {
+ // 第一步:创建一个document对象。
+ Document document = new Document();
+ document.setMargins(0, 0, 0, 0);
+ // 第二步:
+ // 创建一个PdfWriter实例,
+ PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
+ // 第三步:打开文档。
+ document.open();
+ // 第四步:在文档中增加图片。
+ if (imageFile.getName().endsWith(".bmp")
+ || imageFile.getName().endsWith(".jpg")
+ || imageFile.getName().endsWith(".jpeg")
+ || imageFile.getName().endsWith(".gif")
+ || imageFile.getName().endsWith(".png")) {
+ String imagesPath = imageFile.getAbsolutePath();
+ Image img = Image.getInstance(imagesPath);
+ img.setAlignment(Image.ALIGN_CENTER);
+ // 根据图片大小设置页面,一定要先设置页面,再newPage(),否则无效
+ document.setPageSize(new Rectangle(img.getWidth(), img.getHeight()));
+ document.newPage();
+ document.add(img);
+ }
+ // 第五步:关闭文档。
+ document.close();
+ //返回pdf路径
+ fileName = pdfFile.getAbsolutePath();
+ } catch (Exception e) {
+ logger.error("出错咯!错误信息:" + e);
+ throw e;
+ }
+ return fileName;
+ }
+}
diff --git a/src/main/java/com/ann/demo/utils/XMLUtils.java b/src/main/java/com/ann/demo/utils/XMLUtils.java
index 1157fd2..9da72d8 100644
--- a/src/main/java/com/ann/demo/utils/XMLUtils.java
+++ b/src/main/java/com/ann/demo/utils/XMLUtils.java
@@ -1,6 +1,7 @@
package com.ann.demo.utils;
import com.alibaba.fastjson.JSON;
+import com.ann.demo.entity.constant.AliasName;
import com.ann.demo.entity.constant.InterfaceName;
import com.ann.demo.entity.filing.dto.MessageDto;
import com.ann.demo.entity.interfaceEntity.*;
@@ -55,13 +56,22 @@ public class XMLUtils {
@Value("${file.nurseDataPath}")
private String nurseDataPathTemp;
+ // 扫描文件
+ public static String scanningFilePath;
+ @Value("${file.scanningFilePath}")
+ private String scanningFilePathTemp;
+
+
@PostConstruct
public void init() {
path = pathTemp;
nurseDataPath = nurseDataPathTemp;
doctorDataPath = doctorDataPathTemp;
+ scanningFilePath = scanningFilePathTemp;
}
+
+
// private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
// 病案首页独享
// private static SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
@@ -191,6 +201,9 @@ public class XMLUtils {
case InterfaceName.DOCTOR_DATA: // 医生
messageDto = new MessageDto(EMRData.class.getName(), new EMRData(), "", doctorDataPath, source);
break;
+ case InterfaceName.SCANNING_FILE:
+ messageDto = new MessageDto(EMRData.class.getName(), new EMRData(), AliasName.SCANNING_FILE, scanningFilePath, InterfaceName.SCANNING_FILE);
+ break;
}
return messageDto;
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 6ac6710..6f2cf08 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -11,7 +11,7 @@ spring:
# hibernate:
# ddl-auto: update
# database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
- # url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record
+ ## url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record
url: jdbc:sqlserver://10.6.1.127:1433;DatabaseName=DB_PrivilegeManagement_GYFY
username: sa
password: docus@702
@@ -47,4 +47,7 @@ file:
path: D:\\1\MCCI_IN000002UV01.xml
doctorDataPath: D:\\1\doctorData.properties
nurseDataPath: D:\\1\nurseData.properties
+ pdfPath: Z:/project_js/docus_scanningfile/
+ imagePath: Z:/images/docus_scanningfile/
+ scanningFilePath: D:\\1\scanningFile.properties
diff --git a/src/main/resources/templates/demo.html b/src/main/resources/templates/demo.html
index 93fc84d..a0257d6 100644
--- a/src/main/resources/templates/demo.html
+++ b/src/main/resources/templates/demo.html
@@ -31,6 +31,7 @@
+
@@ -45,6 +46,7 @@
+