use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class BeanFactory method createChildren.
/*
* Generate the list of children for a DisplayItemBean. Currently, this
* method must return an ArrayList, because that is the data type for an
* ItemFormMetaDataBean's children field.
*/
public ArrayList<DisplayItemBean> createChildren(List<DisplayItemBean> childrenItems, DisplayItemBean parent) {
ArrayList<DisplayItemBean> children = new ArrayList<DisplayItemBean>();
// a child of that paent ItemBean.
for (DisplayItemBean bean : childrenItems) {
if (bean.getMetadata().getParentLabel().equalsIgnoreCase(parent.getItem().getName())) {
children.add(bean);
}
}
// sort in ascending order based on the column number of
// the ItemFormMetadataBean. This is specified by the DisplayItemBean
// API.
Collections.sort(children, new Comparator<DisplayItemBean>() {
public int compare(DisplayItemBean displayItemBean, DisplayItemBean displayItemBean1) {
return new Integer(displayItemBean.getMetadata().getColumnNumber()).compareTo(displayItemBean1.getMetadata().getColumnNumber());
}
});
return children;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class BeanFactory method createDisplaySectionBean.
// Create a DisplaySectionBean using an items map, a section's title,
// the section's page number, and the CRF name/ The CRF name is needed for
// creating the ResponseSetBean.
public DisplaySectionBean createDisplaySectionBean(Map<Integer, Map<String, String>> map, String sectionTitle, String sectionLabel, String sectionSubtitle, String instructions, String crfName, int sectionBorders) {
// Play defense!
if (map == null)
return new DisplaySectionBean();
// Display a section title in the JSP
SectionBean sbean = new SectionBean();
sbean.setTitle(sectionTitle);
sbean.setSubtitle(sectionSubtitle);
sbean.setInstructions(instructions);
sbean.setBorders(sectionBorders);
DisplaySectionBean displaySectionBean = new DisplaySectionBean();
displaySectionBean.setSection(sbean);
ArrayList<DisplayItemBean> allDisplayItems = new ArrayList<DisplayItemBean>();
List<DisplayItemBean> childrenItems = new ArrayList<DisplayItemBean>();
DisplayItemBean displayItem;
ItemFormMetadataBean itemMeta;
Map.Entry<Integer, Map<String, String>> me;
Map<String, String> innerMap;
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = map.entrySet().iterator(); iter.hasNext(); ) {
displayItem = new DisplayItemBean();
// me is one row in the list of Items, indexed by the item number
me = iter.next();
if (itemSecLabelMatchesSection(me, sectionLabel)) {
itemMeta = this.createItemFormMetadataBean(me, crfName);
displayItem.setMetadata(itemMeta);
innerMap = me.getValue();
displayItem.setItem(this.createItemBean(innerMap));
// Compensate for any items that identify themselves as parents
String parentName = displayItem.getMetadata().getParentLabel();
if (parentName.length() > 0 && !displayItem.getItem().getName().equalsIgnoreCase(parentName)) {
displayItem.getMetadata().setParentId(1);
childrenItems.add(displayItem);
} else {
allDisplayItems.add(displayItem);
}
}
}
// Set the children for each of the display items
for (DisplayItemBean parentBean : allDisplayItems) {
parentBean.setChildren(this.createChildren(childrenItems, parentBean));
}
// Sort the List of DisplayItemBeans based on their ordinal; see
// getDisplayBean() in DataEntryServlet
Collections.sort(allDisplayItems);
displaySectionBean.setItems(allDisplayItems);
return displaySectionBean;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class PrintAllEventCRFServlet method validateDisplayItemBean.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.submit.DataEntryServlet#validateDisplayItemBean(org.akaza.openclinica.core.form.Validator,
* org.akaza.openclinica.bean.submit.DisplayItemBean)
*/
@Override
protected DisplayItemBean validateDisplayItemBean(DiscrepancyValidator v, DisplayItemBean dib, String inputName, HttpServletRequest request) {
ItemBean ib = dib.getItem();
org.akaza.openclinica.bean.core.ResponseType rt = dib.getMetadata().getResponseSet().getResponseType();
// note that this step sets us up both for
// displaying the data on the form again, in the event of an error
// and sending the data to the database, in the event of no error
dib = loadFormValue(dib, request);
// types TEL and ED are not supported yet
if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXT) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXTAREA)) {
dib = validateDisplayItemBeanText(v, dib, inputName, request);
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.RADIO) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECT)) {
dib = validateDisplayItemBeanSingleCV(v, dib, inputName);
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CHECKBOX) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECTMULTI)) {
dib = validateDisplayItemBeanMultipleCV(v, dib, inputName);
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CALCULATION) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.GROUP_CALCULATION)) {
// for now, treat calculation like any other text input --
// eventually this might need to be customized
dib = validateDisplayItemBeanText(v, dib, inputName, request);
}
return dib;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean 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.DisplayItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method loadItemsWithGroupRows.
protected void loadItemsWithGroupRows(DisplayItemWithGroupBean itemWithGroup, SectionBean sb, EventDefinitionCRFBean edcb, EventCRFBean ecb, HttpServletRequest request) {
// this method is a copy of the method: createItemWithGroups ,
// only modified for load one DisplayItemWithGroupBean.
//
ItemDAO idao = new ItemDAO(getDataSource());
// For adding null values to display items
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<String> nullValuesList = new ArrayList<String>();
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(edcb.getId(), getDataSource());
// >>BWP
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ArrayList data = iddao.findAllActiveBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
DisplayItemGroupBean itemGroup = itemWithGroup.getItemGroup();
// to arrange item groups and other single items, the ordinal of
// a item group will be the ordinal of the first item in this
// group
DisplayItemBean firstItem = itemGroup.getItems().get(0);
DisplayItemBean checkItem = firstItem;
// does not work if there is not any data in the first item of the group
// i.e. imports.
// does it make a difference if we take a last item?
boolean noNeedToSwitch = false;
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
if (idb.getItemId() == firstItem.getItem().getId()) {
noNeedToSwitch = true;
}
}
if (!noNeedToSwitch) {
checkItem = itemGroup.getItems().get(itemGroup.getItems().size() - 1);
}
// so we are either checking the first or the last item, BUT ONLY ONCE
itemWithGroup.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
itemWithGroup.setItemGroup(itemGroup);
itemWithGroup.setInGroup(true);
itemWithGroup.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
List<ItemBean> itBeans = idao.findAllItemsByGroupId(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
boolean hasData = false;
int checkAllColumns = 0;
// first item should be same as the row number
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
LOGGER.debug("check all columns: " + checkAllColumns);
if (idb.getItemId() == checkItem.getItem().getId()) {
hasData = true;
LOGGER.debug("set has data to --TRUE--");
checkAllColumns = 0;
// so that we only fire once a row
LOGGER.debug("has data set to true");
DisplayItemGroupBean digb = new DisplayItemGroupBean();
// always get a fresh copy for items, may use other
// better way to
// do deep copy, like clone
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), edcb, 0, getServletContext());
digb.setItems(dibs);
LOGGER.trace("set with dibs list of : " + dibs.size());
digb.setGroupMetaBean(runDynamicsCheck(itemGroup.getGroupMetaBean(), request));
digb.setItemGroupBean(itemGroup.getItemGroupBean());
itemWithGroup.getItemGroups().add(digb);
itemWithGroup.getDbItemGroups().add(digb);
}
}
List<DisplayItemGroupBean> groupRows = itemWithGroup.getItemGroups();
LOGGER.trace("how many group rows:" + groupRows.size());
LOGGER.trace("how big is the data:" + data.size());
if (hasData) {
// the group
for (int i = 0; i < groupRows.size(); i++) {
DisplayItemGroupBean displayGroup = groupRows.get(i);
for (DisplayItemBean dib : displayGroup.getItems()) {
for (int j = 0; j < data.size(); j++) {
ItemDataBean idb = (ItemDataBean) data.get(j);
if (idb.getItemId() == dib.getItem().getId() && !idb.isSelected()) {
idb.setSelected(true);
dib.setData(idb);
LOGGER.debug("--> set data " + idb.getId() + ": " + idb.getValue());
if (shouldLoadDBValues(dib)) {
LOGGER.debug("+++should load db values is true, set value");
dib.loadDBValue();
LOGGER.debug("+++data loaded: " + idb.getName() + ": " + idb.getOrdinal() + " " + idb.getValue());
LOGGER.debug("+++try dib OID: " + dib.getItem().getOid());
}
break;
}
}
}
}
} else {
// no data, still add a blank row for displaying
DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
digb2.setItems(dibs);
LOGGER.trace("set with nullValuesList of : " + nullValuesList);
digb2.setEditFlag("initial");
digb2.setGroupMetaBean(itemGroup.getGroupMetaBean());
digb2.setItemGroupBean(itemGroup.getItemGroupBean());
itemWithGroup.getItemGroups().add(digb2);
itemWithGroup.getDbItemGroups().add(digb2);
}
}
Aggregations