|
|
|
@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.docus.core.util.Func;
|
|
|
|
|
import com.docus.log.annotation.TrackRetryListener;
|
|
|
|
|
import com.docus.server.api.ocr.OcrApi;
|
|
|
|
|
import com.docus.server.common.service.IFileUploadService;
|
|
|
|
|
import com.docus.server.dto.segmentation.FileDTO;
|
|
|
|
|
import com.docus.server.dto.segmentation.UploadBatchFileRequest;
|
|
|
|
|
import com.docus.server.entity.segmentation.*;
|
|
|
|
@ -12,9 +13,11 @@ import com.docus.server.infrastructure.dao.IOcrBasicDao;
|
|
|
|
|
import com.docus.server.infrastructure.dao.IOcrFileInfoDao;
|
|
|
|
|
import com.docus.server.infrastructure.dao.IOcrUrlConfigDao;
|
|
|
|
|
import com.docus.server.infrastructure.dao.IOcrVersionDao;
|
|
|
|
|
import com.docus.server.service.IOcrCutConfigService;
|
|
|
|
|
import com.docus.server.service.IOcrRuleService;
|
|
|
|
|
import com.docus.server.service.IOcrSpecialRuleService;
|
|
|
|
|
import com.docus.server.service.impl.PlatformServiceImpl;
|
|
|
|
|
import com.docus.server.vo.segmentation.ocrcutconfig.OcrCutConfigVO;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -45,7 +48,11 @@ public class StartSegmentHandler {
|
|
|
|
|
@Resource
|
|
|
|
|
private IOcrBasicDao iOcrBasicDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private PlatformServiceImpl platformService;
|
|
|
|
|
private PlatformServiceImpl platformService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IFileUploadService iFileUploadService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IOcrCutConfigService iOcrCutConfigService;
|
|
|
|
|
|
|
|
|
|
@TrackRetryListener("START_SEGMENT")
|
|
|
|
|
public void startSegment(String patientId) {
|
|
|
|
@ -53,21 +60,27 @@ public class StartSegmentHandler {
|
|
|
|
|
boolean isSpecialFile = false;
|
|
|
|
|
OcrSpecialResult lastSpecialResul = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OcrVersion ocrVersion = iOcrVersionDao.findOneBy("isEnable", "1");
|
|
|
|
|
if (ocrVersion==null){
|
|
|
|
|
if (ocrVersion == null) {
|
|
|
|
|
throw new RuntimeException("当前没有启用的版本号");
|
|
|
|
|
}
|
|
|
|
|
Integer version = ocrVersion.getVersion();
|
|
|
|
|
|
|
|
|
|
//根据病案号查询文件列表
|
|
|
|
|
List<OcrBasic> ocrBasicList = iOcrBasicDao.findBy("patientId",patientId);
|
|
|
|
|
String url = iOcrUrlConfigDao.findBy("version",version).get(0).getUrl();
|
|
|
|
|
List<OcrFileInfo> fileInfoList = iOcrFileInfoDao.findBy("patientId",patientId);
|
|
|
|
|
List<OcrBasic> ocrBasicList = iOcrBasicDao.findBy("patientId", patientId);
|
|
|
|
|
String url = iOcrUrlConfigDao.findBy("version", version).get(0).getUrl();
|
|
|
|
|
List<OcrFileInfo> fileInfoList = iOcrFileInfoDao.findBy("patientId", patientId);
|
|
|
|
|
OcrCutConfigVO ocrCutConfigVO = iOcrCutConfigService.findByVersion(ocrVersion.getVersion());
|
|
|
|
|
Double height = ocrCutConfigVO.getHeight();
|
|
|
|
|
Double widthStart = ocrCutConfigVO.getWidthStart();
|
|
|
|
|
Double widthEnd = ocrCutConfigVO.getWidthEnd();
|
|
|
|
|
|
|
|
|
|
List<File> files = new ArrayList<>(fileInfoList.size());
|
|
|
|
|
List<FileDTO> fileDTOList = new ArrayList<>(fileInfoList.size());
|
|
|
|
|
for (OcrFileInfo fileInfo:fileInfoList) {
|
|
|
|
|
for (OcrFileInfo fileInfo : fileInfoList) {
|
|
|
|
|
iFileUploadService.compressFile(fileInfo.getPicCompressUrl(),fileInfo.getPicUrl(),fileInfo.getPicName(),height);
|
|
|
|
|
iFileUploadService.cutPic(fileInfo.getPicCutUrl(),fileInfo.getPicCompressUrl(),fileInfo.getPicName(),widthStart,widthEnd);
|
|
|
|
|
|
|
|
|
|
boolean assortFlag = false;
|
|
|
|
|
String assortId = null;
|
|
|
|
|
String assortName = null;
|
|
|
|
@ -76,19 +89,16 @@ public class StartSegmentHandler {
|
|
|
|
|
Double rate = null;
|
|
|
|
|
|
|
|
|
|
//遍历文件列表 获取ocr识别结果
|
|
|
|
|
List<String> ocrTextList = ocrApi.getText(fileInfo.getPicCutUrl(),url);
|
|
|
|
|
List<String> ocrTextList = ocrApi.getText(fileInfo.getPicCutUrl(), url);
|
|
|
|
|
|
|
|
|
|
fileInfo.setOcrText(Func.toJson(ocrTextList));
|
|
|
|
|
fileInfo.setOcrStatus(OcrStatusEnum.COMPLETE);
|
|
|
|
|
fileInfo.setOcrFinishTime(new Date());
|
|
|
|
|
//判断上次是否特殊文件开始 需要判断是否特殊文件结尾
|
|
|
|
|
if (isSpecialFile){
|
|
|
|
|
assortId = lastSpecialResul.getAssortId();
|
|
|
|
|
assortName = lastSpecialResul.getAssortName();
|
|
|
|
|
ruleId = lastSpecialResul.getRuleId();
|
|
|
|
|
if (isSpecialFile) {
|
|
|
|
|
assortId = lastSpecialResul.getAssortId();
|
|
|
|
|
assortName = lastSpecialResul.getAssortName();
|
|
|
|
|
ruleId = lastSpecialResul.getRuleId();
|
|
|
|
|
|
|
|
|
|
boolean b = iOcrSpecialRuleService.handleSpecialRuleEnd(lastSpecialResul, ocrTextList);
|
|
|
|
|
if (b){
|
|
|
|
|
if (b) {
|
|
|
|
|
//当前分段为特殊分段结尾
|
|
|
|
|
isSpecialFile = false;
|
|
|
|
|
lastSpecialResul = null;
|
|
|
|
@ -96,15 +106,15 @@ public class StartSegmentHandler {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//优先判断是否特殊规则开始
|
|
|
|
|
if (!assortFlag){
|
|
|
|
|
OcrSpecialResult ocrSpecialResult = iOcrSpecialRuleService.handleSpecialRule(ocrTextList,version);
|
|
|
|
|
if (!assortFlag) {
|
|
|
|
|
OcrSpecialResult ocrSpecialResult = iOcrSpecialRuleService.handleSpecialRule(ocrTextList, version);
|
|
|
|
|
//判断是否属于某个分段
|
|
|
|
|
if (ocrSpecialResult!=null){
|
|
|
|
|
assortId = ocrSpecialResult.getAssortId();
|
|
|
|
|
assortName = ocrSpecialResult.getAssortName();
|
|
|
|
|
ruleId = ocrSpecialResult.getRuleId();
|
|
|
|
|
hitKey = ocrSpecialResult.getHitKey();
|
|
|
|
|
rate = ocrSpecialResult.getRate();
|
|
|
|
|
if (ocrSpecialResult != null) {
|
|
|
|
|
assortId = ocrSpecialResult.getAssortId();
|
|
|
|
|
assortName = ocrSpecialResult.getAssortName();
|
|
|
|
|
ruleId = ocrSpecialResult.getRuleId();
|
|
|
|
|
hitKey = ocrSpecialResult.getHitKey();
|
|
|
|
|
rate = ocrSpecialResult.getRate();
|
|
|
|
|
|
|
|
|
|
isSpecialFile = true;
|
|
|
|
|
lastSpecialResul = ocrSpecialResult;
|
|
|
|
@ -112,18 +122,18 @@ public class StartSegmentHandler {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!assortFlag){
|
|
|
|
|
OcrRuleResult ocrRuleResult = iOcrRuleService.handleRule(ocrTextList,version);
|
|
|
|
|
if (!assortFlag) {
|
|
|
|
|
OcrRuleResult ocrRuleResult = iOcrRuleService.handleRule(ocrTextList, version);
|
|
|
|
|
//更新文件数据的分段
|
|
|
|
|
if (ocrRuleResult!=null){
|
|
|
|
|
if (ocrRuleResult != null) {
|
|
|
|
|
assortId = ocrRuleResult.getAssortId();
|
|
|
|
|
assortName = ocrRuleResult.getAssortName();
|
|
|
|
|
ruleId = ocrRuleResult.getRuleId();
|
|
|
|
|
hitKey = ocrRuleResult.getHitKey();
|
|
|
|
|
rate = ocrRuleResult.getRate();
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
assortId = "-1";
|
|
|
|
|
assortName="其他";
|
|
|
|
|
assortName = "其他";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,9 +142,11 @@ public class StartSegmentHandler {
|
|
|
|
|
fileInfo.setRuleId(ruleId);
|
|
|
|
|
fileInfo.setHitKey(hitKey);
|
|
|
|
|
fileInfo.setRate(rate);
|
|
|
|
|
fileInfo.setOcrText(Func.toJson(ocrTextList));
|
|
|
|
|
fileInfo.setOcrStatus(OcrStatusEnum.COMPLETE);
|
|
|
|
|
fileInfo.setOcrFinishTime(new Date());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File file = new File(fileInfo.getPicUrl());
|
|
|
|
|
File file = new File(fileInfo.getPicUrl());
|
|
|
|
|
files.add(file);
|
|
|
|
|
|
|
|
|
|
FileDTO fileDTO = new FileDTO();
|
|
|
|
@ -153,11 +165,11 @@ public class StartSegmentHandler {
|
|
|
|
|
p.setOcrStatue(OcrStatusEnum.COMPLETE);
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
iOcrBasicDao.updateBatchById(collect,iOcrBasicDao.DEFAULT_BATCH_SIZE);
|
|
|
|
|
iOcrFileInfoDao.updateBatchById(fileInfoList,iOcrFileInfoDao.DEFAULT_BATCH_SIZE);
|
|
|
|
|
iOcrBasicDao.updateBatchById(collect, iOcrBasicDao.DEFAULT_BATCH_SIZE);
|
|
|
|
|
iOcrFileInfoDao.updateBatchById(fileInfoList, iOcrFileInfoDao.DEFAULT_BATCH_SIZE);
|
|
|
|
|
|
|
|
|
|
//数据上传到3.0
|
|
|
|
|
OcrBasic ocrBasic =ocrBasicList.get(0);
|
|
|
|
|
OcrBasic ocrBasic = ocrBasicList.get(0);
|
|
|
|
|
|
|
|
|
|
UploadBatchFileRequest request = new UploadBatchFileRequest();
|
|
|
|
|
request.setInpatientNo(ocrBasic.getInpatientNo());
|
|
|
|
|