|
@ -1,6 +1,8 @@ |
|
|
package com.ccsens.ht.service; |
|
|
package com.ccsens.ht.service; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
@ -23,10 +25,15 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.script.ScriptEngine; |
|
|
|
|
|
import javax.script.ScriptEngineManager; |
|
|
|
|
|
import javax.script.ScriptException; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -56,6 +63,8 @@ public class QuestionService implements IQuestionService { |
|
|
private HtPatientReportMapper htPatientReportMapper; |
|
|
private HtPatientReportMapper htPatientReportMapper; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private HtQuestionScoringRuleDao htQuestionScoringRuleDao; |
|
|
private HtQuestionScoringRuleDao htQuestionScoringRuleDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private HtReportDao htReportDao; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,12 +78,27 @@ public class QuestionService implements IQuestionService { |
|
|
questionExample.createCriteria().andEvaluationCodeEqualTo(query.getCode()).andSortEqualTo(query.getNum()); |
|
|
questionExample.createCriteria().andEvaluationCodeEqualTo(query.getCode()).andSortEqualTo(query.getNum()); |
|
|
List<HtQuestion> questionList = htQuestionDao.selectByExample(questionExample); |
|
|
List<HtQuestion> questionList = htQuestionDao.selectByExample(questionExample); |
|
|
log.info("测评试题:{}", questionList); |
|
|
log.info("测评试题:{}", questionList); |
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(questionList)) { |
|
|
if (CollectionUtils.isEmpty(questionList)) { |
|
|
throw new BaseException(CodeEnum.QUESTION_NOT_FOUND); |
|
|
throw new BaseException(CodeEnum.QUESTION_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
HtQuestion question = questionList.get(0); |
|
|
HtQuestion question = questionList.get(0); |
|
|
QuestionVo.Question questionVo = QuestionVo.Question.toQuestionVo(question); |
|
|
QuestionVo.Question questionVo = QuestionVo.Question.toQuestionVo(question); |
|
|
log.info("试题:{}", questionVo); |
|
|
log.info("试题:{}", questionVo); |
|
|
|
|
|
|
|
|
|
|
|
//获取评测信息
|
|
|
|
|
|
HtReportExample reportExample = new HtReportExample(); |
|
|
|
|
|
reportExample.createCriteria().andCodeEqualTo(question.getEvaluationCode()); |
|
|
|
|
|
List<HtReport> htReports = htReportDao.selectByExample(reportExample); |
|
|
|
|
|
QuestionVo.Report reportVo = new QuestionVo.Report(); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(htReports)) { |
|
|
|
|
|
HtReport htReport = htReports.get(0); |
|
|
|
|
|
reportVo.setCode(htReport.getCode()); |
|
|
|
|
|
reportVo.setName(htReport.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer maxSort = htQuestionDao.selectMaxSort(query.getCode()); |
|
|
//查询关联题目
|
|
|
//查询关联题目
|
|
|
if (!StringUtils.isEmpty(question.getRelationCode())) { |
|
|
if (!StringUtils.isEmpty(question.getRelationCode())) { |
|
|
String[] codes = question.getRelationCode().split(Constant.COMMA); |
|
|
String[] codes = question.getRelationCode().split(Constant.COMMA); |
|
@ -94,6 +118,7 @@ public class QuestionService implements IQuestionService { |
|
|
List<QuestionVo.Introduce> introduceVos = QuestionVo.Introduce.toIntroduces(introduces); |
|
|
List<QuestionVo.Introduce> introduceVos = QuestionVo.Introduce.toIntroduces(introduces); |
|
|
//试题选项
|
|
|
//试题选项
|
|
|
List<QuestionVo.Option> options = htQuestionOptionDao.queryOption(question.getId(), query.getPatientReportId()); |
|
|
List<QuestionVo.Option> options = htQuestionOptionDao.queryOption(question.getId(), query.getPatientReportId()); |
|
|
|
|
|
|
|
|
//答题记录
|
|
|
//答题记录
|
|
|
List<QuestionVo.Record> recordVos; |
|
|
List<QuestionVo.Record> recordVos; |
|
|
if (query.getPatientReportId() != null && query.getPatientReportId() != 0) { |
|
|
if (query.getPatientReportId() != null && query.getPatientReportId() != 0) { |
|
@ -107,7 +132,8 @@ public class QuestionService implements IQuestionService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//封装返回
|
|
|
//封装返回
|
|
|
QuestionVo.Query data = new QuestionVo.Query(questionVo, options, introduceVos, recordVos); |
|
|
QuestionVo.Query data = new QuestionVo.Query(questionVo, options, introduceVos, recordVos,maxSort); |
|
|
|
|
|
data.setReport(reportVo); |
|
|
log.info("试题信息:{}", data); |
|
|
log.info("试题信息:{}", data); |
|
|
return data; |
|
|
return data; |
|
|
} |
|
|
} |
|
@ -115,6 +141,11 @@ public class QuestionService implements IQuestionService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public CodeEnum saveScore(QuestionDto.Score score, Long userId) throws IOException, NotSupportedFileTypeException { |
|
|
public CodeEnum saveScore(QuestionDto.Score score, Long userId) throws IOException, NotSupportedFileTypeException { |
|
|
|
|
|
log.info("保存分数"); |
|
|
|
|
|
if (score.getPatientReportId() == null || CollectionUtil.isEmpty(score.getOptions())) { |
|
|
|
|
|
log.info("没有报告单ID或选项,不进行保存"); |
|
|
|
|
|
return CodeEnum.SUCCESS; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//查询试题
|
|
|
//查询试题
|
|
|
HtQuestion question = htQuestionDao.selectByPrimaryKey(score.getQuestionId()); |
|
|
HtQuestion question = htQuestionDao.selectByPrimaryKey(score.getQuestionId()); |
|
@ -132,8 +163,10 @@ public class QuestionService implements IQuestionService { |
|
|
HtQuestionScoringRuleExample ruleExample = new HtQuestionScoringRuleExample(); |
|
|
HtQuestionScoringRuleExample ruleExample = new HtQuestionScoringRuleExample(); |
|
|
ruleExample.createCriteria().andQuestionIdEqualTo(question.getId()); |
|
|
ruleExample.createCriteria().andQuestionIdEqualTo(question.getId()); |
|
|
List<HtQuestionScoringRule> ruleList = htQuestionScoringRuleDao.selectByExample(ruleExample); |
|
|
List<HtQuestionScoringRule> ruleList = htQuestionScoringRuleDao.selectByExample(ruleExample); |
|
|
//生成分数列表
|
|
|
|
|
|
List<HtPatientScore> scores = new ArrayList<>(); |
|
|
//查询选项列表
|
|
|
|
|
|
Map<String, HtQuestionOption> nameOption = new HashMap<>(); |
|
|
|
|
|
Map<Long, HtQuestionOption> idOption = new HashMap<>(); |
|
|
for(QuestionDto.Option option : score.getOptions()) { |
|
|
for(QuestionDto.Option option : score.getOptions()) { |
|
|
HtQuestionOption questionOption = htQuestionOptionDao.selectByPrimaryKey(option.getId()); |
|
|
HtQuestionOption questionOption = htQuestionOptionDao.selectByPrimaryKey(option.getId()); |
|
|
//未找到对应选项 或选项不是该试题的选项
|
|
|
//未找到对应选项 或选项不是该试题的选项
|
|
@ -141,23 +174,11 @@ public class QuestionService implements IQuestionService { |
|
|
log.info("选项不存在或不是对应试题的选项"); |
|
|
log.info("选项不存在或不是对应试题的选项"); |
|
|
return CodeEnum.PARAM_ERROR; |
|
|
return CodeEnum.PARAM_ERROR; |
|
|
} |
|
|
} |
|
|
String path = null; |
|
|
nameOption.put(questionOption.getName(), questionOption); |
|
|
if (option.getPart() != null) { |
|
|
idOption.put(questionOption.getId(), questionOption); |
|
|
path = UploadFileUtil_Servlet3.uploadFile(option.getPart(), Constant.IMG + "," + Constant.VIDEO, PropUtil.path + "answer" + File.separator + question.getEvaluationCode()); |
|
|
|
|
|
} |
|
|
|
|
|
HtPatientScore patientScore = new HtPatientScore(); |
|
|
|
|
|
patientScore.setId(snowflake.nextId()); |
|
|
|
|
|
patientScore.setPatientReportId(score.getPatientReportId()); |
|
|
|
|
|
patientScore.setPatientId(report.getPatientId()); |
|
|
|
|
|
patientScore.setQuestionId(score.getQuestionId()); |
|
|
|
|
|
patientScore.setQuestionParentCode(question.getParentCode()); |
|
|
|
|
|
patientScore.setOptionId(option.getId()); |
|
|
|
|
|
patientScore.setOptionName(questionOption.getName()); |
|
|
|
|
|
patientScore.setScore(questionOption.getScore()); |
|
|
|
|
|
patientScore.setType(ruleList.size() > 0 ? Constant.Ht.Score.ANSWER : Constant.Ht.Score.ANSWER_SCORE); |
|
|
|
|
|
patientScore.setAnswer(StringUtils.isEmpty(path) ? Constant.Ht.STRING_DEFAULT : path); |
|
|
|
|
|
scores.add(patientScore); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
//生成分数列表
|
|
|
|
|
|
List<HtPatientScore> scores = getHtPatientScores(score, question, report, ruleList, nameOption, idOption); |
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(ruleList)) { |
|
|
if (!CollectionUtils.isEmpty(ruleList)) { |
|
|
HtQuestionScoringRule rule = ruleList.get(0); |
|
|
HtQuestionScoringRule rule = ruleList.get(0); |
|
@ -202,4 +223,95 @@ public class QuestionService implements IQuestionService { |
|
|
htPatientScoreDao.insertBatch(scores); |
|
|
htPatientScoreDao.insertBatch(scores); |
|
|
return CodeEnum.SUCCESS; |
|
|
return CodeEnum.SUCCESS; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 分数数据处理 |
|
|
|
|
|
* @param score |
|
|
|
|
|
* @param question |
|
|
|
|
|
* @param report |
|
|
|
|
|
* @param ruleList |
|
|
|
|
|
* @param nameOption |
|
|
|
|
|
* @param idOption |
|
|
|
|
|
* @return |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
* @throws NotSupportedFileTypeException |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<HtPatientScore> getHtPatientScores(QuestionDto.Score score, HtQuestion question, HtPatientReport report, List<HtQuestionScoringRule> ruleList, Map<String, HtQuestionOption> nameOption, Map<Long, HtQuestionOption> idOption) throws IOException, NotSupportedFileTypeException { |
|
|
|
|
|
List<HtPatientScore> scores = new ArrayList<>(); |
|
|
|
|
|
for(QuestionDto.Option option : score.getOptions()) { |
|
|
|
|
|
HtQuestionOption questionOption = idOption.get(option.getId()); |
|
|
|
|
|
String path = null; |
|
|
|
|
|
if (option.getPart() != null) { |
|
|
|
|
|
path = PropUtil.imgDomain + UploadFileUtil_Servlet3.uploadFile(option.getPart(), Constant.IMG + "," + Constant.VIDEO, PropUtil.path); |
|
|
|
|
|
} |
|
|
|
|
|
assembleScore(score, question, report, ruleList, nameOption, scores, questionOption, path); |
|
|
|
|
|
} |
|
|
|
|
|
String special = "NPI"; |
|
|
|
|
|
if (special.equalsIgnoreCase(question.getEvaluationCode())) { |
|
|
|
|
|
HtQuestionOptionExample example = new HtQuestionOptionExample(); |
|
|
|
|
|
example.createCriteria().andQuestionIdEqualTo(question.getId()).andNameEqualTo("result"); |
|
|
|
|
|
List<HtQuestionOption> htQuestionOptions = htQuestionOptionDao.selectByExample(example); |
|
|
|
|
|
for (HtQuestionOption option: htQuestionOptions) { |
|
|
|
|
|
assembleScore(score, question, report, ruleList, nameOption, scores, option, null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return scores; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 组装分数对象 |
|
|
|
|
|
* @param score |
|
|
|
|
|
* @param question |
|
|
|
|
|
* @param report |
|
|
|
|
|
* @param ruleList |
|
|
|
|
|
* @param nameOption |
|
|
|
|
|
* @param scores |
|
|
|
|
|
* @param questionOption |
|
|
|
|
|
* @param path |
|
|
|
|
|
*/ |
|
|
|
|
|
private void assembleScore(QuestionDto.Score score, HtQuestion question, HtPatientReport report, List<HtQuestionScoringRule> ruleList, Map<String, HtQuestionOption> nameOption, List<HtPatientScore> scores, HtQuestionOption questionOption, String path) { |
|
|
|
|
|
HtPatientScore patientScore = new HtPatientScore(); |
|
|
|
|
|
patientScore.setId(snowflake.nextId()); |
|
|
|
|
|
patientScore.setPatientReportId(score.getPatientReportId()); |
|
|
|
|
|
patientScore.setPatientId(report.getPatientId()); |
|
|
|
|
|
patientScore.setQuestionId(score.getQuestionId()); |
|
|
|
|
|
patientScore.setQuestionParentCode(question.getParentCode()); |
|
|
|
|
|
patientScore.setOptionId(questionOption.getId()); |
|
|
|
|
|
patientScore.setOptionName(questionOption.getName()); |
|
|
|
|
|
if (StrUtil.isNotEmpty(questionOption.getRemark())) { |
|
|
|
|
|
JSONObject remark = JSONObject.parseObject(questionOption.getRemark()); |
|
|
|
|
|
countScoreByFormula(nameOption, questionOption, patientScore, remark); |
|
|
|
|
|
} else { |
|
|
|
|
|
patientScore.setScore(questionOption.getScore()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
patientScore.setType(CollectionUtil.isNotEmpty(ruleList) ? Constant.Ht.Score.ANSWER : Constant.Ht.Score.ANSWER_SCORE); |
|
|
|
|
|
patientScore.setAnswer(StringUtils.isEmpty(path) ? Constant.Ht.STRING_DEFAULT : path); |
|
|
|
|
|
scores.add(patientScore); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void countScoreByFormula(Map<String, HtQuestionOption> nameOption, HtQuestionOption questionOption, HtPatientScore patientScore, JSONObject remark) { |
|
|
|
|
|
switch (remark.getIntValue("isAutoformula")) { |
|
|
|
|
|
case 1: |
|
|
|
|
|
String formulaSymbol = remark.getString("formulaSymbol"); |
|
|
|
|
|
String[] params = remark.getString("formulaName").split(","); |
|
|
|
|
|
StringBuilder formula = new StringBuilder(); |
|
|
|
|
|
for (String param: params) { |
|
|
|
|
|
formula.append(formulaSymbol).append(nameOption.get(param) == null ? 0 : nameOption.get(param) .getScore()); |
|
|
|
|
|
} |
|
|
|
|
|
String substring = formula.substring(formulaSymbol.length()); |
|
|
|
|
|
ScriptEngineManager manager = new ScriptEngineManager(); |
|
|
|
|
|
ScriptEngine js = manager.getEngineByName("js"); |
|
|
|
|
|
try { |
|
|
|
|
|
Integer result = (Integer)js.eval(substring); |
|
|
|
|
|
patientScore.setScore(result); |
|
|
|
|
|
} catch (ScriptException e) { |
|
|
|
|
|
log.error("计算出现异常",e); |
|
|
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR) ; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
default: patientScore.setScore(questionOption.getScore());break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|