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 DoubleDataEntryServlet method validateDisplayItemGroupBean.
// 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
//
// we have to do this after adding the validations, so that we don't
// overwrite the value the item data bean had from initial data entry
// before the validator stores it as part of the Matches Initial Data Entry
// Value validation
// dib = loadFormValue(dib);
// return dib;
// }
// should be from the db, we check here for a difference
@Override
protected List<DisplayItemGroupBean> validateDisplayItemGroupBean(DiscrepancyValidator v, DisplayItemGroupBean digb, List<DisplayItemGroupBean> digbs, List<DisplayItemGroupBean> formGroups, HttpServletRequest request, HttpServletResponse response) {
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
HttpSession session = request.getSession();
LOGGER.info("===got this far");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
int keyId = ecb.getId();
Integer validationCount = (Integer) session.getAttribute(COUNT_VALIDATE + keyId);
formGroups = loadFormValueForItemGroup(digb, digbs, formGroups, edcb.getId(), request);
LOGGER.info("found formgroups size for " + digb.getGroupMetaBean().getName() + ": " + formGroups.size() + " compare to db groups size: " + digbs.size());
String inputName = "";
for (int i = 0; i < formGroups.size(); i++) {
DisplayItemGroupBean displayGroup = formGroups.get(i);
List<DisplayItemBean> items = displayGroup.getItems();
int order = displayGroup.getOrdinal();
if (displayGroup.isAuto() && displayGroup.getFormInputOrdinal() > 0) {
order = displayGroup.getFormInputOrdinal();
}
for (DisplayItemBean displayItem : items) {
if (displayGroup.isAuto()) {
inputName = getGroupItemInputName(displayGroup, order, displayItem);
} else {
inputName = getGroupItemManualInputName(displayGroup, order, displayItem);
}
validateDisplayItemBean(v, displayItem, inputName, request);
}
if (validationCount == null || validationCount.intValue() == 0) {
if (i == 0 && formGroups.size() != digbs.size()) {
v.addValidation(inputName + "group", Validator.DIFFERENT_NUMBER_OF_GROUPS_IN_DDE);
// TODO internationalize this string, tbh
v.setErrorMessage("There are additional values here that were not present in the initial data entry. You have entered a different number of groups" + " for the item groups containing " + inputName);
}
}
}
return formGroups;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method populateRuleSpecificHashMaps.
/**
* This method will populate grouped and variableAndValue HashMaps grouped : Used to correctly populate group ordinals variableAndValue : Holds itemOID ,
* value (in Form ) pairs passed in to rule processor
*
* @param allItems
*/
private Container populateRuleSpecificHashMaps(List<DisplayItemWithGroupBean> allItems, Container c, Boolean dryRun) {
for (DisplayItemWithGroupBean displayItemWithGroupBean : allItems) {
// Items in Non Repeating group also known as UNGROUPED
if (displayItemWithGroupBean.getSingleItem() != null) {
if (displayItemWithGroupBean.getSingleItem().getItem().getOid() != null) {
c.grouped.put(displayItemWithGroupBean.getSingleItem().getItem().getOid(), 1);
c.variableAndValue.put(displayItemWithGroupBean.getSingleItem().getItem().getOid(), ifValueIsDate(displayItemWithGroupBean.getSingleItem().getItem(), displayItemWithGroupBean.getSingleItem().getData().getValue(), dryRun));
LOGGER.debug("Type : " + displayItemWithGroupBean.getSingleItem().getItem().getItemDataTypeId());
for (Object displayItemBean : displayItemWithGroupBean.getSingleItem().getChildren()) {
String oid = ((DisplayItemBean) displayItemBean).getItem().getOid();
String value = ifValueIsDate(((DisplayItemBean) displayItemBean).getItem(), ((DisplayItemBean) displayItemBean).getData().getValue(), dryRun);
LOGGER.debug("Type : " + ((DisplayItemBean) displayItemBean).getItem().getItemDataTypeId());
c.grouped.put(oid, 1);
c.variableAndValue.put(oid, value);
}
}
LOGGER.debug("Item Name : {} , Item Value : {} , Item Data Ordinal : {} , Item OID : {} ", new Object[] { displayItemWithGroupBean.getSingleItem().getItem().getName(), displayItemWithGroupBean.getSingleItem().getData().getValue(), displayItemWithGroupBean.getSingleItem().getData().getOrdinal(), displayItemWithGroupBean.getSingleItem().getItem().getOid() });
}
// Items in repeating groups
for (DisplayItemGroupBean itemGroupBean : displayItemWithGroupBean.getItemGroups()) {
LOGGER.debug("Item Group Name : {} , Item Group OID : {} , Ordinal : {} ", new Object[] { itemGroupBean.getItemGroupBean().getName(), itemGroupBean.getItemGroupBean().getOid(), itemGroupBean.getIndex() });
for (DisplayItemBean displayItemBean : itemGroupBean.getItems()) {
String key1 = itemGroupBean.getItemGroupBean().getOid() + "[" + (itemGroupBean.getIndex() + 1) + "]." + displayItemBean.getItem().getOid();
String key = itemGroupBean.getItemGroupBean().getOid() + "." + displayItemBean.getItem().getOid();
c.variableAndValue.put(key1, ifValueIsDate(displayItemBean.getItem(), displayItemBean.getData().getValue(), dryRun));
if (c.grouped.containsKey(key)) {
c.grouped.put(key, c.grouped.get(key) + 1);
} else {
c.grouped.put(key, 1);
}
LOGGER.debug("Item Name : {} , Item Value : {} , Item OID : {} ", new Object[] { displayItemBean.getItem().getName(), displayItemBean.getData().getValue(), displayItemBean.getItem().getOid() });
}
}
}
if (LOGGER.isDebugEnabled()) {
for (String key : c.grouped.keySet()) {
LOGGER.debug("key : {} , value : {}", key, c.grouped.get(key));
}
for (String key : c.variableAndValue.keySet()) {
LOGGER.debug("key : {} , value : {}", key, c.variableAndValue.get(key));
}
}
return c;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method output.
/**
* Output, just logs all contents of the allItems list. tbh, 01/2010
*
* @param displayItemWithGroups
*/
protected void output(List<DisplayItemWithGroupBean> displayItemWithGroups) {
for (int i = 0; i < displayItemWithGroups.size(); ++i) {
DisplayItemWithGroupBean diwb = displayItemWithGroups.get(i);
if (diwb.isInGroup()) {
List<DisplayItemGroupBean> dbGroups = diwb.getDbItemGroups();
LOGGER.trace("+++++++ DB ITEM GROUPS ++++++++");
for (int j = 0; j < dbGroups.size(); j++) {
DisplayItemGroupBean displayGroup = dbGroups.get(j);
List<DisplayItemBean> items = displayGroup.getItems();
for (DisplayItemBean displayItem : items) {
int itemId = displayItem.getItem().getId();
int ordinal = displayItem.getData().getOrdinal();
if ("initial".equalsIgnoreCase(displayGroup.getEditFlag())) {
// nextOrdinals.put(itemId, 1);
LOGGER.trace("* found initial: " + itemId + " " + ordinal);
} else {
LOGGER.trace("** found NOT initial: " + itemId + " " + ordinal);
}
// editFlags.put(displayItem.getData().getId(), displayGroup.getEditFlag());
}
}
List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
LOGGER.trace("+++++++++ ITEM GROUPS ++++++++++");
int nextOrdinal = 0;
for (int j = 0; j < dgbs.size(); j++) {
DisplayItemGroupBean displayGroup = dgbs.get(j);
List<DisplayItemBean> oItems = displayGroup.getItems();
String editFlag = displayGroup.getEditFlag();
for (DisplayItemBean displayItem : oItems) {
int itemId = displayItem.getItem().getId();
// nextOrdinal = nextOrdinals.get(itemId);
int ordinal = 0;
// String editflag = "add".equalsIgnoreCase(editFlag) ? editFlag : editFlags.get(displayItem.getData().getId());
// if (editflag.length() > 0) {
// logger.trace("*** found: edit flag for " + itemId + ": " + editflag);
LOGGER.trace("*** found edit Flag " + itemId + ": " + editFlag);
// }
}
}
}
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class InitialDataEntryServlet method validateDisplayItemGroupBean.
@Override
protected List<DisplayItemGroupBean> validateDisplayItemGroupBean(DiscrepancyValidator v, DisplayItemGroupBean digb, List<DisplayItemGroupBean> digbs, List<DisplayItemGroupBean> formGroups, HttpServletRequest request, HttpServletResponse response) {
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
formGroups = loadFormValueForItemGroup(digb, digbs, formGroups, edcb.getId(), request);
String inputName = "";
for (int i = 0; i < formGroups.size(); i++) {
DisplayItemGroupBean displayGroup = formGroups.get(i);
List<DisplayItemBean> items = displayGroup.getItems();
int order = displayGroup.getOrdinal();
if (displayGroup.isAuto() && displayGroup.getFormInputOrdinal() > 0) {
order = displayGroup.getFormInputOrdinal();
}
for (DisplayItemBean displayItem : items) {
if (displayGroup.isAuto()) {
inputName = getGroupItemInputName(displayGroup, order, displayItem);
} else {
inputName = getGroupItemManualInputName(displayGroup, order, displayItem);
}
validateDisplayItemBean(v, displayItem, inputName, request);
}
}
return formGroups;
}
Aggregations