in study-datastore/src/main/java/com/hphc/mystudies/dao/ActivityMetaDataDao.java [1721:1992]
public SortedMap<Integer, QuestionnaireActivityStepsBean> getQuestionDetailsForQuestionnaire(
List<QuestionsDto> questionsDtoList,
Map<String, Integer> sequenceNoMap,
SortedMap<Integer, QuestionnaireActivityStepsBean> stepsSequenceTreeMap,
Session session,
Map<String, QuestionnairesStepsDto> questionnaireStepDetailsMap,
List<QuestionResponsetypeMasterInfoDto> questionResponseTypeMasterInfoList,
List<QuestionnairesStepsDto> questionaireStepsList,
QuestionnairesDto questionnaireDto,
StudyDto studyDto)
throws DAOException {
LOGGER.entry("begin getQuestionDetailsForQuestionnaire()");
List<QuestionResponseSubTypeDto> destinationConditionList = null;
Transaction transaction = null;
try {
if ((questionsDtoList != null) && !questionsDtoList.isEmpty()) {
for (QuestionsDto questionsDto : questionsDtoList) {
QuestionnairesStepsDto questionStepDetails =
questionnaireStepDetailsMap.get(
(questionsDto.getId() + StudyMetaDataConstants.QUESTIONAIRE_STEP_TYPE_QUESTION)
.toString());
QuestionnaireActivityStepsBean questionBean = new QuestionnaireActivityStepsBean();
questionBean.setType(
StudyMetaDataConstants.QUESTIONAIRE_STEP_TYPE_QUESTION.toLowerCase());
if (questionsDto.getResponseType() != null) {
for (QuestionResponsetypeMasterInfoDto masterInfo :
questionResponseTypeMasterInfoList) {
if (masterInfo.getId().equals(questionsDto.getResponseType())) {
questionBean.setResultType(masterInfo.getResponseTypeCode());
questionBean.setFormat(
this.getQuestionaireQuestionFormatByType(
questionsDto, masterInfo.getResponseTypeCode(), session, studyDto));
break;
}
}
} else {
questionBean.setResultType("");
}
questionBean.setText(
StringUtils.isEmpty(questionsDto.getDescription())
? ""
: questionsDto.getDescription());
questionBean.setKey(
StringUtils.isEmpty(questionStepDetails.getStepShortTitle())
? ""
: questionStepDetails.getStepShortTitle());
questionBean.setTitle(
StringUtils.isEmpty(questionsDto.getQuestion()) ? "" : questionsDto.getQuestion());
questionBean.setSkippable(
(StringUtils.isEmpty(questionStepDetails.getSkiappable())
|| questionStepDetails
.getSkiappable()
.equalsIgnoreCase(StudyMetaDataConstants.NO))
? false
: true);
questionBean.setGroupName("");
questionBean.setRepeatable(false);
questionBean.setRepeatableText(
questionStepDetails.getRepeatableText() == null
? ""
: questionStepDetails.getRepeatableText());
List<DestinationBean> destinationsList = new ArrayList<>();
/**
* Choice based branching allowed only for textchoice, textscale, imagechoice, boolean
* response types
*/
if (!questionsDto.getResponseType().equals(String.valueOf(4))) {
destinationConditionList =
session
.createQuery(
"from QuestionResponseSubTypeDto QRSTDTO"
+ " where QRSTDTO.responseTypeId= :responseTypeId")
.setString(StudyMetaDataEnum.QF_RESPONSE_TYPE_ID.value(), questionsDto.getId())
.list();
if ((destinationConditionList != null) && !destinationConditionList.isEmpty()) {
for (QuestionResponseSubTypeDto destinationDto : destinationConditionList) {
DestinationBean destination = new DestinationBean();
if (questionBean
.getResultType()
.equalsIgnoreCase(StudyMetaDataConstants.QUESTION_BOOLEAN)) {
destination.setCondition(
StringUtils.isEmpty(destinationDto.getValue())
? ""
: destinationDto.getValue().toLowerCase());
} else {
destination.setCondition(
StringUtils.isEmpty(destinationDto.getValue())
? ""
: destinationDto.getValue());
}
if (questionnaireDto.getBranching()) {
if ((destinationDto.getDestinationStepId() != null)
&& (!destinationDto.getDestinationStepId().equals(String.valueOf(0)))) {
destination =
this.getDestinationStepTypeForResponseSubType(
destination, destinationDto, questionaireStepsList);
} else if ((destinationDto.getDestinationStepId() != null)
&& destinationDto.getDestinationStepId().equals(String.valueOf(0))) {
destination.setDestination("");
} else {
destination.setDestination(
((questionStepDetails.getDestinationStepType() == null)
|| questionStepDetails.getDestinationStepType().isEmpty())
? ""
: questionStepDetails.getDestinationStepType());
}
} else {
destination.setDestination(
((questionStepDetails.getDestinationStepType() == null)
|| questionStepDetails.getDestinationStepType().isEmpty())
? ""
: questionStepDetails.getDestinationStepType());
}
destinationsList.add(destination);
}
}
}
if (Arrays.asList(StudyMetaDataConstants.CB_RESPONSE_TYPE.split(","))
.contains(questionBean.getResultType())
&& questionnaireDto.getBranching()) {
QuestionReponseTypeDto reponseType =
(QuestionReponseTypeDto)
session
.createQuery(
"from QuestionReponseTypeDto QRTDTO"
+ " where QRTDTO.questionsResponseTypeId=:questRespType"
+ " ORDER BY QRTDTO.responseTypeId DESC")
.setString("questRespType", questionsDto.getId())
.setMaxResults(1)
.uniqueResult();
if ((reponseType != null)
&& StringUtils.isNotEmpty(reponseType.getFormulaBasedLogic())
&& reponseType
.getFormulaBasedLogic()
.equalsIgnoreCase(StudyMetaDataConstants.YES)) {
boolean isValueOfXSaved = false;
if ((destinationConditionList != null)
&& !destinationConditionList.isEmpty()
&& (destinationConditionList.size() == 2)) {
if (StringUtils.isNotEmpty(destinationConditionList.get(0).getValueOfX())
&& StringUtils.isNotEmpty(destinationConditionList.get(1).getValueOfX())
&& StringUtils.isNotEmpty(destinationConditionList.get(0).getOperator())
&& StringUtils.isNotEmpty(destinationConditionList.get(1).getOperator())) {
isValueOfXSaved = true;
for (int i = 0; i < destinationConditionList.size(); i++) {
destinationsList
.get(i)
.setCondition(
StringUtils.isEmpty(destinationConditionList.get(i).getValueOfX())
? ""
: destinationConditionList.get(i).getValueOfX());
destinationsList
.get(i)
.setOperator(
StringUtils.isEmpty(destinationConditionList.get(i).getOperator())
? ""
: destinationConditionList.get(i).getOperator());
}
}
}
if (!isValueOfXSaved) {
destinationsList =
this.getConditionalBranchingDestinations(
reponseType, destinationsList, questionBean);
transaction = session.beginTransaction();
for (int i = 0; i < destinationsList.size(); i++) {
QuestionResponseSubTypeDto destinationDto = destinationConditionList.get(i);
destinationDto.setValueOfX(destinationsList.get(i).getCondition());
destinationDto.setOperator(destinationsList.get(i).getOperator());
session.save(destinationDto);
}
transaction.commit();
}
}
}
DestinationBean destination = new DestinationBean();
destination.setCondition("");
destination.setDestination(
((questionStepDetails.getDestinationStepType() == null)
|| questionStepDetails.getDestinationStepType().isEmpty())
? ""
: questionStepDetails.getDestinationStepType());
destinationsList.add(destination);
/** other type add destination if there start */
QuestionReponseTypeDto otherReponseSubType =
(QuestionReponseTypeDto)
session
.createQuery(
"from QuestionReponseTypeDto QRTDTO"
+ " where QRTDTO.questionsResponseTypeId=:questRespType"
+ " ORDER BY QRTDTO.responseTypeId DESC")
.setString("questRespType", questionsDto.getId())
.setMaxResults(1)
.uniqueResult();
if ((otherReponseSubType != null)
&& (otherReponseSubType.getOtherType() != null)
&& StringUtils.isNotEmpty(otherReponseSubType.getOtherType())
&& otherReponseSubType.getOtherType().equals("on")) {
DestinationBean otherDestination = new DestinationBean();
otherDestination.setCondition(
StringUtils.isEmpty(otherReponseSubType.getOtherValue())
? ""
: otherReponseSubType.getOtherValue());
if (questionnaireDto.getBranching()) {
if ((otherReponseSubType.getOtherDestinationStepId() != null)
&& (!otherReponseSubType.getOtherDestinationStepId().equals(String.valueOf(0)))) {
for (QuestionnairesStepsDto stepsDto : questionaireStepsList) {
if (otherReponseSubType
.getOtherDestinationStepId()
.equals(stepsDto.getStepId())) {
otherDestination.setDestination(
StringUtils.isEmpty(stepsDto.getStepShortTitle())
? ""
: stepsDto.getStepShortTitle());
break;
}
}
} else if ((otherReponseSubType.getOtherDestinationStepId() != null)
&& otherReponseSubType.getOtherDestinationStepId().equals(String.valueOf(0))) {
otherDestination.setDestination("");
} else {
otherDestination.setDestination(
((questionStepDetails.getDestinationStepType() == null)
|| questionStepDetails.getDestinationStepType().isEmpty())
? ""
: questionStepDetails.getDestinationStepType());
}
} else {
otherDestination.setDestination(
((questionStepDetails.getDestinationStepType() == null)
|| questionStepDetails.getDestinationStepType().isEmpty())
? ""
: questionStepDetails.getDestinationStepType());
}
destinationsList.add(otherDestination);
}
/** other type add destination if there end */
questionBean.setDestinations(destinationsList);
questionBean.setHealthDataKey("");
if (StringUtils.isNotEmpty(questionsDto.getAllowHealthKit())
&& StudyMetaDataConstants.YES.equalsIgnoreCase(questionsDto.getAllowHealthKit())
&& StringUtils.isNotEmpty(questionsDto.getHealthkitDatatype())) {
questionBean.setHealthDataKey(questionsDto.getHealthkitDatatype().trim());
}
stepsSequenceTreeMap.put(
sequenceNoMap.get(
(questionsDto.getId() + StudyMetaDataConstants.QUESTIONAIRE_STEP_TYPE_QUESTION)
.toString()),
questionBean);
}
}
} catch (Exception e) {
if (transaction != null) {
transaction.rollback();
}
LOGGER.error("ActivityMetaDataDao - getQuestionDetailsForQuestionnaire() :: ERROR", e);
}
LOGGER.exit("getQuestionDetailsForQuestionnaire() :: Ends");
return stepsSequenceTreeMap;
}