use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ExtractBean method getMetadata.
/**
* Implements the Column algorithm in "Dataset Export Algorithms" Must be
* called after DatasetDAO.getDatasetData();
*/
public void getMetadata() {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
// SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
studyGroupClasses = new ArrayList();
studyGroupMap = new HashMap();
studyGroupMaps = new HashMap<Integer, ArrayList>();
sedCrfColumns = new HashMap();
displayed = new HashMap();
sedCrfItemFormMetadataBeans = new HashMap();
studyEvents = seddao.findAllByStudy(study);
ArrayList finalStudyEvents = new ArrayList();
if (dataset.isShowSubjectGroupInformation()) {
// logger.info("found study id for maps: "+study.getId());
studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
// below is for a given subject; we need a data structure for
// all subjects
// studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
// problem: can't use currentSubject here, since it's not 'set up'
// properly
// how to get the current subject?
logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
// studyGroupClasses = dataset.getSubjectGroupIds();
for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
// logger.info();
// hmm how to link groups to subjects though? only through
// subject group map
logger.info("found a studygroupclass bean: " + sgclass.getName());
studyGroupClasses.add(sgclass);
}
}
for (int i = 0; i < studyEvents.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
if (!selectedSED(sed)) {
continue;
}
ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
ArrayList CRFsDisplayedInThisSED = new ArrayList();
for (int j = 0; j < CRFs.size(); j++) {
CRFBean cb = (CRFBean) CRFs.get(j);
if (!selectedSEDCRF(sed, cb)) {
continue;
} else {
CRFsDisplayedInThisSED.add(cb);
ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
for (int k = 0; k < CRFVersions.size(); k++) {
CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
// sort by ordinal/name
Collections.sort(Items);
for (int l = 0; l < Items.size(); l++) {
ItemBean ib = (ItemBean) Items.get(l);
if (selected(ib) && !getDisplayed(sed, cb, ib)) {
// logger.info("found at
// itemformmetadatadao: "+ib.getId()+",
// "+cvb.getId());
ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
addColumn(sed, cb, ib);
addItemFormMetadataBeans(sed, cb, ifmb);
markDisplayed(sed, cb, ib);
}
}
}
}
// else
}
// for
sed.setCrfs(CRFsDisplayedInThisSED);
// make the setCrfs call "stick"
finalStudyEvents.add(sed);
}
this.studyEvents = finalStudyEvents;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean 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.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method buildInstance.
// method
/**
* @param model
* @param crfVersion
* @param crfSections
* @return
* @throws Exception
*/
private String buildInstance(Model model, FormLayoutBean formLayout, CRFVersionBean crfVersion, ArrayList<SectionBean> crfSections) throws Exception {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder build = docFactory.newDocumentBuilder();
Document doc = build.newDocument();
Element crfElement = doc.createElement(formLayout.getOid());
crfElement.setAttribute("id", formLayout.getOid());
doc.appendChild(crfElement);
crfElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:jr", "http://openrosa.org/javarosa");
for (SectionBean section : crfSections) {
Element sectionSubTitle = doc.createElement("SECTION_" + section.getId() + ".SUBTITLE");
Element sectionInstructions = doc.createElement("SECTION_" + section.getId() + ".INSTRUCTIONS");
Element sectionElm = doc.createElement("SECTION_" + section.getLabel().replaceAll("\\W", "_"));
crfElement.appendChild(sectionSubTitle);
crfElement.appendChild(sectionInstructions);
crfElement.appendChild(sectionElm);
}
ArrayList<ItemGroupBean> itemGroupBeans = getItemGroupBeansByFormLayout(formLayout);
for (ItemGroupBean itemGroupBean : itemGroupBeans) {
ItemGroupMetadataBean itemGroupMetadataBean = getItemGroupMetadataByGroup(itemGroupBean, crfVersion);
String repeatGroupMin = itemGroupMetadataBean.getRepeatNum().toString();
Boolean isrepeating = itemGroupMetadataBean.isRepeatingGroup();
Element groupElement = doc.createElement(itemGroupBean.getOid());
if (isrepeating) {
groupElement.setTextContent(repeatGroupMin);
groupElement.setAttribute("jr:template", "");
Element hiddenOrdinalItem = doc.createElement("OC.REPEAT_ORDINAL");
groupElement.appendChild(hiddenOrdinalItem);
}
crfElement.appendChild(groupElement);
idao = new ItemDAO(dataSource);
ArrayList<ItemBean> items = (ArrayList<ItemBean>) idao.findAllItemsByGroupIdOrdered(itemGroupBean.getId(), crfVersion.getId());
for (ItemBean item : items) {
ItemFormMetadataBean itemMetaData = getItemFormMetadata(item, crfVersion);
if (itemMetaData.getHeader() != null && !itemMetaData.getHeader().equals("")) {
Element header = doc.createElement(item.getOid() + ".HEADER");
groupElement.appendChild(header);
}
if (itemMetaData.getHeader() != null && !itemMetaData.getSubHeader().equals("")) {
Element subHeader = doc.createElement(item.getOid() + ".SUBHEADER");
groupElement.appendChild(subHeader);
}
Element question = doc.createElement(item.getOid());
groupElement.appendChild(question);
}
// end of item
}
// end of group
// add meta
Element meta = doc.createElement("meta");
// add instanceId
Element instanceId = doc.createElement("instanceID");
meta.appendChild(instanceId);
crfElement.appendChild(meta);
TransformerFactory transformFactory = TransformerFactory.newInstance();
Transformer transformer = transformFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
return writer.toString();
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean 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.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method updateGroupDynItemsInASection.
private void updateGroupDynItemsInASection(DisplayItemWithGroupBean itemWithGroup, List<Integer> showItemIds, int groupId, int sectionId, int crfVersionId, int eventCrfId) {
List<DisplayItemGroupBean> digbs = itemWithGroup.getItemGroups();
List<Integer> showDataIds = this.dynamicsItemFormMetadataDao.findShowItemDataIdsForAGroupInSection(groupId, sectionId, crfVersionId, eventCrfId);
List<Integer> hideDataIds = this.dynamicsItemFormMetadataDao.findHideItemDataIdsForAGroupInSection(groupId, sectionId, crfVersionId, eventCrfId);
for (int n = 0; n < digbs.size(); ++n) {
DisplayItemGroupBean dg = digbs.get(n);
ArrayList<DisplayItemBean> items = (ArrayList<DisplayItemBean>) dg.getItems();
for (int m = 0; m < items.size(); ++m) {
DisplayItemBean dib = items.get(m);
ItemFormMetadataBean meta = dib.getMetadata();
dib.setBlankDwelt(false);
if (hideDataIds != null && hideDataIds.contains(dib.getData().getId())) {
meta.setShowItem(false);
}
if (showDataIds != null && showDataIds.contains(dib.getData().getId())) {
meta.setShowItem(true);
}
if (!meta.isShowItem() && showItemIds != null && showItemIds.contains(dib.getItem().getId())) {
dib.setBlankDwelt(true);
}
}
}
}
Aggregations