use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class ListDiscNotesSubjectTableFactory method setDataAndLimitVariables.
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
StudyBean study = this.getStudyBean();
Limit limit = tableFacade.getLimit();
ListDiscNotesSubjectFilter subjectFilter = getSubjectFilter(limit);
subjectFilter.addFilter("dn.discrepancy_note_type_id", this.discNoteType);
StringBuffer constraints = new StringBuffer();
if (this.discNoteType > 0 && this.discNoteType < 10) {
constraints.append(" and dn.discrepancy_note_type_id=" + this.discNoteType);
}
if (this.resolutionStatusIds != null && this.resolutionStatusIds.size() > 0) {
String s = " and (";
for (Integer resolutionStatusId : this.resolutionStatusIds) {
s += "dn.resolution_status_id = " + resolutionStatusId + " or ";
}
s = s.substring(0, s.length() - 3) + " )";
subjectFilter.addFilter("dn.resolution_status_id", s);
constraints.append(s);
}
if (!limit.isComplete()) {
int totalRows = getStudySubjectDAO().getCountWithFilter(subjectFilter, study);
tableFacade.setTotalRows(totalRows);
}
ListDiscNotesSubjectSort subjectSort = getSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(study, subjectFilter, subjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
boolean hasDN = false;
for (StudySubjectBean studySubjectBean : items) {
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("studySubject", studySubjectBean);
theItem.put("studySubject.label", studySubjectBean.getLabel());
theItem.put("studySubject.status", studySubjectBean.getStatus());
theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
// Get All study events for this study subject and then put list in
// HashMap with study event definition id as
// key and a list of study events as the value.
List<StudyEventBean> allStudyEventsForStudySubject = getStudyEventDAO().findAllByStudySubject(studySubjectBean);
HashMap<Integer, List<StudyEventBean>> allStudyEventsForStudySubjectBySedId = new HashMap<Integer, List<StudyEventBean>>();
theItem.put("isSignable", isSignable(allStudyEventsForStudySubject));
for (StudyEventBean studyEventBean : allStudyEventsForStudySubject) {
if (allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()) == null) {
ArrayList<StudyEventBean> a = new ArrayList<StudyEventBean>();
a.add(studyEventBean);
allStudyEventsForStudySubjectBySedId.put(studyEventBean.getStudyEventDefinitionId(), a);
} else {
allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()).add(studyEventBean);
}
}
for (StudyEventDefinitionBean studyEventDefinition : getStudyEventDefinitions()) {
List<StudyEventBean> studyEvents = allStudyEventsForStudySubjectBySedId.get(studyEventDefinition.getId());
SubjectEventStatus subjectEventStatus = null;
HashMap<ResolutionStatus, Integer> discCounts = new HashMap<ResolutionStatus, Integer>();
studyEvents = studyEvents == null ? new ArrayList<StudyEventBean>() : studyEvents;
if (studyEvents.size() < 1) {
subjectEventStatus = SubjectEventStatus.NOT_SCHEDULED;
} else {
for (StudyEventBean studyEventBean : studyEvents) {
discCounts = countAll(discCounts, studyEventBean, constraints, study.isSite(study.getParentStudyId()));
hasDN = hasDN == false ? discCounts.size() > 0 : hasDN;
if (studyEventBean.getSampleOrdinal() == 1) {
subjectEventStatus = studyEventBean.getSubjectEventStatus();
// break;
}
}
}
theItem.put("sed_" + studyEventDefinition.getId() + "_discCounts", discCounts);
theItem.put("sed_" + studyEventDefinition.getId(), subjectEventStatus.getId());
theItem.put("sed_" + studyEventDefinition.getId() + "_studyEvents", studyEvents);
theItem.put("sed_" + studyEventDefinition.getId() + "_object", studyEventDefinition);
}
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
setStudyHasDiscNotes(hasDN);
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method createEventCRF.
/**
* Creates a new Event CRF or update the exsiting one, that is, an event CRF
* can be created but not item data yet, in this case, still consider it is
* not started(called uncompleted before)
*
* @return
* @throws Exception
*/
private EventCRFBean createEventCRF() throws Exception {
EventCRFBean ecb;
ecdao = new EventCRFDAO(sm.getDataSource());
int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
int subjectId = fp.getInt(INPUT_SUBJECT_ID);
int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
logger.info("Creating event CRF within Table of Contents. Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
if (!ssb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE1"));
}
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
if (!ssb.isActive() || !sedb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE2"));
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
EntityBean eb = cvdao.findByPK(crfVersionId);
if (!eb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE3"));
}
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
StudyBean studyWithSED = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithSED = new StudyBean();
studyWithSED.setId(currentStudy.getParentStudyId());
}
AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
if (!aeb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE4"));
}
ecb = new EventCRFBean();
if (eventCRFId == 0) {
// no event CRF created yet
ecb.setAnnotations("");
ecb.setCreatedDate(new Date());
ecb.setCRFVersionId(crfVersionId);
ecb.setInterviewerName("");
if (sEvent.getDateStarted() != null) {
// default date
ecb.setDateInterviewed(sEvent.getDateStarted());
} else {
ecb.setDateInterviewed(null);
}
ecb.setOwnerId(ub.getId());
ecb.setStatus(Status.AVAILABLE);
ecb.setCompletionStatusId(1);
ecb.setStudySubjectId(ssb.getId());
ecb.setStudyEventId(studyEventId);
ecb.setValidateString("");
ecb.setValidatorAnnotations("");
ecb = (EventCRFBean) ecdao.create(ecb);
logger.info("CREATED EVENT CRF");
} else {
// there is an event CRF already, only need to update
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
ecb.setCRFVersionId(crfVersionId);
ecb.setUpdatedDate(new Date());
ecb.setUpdater(ub);
ecb = (EventCRFBean) ecdao.update(ecb);
}
if (!ecb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created_database_error"));
} else {
sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
sEvent.setUpdater(ub);
sEvent.setUpdatedDate(new Date());
sedao.update(sEvent);
}
return ecb;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class TestRuleServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String action = request.getParameter("action");
Validator v = new Validator(request);
if (StringUtil.isBlank(action)) {
request.setAttribute("result", resword.getString("test_rule_default_result"));
Integer ruleSetRuleId = fp.getInt("ruleSetRuleId");
if (ruleSetRuleId != 0) {
// If testing an existing ruleSetRule
RuleSetRuleBean rsr = getRuleSetRuleDao().findById(ruleSetRuleId);
rsr.getActions().size();
HashMap presetValues = new HashMap();
presetValues.put(TARGET, rsr.getRuleSetBean().getTarget().getValue());
presetValues.put(RULE, rsr.getRuleBean().getExpression().getValue());
presetValues.put(RULE_SET_RULE_ID, String.valueOf(ruleSetRuleId));
fp.setPresetValues(presetValues);
setPresetValues(presetValues);
session.setAttribute("testRuleActions", rsr.getActions());
session.setAttribute("testRulesTarget", rsr.getRuleSetBean().getTarget().getValue());
request.setAttribute("ruleSetRuleId", ruleSetRuleId);
request.setAttribute("ruleSetId", rsr.getRuleSetBean().getId());
ItemBean item = getExpressionService().getItemBeanFromExpression(rsr.getRuleSetBean().getTarget().getValue());
if (item != null) {
request.setAttribute("itemName", item.getName());
request.setAttribute("itemDefinition", item.getDescription());
} else {
StudyEventDefinitionBean studyEventDef = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(rsr.getRuleSetBean().getTarget().getValue(), this.currentStudy);
request.setAttribute("itemName", studyEventDef.getName());
request.setAttribute("itemDefinition", studyEventDef.getDescription());
}
request.setAttribute("ruleSetRuleAvailable", true);
} else {
// free form testing
putDummyActionInSession();
}
session.removeAttribute("testValues");
request.setAttribute("action", "validate");
forwardPage(Page.TEST_RULES);
} else if (action.equals("validate")) {
HashMap<String, String> result = validate(v);
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("validate", "on");
request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_validate_message"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
result.remove("result");
result.remove("ruleValidation");
result.remove("ruleEvaluatesTo");
result.remove("ruleValidationFailMessage");
populateTooltip(result);
session.setAttribute("testValues", result);
populteFormFields(fp);
forwardPage(Page.TEST_RULES);
} else if (action.equals("test")) {
HashMap<String, String> result = validate(v);
HashMap errors = v.validate();
if (!errors.isEmpty()) {
setInputMessages(errors);
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("validate", "on");
request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_rule_fail_invalid_data_type") + " " + resword.getString("test_rules_rule_fail_invalid_data_type_desc"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
request.setAttribute("action", "test");
} else {
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("ruleEvaluatesTo", result.get("ruleEvaluatesTo"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
}
if (result.get("ruleValidation").equals("rule_invalid")) {
session.setAttribute("testValues", new HashMap<String, String>());
} else {
session.setAttribute("testValues", result);
}
result.remove("result");
result.remove("ruleValidation");
result.remove("ruleEvaluatesTo");
result.remove("ruleValidationFailMessage");
populateTooltip(result);
populteFormFields(fp);
forwardPage(Page.TEST_RULES);
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class OdmController method generateStudyEventData.
private ODMcomplexTypeDefinitionStudyEventData generateStudyEventData(StudyEventBean studyEvent) {
ODMcomplexTypeDefinitionStudyEventData studyEventData = new ODMcomplexTypeDefinitionStudyEventData();
studyEventData.setStartDate(studyEvent.getDateStarted().toString());
StudyEventDefinitionBean studyEventDefBean = getStudyEventDefinitionBean(studyEvent.getStudyEventDefinitionId());
studyEventData.setEventName(studyEventDefBean.getName());
studyEventData.setStudyEventOID(studyEventDefBean.getOid());
studyEventData.setStudyEventRepeatKey(String.valueOf(studyEvent.getSampleOrdinal()));
return studyEventData;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class OdmController method getStudyEventDefinitionBean.
private StudyEventDefinitionBean getStudyEventDefinitionBean(int ID) {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) seddao.findByPK(ID);
return studyEventDefinitionBean;
}
Aggregations