use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class PrintDataEntryServlet 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.ItemBean in project OpenClinica by OpenClinica.
the class ViewEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int eventCRFId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO secdao = new SectionDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
request.setAttribute("crf", crf);
ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
ArrayList displayItemData = new ArrayList();
for (int i = 0; i < itemData.size(); i++) {
ItemDataBean id = (ItemDataBean) itemData.get(i);
DisplayItemBean dib = new DisplayItemBean();
ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
item.setItemMeta(ifm);
dib.setItem(item);
dib.setData(id);
dib.setMetadata(ifm);
displayItemData.add(dib);
}
section.setItems(displayItemData);
}
request.setAttribute("sections", sections);
request.setAttribute("studySubId", new Integer(studySubId).toString());
forwardPage(Page.VIEW_EVENT_CRF);
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method getParentDisplayItems.
/**
* For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId
* == 0.
* @param sb
* The section whose items we are retrieving.
* @param hasUngroupedItems
* @param request TODO
*
* @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
* @throws Exception
*/
private ArrayList getParentDisplayItems(boolean hasGroup, SectionBean sb, EventDefinitionCRFBean edcb, ItemDAO idao, ItemFormMetadataDAO ifmdao, ItemDataDAO iddao, boolean hasUngroupedItems, HttpServletRequest request) throws Exception {
ArrayList answer = new ArrayList();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
HashMap displayItems = new HashMap();
// ArrayList items = idao.findAllParentsBySectionId(sb.getId());
ArrayList items = new ArrayList();
ArrayList itemsUngrped = new ArrayList();
if (hasGroup) {
// See: FormBeanUtil.sectionHasUngroupedItems.
if (hasUngroupedItems) {
// @pgawade 05-Aug-2011 fix for issue 10628 - commented out the
// if-else logic based on 'hasGroup' flag.
// 'if' part is unchanged but else part is changed to be
// executed always because that is to get the non-repeating and
// ungrouped item details and was getting skipped in case the
// section has repeating group items plus non-repeating group
// items
itemsUngrped = idao.findAllUngroupedParentsBySectionId(sb.getId(), sb.getCRFVersionId());
}
// however, if we have true:true, we exclude all grouped items
// items.addAll(
// idao.findAllGroupedParentsBySectionId(
// sb.getId(), sb.getCRFVersionId()));
}
// else {
LOGGER.trace("no item groups");
// items = idao.findAllParentsBySectionId(sb.getId());
items = idao.findAllNonRepeatingParentsBySectionId(sb.getId());
items.addAll(itemsUngrped);
// }
LOGGER.debug("items size" + items.size());
for (int i = 0; i < items.size(); i++) {
DisplayItemBean dib = new DisplayItemBean();
dib.setEventDefinitionCRF(edcb);
ItemBean ib = (ItemBean) items.get(i);
dib.setItem(ib);
displayItems.put(new Integer(dib.getItem().getId()), dib);
}
ArrayList data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(idb.getItemId()));
if (dib != null) {
dib.setData(idb);
dib.setDbData((ItemDataBean) BeanUtils.cloneBean(idb));
displayItems.put(new Integer(idb.getItemId()), dib);
}
}
ArrayList metadata = ifmdao.findAllBySectionId(sb.getId());
for (int i = 0; i < metadata.size(); i++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metadata.get(i);
DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(ifmb.getItemId()));
if (dib != null) {
// boolean showItem = false;
boolean needsHighlighting = !ifmb.isShowItem();
logMe("Entering thread before getting ItemMetadataService:::" + Thread.currentThread());
boolean showItem = getItemMetadataService().isShown(ifmb.getItemId(), ecb, dib.getData());
if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
showItem = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
}
// is the above needed for children items too?
boolean passedDDE = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
if (showItem) {
// we are only showing, not hiding
LOGGER.debug("set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE);
// ifmb.setShowItem(showItem);
ifmb.setShowItem(true);
} else {
LOGGER.debug("DID NOT set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE + " value " + dib.getData().getValue());
}
dib.setMetadata(ifmb);
displayItems.put(new Integer(ifmb.getItemId()), dib);
}
}
Iterator hmIt = displayItems.keySet().iterator();
while (hmIt.hasNext()) {
Integer key = (Integer) hmIt.next();
DisplayItemBean dib = (DisplayItemBean) displayItems.get(key);
answer.add(dib);
LOGGER.debug("*** getting with key: " + key + " display item bean with value: " + dib.getData().getValue());
}
LOGGER.debug("*** test of the display items: " + displayItems.toString());
return answer;
}
use of org.akaza.openclinica.bean.submit.ItemBean 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);
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method createItemWithGroups.
//@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method createItemWithGroups
protected List<DisplayItemWithGroupBean> createItemWithGroups(DisplaySectionBean dsb, boolean hasItemGroup, int eventCRFDefId, HttpServletRequest request, boolean isSubmitted) {
HttpSession session = request.getSession();
List<DisplayItemWithGroupBean> displayItemWithGroups = new ArrayList<DisplayItemWithGroupBean>();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
ItemDAO idao = new ItemDAO(getDataSource());
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
// >>BWP
ArrayList items = dsb.getItems();
// For adding null values to display items
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<String> nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(eventCRFDefId, getDataSource());
LOGGER.trace("single items size: " + items.size());
for (int i = 0; i < items.size(); i++) {
DisplayItemBean item = (DisplayItemBean) items.get(i);
DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
newOne.setSingleItem(runDynamicsItemCheck(item, null, request));
newOne.setOrdinal(item.getMetadata().getOrdinal());
newOne.setInGroup(false);
newOne.setPageNumberLabel(item.getMetadata().getPageNumberLabel());
displayItemWithGroups.add(newOne);
// logger.trace("just added on line 1979:
// "+newOne.getSingleItem().getData().getValue());
}
if (hasItemGroup) {
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ArrayList<ItemDataBean> data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
HashMap<String, ItemDataBean> dataMap = (HashMap<String, ItemDataBean>) getAllActive(data);
if (data != null && data.size() > 0) {
session.setAttribute(HAS_DATA_FLAG, true);
}
LOGGER.trace("found data: " + data.size());
LOGGER.trace("data.toString: " + data.toString());
for (DisplayItemGroupBean itemGroup : dsb.getDisplayFormGroups()) {
LOGGER.debug("found one itemGroup");
DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
// 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);
// so we are either checking the first or the last item, BUT ONLY ONCE
newOne.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
newOne.setItemGroup(itemGroup);
newOne.setInGroup(true);
newOne.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
List<ItemBean> itBeans = idao.findAllItemsByGroupIdOrdered(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
List<DisplayItemBean> dibs = new ArrayList();
boolean hasData = false;
int checkAllColumns = 0;
if (data.size() > 0)
hasData = true;
//@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method buildMatrixForRepeatingGroups
newOne = buildMatrixForRepeatingGroups(newOne, itemGroup, ecb, sb, itBeans, dataMap, nullValuesList, isSubmitted);
if (hasData) {
//TODO: fix the group_has_data flag on bean not on session
session.setAttribute(GROUP_HAS_DATA, Boolean.TRUE);
} else {
session.setAttribute(GROUP_HAS_DATA, Boolean.FALSE);
// no data, still add a blank row for displaying
if (nullValuesList != null && nullValuesList.size() > 0) {
LOGGER.trace("set with nullValuesList of : " + nullValuesList);
}
dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
digb2.setItems(dibs);
digb2.setEditFlag("initial");
}
displayItemWithGroups.add(newOne);
}
}
// if hasItemGroup
Collections.sort(displayItemWithGroups);
return displayItemWithGroups;
}
Aggregations