use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.
public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(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) {
//TODO:fix me!
itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
//TODO:fix me add item_form_metadata.section_id to the query
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(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 = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
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