@ -5,11 +5,10 @@ import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.ccsens.ht.bean.dto.PatientReportDto ;
import com.ccsens.ht.bean.po.HtPatientReport ;
import com.ccsens.ht.bean.po.HtReportRelevance ;
import com.ccsens.ht.bean.po.HtReportRelevanceExample ;
import com.ccsens.ht.bean.po.* ;
import com.ccsens.ht.bean.vo.PatientReportVo ;
import com.ccsens.ht.persist.dao.HtPatientReportDao ;
import com.ccsens.ht.persist.dao.HtReportDao ;
import com.ccsens.ht.persist.mapper.HtReportRelevanceMapper ;
import com.ccsens.ht.uitl.Constant ;
import com.ccsens.util.CodeEnum ;
@ -22,6 +21,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional ;
import javax.annotation.Resource ;
import java.text.DecimalFormat ;
import java.util.ArrayList ;
import java.util.List ;
@ -35,6 +35,8 @@ public class ExportService implements IExportService {
@Resource
private HtPatientReportDao htPatientReportDao ;
@Resource
private HtReportDao htReportDao ;
@Resource
private HtReportRelevanceMapper reportRelevanceMapper ;
@Resource
private IPatientReportService patientReportService ;
@ -43,7 +45,7 @@ public class ExportService implements IExportService {
@Override
public String exportReport ( PatientReportDto . QueryDetail param , Long userId ) {
if ( StrUtil . isBlank ( param . getReport ( ) ) ) {
if ( StrUtil . isBlank ( param . getReport ( ) ) ) {
param . setReport ( "REPORT1.0" ) ;
}
log . info ( "根据报告单类型导出报告单:{}, 操作用户:{}" , param , userId ) ;
@ -59,9 +61,9 @@ public class ExportService implements IExportService {
HtReportRelevanceExample relevanceExample = new HtReportRelevanceExample ( ) ;
relevanceExample . createCriteria ( ) . andReportIdEqualTo ( param . getId ( ) ) . andReportCodeEqualTo ( param . getReport ( ) ) ;
List < HtReportRelevance > reportRelevanceList = reportRelevanceMapper . selectByExample ( relevanceExample ) ;
if ( CollectionUtil . isNotEmpty ( reportRelevanceList ) ) {
if ( CollectionUtil . isNotEmpty ( reportRelevanceList ) ) {
reportRelevance = reportRelevanceList . get ( 0 ) ;
} else {
} else {
reportRelevance = new HtReportRelevance ( ) ;
reportRelevance . setId ( snowflake . nextId ( ) ) ;
reportRelevance . setReportCode ( param . getReport ( ) ) ;
@ -79,17 +81,17 @@ public class ExportService implements IExportService {
}
log . info ( "报告单和试题信息 {}" , detail ) ;
//添加受试者合作评分和初步印象
PatientReportVo . ReprotPatient patient = detail . getPatient ( ) ;
patient . setWorkingScore ( ObjectUtil . isNull ( reportRelevance . getSocre ( ) ) ? 0 : reportRelevance . getSocre ( ) ) ;
patient . setInitialImpression ( reportRelevance . getImpression ( ) ) ;
// PatientReportVo.ReprotPatient patient = detail.getPatient();
// patient.setWorkingScore(ObjectUtil.isNull(reportRelevance.getSocre()) ? 0 : reportRelevance.getSocre());
// patient.setInitialImpression(reportRelevance.getImpression());
//生成写入pdf数据
List < PdfUtil . Row > content = new ArrayList < > ( ) ;
switch ( param . getReport ( ) ) {
switch ( param . getReport ( ) ) {
case Constant . Ht . Report . PARENT_CODE_2 :
case Constant . Ht . Report . PARENT_CODE_3 :
writeParentCode2 ( content , detail . getScores ( ) ) ;
writeParentCode2 ( content , detail . getScores ( ) ) ;
//添加初步印象和受试者合作评分
addScoreAndImpression ( detail , content ) ;
addScoreAndImpression ( detail . getPatient ( ) . getInitialImpression ( ) , content ) ;
//添加测评员和报告日期
initLast ( content , 2 ) ;
break ;
@ -121,9 +123,77 @@ public class ExportService implements IExportService {
return path ;
}
private void addScoreAndImpression ( PatientReportVo . ReprotDetail detail , List < PdfUtil . Row > content ) {
@Override
public String exportByCode ( PatientReportDto . ExportCode param , Long userId ) {
if ( StrUtil . isBlank ( param . getCode ( ) ) ) {
return null ;
}
log . info ( "导出指定类型的量表:{}, 操作用户:{}" , param , userId ) ;
//查看当前类型属于哪个报告单
String report = "" ;
HtReportExample reportExample = new HtReportExample ( ) ;
reportExample . createCriteria ( ) . andCodeEqualTo ( param . getCode ( ) ) ;
List < HtReport > reportList = htReportDao . selectByExample ( reportExample ) ;
if ( CollectionUtil . isEmpty ( reportList ) ) {
report = reportList . get ( 0 ) . getParentCode ( ) ;
}
// //查询报告单类型关联的信息
// HtReportRelevance reportRelevance;
// HtReportRelevanceExample relevanceExample = new HtReportRelevanceExample();
// relevanceExample.createCriteria().andReportIdEqualTo(param.getId()).andReportCodeEqualTo(report);
// List<HtReportRelevance> reportRelevanceList = reportRelevanceMapper.selectByExample(relevanceExample);
// if(CollectionUtil.isNotEmpty(reportRelevanceList)){
// reportRelevance = reportRelevanceList.get(0);
// }else {
// reportRelevance = new HtReportRelevance();
// reportRelevance.setId(snowflake.nextId());
// reportRelevance.setReportCode(report);
// reportRelevance.setReportId(param.getId());
// reportRelevanceMapper.insertSelective(reportRelevance);
// }
//查看报告单和试题分数信息
// PatientReportVo.ReprotDetail detail = patientReportService.queryReportDetail(param, userId);
// if (detail == null) {
// throw new BaseException(CodeEnum.REPORT_NOT_FOUND);
// }
//查询报告单信息和病人信息
PatientReportVo . ReprotPatient reportPatient = htPatientReportDao . queryReportResult ( param . getId ( ) ) ;
//查询报告单的关联信息
HtReportRelevanceExample relevanceExample = new HtReportRelevanceExample ( ) ;
relevanceExample . createCriteria ( ) . andReportIdEqualTo ( param . getId ( ) ) . andReportCodeEqualTo ( report ) ;
List < HtReportRelevance > reportRelevanceList = reportRelevanceMapper . selectByExample ( relevanceExample ) ;
if ( CollectionUtil . isNotEmpty ( reportRelevanceList ) ) {
reportPatient . setWorkingScore ( ObjectUtil . isNull ( reportRelevanceList . get ( 0 ) . getSocre ( ) ) ? 0 : reportRelevanceList . get ( 0 ) . getSocre ( ) ) ;
reportPatient . setInitialImpression ( reportRelevanceList . get ( 0 ) . getImpression ( ) ) ;
}
//查询报告单分数
List < PatientReportVo . ReportScore > reportScore = htPatientReportDao . queryReportScore2 ( param . getId ( ) , param . getCode ( ) ) ;
//重新封装报告单信息
List < PatientReportVo . ReportScore > scores = patientReportService . getReportScores ( reportScore , param . getId ( ) ) ;
//生成写入pdf数据
List < PdfUtil . Row > content = new ArrayList < > ( ) ;
writeParentCode2 ( content , scores ) ;
//添加初步印象和受试者合作评分
addScoreAndImpression ( reportPatient . getInitialImpression ( ) , content ) ;
//添加测评员和报告日期
initLast ( content , 2 ) ;
//表头
String [ ] split = reportPatient . getHospital ( ) . split ( "" ) ;
String title = String . join ( " " , split ) ;
//生成pdf并返回路径
String path = PropUtil . imgDomain + "/" + PdfUtil . createPdf ( PropUtil . path , title , Constant . Ht . Report . PARENT_NAME , new PdfUtil . Margin ( ) , reportPatient . toPdfRow ( ) , content ) ;
//TODO 将路径存入报告单关联信息表
// reportRelevance.setPdfUrl(path);
// reportRelevanceMapper.updateByPrimaryKeySelective(reportRelevance);
log . info ( "生成文件路径:{}" , path ) ;
return path ;
}
private void addScoreAndImpression ( String initialImpression , List < PdfUtil . Row > content ) {
PdfUtil . Row workingScore = new PdfUtil . Row ( ) ;
workingScore . addCell ( new PdfUtil . Cell ( "受试者合作评分" , 1 , 1 ) ) ;
workingScore . addCell ( new PdfUtil . Cell ( "受试者合作评分" , 1 , 1 ) ) ;
String a = "A 感兴趣、配合关心结果;\n" ;
String b = "B 表现出感兴趣和合作,出于对医生的友好;\n" ;
String c = "C 顺从、不感兴趣;\n" ;
@ -164,16 +234,15 @@ public class ExportService implements IExportService {
PdfUtil . Row impression = new PdfUtil . Row ( ) ;
impression . addCell ( new PdfUtil . Cell ( "初步印象" , 1 , 1 ) ) ;
impression . addCell ( new PdfUtil . Cell ( String . valueOf ( detail . getPatient ( ) . getInitialImpression ( ) ) , 3 , 1 , 1 ) ) ;
impression . addCell ( new PdfUtil . Cell ( "初步印象" , 1 , 1 ) ) ;
impression . addCell ( new PdfUtil . Cell ( initialImpression , 3 , 1 , 1 ) ) ;
content . add ( impression ) ;
}
private void writeParentCode2 ( List < PdfUtil . Row > content , List < PatientReportVo . ReportScore > scores ) {
PdfUtil . Row title = new PdfUtil . Row ( ) ;
title . addCell ( new PdfUtil . Cell ( "项目" ) ) ;
title . addCell ( new PdfUtil . Cell ( ) ) ;
title . addCell ( new PdfUtil . Cell ( "项目" , 2 , 1 ) ) ;
// title.addCell(new PdfUtil.Cell());
title . addCell ( new PdfUtil . Cell ( "得分" ) ) ;
PdfUtil . Cell r = new PdfUtil . Cell ( ) ;
r . setContent ( "异常参考值/说明" ) ;
@ -181,7 +250,7 @@ public class ExportService implements IExportService {
title . addCell ( r ) ;
content . add ( title ) ;
scores . forEach ( reportScore - > {
if ( CollectionUtil . isEmpty ( reportScore . getSubReport ( ) ) ) {
if ( CollectionUtil . isEmpty ( reportScore . getSubReport ( ) ) ) {
PdfUtil . Row row = new PdfUtil . Row ( ) ;
PdfUtil . Cell cellName = new PdfUtil . Cell ( ) ;
@ -189,7 +258,9 @@ public class ExportService implements IExportService {
cellName . setContent ( reportScore . getName ( ) ) ;
row . addCell ( cellName ) ;
PdfUtil . Cell cellScore = new PdfUtil . Cell ( ) ;
cellScore . setContent ( ObjectUtil . isNotNull ( reportScore . getScore ( ) ) ? reportScore . getScore ( ) . toString ( ) : "" ) ;
DecimalFormat df = new DecimalFormat ( "#.#" ) ;
cellScore . setContent ( ObjectUtil . isNotNull ( reportScore . getScore ( ) ) ? df . format ( reportScore . getScore ( ) ) : "" ) ;
row . addCell ( cellScore ) ;
PdfUtil . Cell remark = new PdfUtil . Cell ( ) ;
remark . setContent ( reportScore . getRemark ( ) ) ;
@ -197,11 +268,11 @@ public class ExportService implements IExportService {
row . addCell ( remark ) ;
content . add ( row ) ;
} else {
} else {
for ( int i = 0 ; i < reportScore . getSubReport ( ) . size ( ) ; i + + ) {
PatientReportVo . ReportScore score = reportScore . getSubReport ( ) . get ( i ) ;
PdfUtil . Row row = new PdfUtil . Row ( ) ;
if ( i = = 0 ) {
if ( i = = 0 ) {
PdfUtil . Cell cellName = new PdfUtil . Cell ( ) ;
cellName . setRowSpan ( reportScore . getSubReport ( ) . size ( ) ) ;
cellName . setContent ( reportScore . getName ( ) ) ;
@ -220,7 +291,6 @@ public class ExportService implements IExportService {
}
private PdfUtil . Cell addCell ( PdfUtil . Row row , String content , int colSpan , int rowSpan , int . . . border ) {
PdfUtil . Cell cell1 = new PdfUtil . Cell ( ) ;
cell1 . setContent ( content ) ;