use of org.akaza.openclinica.bean.submit.ItemDataBean 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.ItemDataBean 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.ItemDataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method writeToDB.
protected boolean writeToDB(ItemDataBean itemData, DisplayItemBean dib, ItemDataDAO iddao, int ordinal, HttpServletRequest request) {
ItemDataBean idb = itemData;
UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
idb.setItemId(dib.getItem().getId());
idb.setEventCRFId(ecb.getId());
if (idb.getValue().equals("")) {
idb.setStatus(getBlankItemStatus());
} else {
idb.setStatus(getNonBlankItemStatus(request));
}
if (StringUtils.isBlank(dib.getEditFlag())) {
if (!idb.isActive()) {
// will this need to change for double data entry?
idb.setOrdinal(ordinal);
idb.setCreatedDate(new Date());
idb.setOwner(ub);
idb = (ItemDataBean) iddao.create(idb);
} else {
idb.setUpdater(ub);
// tbh 5990: should we update the logic here for nonrepeats?
// //System.out.println("string util is blank: update an item data " + idb.getId() + " :" + idb.getValue());
LOGGER.debug("update item update_id " + idb.getUpdater().getId());
idb = (ItemDataBean) iddao.updateValue(idb);
}
} else {
// for the items in group, they have editFlag
if ("add".equalsIgnoreCase(dib.getEditFlag())) {
idb.setOrdinal(ordinal);
idb.setCreatedDate(new Date());
idb.setOwner(ub);
LOGGER.debug("create a new item data" + idb.getItemId() + idb.getValue());
// idb = (ItemDataBean) iddao.create(idb);
// >>tbh 08/2008
idb.setUpdater(ub);
// idb = (ItemDataBean) iddao.updateValue(idb);
// instead of two hits to the db, we perform an 'upsert'
// combining them into one
idb = (ItemDataBean) iddao.upsert(idb);
// <<tbh
} else if ("edit".equalsIgnoreCase(dib.getEditFlag())) {
idb.setUpdater(ub);
// //System.out.println("update an item data - running update value " + idb.getId() + " :" + idb.getValue());
LOGGER.debug("update item update_id " + idb.getUpdater().getId());
// to make sure we are running the correct command on the db
if (idb.getId() != 0) {
idb.setUpdatedDate(new Date());
idb = (ItemDataBean) iddao.updateValue(idb);
} else {
idb.setCreatedDate(new Date());
idb.setOrdinal(ordinal);
idb.setOwner(ub);
idb = (ItemDataBean) iddao.upsert(idb);
LOGGER.debug("just ran upsert! " + idb.getId());
}
}
// else if ("remove".equalsIgnoreCase(dib.getEditFlag())) {
// LOGGER.debug("REMOVE an item data" + idb.getItemId() + idb.getValue());
// idb.setUpdater(ub);
// idb.setStatus(Status.DELETED);
// idb = (ItemDataBean) iddao.updateValueForRemoved(idb);
//
// DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(getDataSource());
// List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(idb.getId());
// if (!dnNotesOfRemovedItem.isEmpty()) {
// DiscrepancyNoteBean itemParentNote = null;
// for (Object obj : dnNotesOfRemovedItem) {
// if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
// itemParentNote = (DiscrepancyNoteBean) obj;
// }
// }
// DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
// if (itemParentNote != null) {
// dnb.setParentDnId(itemParentNote.getId());
// dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
// }
// dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
// dnb.setStudyId(currentStudy.getId());
// dnb.setAssignedUserId(ub.getId());
// dnb.setOwner(ub);
// dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
// dnb.setEntityId(idb.getId());
// dnb.setCreatedDate(new Date());
// dnb.setColumn("value");
// dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
// dnDao.create(dnb);
// dnDao.createMapping(dnb);
// itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
// dnDao.update(itemParentNote);
// }
// }
}
return idb.isActive();
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method validateDisplayItemBeanMultipleCV.
/**
* Peform validation on a item which has a RADIO or SINGLESELECT response type. This function checks that the input isn't blank, and that its value comes
* from the controlled vocabulary (ResponseSetBean) in the DisplayItemBean.
*
* @param v
* The Validator to add validations to.
* @param dib
* The DisplayItemBean to validate.
* @return The DisplayItemBean which is validated.
*/
protected DisplayItemBean validateDisplayItemBeanMultipleCV(DiscrepancyValidator v, DisplayItemBean dib, String inputName) {
if (StringUtil.isBlank(inputName)) {
inputName = getInputName(dib);
}
ItemFormMetadataBean ibMeta = dib.getMetadata();
ItemDataBean idb = dib.getData();
if (StringUtil.isBlank(idb.getValue())) {
if (ibMeta.isRequired() && ibMeta.isShowItem()) {
v.addValidation(inputName, Validator.IS_REQUIRED);
}
} else {
v.addValidation(inputName, Validator.IN_RESPONSE_SET, dib.getMetadata().getResponseSet());
}
customValidation(v, dib, inputName);
return dib;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean 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