use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method showNew.
public void showNew(Integer itemDataId, List<PropertyBean> properties, UserAccountBean ub, RuleSetBean ruleSet) {
ItemDataBean itemDataBeanA = (ItemDataBean) getItemDataDAO().findByPK(itemDataId);
EventCRFBean eventCrfBeanA = (EventCRFBean) getEventCRFDAO().findByPK(itemDataBeanA.getEventCRFId());
ItemGroupMetadataBean itemGroupMetadataBeanA = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemDataBeanA.getItemId(), eventCrfBeanA.getCRFVersionId());
Boolean isGroupARepeating = isGroupRepeating(itemGroupMetadataBeanA);
String itemGroupAOrdinal = getExpressionService().getGroupOrdninalCurated(ruleSet.getTarget().getValue());
for (PropertyBean propertyBean : properties) {
String oid = propertyBean.getOid();
ItemOrItemGroupHolder itemOrItemGroup = getItemOrItemGroup(oid);
// OID is an item
if (itemOrItemGroup.getItemBean() != null) {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), ruleSet.getTarget().getValue());
ItemBean itemBeanB = getExpressionService().getItemBeanFromExpression(expression);
ItemGroupBean itemGroupBeanB = getExpressionService().getItemGroupExpression(expression);
EventCRFBean eventCrfBeanB = eventCrfBeanA;
ItemGroupMetadataBean itemGroupMetadataBeanB = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemBeanB.getId(), eventCrfBeanB.getCRFVersionId());
Boolean isGroupBRepeating = isGroupRepeating(itemGroupMetadataBeanB);
String itemGroupBOrdinal = getExpressionService().getGroupOrdninalCurated(expression);
List<ItemDataBean> itemDataBeans = new ArrayList<ItemDataBean>();
// If A and B are both non repeating groups
if (!isGroupARepeating && !isGroupBRepeating) {
ItemDataBean oidBasedItemData = oneToOne(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, 1);
itemDataBeans.add(oidBasedItemData);
}
// If A is not repeating group & B is a repeating group with no index selected
if (!isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
List<ItemDataBean> oidBasedItemDatas = oneToMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub);
itemDataBeans.addAll(oidBasedItemDatas);
}
// If A is not repeating group & B is a repeating group with index selected
if (!isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
itemDataBeans.add(oidBasedItemData);
}
// If A is repeating group with index & B is a repeating group with index selected
if (isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
itemDataBeans.add(oidBasedItemData);
}
// If A is repeating group with index & B is a repeating group with no index selected
if (isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupAOrdinal));
itemDataBeans.add(oidBasedItemData);
}
logger.debug("** found item data beans: " + itemDataBeans.toString());
for (ItemDataBean oidBasedItemData : itemDataBeans) {
ItemFormMetadataBean itemFormMetadataBean = getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemBeanB.getId(), eventCrfBeanB.getCRFVersionId());
DynamicsItemFormMetadataBean dynamicsMetadataBean = getDynamicsItemFormMetadataBean(itemFormMetadataBean, eventCrfBeanA, oidBasedItemData);
if (dynamicsMetadataBean == null) {
showItem(itemFormMetadataBean, eventCrfBeanA, oidBasedItemData);
// itemsAlreadyShown.add(new Integer(oidBasedItemData.getId()));
} else if (dynamicsMetadataBean != null && !dynamicsMetadataBean.isShowItem()) {
dynamicsMetadataBean.setShowItem(true);
getDynamicsItemFormMetadataDao().saveOrUpdate(dynamicsMetadataBean);
// itemsAlreadyShown.add(new Integer(oidBasedItemData.getId()));
} else if (eventCrfBeanA.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
logger.debug("hit DDE here: idb " + oidBasedItemData.getId());
// need a guard clause to guarantee DDE
// if we get there, it means that we've hit DDE and the bean exists
//setVersion(1);// version 1 = passed DDE
dynamicsMetadataBean.setPassedDde(1);
getDynamicsItemFormMetadataDao().saveOrUpdate(dynamicsMetadataBean);
}
}
} else // OID is a group
{
logger.debug("found item group id 1 " + oid);
ItemGroupBean itemGroupBean = itemOrItemGroup.getItemGroupBean();
ArrayList sectionBeans = getSectionDAO().findAllByCRFVersionId(eventCrfBeanA.getCRFVersionId());
for (int i = 0; i < sectionBeans.size(); i++) {
SectionBean sectionBean = (SectionBean) sectionBeans.get(i);
// System.out.println("found section " + sectionBean.getId());
List<ItemGroupMetadataBean> itemGroupMetadataBeans = getItemGroupMetadataDAO().findMetaByGroupAndSection(itemGroupBean.getId(), eventCrfBeanA.getCRFVersionId(), sectionBean.getId());
for (ItemGroupMetadataBean itemGroupMetadataBean : itemGroupMetadataBeans) {
if (itemGroupMetadataBean.getItemGroupId() == itemGroupBean.getId()) {
// System.out.println("found item group id 2 " + oid);
DynamicsItemGroupMetadataBean dynamicsGroupBean = getDynamicsItemGroupMetadataBean(itemGroupMetadataBean, eventCrfBeanA);
if (dynamicsGroupBean == null) {
showGroup(itemGroupMetadataBean, eventCrfBeanA);
} else if (dynamicsGroupBean != null && !dynamicsGroupBean.isShowGroup()) {
dynamicsGroupBean.setShowGroup(true);
getDynamicsItemGroupMetadataDao().saveOrUpdate(dynamicsGroupBean);
} else if (eventCrfBeanA.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
//setVersion(1); // version 1 = passed DDE
dynamicsGroupBean.setPassedDde(1);
getDynamicsItemGroupMetadataDao().saveOrUpdate(dynamicsGroupBean);
}
}
}
}
}
}
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method getItemOrItemGroup.
private ItemOrItemGroupHolder getItemOrItemGroup(String oid) {
String[] theOid = oid.split(ESCAPED_SEPERATOR);
if (theOid.length == 2) {
ItemGroupBean itemGroup = getItemGroupDAO().findByOid(theOid[0].trim());
if (itemGroup != null) {
ItemBean item = getItemDAO().findItemByGroupIdandItemOid(itemGroup.getId(), theOid[1].trim());
if (item != null) {
// System.out.println("returning two non nulls");
return new ItemOrItemGroupHolder(item, itemGroup);
}
}
}
if (theOid.length == 1) {
ItemGroupBean itemGroup = getItemGroupDAO().findByOid(oid.trim());
if (itemGroup != null) {
// System.out.println("returning item group not null");
return new ItemOrItemGroupHolder(null, itemGroup);
}
List<ItemBean> items = getItemDAO().findByOid(oid.trim());
ItemBean item = items.size() > 0 ? items.get(0) : null;
if (item != null) {
// System.out.println("returning item not null");
return new ItemOrItemGroupHolder(item, null);
}
}
return new ItemOrItemGroupHolder(null, null);
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class BeanFactory method createGroupBeans.
/**
* This method creates a List of DisplayItemGroupBeans. The
* DisplayItemGroupBeans are listed in the order their items are defined in
* the CRF spreadsheet. These beans include the items that are and are not
* associated with a group. If an item is defined in a spreadsheet but does
* not have a group label, that item is included in a DisplayItemGroupBean,
* but not linked to any groups (i.e., that DisplayItemGroupBean has an
* empty FormGroupBean object, with an empty String for a group label). For
* example, if the spreadsheet defines two items first, but does not assign
* them a group, then those items will make up the first
* DisplayItemGroupBean. The spreadsheet then might define a <em>group</em>
* of items followed by more items that are not part of a group. The former
* items will represent the second DisplayItemGroupBean. The third
* DisplayItemGroupBean will include the last collection of "orphaned"
* items, accompanied by an empty FormGroupBean object.
*
* @param itemsMap
* A Map containing rows of Item information from the
* spreadsheet. The items are in the order they were defined in
* the spreadsheet.
* @param sectionLabel
* A String specifying the name of the section we are displaying.
* @param groupsMap
* A Map containing rows of Group information from the
* spreadsheet.
* @param crfName
* The name of the CRF, a String.
* @see org.akaza.openclinica.bean.submit.ItemGroupBean
* @return A List of DisplayItemGroupBeans
*/
public List<DisplayItemGroupBean> createGroupBeans(Map<Integer, Map<String, String>> itemsMap, Map<Integer, Map<String, String>> groupsMap, String sectionLabel, String crfName) {
List<DisplayItemGroupBean> groupBeans = new ArrayList<DisplayItemGroupBean>();
// properly build group beans
if (groupsMap == null || groupsMap.isEmpty() || sectionLabel == null || sectionLabel.length() < 1 || sectionLabel.equalsIgnoreCase(UNGROUPED) || itemsMap == null || itemsMap.isEmpty()) {
return groupBeans;
}
// First, separate the items into those only associated with this
// section
Map<String, String> innermap;
List<DisplayItemBean> displayItems;
Map.Entry<Integer, Map<String, String>> me;
// This Map will hold the DisplayitemBeans that are associated with this
// section
Map<Integer, Map<String, String>> newMap = new HashMap<Integer, Map<String, String>>();
String lab;
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = itemsMap.entrySet().iterator(); iter.hasNext(); ) {
me = iter.next();
innermap = me.getValue();
lab = innermap.get("section_label");
if (lab != null && lab.equalsIgnoreCase(sectionLabel)) {
newMap.put(me.getKey(), innermap);
}
}
displayItems = this.createDisplayItemBeansFromMap(newMap, crfName);
// Now, separate the DisplayItemBeans into those associated with groups,
// and any others that do not have groups
ItemGroupBean fgBean;
DisplayItemGroupBean disFgBean;
String latestGroupLabel;
boolean validGroupFlag = false;
int ordinal = 0;
// the List.
for (DisplayItemBean disBean : displayItems) {
latestGroupLabel = disBean.getMetadata().getGroupLabel();
// to a group. Store it in a FormGroupBean.
if (latestGroupLabel != null && latestGroupLabel.length() > 0 && !latestGroupLabel.equalsIgnoreCase(UNGROUPED)) {
// set this flag to true, indicating that the items being
// processed now
// are associated with a valid group
validGroupFlag = true;
// If lastGroupLabel is not yet stored in the List of
// DisplayGroupBeans
// then the beans associated with that label (DisplayGroupBeans
// and
// FormGroupBeans) have to be initialized.
// Otherwise, just store the new displayitembean in the existing
// FormGroupBean/DisplayFormGroupBean
disFgBean = getGroupFromLabel(latestGroupLabel, groupBeans);
// then a new one has to be initialized for this DisplayItemBean
if (!(disFgBean.getItemGroupBean().getName().length() > 0)) {
// Get FormGroupBean from group label
fgBean = initFormGroupFromMap(latestGroupLabel, groupsMap);
ordinal++;
fgBean.getMeta().setOrdinal(ordinal);
disFgBean.setItemGroupBean(fgBean);
disFgBean.setGroupMetaBean(fgBean.getMeta());
groupBeans.add(disFgBean);
}
} else {
// if there is no group label associated with the
// DisplayItemBean, then it
// does not have a group; it is an "orphaned" item. In this
// case, create a
// DisplayFormGroup with a group label signified with an empty
// string. This
// "group" will hold the orphaned items. What if there are
// orphaned items
// in the spreadsheet that are divided by grouped items? Then
// these orphaned
// items have to be in separate DisplayFormGroups. To handle
// this case, the
// code checks the validGroupFlag boolean variable. if "true,"
// indicating that
// non-orphaned beans have just been processed, then create a
// new
// DisplayFormGroup for these orphaned items.
boolean isFirst = isFirstUngroupedItem(groupBeans);
if (validGroupFlag || isFirst) {
disFgBean = new DisplayItemGroupBean();
fgBean = new ItemGroupBean();
ordinal++;
fgBean.getMeta().setOrdinal(ordinal);
fgBean.setName(UNGROUPED);
disFgBean.setItemGroupBean(fgBean);
disFgBean.setGroupMetaBean(fgBean.getMeta());
groupBeans.add(disFgBean);
} else {
// The existing DisplayFormGroupBean for orphaned items
// is the FormGroupBean containing the highest ordinal, and
// with a group label
// containing an empty string
disFgBean = getLatestDisFormBeanForOrphanedItems(groupBeans);
}
validGroupFlag = false;
}
disFgBean.getItems().add(disBean);
}
return groupBeans;
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class BeanFactory method createFormGroupBeanFromMap.
public ItemGroupBean createFormGroupBeanFromMap(Map<Integer, Map<String, String>> groupMap) {
ItemGroupBean fBean = new ItemGroupBean();
Map<String, String> beanMap;
Map.Entry<Integer, Map<String, String>> me;
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
String tempValue;
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = groupMap.entrySet().iterator(); iter.hasNext(); ) {
me = iter.next();
beanMap = me.getValue();
fBean.setName(beanMap.get("group_label"));
tempValue = beanMap.get("group_repeat_number");
// exception, but is still unacceptable
if ("0.0".equalsIgnoreCase(tempValue)) {
tempValue = "1";
}
try {
fBean.getMeta().setRepeatNum(new Integer(numFormatter.format(Double.parseDouble(tempValue))));
} catch (NumberFormatException nfe) {
// BWP 10-13-07
fBean.getMeta().setRepeatNum(1);
}
tempValue = beanMap.get("group_repeat_max");
// exception, but is still unacceptable
if ("0.0".equalsIgnoreCase(tempValue)) {
tempValue = "22000";
}
try {
fBean.getMeta().setRepeatMax(new Integer(numFormatter.format(Double.parseDouble(tempValue))));
} catch (NumberFormatException nfe) {
// BWP >>an arbitrarily large number allows infinite repeats; it
// could also be -1
fBean.getMeta().setRepeatMax(22000);
}
fBean.getMeta().setHeader(beanMap.get("group_header"));
}
return fBean;
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class CRFVersionMetadataUtil method retrieveFormMetadata.
/**
* Builds and returns an ArrayList of SectionBeans that comprise the metadata of a CRFVersion.
*/
public ArrayList<SectionBean> retrieveFormMetadata(FormLayoutBean formLayout) throws Exception {
ItemDAO idao = new ItemDAO(dataSource);
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(dataSource);
// tbh, 102007
SectionDAO sdao = new SectionDAO(dataSource);
ItemGroupDAO igdao = new ItemGroupDAO(dataSource);
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO(dataSource);
ArrayList sections = (ArrayList) sdao.findByLayoutId(formLayout.getId());
HashMap versionMap = new HashMap();
for (int i = 0; i < sections.size(); i++) {
SectionBean section = (SectionBean) sections.get(i);
versionMap.put(new Integer(section.getId()), section.getItems());
// YW 08-21-2007, add group metadata
ArrayList<ItemGroupBean> igs = (ArrayList<ItemGroupBean>) igdao.findGroupByLayoutId(formLayout.getId());
for (int j = 0; j < igs.size(); ++j) {
ArrayList<ItemGroupMetadataBean> igms = (ArrayList<ItemGroupMetadataBean>) igmdao.findMetaByGroupAndSection(igs.get(j).getId(), section.getCRFVersionId(), section.getId());
if (!igms.isEmpty()) {
// Note, the following logic has been adapted here -
// "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"
igs.get(j).setMeta(igms.get(0));
igs.get(j).setItemGroupMetaBeans(igms);
}
}
((SectionBean) sections.get(i)).setGroups(igs);
// YW >>
}
ArrayList items = idao.findAllItemsByLayoutId(formLayout.getId());
// then different query will be used
if (igmdao.versionIncluded(formLayout.getId())) {
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndFormLayoutId(item.getId(), formLayout.getId());
item.setItemMeta(ifm);
// logger.info("option******" +
// ifm.getResponseSet().getOptions().size());
ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
its.add(item);
}
} else {
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndFormLayoutIdNotInIGM(item.getId(), formLayout.getId());
item.setItemMeta(ifm);
// logger.info("option******" +
// ifm.getResponseSet().getOptions().size());
ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
its.add(item);
}
}
for (int i = 0; i < sections.size(); i++) {
SectionBean section = (SectionBean) sections.get(i);
section.setItems((ArrayList) versionMap.get(new Integer(section.getId())));
}
return sections;
}
Aggregations