@ -114,6 +114,100 @@ public class RmsServiceImpl implements IRmsService {
return 0 ;
}
/ * *
* 递归组装ReportScore的父子级树形结构
* @param allReportScores 所有未组装的ReportScore列表
* @param rootParentId 根节点的parentId ( 比如0或null , 根据业务定义 )
* @return 组装好的树形结构根节点列表
* /
public static List < RmsVo . ReportScore > buildReportScoreTree ( List < RmsVo . ReportScore > allReportScores , Long rootParentId ) {
// 1. 预处理:将所有节点放入Map,key=scaleId,方便快速查找
Map < String , RmsVo . ReportScore > scoreMap = new HashMap < > ( ) ;
for ( RmsVo . ReportScore score : allReportScores ) {
scoreMap . put ( score . getScaleId ( ) , score ) ;
// 初始化子列表(避免空指针)
if ( score . getSubReport ( ) = = null ) {
score . setSubReport ( new ArrayList < > ( ) ) ;
}
}
// 2. 筛选根节点(parentId等于rootParentId的节点)
List < RmsVo . ReportScore > rootNodes = new ArrayList < > ( ) ;
for ( RmsVo . ReportScore score : allReportScores ) {
Long parentId = score . getParentId ( ) ;
// 判断是否为根节点(适配parentId=null或0的情况)
boolean isRoot = ( rootParentId = = null & & parentId = = null )
| | ( rootParentId ! = null & & rootParentId . equals ( parentId ) ) ;
if ( isRoot ) {
rootNodes . add ( score ) ;
// 递归组装子节点
buildChildren ( score , scoreMap ) ;
}
}
// 3. 按sort/ecrSort排序(可选,根据业务需求)
sortReportScoreTree ( rootNodes ) ;
return rootNodes ;
}
/ * *
* 递归为单个节点组装子节点
* @param parentNode 父节点
* @param scoreMap 所有节点的Map ( key = scaleId )
* /
private static void buildChildren ( RmsVo . ReportScore parentNode , Map < String , RmsVo . ReportScore > scoreMap ) {
// 遍历所有节点,找到当前父节点的子节点(子节点的parentId=父节点的scaleId转Long)
for ( RmsVo . ReportScore childNode : scoreMap . values ( ) ) {
Long childParentId = childNode . getParentId ( ) ;
String parentScaleId = parentNode . getScaleId ( ) ;
// 避免空指针,先判断parentScaleId是否能转Long(根据业务,scaleId应为数字字符串)
if ( childParentId = = null | | parentScaleId = = null ) {
continue ;
}
// 匹配子节点:子节点的parentId = 父节点的scaleId(转Long)
try {
Long parentIdLong = Long . parseLong ( parentScaleId ) ;
if ( childParentId . equals ( parentIdLong ) ) {
// 加入子列表
parentNode . getSubReport ( ) . add ( childNode ) ;
// 递归组装子节点的子节点
buildChildren ( childNode , scoreMap ) ;
}
} catch ( NumberFormatException e ) {
// 若scaleId非数字,根据业务处理(此处打印日志,跳过)
System . err . println ( "scaleId转换Long失败:" + parentScaleId + ",原因:" + e . getMessage ( ) ) ;
continue ;
}
}
// 子节点排序(可选)
if ( CollectionUtil . isNotEmpty ( parentNode . getSubReport ( ) ) ) {
sortReportScoreTree ( parentNode . getSubReport ( ) ) ;
}
}
/ * *
* 对ReportScore列表按排序字段排序 ( 优先sort , 其次ecrSort )
* @param reportScores 待排序的列表
* /
private static void sortReportScoreTree ( List < RmsVo . ReportScore > reportScores ) {
reportScores . sort ( ( o1 , o2 ) - > {
// 先按sort排序
if ( o1 . getSort ( ) ! = null & & o2 . getSort ( ) ! = null ) {
return o1 . getSort ( ) . compareTo ( o2 . getSort ( ) ) ;
}
// sort为空则按ecrSort排序
if ( o1 . getEcrSort ( ) ! = null & & o2 . getEcrSort ( ) ! = null ) {
return o1 . getEcrSort ( ) . compareTo ( o2 . getEcrSort ( ) ) ;
}
// 都为空则按scaleId排序
return o1 . getScaleId ( ) . compareTo ( o2 . getScaleId ( ) ) ;
} ) ;
}
@Override
public RmsVo . ReportDetail queryReportDetail ( RmsDto . QueryDetail dto ) {
//根据测评id查找报告单
@ -121,7 +215,12 @@ public class RmsServiceImpl implements IRmsService {
reportExample . createCriteria ( ) . andEvaluationIdEqualTo ( dto . getEvaluationId ( ) ) . andDelFlagEqualTo ( ( byte ) 0 ) ;
List < RmsReport > rmsReports = rmsReportMapper . selectByExample ( reportExample ) ;
RmsReport report ;
List < RmsVo . ReportScore > scores = new ArrayList < > ( ) ;
//查询测评量表
List < RmsVo . ReportScore > scores = rmsDao . queryEmsScaleScore ( dto . getEvaluationId ( ) , CollectionUtil . newArrayList ( ) ) ;
if ( CollUtil . isNotEmpty ( scores ) ) {
//组装成父子级关系
scores = buildReportScoreTree ( scores , 0L ) ;
}
Map < String , RmsReportScaleScore > reportScaleScoreMap = new HashMap < > ( ) ;
if ( CollUtil . isEmpty ( rmsReports ) ) {
//生成报告单
@ -136,7 +235,6 @@ public class RmsServiceImpl implements IRmsService {
//查找病人信息
PmsPatient pmsPatient = pmsPatientMapper . selectByPrimaryKey ( emsEvaluation . getPatientId ( ) ) ;
if ( ObjectUtil . isNotNull ( pmsPatient ) ) {
// report.setPatientAge(IdcardUtil.getAgeByIdCard(pmsPatient.getIdcard()));
report . setPatientAge ( getAge ( pmsPatient ) ) ;
}
//修改测评的状态
@ -148,11 +246,6 @@ public class RmsServiceImpl implements IRmsService {
}
rmsReportMapper . insertSelective ( report ) ;
//查询报告单分数
List < RmsVo . ReportScore > reportScore = rmsDao . queryReportScore1 ( dto . getEvaluationId ( ) , null , dto . getSex ( ) ) ;
//重新封装报告单信息
scores = getReportScores ( reportScore , dto . getEvaluationId ( ) ) ;
if ( CollUtil . isNotEmpty ( scores ) ) {
scores . forEach ( score - > {
if ( "TZBS_LN" . equals ( score . getCode ( ) ) | | "TZBS_BZ" . equals ( score . getCode ( ) ) ) {
@ -197,43 +290,6 @@ public class RmsServiceImpl implements IRmsService {
}
}
}
//每次查询报告单 都重新生成分数
//查询报告单分数
// List<RmsVo.ReportScore> reportScore = rmsDao.queryReportScore3(dto.getEvaluationId(), null, dto.getSex());
// //重新封装报告单信息
// scores = getReportScores(reportScore, dto.getEvaluationId());
// if (CollUtil.isNotEmpty(scores)) {
// scores = scores.stream().sorted(Comparator.comparing(RmsVo.ReportScore::getEcrSort)).collect(Collectors.toList());
// scores.forEach(score -> {
//// //查找初步印象
//// RmsReportScaleScoreExample scoreExample = new RmsReportScaleScoreExample();
//// scoreExample.createCriteria().andReportIdEqualTo(report.getId()).andScaleCodeEqualTo(score.getCode()).andDelFlagEqualTo((byte) 0);
//// List<RmsReportScaleScore> rmsReportScaleScores = rmsReportScaleScoreMapper.selectByExample(scoreExample);
//// if (CollUtil.isNotEmpty(rmsReportScaleScores)) {
//// score.setImpression(rmsReportScaleScores.get(0).getImpression());
////// if ("TZBS_LN".equals(score.getCode()) || "TZBS_BZ".equals(score.getCode())) {
////// score.setScore(rmsReportScaleScores.get(0).getScore());
////// }
//// reportScaleScoreMap.put(score.getCode(), rmsReportScaleScores.get(0));
//// }
//
//// //查询量表试题
//// QmsQuestionExample qmsQuestionExample = new QmsQuestionExample();
//// qmsQuestionExample.createCriteria().andScaleCodeEqualTo(score.getCode()).andDelFlagEqualTo((byte) 0);
//// List<QmsQuestion> qmsQuestions = qmsQuestionMapper.selectByExample(qmsQuestionExample);
//// if (CollUtil.isNotEmpty(qmsQuestions)) {
//// //查询量表试题时长
//// EmsEvaluationQuestionDurationExample questionDurationExample = new EmsEvaluationQuestionDurationExample();
//// questionDurationExample.createCriteria().andEvaluationIdEqualTo(dto.getEvaluationId()).andDelFlagEqualTo((byte) 0)
//// .andQuestionIdIn(qmsQuestions.stream().map(QmsQuestion::getId).collect(Collectors.toList()));
//// List<EmsEvaluationQuestionDuration> emsEvaluationQuestionDurations = emsEvaluationQuestionDurationMapper.selectByExample(questionDurationExample);
//// if (CollUtil.isNotEmpty(emsEvaluationQuestionDurations)) {
//// score.setQuestionDuration(emsEvaluationQuestionDurations.stream().mapToLong(EmsEvaluationQuestionDuration::getDuration).sum());
//// }
//// }
// });
// }
RmsVo . ReportDetail detail = new RmsVo . ReportDetail ( ) ;
//查询报告单信息和病人信息
@ -322,16 +378,11 @@ public class RmsServiceImpl implements IRmsService {
if ( CollectionUtil . isNotEmpty ( set ) ) {
MessageDto . QuestionInform questionInform = new MessageDto . QuestionInform ( ) ;
questionInform . setQuestionId ( 0L ) ;
boolean remove = set . remove ( questionInform ) ;
set . remove ( questionInform ) ;
}
// if (set.size() > 0) {
//list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MessageDto.QuestionInform::getQuestionId))), ArrayList::new));
// redisUtil.set("message_" + score.getPatientReportId(), set, 7200);
redisUtil . deleteObject ( "message_" + dto . getEvaluationId ( ) ) ;
// }
}
// scores = scores.stream().sorted(Comparator.comparing(RmsVo.ReportScore::getSort)).collect(Collectors.toList());
detail . setPatient ( reportPatient ) ;
detail . setScores ( scores ) ;
return detail ;