@ -116,7 +116,7 @@ public class PatientReportService implements IPatientReportService {
example . createCriteria ( ) . andUserIdEqualTo ( userId ) . andAuditStateEqualTo ( Constant . Ht . Doctor . CHECK_SUCCESS ) ;
List < HtDoctor > doctors = htDoctorDao . selectByExample ( example ) ;
if ( CollectionUtils . isEmpty ( doctors ) ) {
log . info ( "{}医生信息尚未审核通过" ) ;
log . info ( "{}医生信息尚未审核通过" , userId ) ;
return CodeEnum . AUDIT_NOT_PASS ;
}
HtDoctor doctor = doctors . get ( 0 ) ;
@ -224,53 +224,24 @@ public class PatientReportService implements IPatientReportService {
PatientReportVo . ReprotPatient reportPatient = htPatientReportDao . queryReportResult ( queryDetail . getId ( ) ) ;
//查询报告单分数
List < PatientReportVo . ReportScore > reportScore = htPatientReportDao . queryReportScore ( queryDetail . getId ( ) , queryDetail . getRey ( ) , queryDetail . getReport ( ) ) ;
long reportId = queryDetail . getId ( ) ;
//重新封装报告单信息
Map < String , PatientReportVo . ReportScore > map = new HashMap < > ( 32 ) ;
List < PatientReportVo . ReportScore > scores = new ArrayList < > ( ) ;
reportScore . forEach ( score - > {
if ( ObjectUtil . isNotNull ( score . getScore ( ) ) ) {
if ( BigDecimal . valueOf ( score . getScore ( ) . intValue ( ) ) . compareTo ( score . getScore ( ) ) = = 0 ) {
score . setScore ( score . getScore ( ) . setScale ( 0 , BigDecimal . ROUND_HALF_UP ) ) ;
}
}
map . put ( score . getCode ( ) , score ) ;
//测评类(MOCA等)
if ( Constant . Ht . Report . TYPE_EVALUATION = = score . getType ( ) ) {
String specialCode = "NPI" ;
if ( specialCode . equalsIgnoreCase ( score . getCode ( ) ) ) {
initNPI ( queryDetail , score ) ;
}
scores . add ( score ) ;
} else {
log . info ( "score:{}" , score ) ;
map . get ( score . getParentCode ( ) ) . addSub ( score ) ;
}
} ) ;
scores . forEach ( score - > {
if ( Constant . Ht . Report . MOCA_SJZ . equalsIgnoreCase ( score . getCode ( ) ) ) {
return ;
}
sumScore ( score ) ;
} ) ;
List < PatientReportVo . ReportScore > scores = getReportScores ( reportScore , reportId ) ;
detail . setPatient ( reportPatient ) ;
detail . setScores ( scores ) ;
return detail ;
}
private void initNPI ( PatientReportDto . QueryDetail queryDetail , PatientReportVo . ReportScore score ) {
List < Map < String , Object > > list = htPatientReportDao . queryNPIScore ( queryDeta il . getI d( ) ) ;
private void initNPI ( long id , PatientReportVo . ReportScore score ) {
List < Map < String , Object > > list = htPatientReportDao . queryNPIScore ( id ) ;
Map < String , Object > npiScore = new HashMap < > ( ) ;
list . forEach ( map - > {
npiScore . put ( ( String ) map . get ( "optionName" ) , map . get ( "score" ) ) ;
} ) ;
list . forEach ( map - > npiScore . put ( ( String ) map . get ( "optionName" ) , map . get ( "score" ) ) ) ;
PatientReportVo . ReportScore carer = new PatientReportVo . ReportScore ( ) ;
carer . setCode ( "carer" ) ;
carer . setName ( "照顾者" ) ;
carer . setTotalScore ( - 1 ) ;
carer . setScore ( npiScore = = null | | npiScore . get ( "carer" ) = = null ? null : ( ( BigDecimal ) npiScore . get ( "carer" ) ) ) ;
carer . setScore ( npiScore . get ( "carer" ) = = null ? null : ( ( BigDecimal ) npiScore . get ( "carer" ) ) ) ;
if ( ObjectUtil . isNotNull ( carer . getScore ( ) ) ) {
carer . setScore ( carer . getScore ( ) . setScale ( 0 , BigDecimal . ROUND_HALF_UP ) ) ;
}
@ -281,7 +252,7 @@ public class PatientReportService implements IPatientReportService {
patient . setCode ( "result" ) ;
patient . setName ( "患者" ) ;
patient . setTotalScore ( - 1 ) ;
patient . setScore ( npiScore = = null | | npiScore . get ( "result" ) = = null ? null : ( ( BigDecimal ) npiScore . get ( "result" ) ) ) ;
patient . setScore ( npiScore . get ( "result" ) = = null ? null : ( ( BigDecimal ) npiScore . get ( "result" ) ) ) ;
if ( ObjectUtil . isNotNull ( patient . getScore ( ) ) ) {
patient . setScore ( patient . getScore ( ) . setScale ( 0 , BigDecimal . ROUND_HALF_UP ) ) ;
}
@ -331,17 +302,15 @@ public class PatientReportService implements IPatientReportService {
/ * *
* 为上级求和
* @param score
* @return : java . lang . Integer
* @Author : wuHuiJuan
* @param score 分数
* @author wuHuiJuan
* @date : 2019 / 11 / 19 15 : 42
* /
private BigDecimal sumScore ( PatientReportVo . ReportScore score ) {
AtomicReference < BigDecimal > sum = new AtomicReference < > ( score . getScore ( ) = = null ? BigDecimal . valueOf ( 0 ) : score . getScore ( ) ) ;
AtomicBoolean hasAdd = new AtomicBoolean ( false ) ;
if ( ! CollectionUtils . isEmpty ( score . getSubReport ( ) ) ) {
score . getSubReport ( ) . forEach ( sub - > {
sum . updateAndGet ( v - > {
score . getSubReport ( ) . forEach ( sub - > sum . updateAndGet ( v - > {
BigDecimal sumScore = sumScore ( sub ) ;
if ( sumScore = = null ) {
return v ;
@ -350,8 +319,7 @@ public class PatientReportService implements IPatientReportService {
// return v += sumScore;
v = v . add ( sumScore ) ;
return v ;
} ) ;
} ) ;
} ) ) ;
} else {
if ( StringUtil . isNotEmpty ( score . getRemark ( ) ) & & score . getRemark ( ) . matches ( Constant . Ht . Report . IGNORE_SCORE ) ) {
return score . getScore ( ) = = null ? null : BigDecimal . valueOf ( 0 ) ;
@ -387,9 +355,7 @@ public class PatientReportService implements IPatientReportService {
throw new BaseException ( CodeEnum . REPORT_NOT_FOUND ) ;
}
List < PdfUtil . Row > content = new ArrayList < > ( ) ;
detail . getScores ( ) . forEach ( reportScore - > {
content . addAll ( reportScore . toRow ( ) ) ;
} ) ;
detail . getScores ( ) . forEach ( reportScore - > content . addAll ( reportScore . toRow ( ) ) ) ;
PdfUtil . Row row = new PdfUtil . Row ( ) ;
PdfUtil . Cell initWordCell = addCell ( row , "初步印象" , 2 , 2 ) ;
initWordCell . setHeight ( PdfUtil . Cell . defaultHeight * 2 ) ;
@ -398,16 +364,9 @@ public class PatientReportService implements IPatientReportService {
initImplCell . setBorderRight ( 1 ) ;
initImplCell . setCenter ( false ) ;
content . add ( row ) ;
PdfUtil . Row row2 = new PdfUtil . Row ( ) ;
PdfUtil . Cell doctorCell = addCell ( row2 , "测评员:" , 4 , 1 , 0 ) ;
doctorCell . setBorderBottom ( null ) ;
doctorCell . setBorderLeft ( null ) ;
PdfUtil . Cell dateCell = addCell ( row2 , "报告日期:" , 4 , 1 , 0 ) ;
dateCell . setBorderBottom ( null ) ;
dateCell . setBorderLeft ( null ) ;
content . add ( row2 ) ;
initLast ( content , 8 ) ;
String path = PropUtil . imgDomain + "/" + PdfUtil . cred atePdf ( PropUtil . path , detail . getPatient ( ) . getHospital ( ) , Constant . Ht . Report . PARENT_NAME , detail . getPatient ( ) . toPdfRow ( ) , content , new PdfUtil . Margin ( ) ) ;
String path = PropUtil . imgDomain + "/" + PdfUtil . createPdf ( PropUtil . path , detail . getPatient ( ) . getHospital ( ) , Constant . Ht . Report . PARENT_NAME , new PdfUtil . Margin ( ) , detail . getPatient ( ) . toPdfRow ( ) , content ) ;
report . setUrl ( path ) ;
htPatientReportDao . updateByPrimaryKeySelective ( report ) ;
log . info ( "生成文件路径:{}" , path ) ;
@ -431,8 +390,7 @@ public class PatientReportService implements IPatientReportService {
@Override
public PatientReportVo . Complete checkComplete ( Long userId ) {
PatientReportVo . Complete complete = htPatientReportDao . checkComplete ( userId ) ;
return complete ;
return htPatientReportDao . checkComplete ( userId ) ;
}
@Override
@ -491,9 +449,7 @@ public class PatientReportService implements IPatientReportService {
log . info ( "未查询到报告单" ) ;
return new PageInfo < > ( reports ) ;
}
reports . forEach ( report - > {
report . setAuthority ( ( byte ) 1 ) ;
} ) ;
reports . forEach ( report - > report . setAuthority ( ( byte ) 1 ) ) ;
return new PageInfo < > ( reports ) ;
}
@ -531,7 +487,7 @@ public class PatientReportService implements IPatientReportService {
}
byte prevAge = ages . get ( ages . size ( ) - 1 ) ;
PatientReportVo . AgeAndSexGroup prevGroup = groups . get ( groups . size ( ) - 1 ) ;
byte nowAge = ageAndSex . getAgeLevel ( ) . byteValue ( ) ;
byte nowAge = ageAndSex . getAgeLevel ( ) ;
if ( prevAge = = nowAge ) {
fillBySex ( ageAndSex , prevGroup ) ;
} else {
@ -564,8 +520,7 @@ public class PatientReportService implements IPatientReportService {
private void fillBySex ( PatientReportVo . AgeAndSex ageAndSex , PatientReportVo . AgeAndSexGroup group ) {
if ( ageAndSex . getAgeLevel ( ) = = null ) {
log . info ( "性别不确定" ) ;
return ;
} else if ( ageAndSex . getSex ( ) . byteValue ( ) = = Constant . Ht . SEX_MAN ) {
} else if ( ageAndSex . getSex ( ) = = Constant . Ht . SEX_MAN ) {
group . setMan ( ageAndSex ) ;
} else {
group . setWoman ( ageAndSex ) ;
@ -610,5 +565,218 @@ public class PatientReportService implements IPatientReportService {
return new PageInfo < > ( list ) ;
}
@Override
public String export ( PatientReportDto . ExportCode param , Long userId ) {
// 详细试题
List < PdfUtil . Row > questionTable = new ArrayList < > ( ) ;
if ( Constant . Export . TITLE_MAP . containsKey ( param . getCode ( ) ) ) {
List < PatientReportVo . QuestionAndAnswer > questionAndAnswerList = htPatientReportDao . queryQuestionAndScore ( param . getId ( ) , param . getCode ( ) ) ;
// 几列试题
int cols = questionAndAnswerList . size ( ) > 20 ? 2 : 1 ;
// 题目占几行
int questionSpan = 2 ;
// 表格头
initQuestionTitle ( param . getCode ( ) , cols , questionSpan , questionTable ) ;
// 表格体
int rowNum = cols > 1 ? ( questionAndAnswerList . size ( ) + 1 ) / 2 : questionAndAnswerList . size ( ) ;
int optionSize = Constant . Export . TITLE_MAP . get ( param . getCode ( ) ) . optionList . size ( ) ;
for ( int i = 0 ; i < rowNum ; i + + ) {
PatientReportVo . QuestionAndAnswer question = questionAndAnswerList . get ( i ) ;
PdfUtil . Row row = new PdfUtil . Row ( ) ;
initQuestionBody ( questionSpan , question , row , cols = = 1 , optionSize ) ;
if ( cols > 1 ) {
PatientReportVo . QuestionAndAnswer question2 = null ;
if ( rowNum + i < questionAndAnswerList . size ( ) ) {
question2 = questionAndAnswerList . get ( rowNum + i ) ;
}
initQuestionBody ( questionSpan , question2 , row , true , Constant . Export . TITLE_MAP . get ( param . getCode ( ) ) . optionList . size ( ) ) ;
}
questionTable . add ( row ) ;
}
if ( Constant . Ht . Report . ADL . equals ( param . getCode ( ) ) ) {
List < PatientReportVo . ReportScore > reportScores = htPatientReportDao . queryReportScore2 ( param . getId ( ) , param . getCode ( ) ) ;
PdfUtil . Row row = new PdfUtil . Row ( ) ;
addCell ( row , "总分" , questionSpan + 1 , 1 ) ;
int scoreSpan = 1 + questionSpan + cols * optionSize ;
String score = ( reportScores . isEmpty ( ) ? "" : reportScores . get ( 0 ) . getScore ( ) = = null ? "" : reportScores . get ( 0 ) . getScore ( ) . intValue ( ) ) + ( reportScores . get ( 0 ) . getTotalScore ( ) > 0 ? "/" + reportScores . get ( 0 ) . getTotalScore ( ) : "" ) ;
PdfUtil . Cell scoreCell = addCell ( row , score , scoreSpan , 1 ) ;
scoreCell . setBorderRight ( 1 ) ;
questionTable . add ( row ) ;
PdfUtil . Row tempRow = new PdfUtil . Row ( ) ;
PdfUtil . Cell cell = addCell ( tempRow , "仅供临床医生参考。" , scoreSpan + questionSpan + 1 , 1 ) ;
initLast ( questionTable , scoreSpan + questionSpan + 1 ) ;
}
}
List < PdfUtil . Row > content = new ArrayList < > ( ) ;
//查询报告单信息和病人信息
PatientReportVo . ReprotPatient reportPatient = htPatientReportDao . queryReportResult ( param . getId ( ) ) ;
//查询报告单分数
List < PatientReportVo . ReportScore > reportScores = htPatientReportDao . queryReportScore2 ( param . getId ( ) , param . getCode ( ) ) ;
if ( ! Constant . Ht . Report . ADL . equals ( param . getCode ( ) ) ) {
getReportScores ( param , content , reportScores ) ;
}
String subHead = CollectionUtil . isEmpty ( reportScores ) ? "" : reportScores . get ( 0 ) . getName ( ) + "(" + reportScores . get ( 0 ) . getCode ( ) + ")报告单" ;
PdfUtil . Margin margin = new PdfUtil . Margin ( ) ;
margin . setTop ( 12 ) ;
margin . setBottom ( 12 ) ;
margin . setLeft ( 36 ) ;
String path = PropUtil . imgDomain + "/" + PdfUtil . createPdf ( PropUtil . path , reportPatient . getHospital ( ) , subHead , margin , reportPatient . toPdfSimpleCodeRow ( ) , questionTable , content ) ;
log . info ( "{}报告单导出路径:{}" , param , path ) ;
return path ;
}
private List < PatientReportVo . ReportScore > getReportScores ( PatientReportDto . ExportCode param , List < PdfUtil . Row > content , List < PatientReportVo . ReportScore > reportScores ) {
long reportId = param . getId ( ) ;
//重新封装报告单信息
List < PatientReportVo . ReportScore > scores = getReportScores ( reportScores , reportId ) ;
// 分数汇总
int colNum = Constant . Ht . Report . HAMD . equalsIgnoreCase ( param . getCode ( ) ) ? 9 : 8 ;
scores . forEach ( reportScore - > content . addAll ( reportScore . toSingleRow ( ) ) ) ;
PdfUtil . Row row = new PdfUtil . Row ( ) ;
int titleSpan = 2 ;
PdfUtil . Cell initWordCell = addCell ( row , "初步印象" , titleSpan , 2 ) ;
initWordCell . setHeight ( PdfUtil . Cell . defaultHeight * 2 ) ;
String initialImpression = "" ;
PdfUtil . Cell initImplCell = addCell ( row , initialImpression , colNum - titleSpan , 2 ) ;
initImplCell . setHeight ( PdfUtil . Cell . defaultHeight * 2 ) ;
initImplCell . setBorderRight ( 1 ) ;
initImplCell . setCenter ( false ) ;
content . add ( row ) ;
PdfUtil . Row tempRow = new PdfUtil . Row ( ) ;
PdfUtil . Cell cell = addCell ( tempRow , "仅供临床医生参考。" , colNum , 1 ) ;
initLast ( content , colNum ) ;
return scores ;
}
private List < PatientReportVo . ReportScore > getReportScores ( List < PatientReportVo . ReportScore > reportScores , long reportId ) {
Map < String , PatientReportVo . ReportScore > map = new HashMap < > ( 32 ) ;
List < PatientReportVo . ReportScore > scores = new ArrayList < > ( ) ;
reportScores . forEach ( score - > {
if ( ObjectUtil . isNotNull ( score . getScore ( ) ) ) {
if ( BigDecimal . valueOf ( score . getScore ( ) . intValue ( ) ) . compareTo ( score . getScore ( ) ) = = 0 ) {
score . setScore ( score . getScore ( ) . setScale ( 0 , BigDecimal . ROUND_HALF_UP ) ) ;
}
}
map . put ( score . getCode ( ) , score ) ;
//测评类(MOCA等)
if ( Constant . Ht . Report . TYPE_EVALUATION = = score . getType ( ) ) {
String specialCode = "NPI" ;
if ( specialCode . equalsIgnoreCase ( score . getCode ( ) ) ) {
initNPI ( reportId , score ) ;
}
scores . add ( score ) ;
} else {
log . info ( "score:{}" , score ) ;
map . get ( score . getParentCode ( ) ) . addSub ( score ) ;
}
} ) ;
scores . forEach ( score - > {
if ( Constant . Ht . Report . MOCA_SJZ . equalsIgnoreCase ( score . getCode ( ) ) ) {
return ;
}
sumScore ( score ) ;
} ) ;
return scores ;
}
private void initQuestionBody ( int questionSpan , PatientReportVo . QuestionAndAnswer question , PdfUtil . Row row , boolean isLast , int optionSize ) {
addCell ( row , question = = null ? Constant . Ht . STRING_DEFAULT : String . valueOf ( question . getSort ( ) ) , 1 , 1 ) ;
addCell ( row , question = = null ? Constant . Ht . STRING_DEFAULT : question . getQuestion ( ) , questionSpan , 1 ) ;
if ( question = = null ) {
for ( int i = 0 ; i < optionSize ; i + + ) {
PdfUtil . Cell cell = addCell ( row , "" , 1 , 1 ) ;
cell . setBorderRight ( isLast & & i = = optionSize - 1 ? 1 : 0 ) ;
}
return ;
}
int size = question . getOptionList ( ) . size ( ) ;
for ( int j = 0 ; j < size ; j + + ) {
String content = question . getOptionList ( ) . get ( j ) . getChooseStatus ( ) = = 1 ? "√" : "--" ;
PdfUtil . Cell cell = addCell ( row , content , 1 , 1 ) ;
cell . setBorderRight ( isLast & & j = = optionSize - 1 ? 1 : 0 ) ;
}
if ( size > = optionSize ) {
return ;
}
for ( int i = size ; i < optionSize ; i + + ) {
PdfUtil . Cell cell = addCell ( row , "--" , 1 , 1 ) ;
cell . setBorderRight ( isLast & & i = = optionSize - 1 ? 1 : 0 ) ;
}
}
/ * *
* 表格头
* @param code code
* @param cols 几列题目
* @param questionSpan 题目占几列
* @param questionTable 表格
* /
private void initQuestionTitle ( String code , int cols , int questionSpan , List < PdfUtil . Row > questionTable ) {
Constant . ReportExportTitle title = Constant . Export . TITLE_MAP . get ( code ) ;
// 检查目的
if ( StrUtil . isNotBlank ( title . checkPurpose ) ) {
PdfUtil . Row row = new PdfUtil . Row ( ) ;
PdfUtil . Cell cell = addCell ( row , title . checkPurpose , ( title . optionList . size ( ) + questionSpan + 1 ) * cols , 1 ) ;
cell . setCenter ( false ) ;
cell . setBorderRight ( 1 ) ;
questionTable . add ( row ) ;
}
// 设置表头
PdfUtil . Row row1 = new PdfUtil . Row ( ) ;
PdfUtil . Row row2 = new PdfUtil . Row ( ) ;
for ( int i = 0 ; i < cols ; i + + ) {
addCell ( row1 , "序号" , 1 , 2 ) ;
// addCell(row2, "", 1, 1);
if ( StrUtil . isBlank ( title . projectDesc ) ) {
addCell ( row1 , "项目" , questionSpan , 2 ) ;
// addCell(row2, "", questionSpan, 1);
} else {
addCell ( row1 , title . projectDesc , questionSpan , 1 ) ;
addCell ( row2 , "项目" , questionSpan , 1 ) ;
}
// 选项
PdfUtil . Cell optionDescCell = addCell ( row1 , title . optionDesc , title . optionList . size ( ) , 1 ) ;
optionDescCell . setBorderRight ( i = = cols - 1 ? 1 : 0 ) ;
for ( int j = 0 ; j < title . optionList . size ( ) ; j + + ) {
PdfUtil . Cell optionCell = addCell ( row2 , title . optionList . get ( j ) , 1 , 1 ) ;
optionCell . setBorderRight ( i = = cols - 1 & & j = = title . optionList . size ( ) - 1 ? 1 : 0 ) ;
}
}
questionTable . add ( row1 ) ;
questionTable . add ( row2 ) ;
}
private void initLast ( List < PdfUtil . Row > content , int totalSpan ) {
PdfUtil . Row row2 = new PdfUtil . Row ( ) ;
PdfUtil . Cell doctorCell = addCell ( row2 , "测评员:" , 4 , 1 , 0 ) ;
doctorCell . setBorderBottom ( null ) ;
doctorCell . setBorderLeft ( null ) ;
PdfUtil . Cell dateCell = addCell ( row2 , "报告日期:" , totalSpan - 4 , 1 , 0 ) ;
dateCell . setBorderBottom ( null ) ;
dateCell . setBorderLeft ( null ) ;
content . add ( row2 ) ;
}
}