use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class ExpressionService method fixGroupOrdinal.
private String fixGroupOrdinal(String ruleExpression, String targetExpression, List<ItemDataBean> itemData, EventCRFBean eventCrf) {
String returnedRuleExpression = ruleExpression;
if (getItemGroupOid(ruleExpression).equals(getItemGroupOid(targetExpression))) {
if (getGroupOrdninalCurated(ruleExpression).equals("") && !getGroupOrdninalCurated(targetExpression).equals("")) {
returnedRuleExpression = replaceGroupOidOrdinalInExpression(ruleExpression, Integer.valueOf(getGroupOrdninalCurated(targetExpression)));
}
} else {
EventCRFBean theEventCrfBean = null;
if (eventCrf != null) {
theEventCrfBean = eventCrf;
} else if (!itemData.isEmpty()) {
theEventCrfBean = (EventCRFBean) getEventCRFDao().findByPK(itemData.get(0).getEventCRFId());
} else {
return returnedRuleExpression;
}
Integer itemId = itemData.isEmpty() ? ((EntityBean) getItemDao().findByOid(getItemOid(ruleExpression)).get(0)).getId() : itemData.get(0).getItemId();
ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) getItemGroupMetadataDao().findByItemAndCrfVersion(itemId, theEventCrfBean.getCRFVersionId());
if (isGroupRepeating(itemGroupMetadataBean) && getGroupOrdninalCurated(ruleExpression).equals("")) {
returnedRuleExpression = replaceGroupOidOrdinalInExpression(ruleExpression, Integer.valueOf(getGroupOrdninalCurated(targetExpression)));
}
}
return returnedRuleExpression;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class ExpressionService method constructFullExpressionIfPartialProvided.
public String constructFullExpressionIfPartialProvided(String expression, CRFVersionBean crfVersion, StudyEventDefinitionBean studyEventDefinition) {
String[] splitExpression = expression.split(ESCAPED_SEPERATOR);
String resultingExpression = null;
if (splitExpression.length == 1) {
ItemGroupMetadataBean itemGroupMetadata = (ItemGroupMetadataBean) getItemGroupMetadataDao().findByItemAndCrfVersion(getItemBeanFromExpression(expression).getId(), crfVersion.getId());
ItemGroupBean itemGroup = (ItemGroupBean) getItemGroupDao().findByPK(itemGroupMetadata.getItemGroupId());
resultingExpression = studyEventDefinition.getOid() + SEPERATOR + crfVersion.getOid() + SEPERATOR + itemGroup.getOid() + SEPERATOR + expression;
}
if (splitExpression.length == 2) {
resultingExpression = studyEventDefinition.getOid() + SEPERATOR + crfVersion.getOid() + SEPERATOR + expression;
}
if (splitExpression.length == 3) {
resultingExpression = studyEventDefinition.getOid() + SEPERATOR + expression;
}
return resultingExpression;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class BeanFactory method initFormGroupFromMap.
/**
* This method places a group metadata bean into an ItemGroupBean
*
* @param groupLabel
* The String specifying a group label.
* @param groupMap
* The Map containing the data for a group.
* @return ItemGroupBean
*/
private ItemGroupBean initFormGroupFromMap(String groupLabel, Map<Integer, Map<String, String>> groupMap) {
ItemGroupBean formGroupBean = new ItemGroupBean();
ItemGroupMetadataBean igMetaBean = new ItemGroupMetadataBean();
Map<String, String> groupValues;
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
String tempValue;
for (Entry<Integer, Map<String, String>> entry : groupMap.entrySet()) {
groupValues = entry.getValue();
if (groupValues.get("group_label").equalsIgnoreCase(groupLabel)) {
formGroupBean.setName(groupLabel);
igMetaBean.setHeader(groupValues.get("group_header"));
//Hamid repeating group or not
if (groupValues.get("repeating_group") != null) {
igMetaBean.setRepeatingGroup(Boolean.parseBoolean(groupValues.get("repeating_group")));
// System.out.println("=============" + groupValues.get("repeating_group"));
}
// YW 10-04-2007 <<
// BWP changed to try/catch block
tempValue = groupValues.get("group_repeat_max");
// exception, but is still unacceptable
if (StringUtil.isBlank(tempValue)) {
tempValue = "0";
} else if ("0.0".equalsIgnoreCase(tempValue)) {
tempValue = "22000";
}
try {
igMetaBean.setRepeatMax(new Integer(numFormatter.format(Double.parseDouble(tempValue))));
} catch (NumberFormatException nfe) {
// BWP >>an arbitrarily large number allows infinite
// repeats; it could also be -1
igMetaBean.setRepeatMax(22000);
}
// YW >>
// YW 10-04-2007 <<
// BWP changed to try/catch block
tempValue = groupValues.get("group_repeat_number");
// exception, but is still unacceptable
if (igMetaBean.isRepeatingGroup() && StringUtil.isBlank(tempValue)) {
tempValue = "1";
} else if (StringUtil.isBlank(tempValue)) {
tempValue = "0";
} else if ("0.0".equalsIgnoreCase(tempValue)) {
tempValue = "1";
}
try {
igMetaBean.setRepeatNum(new Integer(numFormatter.format(Double.parseDouble(tempValue))));
} catch (NumberFormatException nfe) {
// BWP 10-13-07
igMetaBean.setRepeatNum(1);
}
// YW >>
}
}
formGroupBean.setMeta(igMetaBean);
return formGroupBean;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean 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;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionWithItemGroups.
/**
* Create a DisplaySectionBean with a list of ItemGroupBeans. NOTE:
* unGrouped Items are not included
*
* @param study
* The StudyBean
* @param sectionId
* The Section ID associated with the Items, which end up
* providing the content of the tables.
* @param crfVersionId
* The CRF version ID associated with the Items.
* @param studyEventId
* The Study Event ID associated with the CRF Version ID.
* @param sm
* A SessionManager, from which DataSources are acquired for the
* DAO objects.
* @return A DisplaySectionBean.
*/
public DisplaySectionBean createDisplaySectionWithItemGroups(StudyBean study, int sectionId, EventCRFBean eventCrfBean, int studyEventId, SessionManager sm, int eventDefinitionCRFId, ServletContext context) {
DisplaySectionBean dBean = new DisplaySectionBean();
ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
ItemDAO itemDao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(sm.getDataSource());
List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
// all items associated with the section, including those not in a group
List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
try {
allMetas = metaDao.findAllBySectionId(sectionId);
} catch (OpenClinicaException oce) {
logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
}
// Collections.sort(allMetas);
if (arrList.isEmpty())
return dBean;
// Find out whether there are any checkboxes/radios/select elements
// and if so, get any null values
// associated with them
List<String> nullValuesList = new ArrayList<String>();
boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
// "+eventDefinitionCRFId);
if (eventDefinitionCRFId <= 0) {
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, studyEventId, eventCrfBean.getCRFVersionId());
eventDefinitionCRFId = edcBean.getId();
}
// "+eventDefinitionCRFId);
if (itemsHaveChecksRadios && eventDefinitionCRFId > 0) {
// method returns null values as a List<String>
nullValuesList = this.getNullValuesByEventCRFDefId(eventDefinitionCRFId, sm.getDataSource());
}
// Get the items associated with each group
List<ItemBean> itBeans;
List<DisplayItemBean> displayItems;
List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
DisplayItemGroupBean displayItemGBean;
for (ItemGroupBean itemGroup : arrList) {
itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
if (!metadata.isEmpty()) {
// for a given crf version, all the items in the same group
// have the same group metadata
// so we can get one of them and set metadata for the group
ItemGroupMetadataBean meta = metadata.get(0);
itemGroup.setMeta(meta);
}
// include arrayList parameter until I determine difference in
// classes
displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionId, nullValuesList, context);
displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
displayFormBeans.add(displayItemGBean);
}
// We still have to sort these display item group beans on their
// ItemGroupMetadataBean?
// then number their ordinals accordingly
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
}
});
// Now provide the display item group beans with an ordinal
int digOrdinal = 0;
for (DisplayItemGroupBean digBean : displayFormBeans) {
digBean.setOrdinal(++digOrdinal);
}
dBean.setDisplayFormGroups(displayFormBeans);
return dBean;
}
Aggregations