feat: 厦门中医院联众采集端

厦门中医院联众-XiaMenZhongLianZhong
wyb 5 months ago
parent 93b710be70
commit 930a9b3494

@ -19,6 +19,8 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@Repository
@Slf4j
@ -34,82 +36,118 @@ public class DataQuery {
@Value("${lz.disdate-range:}")
private String disdateRange;
private static final Lock cardInfoTableLock = new ReentrantLock();
public List<CardInfo> dateQuery() {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("state"), 0));
if (StringUtils.hasText(disdateRange)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String[] split = disdateRange.split(",");
try {
predicates.add(cb.between(root.<Date>get("outdate"), simpleDateFormat.parse(split[0]), simpleDateFormat.parse(split[1])));
} catch (ParseException e) {
log.error("出院时间条件错误:" + disdateRange + "," + e.getMessage(), e);
cardInfoTableLock.lock();
try {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("state"), 0));
if (StringUtils.hasText(disdateRange)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String[] split = disdateRange.split(",");
try {
predicates.add(cb.between(root.<Date>get("outdate"), simpleDateFormat.parse(split[0]), simpleDateFormat.parse(split[1])));
} catch (ParseException e) {
log.error("出院时间条件错误:" + disdateRange + "," + e.getMessage(), e);
}
}
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
Sort sort = Sort.by(sortCreateTime);
Pageable pageable = PageRequest.of(0, 1000, sort);
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
return all.toList();
} finally {
cardInfoTableLock.unlock();
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
Sort sort = Sort.by(sortCreateTime);
Pageable pageable = PageRequest.of(0, 1000, sort);
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
return all.toList();
}
}
public List<CardInfo> dateQuery(int state) {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("state"), state));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
cardInfoTableLock.lock();
try {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("state"), state));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
List<CardInfo> all = cardInfoRepository.findAll(specification);
return all;
} finally {
cardInfoTableLock.unlock();
List<CardInfo> all = cardInfoRepository.findAll(specification);
return all;
}
}
public List<CardInfo> dateQueryByInpNo(String inpNo) {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("patno"), inpNo));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
cardInfoTableLock.lock();
try {
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("patno"), inpNo));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
Sort sort = Sort.by(sortCreateTime);
Pageable pageable = PageRequest.of(0, 1000, sort);
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
return all.toList();
} finally {
cardInfoTableLock.unlock();
}
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
Sort sort = Sort.by(sortCreateTime);
Pageable pageable = PageRequest.of(0, 1000, sort);
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
return all.toList();
}
public void updateBatch(List<CardInfo> cardInfos) {
for (CardInfo cardInfo : cardInfos) {
cardInfo.setState(1);
cardInfoTableLock.lock();
try {
for (CardInfo cardInfo : cardInfos) {
cardInfo.setState(1);
}
cardInfoRepository.saveAll(cardInfos);
} finally {
cardInfoTableLock.unlock();
}
cardInfoRepository.saveAll(cardInfos);
}
public void updateBatchState(List<CardInfo> cardInfos, Integer state) {
List<String> ids = new ArrayList<>();
for (CardInfo cardInfo : cardInfos) {
String id = cardInfo.getId();
ids.add(id);
cardInfoTableLock.lock();
try {
List<String> ids = new ArrayList<>();
for (CardInfo cardInfo : cardInfos) {
String id = cardInfo.getId();
ids.add(id);
}
cardInfoRepository.updateState(ids, state);
} finally {
cardInfoTableLock.unlock();
}
cardInfoRepository.updateState(ids, state);
}
public void updateBatchState(CardInfo cardInfo, Integer state) {
cardInfoTableLock.lock();
try {
cardInfoRepository.updateState(cardInfo.getId(), state);
} finally {
cardInfoTableLock.unlock();
cardInfoRepository.updateState(cardInfo.getId(), state);
}
}
public List<Picture> getPictures(String FileId) {
Specification<Picture> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("fileid"), FileId));
@ -121,11 +159,23 @@ public class DataQuery {
public void updateBatchState(CardInfo cardInfo, Integer state, String desc) {
cardInfoRepository.updateState(cardInfo.getId(), state, desc);
cardInfoTableLock.lock();
try {
cardInfoRepository.updateState(cardInfo.getId(), state, desc);
} finally {
cardInfoTableLock.unlock();
}
}
public void updatePicPath(CardInfo cardInfo, String findpicpath) {
cardInfoRepository.updatePicPath(cardInfo.getId(), findpicpath);
cardInfoTableLock.lock();
try {
cardInfoRepository.updatePicPath(cardInfo.getId(), findpicpath);
} finally {
cardInfoTableLock.unlock();
}
}
}

@ -8,7 +8,6 @@ import java.util.List;
*
*/
@Data
public class LianZhongUploadInfo {
/**
*
@ -36,6 +35,10 @@ public class LianZhongUploadInfo {
*
*/
private String sexName;
/**
* -
*/
private Integer age;
/**
* yyyy-MM-dd HH:mm:ss
*/

@ -28,4 +28,7 @@ public class Picture {
@Column(name="pickind")
private String pickind;
@Column(name="picno")
private Integer picno;
}

@ -10,18 +10,24 @@ import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -37,6 +43,8 @@ public class UpdateService {
@Autowired
private DataQuery dataQuery;
private Set<String> lianZhongPatPicDirs = new HashSet<>();
public List<CardInfo> updateData() {
List<CardInfo> cardInfos = dataQuery.dateQuery();
dataQuery.updateBatchState(cardInfos, 1);
@ -49,6 +57,7 @@ public class UpdateService {
@PostConstruct
public void upload() {
initLianZhongPatPicDir();
log.info("联众同步数据启动>>>>>>>>>>>>>>>>>>>>");
String syncDir = FilePathUtil.currentPath() + File.separator + "lianzhong-sync";
FilePathUtil.mkdirs(syncDir);
@ -115,7 +124,7 @@ public class UpdateService {
LianZhongUploadInfo.PatientInfo patientInfo = convert(cardInfo);
List<LianZhongUploadInfo.FileInfo> fileInfos = new ArrayList<>();
List<String> faultFileNames = new ArrayList<>();
List<String> faultFileNames = new ArrayList<>();
List<File> files = new ArrayList<>();
for (Picture picture : pictures) {
File pictureFile = new File(picDir + File.separator + removeFileExtension(picture.getPicname()) + ".jpg");
@ -124,17 +133,16 @@ public class UpdateService {
continue;
}
files.add(pictureFile);
LianZhongUploadInfo.FileInfo fileInfo=new LianZhongUploadInfo.FileInfo();
LianZhongUploadInfo.FileInfo fileInfo = new LianZhongUploadInfo.FileInfo();
fileInfo.setFileTitle(picture.getPicname());
fileInfo.setUploadFileName(pictureFile.getName());
fileInfo.setAssortId(picture.getPickind());
// todo 应该有个排序
fileInfo.setSort(0);
fileInfo.setSort(picture.getPicno());
fileInfos.add(fileInfo);
}
if (files.isEmpty()) {
dataQuery.updateBatchState(cardInfo, 2,"未获取到图片!");
dataQuery.updateBatchState(cardInfo, 2, "未获取到图片!");
// 删除文件
FilePathUtil.deleteDir(picDir);
return;
@ -166,7 +174,7 @@ public class UpdateService {
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(batch, "http://192.168.161.102:9511/lianzhong/batchFileUploadJpg", params);
CommonResult commonResult = FileUploader.uploadFilesWithParams(batch, "http://129.7.1.25:9511/lianzhong/batchFileUploadJpg", params);
boolean res = commonResult.getCode() == 0;
success = success && res;
}
@ -175,7 +183,7 @@ public class UpdateService {
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, "http://192.168.161.102:9511/lianzhong/batchFileUploadJpg", params);
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, "http://129.7.1.25:9511/lianzhong/batchFileUploadJpg", params);
success = commonResult.getCode() == 0;
}
@ -183,24 +191,24 @@ public class UpdateService {
dataQuery.updateBatchState(cardInfo, 3);
} else {
dataQuery.updateBatchState(cardInfo, 2,"上传服务端出现异常!");
dataQuery.updateBatchState(cardInfo, 2, "上传服务端出现异常!");
}
} catch (Exception e) {
dataQuery.updateBatchState(cardInfo, 2,e.getMessage());
dataQuery.updateBatchState(cardInfo, 2, e.getMessage());
log.error(e.getMessage(), e);
}
if (!faultFileNames.isEmpty()) {
// 不完整
dataQuery.updateBatchState(cardInfo, 2,String.join(",",faultFileNames+" 无法转换jpg图片"));
dataQuery.updateBatchState(cardInfo, 2, String.join(",", faultFileNames + " 无法转换jpg图片"));
}
// 删除文件
FilePathUtil.deleteDir(picDir);
}catch (Exception ex){
log.error(ex.getMessage(),ex);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
FilePathUtil.deleteDir(picDir);
dataQuery.updateBatchState(cardInfo, 2,ex.getMessage());
dataQuery.updateBatchState(cardInfo, 2, ex.getMessage());
}
});
patientFutures.add(patientFuture);
@ -217,24 +225,121 @@ public class UpdateService {
}
}
public static void main(String[] args) {
UpdateService updateService = new UpdateService();
System.out.println(new Gson().toJson(updateService.lianZhongPatPicDirs));
updateService.initLianZhongPatPicDir();
System.out.println(new Gson().toJson(updateService.lianZhongPatPicDirs));
}
private void initLianZhongPatPicDir() {
log.info(">>>>>>>>>>>>初始化联众患者文件目录");
String readFilePath = FilePathUtil.currentPath() + File.separator + "lianzhong-patpic-dir.txt";
File readFile = new File(readFilePath);
if (readFile.exists()) {
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(readFile))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
lianZhongPatPicDirs.add(line);
}
return;
} catch (Exception ex) {
log.error(">>>>>>>>>>>> 初始化联众患者文件目录读取存储文件错误!");
}
}
List<String> rootDirs = Arrays.asList("D:\\UnionNet\\ServerD", "D:\\UnionNet\\ServerD_ny", "D:\\UnionNet\\ServerDTemp",
"G:\\UnionNet\\ServerD", "G:\\UnionNet\\ServerD_ny", "G:\\UnionNet\\ServerDTemp");
for (String rootDir : rootDirs) {
File rootDirFile = new File(rootDir);
if (!rootDirFile.exists()) {
continue;
}
// 第一层 年 ,如果有,后面基本都会有
File[] level1 = rootDirFile.listFiles();
if (level1 == null || level1.length <= 0) {
continue;
}
for (File level1File : level1) {
// 第二层 年月
File[] level2 = level1File.listFiles();
if (level2 == null || level2.length <= 0) {
continue;
}
for (File level2File : level2) {
if (level2File.isDirectory()) {
// 第三层 年月日
File[] level3 = level2File.listFiles();
if (level3 == null || level3.length <= 0) {
continue;
}
for (File level3File : level3) {
if (level3File.isDirectory()) {
// 第四层,患者存放文件的最后一级目录
File[] level4 = level3File.listFiles();
if (level4 == null || level4.length <= 0) {
continue;
}
for (File level4File : level4) {
if (level4File.isDirectory()) {
lianZhongPatPicDirs.add(level4File.getPath());
}
}
}
}
}
}
}
}
if (!lianZhongPatPicDirs.isEmpty()) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(readFile));) {
for (String picDir : lianZhongPatPicDirs) {
writer.write(picDir);
writer.newLine();
}
} catch (Exception ex) {
log.error("持久化联众患者文件目录错误:" + ex.getMessage(), ex);
if (readFile.exists()) {
readFile.delete();
}
}
}
}
private LianZhongUploadInfo.PatientInfo convert(CardInfo cardInfo) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LianZhongUploadInfo.PatientInfo patientInfo=new LianZhongUploadInfo.PatientInfo();
// todo 病案号
patientInfo.setInpatientNo(null);
// todo 住院次数
patientInfo.setAdmissTimes(null);
LianZhongUploadInfo.PatientInfo patientInfo = new LianZhongUploadInfo.PatientInfo();
patientInfo.setInpatientNo(cardInfo.getPatno());
String gestno = cardInfo.getGestno();
// 123步设置住院次数
Integer admissTimes = cardInfo.getPatnum();
if (admissTimes == null && StringUtils.hasText(gestno)) {
try {
String admissTimesStr = removeLeadingZeros(gestno.substring(gestno.length() - 3));
admissTimes = Integer.valueOf(admissTimesStr);
} catch (Exception ex) {
log.error("无法解析gestno{} 当中的住院次数!", gestno);
}
}
// 没办法获取那就直接用出院的日期当住院次数
if (admissTimes == null) {
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
admissTimes = Integer.valueOf(sdf2.format(cardInfo.getOutdate()));
}
patientInfo.setAdmissTimes(admissTimes);
patientInfo.setAge(cardInfo.getPatage());
patientInfo.setName(cardInfo.getPatname());
// todo 年龄
patientInfo.setSex("") ;
patientInfo.setSexName("") ;
patientInfo.setAdmissDate(cardInfo.getIndate() == null ?null:sdf.format(cardInfo.getIndate())) ;
patientInfo.setDisDate(cardInfo.getOutdate() == null ?null:sdf.format(cardInfo.getOutdate()));
patientInfo.setAdmissDeptName(cardInfo.getIndeptname()) ;
patientInfo.setSex("1".equals(cardInfo.getPatsex()) ? "男" : "女");
patientInfo.setSexName("");
patientInfo.setAdmissDate(cardInfo.getIndate() == null ? null : sdf.format(cardInfo.getIndate()));
patientInfo.setDisDate(cardInfo.getOutdate() == null ? null : sdf.format(cardInfo.getOutdate()));
patientInfo.setAdmissDeptName(cardInfo.getIndeptname());
patientInfo.setDisDeptName(cardInfo.getOutdeptname());
patientInfo.setIdCard(cardInfo.getPatciticard()) ;
patientInfo.setMainDiagCode(null) ;
patientInfo.setMainDiagName(null) ;
patientInfo.setIdCard(cardInfo.getPatciticard());
patientInfo.setMainDiagCode(null);
patientInfo.setMainDiagName(null);
patientInfo.setMainOperateCode(null);
patientInfo.setMainOperateName(null);
return patientInfo;
@ -243,41 +348,20 @@ public class UpdateService {
private String findLianZhongDir(CardInfo cardInfo) {
String gestno = cardInfo.getGestno();
String patno = cardInfo.getPatno();
Date outdate = cardInfo.getOutdate();
SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
SimpleDateFormat yearMonthSdf = new SimpleDateFormat("yyyyMM");
SimpleDateFormat yearMonthDaySdf = new SimpleDateFormat("yyyyMMdd");
String yFormat = yearSdf.format(outdate);
String ymFormat = yearMonthSdf.format(outdate);
String ymdFormat = yearMonthDaySdf.format(outdate);
List<String> archiveDirs = Arrays.asList(
"D:\\UnionNet\\ServerD",
"D:\\UnionNet\\ServerD_ny",
"D:\\UnionNet\\ServerDTemp",
"G:\\UnionNet\\ServerD",
"G:\\UnionNet\\ServerD_ny",
"G:\\UnionNet\\ServerDTemp");
for (String archiveDir : archiveDirs) {
String ymdDateDir = archiveDir + File.separator + yFormat + File.separator + ymFormat + File.separator + ymdFormat;
File ymdDateDirFile = new File(ymdDateDir);
if (!ymdDateDirFile.exists()) {
continue;
}
File[] patPicDirs = ymdDateDirFile.listFiles();
if (patPicDirs != null && patPicDirs.length > 0) {
for (File patPicDir : patPicDirs) {
String dirName = patPicDir.getName();
String comparePart = dirName.substring(2).substring(0, 10);
comparePart = removeLeadingZeros(comparePart);
//TODO gestno 或者 patno 进行 识别
boolean match = comparePart.contains(removeLeadingZeros(patno));
if (match) {
return patPicDir.getPath();
}
for (String lianZhongPatPicDir : lianZhongPatPicDirs) {
String dirName = new File(lianZhongPatPicDir).getName();
String comparePart = dirName.substring(2).substring(0, 10);
comparePart = removeLeadingZeros(comparePart);
// gestno 或者 patno 进行 识别
if (StringUtils.hasText(gestno)) {
if (comparePart.contains(removeLeadingZeros(gestno))) {
return lianZhongPatPicDir;
}
}
if (comparePart.contains(removeLeadingZeros(patno))) {
return lianZhongPatPicDir;
}
}
return null;
}

@ -7,9 +7,9 @@ lz:
spring:
datasource:
url: jdbc:sqlserver://192.168.8.74:1433;DatabaseName=u_medrecord
url: jdbc:sqlserver://192.169.2.170:1433;DatabaseName=u_medrecord
username: sa
password: 17931
password: 17931@Uni
# url: jdbc:sqlserver://10.36.116.108:1433;DatabaseName=emr_record
# username: sa
# password: xjgs+docus911

@ -1,5 +1,7 @@
package com.jiashi;
import com.google.gson.Gson;
import com.jiashi.service.LianZhongUploadInfo;
import okhttp3.*;
@ -43,23 +45,17 @@ public class FileUploader {
public static void main(String[] args) throws IOException {
List<File> files = new ArrayList<>();
files.add(new File("C:\\Downloads\\LH0001.jpg"));
files.add(new File("C:\\Users\\wyb\\Pictures\\head.jpg"));
// files.add(new File("C:\\jiahsi-saomiao\\413425_刘燊杨_20221009_004624\\16763947060420811242.jpg"));
// 额外的表单字段参数
List<FormField> params = new ArrayList<>();
params.add(new FormField("uploadFileParams", "[ {\"inpatientNo\":\"35131\", \"disDate\":\"2020-07-30 00:00:00.000\", \"fileTitle\":\"16763947060057863381.jpg\", \"uploadFileName\":\"16763947060057863381.jpg\", \"assortId\":\"078F7675CB0048EDBE586D59831C57B0\" ,\n" +
"\"patientId\":\"12312312\",\n" +
"\"name\":\"长三\",\n" +
"\"admissDate\":\"2022-02-01\",\n" +
"\"sex\":\"男女\"\n" +
"}\n" +
"]"));
params.add(new FormField("uploadFileParams", new Gson().toJson(new LianZhongUploadInfo())));
// 上传URL
String uploadUrl = "http://192.168.16.116:9511/sync/fileUploadJpg";
String uploadUrl = "http://127.0.0.1:9511/lianzhong/batchFileUploadJpg";
// 执行批量上传
uploadFilesWithParams(files, uploadUrl, params);

Loading…
Cancel
Save