use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean 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.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method isGroupShown.
public boolean isGroupShown(int metadataId, int eventCrfBeanId) throws OpenClinicaException {
ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByPK(metadataId);
DynamicsItemGroupMetadataBean dynamicsMetadataBean = getDynamicsItemGroupMetadataBean(itemGroupMetadataBean, eventCrfBeanId);
if (dynamicsMetadataBean != null) {
return dynamicsMetadataBean.isShowGroup();
} else {
// System.out.println("didnt find a group row in the db ");
return false;
}
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method hideGroup.
public boolean hideGroup(ItemGroupMetadataBean metadataBean, EventCRFBean eventCrfBean) {
ItemGroupMetadataBean itemGroupMetadataBean = metadataBean;
itemGroupMetadataBean.setShowGroup(false);
DynamicsItemGroupMetadataBean dynamicsMetadataBean = new DynamicsItemGroupMetadataBean(itemGroupMetadataBean, eventCrfBean);
dynamicsMetadataBean.setPassedDde(0);
getDynamicsItemGroupMetadataDao().saveOrUpdate(dynamicsMetadataBean);
return true;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean 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;
}
use of org.akaza.openclinica.bean.submit.ItemGroupMetadataBean in project OpenClinica by OpenClinica.
the class ResolveDiscrepancyServlet method prepareRequestForResolution.
public boolean prepareRequestForResolution(HttpServletRequest request, DataSource ds, StudyBean currentStudy, DiscrepancyNoteBean note, boolean isCompleted) throws Exception {
String entityType = note.getEntityType().toLowerCase();
int id = note.getEntityId();
if ("subject".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(id, currentStudy);
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
request.setAttribute("studySubId", String.valueOf(ssb.getId()));
} else if ("studysub".equalsIgnoreCase(entityType)) {
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
} else if ("eventcrf".equalsIgnoreCase(entityType)) {
request.setAttribute("editInterview", "1");
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(id);
request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
// If the request is passed along to ViewSectionDataEntryServlet,
// that code needs
// an event crf id; the (ecb.getId()+"") is necessary because
// FormProcessor throws
// a ClassCastException without the casting to a String
request.setAttribute(ViewSectionDataEntryServlet.EVENT_CRF_ID, ecb.getId() + "");
} else if ("studyevent".equalsIgnoreCase(entityType)) {
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(id);
request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.STUDY_SUBJECT_ID, String.valueOf(seb.getStudySubjectId()));
} else // this is for item data
if ("itemdata".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemDataBean idb = (ItemDataBean) iddao.findByPK(id);
ItemBean item = (ItemBean) idao.findByPK(idb.getItemId());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO<>(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
FormLayoutDAO fldao = new FormLayoutDAO(ds);
FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(ecb.getFormLayoutId());
StudyEventDAO sedao = new StudyEventDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(ds);
ItemFormMetadataBean ifmb = ifmdao.findByItemIdAndCRFVersionId(idb.getItemId(), ecb.getFormLayoutId());
ItemGroupMetadataBean igmBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(idb.getItemId(), ecb.getCRFVersionId());
ItemGroupDAO igdao = new ItemGroupDAO<>(ds);
ItemGroupBean igBean = (ItemGroupBean) igdao.findByPK(igmBean.getItemGroupId());
int repeatOrdinal = idb.getOrdinal();
ItemDataBean idata = null;
if (idb != null && idb.isDeleted()) {
return false;
}
if (igmBean.isRepeatingGroup() && repeatOrdinal > 1) {
List<ItemGroupMetadataBean> igms = igmdao.findMetaByGroupAndCrfVersion(igBean.getId(), ecb.getCRFVersionId());
for (int i = 0; i < idb.getOrdinal(); i++) {
for (ItemGroupMetadataBean igm : igms) {
idata = iddao.findByItemIdAndEventCRFIdAndOrdinal(igm.getItemId(), ecb.getId(), i + 1);
if (idata != null && idata.isDeleted()) {
repeatOrdinal--;
break;
}
}
}
}
EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// Cache the subject context for use during xform submission
PFormCache cache = PFormCache.getInstance(context);
PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
subjectContext.setStudySubjectOid(ssb.getOid());
subjectContext.setStudyEventDefinitionId(seb.getStudyEventDefinitionId());
subjectContext.setOrdinal(seb.getSampleOrdinal());
subjectContext.setFormLayoutOid(formLayout.getOid());
subjectContext.setUserAccountId(ub.getId());
subjectContext.setItemName(item.getName() + COMMENT);
subjectContext.setItemRepeatOrdinal(repeatOrdinal);
subjectContext.setItemInRepeatingGroup(igmBean.isRepeatingGroup());
subjectContext.setItemRepeatGroupName(igBean.getLayoutGroupPath());
String contextHash = cache.putSubjectContext(subjectContext);
String formUrl = null;
if (ecb.getId() > 0) {
formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, currentStudy.getOid(), null, null, QUERY_FLAVOR);
} else {
formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, currentStudy.getOid(), QUERY_FLAVOR);
}
int hashIndex = formUrl.lastIndexOf("#");
String part1 = formUrl;
String part2 = "";
if (hashIndex != -1) {
part1 = formUrl.substring(0, hashIndex);
part2 = formUrl.substring(hashIndex);
}
request.setAttribute(EnketoFormServlet.FORM_URL1, part1);
request.setAttribute(EnketoFormServlet.FORM_URL2, part2);
}
return true;
}
Aggregations