use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method getDisplayBean.
/**
* Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
* @param request TODO
* @param isSubmitted TODO
*/
protected DisplaySectionBean getDisplayBean(boolean hasGroup, boolean includeUngroupedItems, HttpServletRequest request, boolean isSubmitted) throws Exception {
DisplaySectionBean section = new DisplaySectionBean();
FormProcessor fp = new FormProcessor(request);
HttpSession session = request.getSession();
Locale loc = this.locale == null ? LocaleResolver.getLocale(request) : this.locale;
StudyBean study = (StudyBean) session.getAttribute("study");
SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
SectionDAO sdao;
// Find out whether there are ungrouped items in this section
boolean hasUngroupedItems = false;
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
if (eventDefinitionCRFId <= 0) {
// TODO: this block of code repeats
// many times, need to clean up
//synchronized(this)
{
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
eventDefinitionCRFId = edcBean.getId();
}
}
LOGGER.trace("eventDefinitionCRFId " + eventDefinitionCRFId);
// Use this class to find out whether there are ungrouped items in this
// section
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
if (hasGroup) {
DisplaySectionBean newDisplayBean = new DisplaySectionBean();
if (includeUngroupedItems) {
// Null values: this method adds null values to the
// displayitembeans
newDisplayBean = formBeanUtil.createDisplaySectionBWithFormGroups(sb.getId(), ecb.getCRFVersionId(), getDataSource(), eventDefinitionCRFId, ecb, getServletContext());
} else {
newDisplayBean = formBeanUtil.createDisplaySectionWithItemGroups(study, sb.getId(), ecb, ecb.getStudyEventId(), sm, eventDefinitionCRFId, getServletContext());
}
itemGroups = newDisplayBean.getDisplayFormGroups();
// setDataForDisplayItemGroups(itemGroups, sb,ecb,sm);
LOGGER.trace("found item group size: " + itemGroups.size() + " and to string: " + itemGroups.toString());
section.setDisplayFormGroups(itemGroups);
}
// Find out whether any display items are *not* grouped; see issue 1689
hasUngroupedItems = formBeanUtil.sectionHasUngroupedItems(getDataSource(), sb.getId(), itemGroups);
sdao = new SectionDAO(getDataSource());
//
sb.setHasSCDItem(hasUngroupedItems ? sdao.hasSCDItem(sb.getId()) : false);
section.setEventCRF(ecb);
if (sb.getParentId() > 0) {
SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
sb.setParent(parent);
}
section.setSection(sb);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
section.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(getDataSource());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
section.setCrf(cb);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
// EventDefinitionCRFBean edcb =
// edcdao.findByStudyEventIdAndCRFVersionId(study,
// ecb.getStudyEventId(), cvb.getId());
section.setEventDefinitionCRF(edcb);
// setup DAO's here to avoid creating too many objects
ItemDAO idao = new ItemDAO(getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), loc);
// Use itemGroups to determine if there are any ungrouped items
// get all the parent display item beans not in group
logMe("Entering getParentDisplayItems::: Thread is? " + Thread.currentThread());
ArrayList displayItems = getParentDisplayItems(hasGroup, sb, edcb, idao, ifmdao, iddao, hasUngroupedItems, request);
logMe("Entering getParentDisplayItems::: Done and Thread is? " + Thread.currentThread());
LOGGER.debug("just ran get parent display, has group " + hasGroup + " has ungrouped " + hasUngroupedItems);
// now sort them by ordinal,
//JN: Commenting out this logic, its wrong and will give erroneous results.
Collections.sort(displayItems);
// now get the child DisplayItemBeans
for (int i = 0; i < displayItems.size(); i++) {
DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
//
if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
if (shouldLoadDBValues(dib) && !isSubmitted) {
dib.loadDBValue();
}
} else {
if (shouldLoadDBValues(dib)) {
LOGGER.trace("should load db values is true, set value");
dib.loadDBValue();
LOGGER.trace("just got data loaded: " + dib.getData().getValue());
}
}
displayItems.set(i, dib);
}
section.setItems(displayItems);
return section;
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method nextSection.
protected SectionBean nextSection(SectionBean sb, EventCRFBean ecb, DisplayTableOfContentsBean toc, int sbPos) {
SectionBean n = new SectionBean();
ArrayList<SectionBean> sectionBeans = new ArrayList<SectionBean>();
if (toc != null) {
sectionBeans = toc.getSections();
int size = sectionBeans.size();
if (sbPos >= 0 && size > 1 && sbPos < size - 1) {
n = sectionBeans.get(sbPos + 1);
}
}
return n != null && n.getId() > 0 ? n : new SectionBean();
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class MarkEventCRFCompleteServlet method isEachSectionReviewedOnce.
private boolean isEachSectionReviewedOnce() {
SectionDAO sdao = new SectionDAO(sm.getDataSource());
DataEntryStage stage = ecb.getStage();
ArrayList sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
HashMap numItemsHM = sdao.getNumItemsBySectionId();
HashMap numItemsPendingHM = sdao.getNumItemsPendingBySectionId(ecb);
HashMap numItemsCompletedHM = sdao.getNumItemsCompletedBySectionId(ecb);
for (int i = 0; i < sections.size(); i++) {
SectionBean sb = (SectionBean) sections.get(i);
Integer key = new Integer(sb.getId());
int numItems = TableOfContentsServlet.getIntById(numItemsHM, key);
int numItemsPending = TableOfContentsServlet.getIntById(numItemsPendingHM, key);
int numItemsCompleted = TableOfContentsServlet.getIntById(numItemsCompletedHM, key);
if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
if (numItemsPending == 0 && numItems > 0) {
return false;
}
} else {
if (numItemsCompleted == 0 && numItems > 0) {
return false;
}
}
}
return true;
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method getSections.
public static ArrayList getSections(EventCRFBean ecb, DataSource ds) {
SectionDAO sdao = new SectionDAO(ds);
ItemGroupDAO igdao = new ItemGroupDAO(ds);
HashMap numItemsBySectionId = sdao.getNumItemsBySectionId();
HashMap numItemsPlusRepeatBySectionId = sdao.getNumItemsPlusRepeatBySectionId(ecb);
HashMap numItemsCompletedBySectionId = sdao.getNumItemsCompletedBySectionId(ecb);
HashMap numItemsPendingBySectionId = sdao.getNumItemsPendingBySectionId(ecb);
ArrayList sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
for (int i = 0; i < sections.size(); i++) {
SectionBean sb = (SectionBean) sections.get(i);
int sectionId = sb.getId();
Integer key = new Integer(sectionId);
// YW 10-11-2007 << handle number of item completion on tab.
int numItems = getIntById(numItemsBySectionId, key);
List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
if (!itemGroups.isEmpty()) {
// this section has repeating rows-jxu
int numItemsPlusRepeat = getIntById(numItemsPlusRepeatBySectionId, key);
if (numItemsPlusRepeat > numItems) {
sb.setNumItems(numItemsPlusRepeat);
} else {
sb.setNumItems(numItems);
}
} else {
sb.setNumItems(numItems);
}
// According to logic that I searched from code of this package by
// this time,
// for double data entry and stage.initial_data_entry,
// pending should be the status in query.
int numItemsCompleted = getIntById(numItemsCompletedBySectionId, key);
// the following is removed to fix issue 2091-jxu
// if(numItemsCompleted == 0) {
// numItemsCompleted = getIntById(numItemsPendingBySectionId, key) ;
// }
sb.setNumItemsCompleted(numItemsCompleted);
// YW >>
sb.setNumItemsNeedingValidation(getIntById(numItemsPendingBySectionId, key));
sections.set(i, sb);
}
return sections;
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionBWithFormGroups.
/**
* Create a DisplaySectionBean with a list of ItemGroupBeans. This List will
* include any ItemGroupBeans that are associated with ungrouped items; in
* other words, the DisplaySectionBean will represent a section that has
* both ungrouped and grouped tables.
*
* @param sectionId
* The Section ID associated with the Items, which end up
* providing the content of the tables.
* @param crfVersionId
* The CRF version ID associated with the Items.
* @param dataSource
* @param eventCRFDefId
* The id for the Event CRF Definition.
* @return A DisplaySectionBean with sorted ItemGroupBeans, meaning the
* ItemGroupBeans should be listed in the order that they appear on
* the CRF section.
* @return A DisplaySectionBean representing a CRF section.
*/
public DisplaySectionBean createDisplaySectionBWithFormGroups(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
DisplaySectionBean displaySectionBean = new DisplaySectionBean();
ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
ItemDAO itemDao = new ItemDAO(dataSource);
ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
SectionDAO sectionDao = new SectionDAO(dataSource);
// Give the DisplaySectionBean a legitimate SectionBean
SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
displaySectionBean.setSection(secBean);
// changed from: findGroupBySectionId
List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
// all items associated with the section, including those not in a group
List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
try {
allMetas = metaDao.findAllBySectionId(sectionId);
} catch (OpenClinicaException oce) {
logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
}
// Sort these items according to their position on the CRF; their
// ordinal
Collections.sort(allMetas);
// The DisplayItemGroupBean(s) for "nongrouped" items
List<DisplayItemGroupBean> nonGroupBeans = null;
// if(itemGroupBeans.isEmpty()) return displaySectionBean;
// Find out whether there are any checkboxes/radios/select elements
// and if so, get any null values
// associated with them
List<String> nullValuesList = new ArrayList<String>();
boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
if (itemsHaveChecksRadios && eventCRFDefId > 0) {
// method returns null values as a List<String>
nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
}
// Get the items associated with each group
List<ItemBean> itBeans;
List<DisplayItemBean> displayItems;
List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
DisplayItemGroupBean displayItemGBean;
for (ItemGroupBean itemGroup : itemGroupBeans) {
itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), crfVersionId);
logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), crfVersionId, sectionId);
if (!metadata.isEmpty()) {
// for a given crf version, all the items in the same group
// have the same group metadata info
// so we can get one of the metadata and set the metadata for
// the group
ItemGroupMetadataBean meta = metadata.get(0);
itemGroup.setMeta(meta);
}
displayItems = getDisplayBeansFromItems(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context);
displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
displayFormBeans.add(displayItemGBean);
}
// We still have to sort these display item group beans on their
// ItemGroupMetadataBean?
// then number their ordinals accordingly
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
}
});
// Now provide the display item group beans with an ordinal
int digOrdinal = 0;
for (DisplayItemGroupBean digBean : displayFormBeans) {
digBean.setOrdinal(++digOrdinal);
}
// find out whether there are any ungrouped items by comparing the
// number of
// grouped items to allMetas.size()
// List<DisplayItemGroupBean> nonGroupBeans=null;
int tempCount = 0;
for (DisplayItemGroupBean groupBean : displayFormBeans) {
tempCount += groupBean.getItems().size();
}
if (tempCount < allMetas.size()) {
nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
}
if (nonGroupBeans != null) {
displayFormBeans.addAll(nonGroupBeans);
}
// sort the list according to the ordinal of the contained
// DisplayItemGroupBeans
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
Integer compInt = disFormGroupBean1.getOrdinal();
Integer compInt2 = disFormGroupBean.getOrdinal();
return compInt2.compareTo(compInt);
}
});
displaySectionBean.setDisplayFormGroups(displayFormBeans);
return displaySectionBean;
}
Aggregations