use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ViewSelectedServlet method getAllSelected.
public static ArrayList getAllSelected(DatasetBean db, ItemDAO idao, ItemFormMetadataDAO imfdao) throws Exception {
ArrayList items = new ArrayList();
// ArrayList itemIds = db.getItemIds();
ArrayList itemDefCrfs = db.getItemDefCrf();
for (int i = 0; i < itemDefCrfs.size(); i++) {
ItemBean item = (ItemBean) itemDefCrfs.get(i);
item.setSelected(true);
ArrayList metas = imfdao.findAllByItemId(item.getId());
for (int h = 0; h < metas.size(); h++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(h);
// logger.info("group name found:
// "+ifmb.getGroupLabel());
}
item.setItemMetas(metas);
items.add(item);
}
return items;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class BeanFactory method createDisplaySectionBean.
// Create a DisplaySectionBean using an items map, a section's title,
// the section's page number, and the CRF name/ The CRF name is needed for
// creating the ResponseSetBean.
public DisplaySectionBean createDisplaySectionBean(Map<Integer, Map<String, String>> map, String sectionTitle, String sectionLabel, String sectionSubtitle, String instructions, String crfName, int sectionBorders) {
// Play defense!
if (map == null)
return new DisplaySectionBean();
// Display a section title in the JSP
SectionBean sbean = new SectionBean();
sbean.setTitle(sectionTitle);
sbean.setSubtitle(sectionSubtitle);
sbean.setInstructions(instructions);
sbean.setBorders(sectionBorders);
DisplaySectionBean displaySectionBean = new DisplaySectionBean();
displaySectionBean.setSection(sbean);
ArrayList<DisplayItemBean> allDisplayItems = new ArrayList<DisplayItemBean>();
List<DisplayItemBean> childrenItems = new ArrayList<DisplayItemBean>();
DisplayItemBean displayItem;
ItemFormMetadataBean itemMeta;
Map.Entry<Integer, Map<String, String>> me;
Map<String, String> innerMap;
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = map.entrySet().iterator(); iter.hasNext(); ) {
displayItem = new DisplayItemBean();
// me is one row in the list of Items, indexed by the item number
me = iter.next();
if (itemSecLabelMatchesSection(me, sectionLabel)) {
itemMeta = this.createItemFormMetadataBean(me, crfName);
displayItem.setMetadata(itemMeta);
innerMap = me.getValue();
displayItem.setItem(this.createItemBean(innerMap));
// Compensate for any items that identify themselves as parents
String parentName = displayItem.getMetadata().getParentLabel();
if (parentName.length() > 0 && !displayItem.getItem().getName().equalsIgnoreCase(parentName)) {
displayItem.getMetadata().setParentId(1);
childrenItems.add(displayItem);
} else {
allDisplayItems.add(displayItem);
}
}
}
// Set the children for each of the display items
for (DisplayItemBean parentBean : allDisplayItems) {
parentBean.setChildren(this.createChildren(childrenItems, parentBean));
}
// Sort the List of DisplayItemBeans based on their ordinal; see
// getDisplayBean() in DataEntryServlet
Collections.sort(allDisplayItems);
displaySectionBean.setItems(allDisplayItems);
return displaySectionBean;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class BeanFactory method createMetadataBean.
/**
* Create an ItemFormMetadataBean from the values referred to by a Map
* object. The Map contains the Item values from the Sreadsheet template, as
* in (item_name: Item1, etc...}
*
* @param map
* A Map involving the column names and values Of items.
* @param ordinal
* The ordinal property for the meta data bean.
* @param crfName
* The CRF name.
* @return An ItemFormMetadataBean representing the values from the Map.
*/
public ItemFormMetadataBean createMetadataBean(Map<String, String> map, int ordinal, String crfName) {
if (map == null)
return new ItemFormMetadataBean();
ItemFormMetadataBean metadataBean = new ItemFormMetadataBean();
// the POI library returns all numbers as doubles (2.0), we round
// off the numbers to 2, for instance
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
String itemPageNum;
String columnNum;
String questNum;
metadataBean.setOrdinal(ordinal);
metadataBean.setResponseLayout(map.get("response_layout"));
metadataBean.setParentLabel(map.get("parent_item"));
metadataBean.setLeftItemText(map.get("left_item_text"));
metadataBean.setRightItemText(map.get("right_item_text"));
metadataBean.setDefaultValue(map.get("default_value"));
metadataBean.setHeader(map.get("header"));
metadataBean.setSubHeader(map.get("subheader"));
itemPageNum = map.get("page_number");
try {
itemPageNum = numFormatter.format(Double.parseDouble(itemPageNum));
} catch (NumberFormatException nfe) {
itemPageNum = "";
}
metadataBean.setPageNumberLabel(itemPageNum);
columnNum = map.get("column_number");
try {
columnNum = numFormatter.format(Double.parseDouble(columnNum));
metadataBean.setColumnNumber(Integer.parseInt(columnNum));
} catch (NumberFormatException nfe) {
metadataBean.setColumnNumber(0);
}
questNum = map.get("question_number");
try {
questNum = numFormatter.format(Double.parseDouble(questNum));
} catch (NumberFormatException nfe) {
questNum = "";
}
metadataBean.setQuestionNumberLabel(questNum);
String requStr = map.get("required");
requStr = requStr.equalsIgnoreCase("") ? "0" : requStr;
double required;
try {
required = Double.parseDouble(requStr);
} catch (NumberFormatException nfe) {
required = 0;
}
if (required > 0) {
metadataBean.setRequired(true);
}
ResponseSetBean respBean = this.createResponseSetBean(map, crfName);
metadataBean.setResponseSet(respBean);
return metadataBean;
}
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 DataEntryServlet method getParentDisplayItems.
/**
* For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId
* == 0.
* @param sb
* The section whose items we are retrieving.
* @param hasUngroupedItems
* @param request TODO
*
* @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
* @throws Exception
*/
private ArrayList getParentDisplayItems(boolean hasGroup, SectionBean sb, EventDefinitionCRFBean edcb, ItemDAO idao, ItemFormMetadataDAO ifmdao, ItemDataDAO iddao, boolean hasUngroupedItems, HttpServletRequest request) throws Exception {
ArrayList answer = new ArrayList();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
HashMap displayItems = new HashMap();
// ArrayList items = idao.findAllParentsBySectionId(sb.getId());
ArrayList items = new ArrayList();
ArrayList itemsUngrped = new ArrayList();
if (hasGroup) {
// See: FormBeanUtil.sectionHasUngroupedItems.
if (hasUngroupedItems) {
// @pgawade 05-Aug-2011 fix for issue 10628 - commented out the
// if-else logic based on 'hasGroup' flag.
// 'if' part is unchanged but else part is changed to be
// executed always because that is to get the non-repeating and
// ungrouped item details and was getting skipped in case the
// section has repeating group items plus non-repeating group
// items
itemsUngrped = idao.findAllUngroupedParentsBySectionId(sb.getId(), sb.getCRFVersionId());
}
// however, if we have true:true, we exclude all grouped items
// items.addAll(
// idao.findAllGroupedParentsBySectionId(
// sb.getId(), sb.getCRFVersionId()));
}
// else {
LOGGER.trace("no item groups");
// items = idao.findAllParentsBySectionId(sb.getId());
items = idao.findAllNonRepeatingParentsBySectionId(sb.getId());
items.addAll(itemsUngrped);
// }
LOGGER.debug("items size" + items.size());
for (int i = 0; i < items.size(); i++) {
DisplayItemBean dib = new DisplayItemBean();
dib.setEventDefinitionCRF(edcb);
ItemBean ib = (ItemBean) items.get(i);
dib.setItem(ib);
displayItems.put(new Integer(dib.getItem().getId()), dib);
}
ArrayList data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(idb.getItemId()));
if (dib != null) {
dib.setData(idb);
dib.setDbData((ItemDataBean) BeanUtils.cloneBean(idb));
displayItems.put(new Integer(idb.getItemId()), dib);
}
}
ArrayList metadata = ifmdao.findAllBySectionId(sb.getId());
for (int i = 0; i < metadata.size(); i++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metadata.get(i);
DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(ifmb.getItemId()));
if (dib != null) {
// boolean showItem = false;
boolean needsHighlighting = !ifmb.isShowItem();
logMe("Entering thread before getting ItemMetadataService:::" + Thread.currentThread());
boolean showItem = getItemMetadataService().isShown(ifmb.getItemId(), ecb, dib.getData());
if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
showItem = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
}
// is the above needed for children items too?
boolean passedDDE = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
if (showItem) {
// we are only showing, not hiding
LOGGER.debug("set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE);
// ifmb.setShowItem(showItem);
ifmb.setShowItem(true);
} else {
LOGGER.debug("DID NOT set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE + " value " + dib.getData().getValue());
}
dib.setMetadata(ifmb);
displayItems.put(new Integer(ifmb.getItemId()), dib);
}
}
Iterator hmIt = displayItems.keySet().iterator();
while (hmIt.hasNext()) {
Integer key = (Integer) hmIt.next();
DisplayItemBean dib = (DisplayItemBean) displayItems.get(key);
answer.add(dib);
LOGGER.debug("*** getting with key: " + key + " display item bean with value: " + dib.getData().getValue());
}
LOGGER.debug("*** test of the display items: " + displayItems.toString());
return answer;
}
Aggregations