in study-builder/fdahpStudyDesigner/src/main/java/com/fdahpstudydesigner/dao/StudyActiveTasksDAOImpl.java [814:1068]
public boolean validateActiveTaskAttrById(
String studyId,
String activeTaskAttName,
String activeTaskAttIdVal,
String activeTaskAttIdName,
String customStudyId) {
logger.entry("begin validateActiveTaskAttrById()");
boolean flag = false;
Session session = null;
String queryString = "";
String subString = "";
List<ActiveTaskBo> taskBos = null;
new ArrayList<>();
List<QuestionnaireBo> questionnaireBo = null;
List<ActiveTaskAtrributeValuesBo> activeTaskAtrributeValuesBos = null;
List<QuestionsBo> questionnairesStepsBo = null;
List<String> idArr = new ArrayList<String>();
try {
session = hibernateTemplate.getSessionFactory().openSession();
if ((studyId != null)
&& StringUtils.isNotEmpty(activeTaskAttName)
&& StringUtils.isNotEmpty(activeTaskAttIdVal)) {
// to check uniqueness of chart short title in activity(active
// task and questionnaire) of study
if (activeTaskAttName.equalsIgnoreCase(FdahpStudyDesignerConstants.SHORT_NAME_STATISTIC)) {
if ((customStudyId != null) && !customStudyId.isEmpty()) {
if (!activeTaskAttIdName.equals("static")) {
if (activeTaskAttIdName.contains(",")) {
String[] arr;
arr = activeTaskAttIdName.split(",");
if ((arr != null) && (arr.length > 0)) {
for (String id : arr) {
if (!id.isEmpty()) {
idArr.add(id);
}
}
}
activeTaskAttIdName = StringUtils.join(idArr, ',');
}
subString = " and attributeValueId NOT IN(:activeTaskAttIdName)";
}
// to check chart short title exist in active task or
// not
queryString =
"from ActiveTaskAtrributeValuesBo where activeTaskId in(select id from ActiveTaskBo where studyId IN "
+ "(select id From StudyBo SBO WHERE customStudyId=:customStudyId )) and identifierNameStat=:activeTaskAttIdVal "
+ subString;
if (!activeTaskAttIdName.equals("static")) {
activeTaskAtrributeValuesBos =
session
.createQuery(queryString)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.setParameterList("activeTaskAttIdName", idArr)
.list();
} else {
activeTaskAtrributeValuesBos =
session
.createQuery(queryString)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.list();
}
if ((activeTaskAtrributeValuesBos != null) && !activeTaskAtrributeValuesBos.isEmpty()) {
flag = true;
} else {
// to check chart short title exist in question of
// questionnaire
queryString =
"From QuestionsBo QBO where QBO.id IN (select QSBO.instructionFormId from QuestionnairesStepsBo QSBO where QSBO.questionnairesId IN (select id from QuestionnaireBo Q where Q.studyId in(select id From StudyBo SBO WHERE customStudyId= :customStudyId"
+ ")) and QSBO.stepType=:type) and QBO.statShortName=:activeTaskAttIdVal";
query =
session
.createQuery(queryString)
.setParameter("type", FdahpStudyDesignerConstants.QUESTION_STEP)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal);
questionnairesStepsBo = query.list();
if ((questionnairesStepsBo != null) && !questionnairesStepsBo.isEmpty()) {
flag = true;
} else {
// to check chart short title exist in form
// question of questionnaire
queryString =
"select count(*) From questions QBO,form_mapping f,questionnaires_steps QSBO,questionnaires Q where QBO.id=f.question_id "
+ " and f.form_id=QSBO.instruction_form_id and QSBO.questionnaires_id=Q.id and Q.study_id IN(select id From studies SBO WHERE custom_study_id=:customStudyId"
+ ") and QSBO.step_type='Form' and QBO.stat_short_name=:activeTaskAttIdVal";
BigInteger subCount =
(BigInteger)
session
.createSQLQuery(queryString)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.uniqueResult();
if ((subCount != null) && (subCount.intValue() > 0)) {
flag = true;
} else {
flag = false;
}
}
}
} else {
if (!activeTaskAttIdName.equals("static")) {
if (activeTaskAttIdName.contains(",")) {
String[] arr;
arr = activeTaskAttIdName.split(",");
if ((arr != null) && (arr.length > 0)) {
for (String id : arr) {
if (!id.isEmpty()) {
idArr.add(id);
}
}
}
}
subString = " and attributeValueId NOT IN(:activeTaskAttIdName)";
}
// to check chart short title exist in active task or
// not
queryString =
"from ActiveTaskAtrributeValuesBo where activeTaskId in(select id from ActiveTaskBo where studyId=:studyId)"
+ " and identifierNameStat=:activeTaskAttIdVal"
+ subString;
if (!activeTaskAttIdName.equals("static")) {
activeTaskAtrributeValuesBos =
session
.createQuery(queryString)
.setParameterList("activeTaskAttIdName", Arrays.asList(activeTaskAttIdName))
.setParameter("studyId", studyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.list();
} else {
activeTaskAtrributeValuesBos =
session
.createQuery(queryString)
.setParameter("studyId", studyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.list();
}
if ((activeTaskAtrributeValuesBos != null) && !activeTaskAtrributeValuesBos.isEmpty()) {
flag = true;
} else {
// to check chart short title exist in question of
// questionnaire
queryString =
"From QuestionsBo QBO where QBO.id IN (select QSBO.instructionFormId from QuestionnairesStepsBo QSBO where QSBO.questionnairesId IN (select id from QuestionnaireBo Q where Q.studyId=:studyId"
+ ") and QSBO.stepType=:type) and QBO.statShortName=:activeTaskAttIdVal";
query =
session
.createQuery(queryString)
.setParameter("type", FdahpStudyDesignerConstants.QUESTION_STEP)
.setParameter("studyId", studyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal);
questionnairesStepsBo = query.list();
if ((questionnairesStepsBo != null) && !questionnairesStepsBo.isEmpty()) {
flag = true;
} else {
// to check chart short title exist in form
// question of questionnaire
queryString =
"select count(*) From questions QBO,form_mapping f,questionnaires_steps QSBO,questionnaires Q where QBO.id=f.question_id "
+ "and f.form_id=QSBO.instruction_form_id and QSBO.questionnaires_id=Q.id and Q.study_id=:studyId"
+ " and QSBO.step_type='Form' and QBO.stat_short_name=:activeTaskAttIdVal";
BigInteger subCount =
(BigInteger)
session
.createSQLQuery(queryString)
.setParameter("studyId", studyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.uniqueResult();
if ((subCount != null) && (subCount.intValue() > 0)) {
flag = true;
} else {
flag = false;
}
}
}
}
} else if (activeTaskAttName.equalsIgnoreCase(FdahpStudyDesignerConstants.SHORT_TITLE)) {
// to check uniqueness of short title in activity(active
// task and questionnaire) of study
if ((customStudyId != null) && !customStudyId.isEmpty()) {
// to check short title exist in active task or not
queryString =
"from ActiveTaskBo where studyId IN (select id From StudyBo SBO WHERE customStudyId=:customStudyId ) and shortTitle=:activeTaskAttIdVal";
taskBos =
session
.createQuery(queryString)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.list();
if ((taskBos != null) && !taskBos.isEmpty()) {
flag = true;
} else {
// to check short title exist in questionnaire or
// not
queryString =
"From QuestionnaireBo QBO where QBO.studyId IN(select id From StudyBo SBO WHERE customStudyId=:customStudyId) and QBO.shortTitle=:activeTaskAttIdVal";
query =
session
.createQuery(queryString)
.setParameter("customStudyId", customStudyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal);
questionnaireBo = query.list();
if ((questionnaireBo != null) && !questionnaireBo.isEmpty()) {
flag = true;
} else {
flag = false;
}
}
} else {
// to check short title exist in active task or not
queryString =
"from ActiveTaskBo where studyId=:studyId and shortTitle=:activeTaskAttIdVal ";
taskBos =
session
.createQuery(queryString)
.setParameter("studyId", studyId)
.setParameter("activeTaskAttIdVal", activeTaskAttIdVal)
.list();
if ((taskBos != null) && !taskBos.isEmpty()) {
flag = true;
} else {
// to check short title exist in questionnaire or
// not
questionnaireBo =
session
.getNamedQuery("checkQuestionnaireShortTitle")
.setString("studyId", studyId)
.setString("shortTitle", activeTaskAttIdVal)
.list();
if ((questionnaireBo != null) && !questionnaireBo.isEmpty()) {
flag = true;
} else {
flag = false;
}
}
}
}
}
} catch (Exception e) {
logger.error("StudyActiveTasksDAOImpl - validateActiveTaskAttrById() - ERROR", e);
} finally {
if ((null != session) && session.isOpen()) {
session.close();
}
}
logger.exit("validateActiveTaskAttrById() - Ends");
return flag;
}