use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionBeanWithItemGroups.
/**
* Create a DisplaySectionBean with a list of FormGroupBeans.
*
* @param crfVersionId
* The CRF version ID associated with the Items.
* @param sectionBean
* The SectionBean with an ID associated with the Items, which
* end up providing the content of the tables.
* @param sm
* A SessionManager, from which DataSources are acquired for the
* DAO objects.
* @return A DisplaySectionBean.
*/
public DisplaySectionBean createDisplaySectionBeanWithItemGroups(int sectionId, EventCRFBean eventCrfBean, SectionBean sectionBean, SessionManager sm, ServletContext context) {
DisplaySectionBean dBean = new DisplaySectionBean();
ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
ItemDAO itemDao = new ItemDAO(sm.getDataSource());
// Get all items associated with this crfVersion ID; divide them up into
// items with a group, and those without a group.
// get all items associated with a section id, then split them up into
// grouped
// and non-grouped items
List<ItemBean> allItems = itemDao.findAllParentsBySectionId(sectionId);
// Get a List of FormGroupBeans for each group associated with
// this crfVersionId.
// List<ItemGroupBean> arrList =
// formGroupDAO.findGroupByCRFVersionIDMap(crfVersionId);
List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
if (arrList.isEmpty())
return dBean;
// Get the items associated with each group
List<ItemBean> itBeans;
List<DisplayItemBean> displayItems;
List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
DisplayItemGroupBean displayFormGBean;
for (ItemGroupBean itemGroup : arrList) {
itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
// this requirement
if (!metadata.isEmpty()) {
// for a given crf version, all the items in the same group have
// the same group metadata
// so we can get one of them and set metadata for the group
ItemGroupMetadataBean meta = metadata.get(0);
itemGroup.setMeta(meta);
}
// TODO: the last arg is a list of null value strings
displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionBean.getId(), null, context);
displayFormGBean = this.createDisplayFormGroup(displayItems, itemGroup);
displayFormBeans.add(displayFormGBean);
}
// sort the list according to the ordinal of the contained
// FormGroupBeans
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
return disFormGroupBean.getGroupMetaBean().getOrdinal().compareTo(disFormGroupBean1.getGroupMetaBean().getOrdinal());
}
});
dBean.setDisplayFormGroups(displayFormBeans);
return dBean;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method getNumberOfColumnsFromItems.
/**
* Get the highest column number for a List of DisplayItemBeans.
*
* @param displayItems
* The List of DisplayItemBeans.
* @return An int representing the highest column number in the List,
* obained by getting the ItemFormMetadataBean columnNumber
* property.
*/
public int getNumberOfColumnsFromItems(List<DisplayItemBean> displayItems) {
if (displayItems == null)
return 0;
// one column is the default
int highestColumnNum = 1;
int temp;
for (DisplayItemBean displayItem : displayItems) {
temp = displayItem.getMetadata().getColumnNumber();
highestColumnNum = highestColumnNum < temp ? temp : highestColumnNum;
}
return highestColumnNum;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class PrintHorizontalFormBuilder method createTheadContentsFromDisplayItems.
public List<Element> createTheadContentsFromDisplayItems(List<DisplayItemBean> displayBeans, boolean generateExtraColumn) {
List<Element> elements = new ArrayList<Element>();
ItemFormMetadataBean itemFormBean;
// header is blank; add question number labels potentially
for (DisplayItemBean displayBean : displayBeans) {
itemFormBean = displayBean.getMetadata();
elements.add(createTHTagFromItemMeta(itemFormBean));
}
// }
return elements;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class ViewPersistanceHandler method sortDuplicatesIntoRows.
public Map<Integer, List<DisplayItemBean>> sortDuplicatesIntoRows(List<DisplayItemBean> displayBeans) {
// We know a DisplayItemBean is part of a duplicate row because its:
// 1. ItemDataBean ordinal is greater than 1 and
// 2. it shares the same ordinal with other members of its row.
Map<Integer, List<DisplayItemBean>> rowMap = new HashMap<Integer, List<DisplayItemBean>>();
List<DisplayItemBean> mapList = new ArrayList<DisplayItemBean>();
List<DisplayItemBean> dupesList = new ArrayList<DisplayItemBean>();
for (DisplayItemBean disBean : displayBeans) {
if (disBean.getData().getOrdinal() > 1) {
dupesList.add(disBean);
}
}
// Now separate clusters of the same ordinal into different Lists
int currentOrdinal = 0;
int currentItemId = 0;
for (DisplayItemBean disBean : dupesList) {
if (currentItemId == 0) {
currentItemId = disBean.getItem().getId();
currentOrdinal = disBean.getData().getOrdinal();
mapList.add(disBean);
rowMap.put(currentItemId, mapList);
continue;
}
if (disBean.getData().getOrdinal() == currentOrdinal) {
mapList.add(disBean);
} else {
// A different ordinal means create a new row
currentOrdinal = disBean.getData().getOrdinal();
mapList = new ArrayList<DisplayItemBean>();
mapList.add(disBean);
rowMap.put(disBean.getItem().getId(), mapList);
}
}
return rowMap;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class DataImportService method submitData.
public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
boolean discNotesGenerated = false;
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
StringBuffer auditMsg = new StringBuffer();
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = null;
ArrayList<Integer> eventCrfInts;
ItemDataBean itemDataBean;
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
eventCrfInts = new ArrayList<Integer>();
logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
return getReturnList("fail", "", "No items to submit. Please check your XML.");
}
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.debug("found value here: " + displayItemBean.getData().getValue());
logger.debug("found status here: " + eventCrfBean.getStatus().getName());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
resetSDV = true;
logger.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(userBean);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.debug("updated: " + itemDataBean.getItemId());
// need to set pk here in order to create dn
displayItemBean.getData().setId(itemDataBean.getId());
} else {
resetSDV = true;
itemDataDao.create(displayItemBean.getData());
logger.debug("created: " + displayItemBean.getData().getItemId());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
// logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean.getId());
}
ItemDAO idao = new ItemDAO(dataSource);
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.debug("*** checking for validation errors: " + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
// wrapper.getValidationErrors().toString());
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
for (String message : messageList) {
DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
discNotesGenerated = true;
logger.debug("*** created disc note with message: " + message);
auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
// split by this ? later, tbh
// displayItemBean);
}
}
if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
crfBusinessLogicHelper.markCRFStarted(eventCrfBean, userBean, true);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
}
eventCrfInts.add(new Integer(eventCrfBean.getId()));
}
}
// Reset the SDV status if item data has been changed or added
if (eventCrfBean != null && resetSDV)
eventCrfDao.setSDVStatus(false, userBean.getId(), eventCrfBean.getId());
}
}
if (!discNotesGenerated) {
return getReturnList("success", "", auditMsg.toString());
} else {
return getReturnList("warn", "", auditMsg.toString());
}
}
Aggregations