use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class VerifyImportedCRFDataServlet method processRequest.
@Override
@SuppressWarnings(value = "unchecked")
public void processRequest() throws Exception {
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(sm.getDataSource());
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
if ("confirm".equalsIgnoreCase(action)) {
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
logger.info("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());
forwardPage(Page.VERIFY_IMPORT_CRF_DATA);
}
if ("save".equalsIgnoreCase(action)) {
// setup ruleSets to run if applicable
RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) SpringServletAccess.getApplicationContext(context).getBean("ruleSetService");
List<ImportDataRuleRunnerContainer> containers = this.ruleRunSetup(sm.getDataSource(), currentStudy, ub, ruleSetService);
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
// System.out.println("Size of displayItemBeanWrappers : " +
// displayItemBeanWrappers.size());
HashMap<Integer, String> importedCRFStatuses = (HashMap<Integer, String>) session.getAttribute("importedCRFStatuses");
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = new EventCRFBean();
// TODO : tom , the wrapper object has all the necessary data -
// as you see we check the
// is to see if this data is Savable if it is then we go ahead
// and save it. if not we discard.
// So the change needs to happen here , instead of discarding we
// need to file discrepancy notes
// and save the data. If you look in the
// Page.VERIFY_IMPORT_CRF_DATA jsp file you can see how I am
// pulling the errors. and use that in the same way.
logger.info("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
ArrayList<Integer> eventCrfInts = new ArrayList<Integer>();
// wrapper.getValidationErrors().toString());
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.info("found value here: " + displayItemBean.getData().getValue());
logger.info("found status here: " + eventCrfBean.getStatus().getName());
// System.out.println("found event crf bean name here: "
// +
// eventCrfBean.getEventName()+" id "+eventCrfBean.getId
// ());
// SO, items can be created in a wrapper which is set to
// overwrite
// we get around this by checking the bean first, to
// make sure it's not null
ItemDataBean itemDataBean = new ItemDataBean();
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.info("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(ub);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.info("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.info("created: " + displayItemBean.getData().getItemId() + "event CRF ID = " + eventCrfBean.getId() + "CRF VERSION ID =" + eventCrfBean.getCRFVersionId());
// does this dao function work for repeating
// events/groups?
// ItemDataBean itemDataBean =
// itemDataDao.findByEventCRFIdAndItemName(
// eventCrfBean,
// displayItemBean.getItem().getName());
ItemDataBean itemDataBean2 = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
logger.info("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean2.getId());
}
// logger.info("created item data bean:
// "+displayItemBean.getData().getId());
// logger.info("created:
// "+displayItemBean.getData().getName());
// logger.info("continued:
// "+displayItemBean.getData().getItemId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.info("continued2: getName " +
// ibean.getName());
// System.out.println("*** checking for validation errors: "
// + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList messageList = (ArrayList) wrapper.getValidationErrors().get(itemOid);
// could it be more than one? tbh 08/2008
for (int iter = 0; iter < messageList.size(); iter++) {
String message = (String) messageList.get(iter);
DiscrepancyNoteBean parentDn = ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, ub, sm.getDataSource(), currentStudy);
ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), ub, sm.getDataSource(), currentStudy);
// System.out.println("*** created disc note with message: "
// + message);
// displayItemBean);
}
}
// "+displayItemBean.getDbData().getName());
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, ub);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
}
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, ub.getId(), eventCrfBean.getId());
// end of item datas, tbh
// crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
// System .out.println("*** just updated event crf bean: "+
// eventCrfBean.getId());
// need to update the study event status as well, tbh
// crfBusinessLogicHelper.updateStudyEvent(eventCrfBean,
// ub);
// above should do it for us, tbh 08/2008
}
}
addPageMessage(respage.getString("data_has_been_successfully_import"));
addPageMessage(this.ruleActionWarnings(this.runRules(currentStudy, ub, containers, ruleSetService, ExecutionMode.SAVE)));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// replaced tbh, 06/2009
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class VariableSubstitutionHelper method replaceVariables.
/**
* Replaces the variables in each {@link DisplayItemBean} of the {@link DisplaySectionBean}.
*
* @param section
* The display section to have its items processed.
* @param study
* Study associated with the display section.
* @param studySubject
* Subject associated with the display section.
*/
public static void replaceVariables(DisplaySectionBean section, StudyBean study, StudySubjectBean studySubject, StudyEventDefinitionBean eventDef, StudyEventBean event, DataSource dataSource) {
StrSubstitutor subst = new StrSubstitutor(buildTokensMap(section, studySubject, study, eventDef, event, dataSource));
for (DisplayItemBean displayItem : section.getItems()) {
ItemFormMetadataBean metadata = displayItem.getMetadata();
metadata.setRightItemText(replace(subst, metadata.getRightItemText()));
metadata.setLeftItemText(replace(subst, metadata.getLeftItemText()));
metadata.setHeader(replace(subst, metadata.getHeader()));
metadata.setSubHeader(replace(subst, metadata.getSubHeader()));
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class CellFactoryPrintDecorator method addUnits.
public Element addUnits(Element tdCell, DisplayItemBean displayBean) {
if (displayBean == null) {
return tdCell;
}
ItemBean itemBean = displayBean.getItem();
if (itemBean == null) {
return tdCell;
}
StringBuilder units = new StringBuilder(displayBean.getItem().getUnits());
if (units.length() < 1) {
return tdCell;
}
Element spanElement = new Element("span");
spanElement.setAttribute("style", "float:left;clear:both");
// surround units with parentheses
units = units.insert(0, "(");
units = units.append(")");
spanElement.addContent(" " + units.toString());
tdCell.addContent(spanElement);
return tdCell;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createSingleColumn.
/**
* Create a table containing a single column of Items.
*
* @param tbody
* The JDOM Element representing a tbody tag for the XHTML table.
* @param items
* The DisplayItemBeans representing the Items for the table.
* @param tabindex
* The Integer representing the form field's tab index.
* @param hasDiscrepancyMgt
* A boolean value specifying whether discrepancy icons should be
* displayed.
* @param hasDBValues
* A boolean value specifying whether the input elements are
* prefiled with database values.
* @param forPrinting
* A boolean value specifying whether the CRF is being displayed
* for printing (therefore, the D Note icons should not be
* enabled or clickable).
*/
private void createSingleColumn(Element tbody, List<DisplayItemBean> items, Integer tabindex, boolean hasDiscrepancyMgt, boolean hasDBValues, boolean forPrinting) {
CellFactory cellFactory = new CellFactory();
// Use this decorator class to generate vertical checkboxes, if any of
// the
// items have this type of layout
CellFactoryPrintDecorator cellFactoryPrintDecorator = new CellFactoryPrintDecorator();
// Create header/subheader rows, if necessary
String tmpName;
for (DisplayItemBean disBean : items) {
tmpName = disBean.getMetadata().getHeader();
if (tmpName != null && tmpName.length() > 0) {
Element tr = createHeaderSubheaderCell(disBean, true);
// add the row to the tbody element]
tbody.addContent(tr);
}
// Does the row tag need a subheader type background?
tmpName = disBean.getMetadata().getSubHeader();
if (tmpName != null && tmpName.length() > 0) {
Element tr2 = createHeaderSubheaderCell(disBean, false);
tbody.addContent(tr2);
}
// Create the row containing the item + form field
Element trRow = new Element("tr");
String leftSideTxt = "";
String questNumber = "";
tbody.addContent(trRow);
String responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
Element tdCell = new Element("td");
String classNames = CssRules.getClassNamesForTag("td");
tdCell.setAttribute("class", classNames);
// use vertical-alignment for these TD cells
tdCell.setAttribute("style", "vertical-align:top");
boolean horizontalLayout = "horizontal".equalsIgnoreCase(disBean.getMetadata().getResponseLayout());
// Just use this method for vertical checkboxes and radio buttons
if (("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName)) && !horizontalLayout) {
cellFactoryPrintDecorator.createCellContentsForVerticalLayout(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
} else {
cellFactory.createCellContents(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
}
questNumber = disBean.getMetadata().getQuestionNumberLabel();
boolean hasQuestion = questNumber.length() > 0;
leftSideTxt = disBean.getMetadata().getLeftItemText();
cellFactory.addTextToCell(tdCell, leftSideTxt, CellFactory.LEFT);
if (hasQuestion) {
addQuestionNumbers(tdCell, questNumber);
}
trRow.addContent(tdCell);
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createGroupBeansForNongroupedItems.
/**
* This method is designed to make it easier to order grouped and nongrouped
* items on a CRF. This method generates a List of DisplayItemGroupBeans
* representing the items that are not formally part of a group-type
* horizontal table (they have a name in the database of 'Ungrouped' ). The
* DisplayItemGroupBeans are ordered according to the position of the items
* on the CRF, compared with the CRF items that are in groups. When this
* List is combined with a List of DisplayItemGroupBeans representing
* *grouped* items, the combined List can be sorted and displayed in the
* proper order on a CRF.
*
* @param allItems
* A List of the ItemFormMetadataBeans associated with the CRF.
* @param displayFormBeans
* The List of DisplayItemGroupBeans
* @param sectionId
* The section ID associated with the items
* @param dataSource
* The DataSource used to acquire the DAO-related connections
* @param nullValuesList
* The list of any "null values" associated with the items (like
* "not applicable")
* @return An ArrayList of DisplayItemGroupBeans for 'Ungrouped' items.
*/
private List<DisplayItemGroupBean> createGroupBeansForNongroupedItems(List<ItemFormMetadataBean> allItems, List<DisplayItemGroupBean> displayFormBeans, int sectionId, DataSource dataSource, List<String> nullValuesList, EventCRFBean eventCrfBean, ServletContext context) {
// This will hold the List of placeholder groupBeans for orphaned items
List<DisplayItemGroupBean> groupBeans = new ArrayList<DisplayItemGroupBean>();
// Now create a Map that maps the item to the group ordinal
// (e.g., 1) or 0 (non-group),
// as a convenient way to position an item on a CRF
// and associate an item with the ordinal of its group.
// The inner Map maps the ItemFormMetadataBean to its group ordinal;
// The Integer index to this Map represents the order of the item on the
// CRF.
SortedMap<Integer, Map<ItemFormMetadataBean, Integer>> groupMapping = new TreeMap<Integer, Map<ItemFormMetadataBean, Integer>>();
Map<ItemFormMetadataBean, Integer> innerMap;
int counter = 0;
int tmpOrdinal;
for (ItemFormMetadataBean imetaBean : allItems) {
innerMap = new HashMap<ItemFormMetadataBean, Integer>();
if (isGrouped(imetaBean, displayFormBeans)) {
tmpOrdinal = getGroupOrdinal(imetaBean, displayFormBeans);
innerMap.put(imetaBean, tmpOrdinal);
} else {
innerMap.put(imetaBean, 0);
}
groupMapping.put(++counter, innerMap);
}
// The groupMapping Map maps the index position of the item on the CRF
// form (1,2,3...) to
// the ItemFormMetadataBean and its associated group ordinal, if it has
// one
// If the ordinal is 0, then the associated ItemFormMetadataBean
// represents an
// ungrouped or orphaned item
DisplayItemGroupBean nongroupedBean;
ItemGroupBean itemGroup = new ItemGroupBean();
ItemGroupMetadataBean metaBean = new ItemGroupMetadataBean();
metaBean.setName(UNGROUPED);
List<DisplayItemBean> items;
// Now cycle through the groupMapping and create default groups or
// DisplayItemGroupBeans, in order, for
// the orphaned items.
// A DisplayItemGroupBean is only created and stored in the returned
// List
// if its contents or associated items are nongrouped.
// This int tracks the ordinal associated with each grouped item's
// associated
// DisplayItemGroupBean
// as that item is incremented
int ordinalTracker = 0;
// This int is set to the latest DisplayItemGroupBean ordinal containing
// nongrouped beans, so that it can be incremented and used to change
// the ordinal of any DisplayItemGroupBeans (containing *grouped* items)
// that follow this bean on the CRF
// int nonGroupOrdinal=0;
Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>> entry;
Map<ItemFormMetadataBean, Integer> beanMap;
nongroupedBean = new DisplayItemGroupBean();
ItemFormMetadataBean tempItemMeta;
int tempOrdinal;
// a flag indicating that the last item handled was an orphaned one
// so that if the next item is grouped, that's a signal to store the
// new itemgroupbean just created for orphaned items in in the
// itemgroupbean List.
boolean isOrphaned = false;
// any of the orphaned items
for (Iterator<Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>>> iter = groupMapping.entrySet().iterator(); iter.hasNext(); ) {
entry = iter.next();
// the ItemFormMetadataBean and any
beanMap = entry.getValue();
// group ordinal
// the
tempItemMeta = beanMap.keySet().iterator().next();
// ItemFormMetadataBean
// If this value is 0, the item is orphaned; if > 0 the item is
// grouped
// and doesn't need a new itemgroupbean
tempOrdinal = beanMap.get(tempItemMeta);
// ordinalTracker != 0
if (tempOrdinal == 0) {
if (ordinalTracker == 0 || !isOrphaned) {
// initialize a new group for the item
nongroupedBean = new DisplayItemGroupBean();
itemGroup = new ItemGroupBean();
itemGroup.setName(UNGROUPED);
nongroupedBean.setItemGroupBean(itemGroup);
// set this flag, so that if the next item is orphaned, then
// the code can place it in the existing itemgroupbean
isOrphaned = true;
ordinalTracker++;
nongroupedBean.setOrdinal(ordinalTracker);
// nonGroupOrdinal=nongroupedBean.getOrdinal();
// nonGroupOrdinal= ordinalTracker;
}
// Add the item as a displayitem to the itemgroupbean
nongroupedBean.getItems().add(getDisplayBeanFromSingleItem(tempItemMeta, sectionId, dataSource, eventCrfBean, nullValuesList, context));
} else {
// been created; therefore, store it in the List.
if (isOrphaned) {
groupBeans.add(nongroupedBean);
// We also know that the ordinal has changed, because a
// nongroupedBean
// has been created
ordinalTracker++;
incrementOrdinal(tempItemMeta, displayFormBeans, ordinalTracker);
} else {
ordinalTracker = getGroupOrdinal(tempItemMeta, displayFormBeans);
}
isOrphaned = false;
}
}
// is leftover and must be added to the List
if (isOrphaned) {
groupBeans.add(nongroupedBean);
}
return groupBeans;
}
Aggregations