use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class BeanFactory method createItemBeanList.
// This has to return an ArrayList (not a List, as it should, if you program
// to interfaces), because the SectionBean.setitems method takes an
// ArrayList
public ArrayList createItemBeanList(Map<Integer, Map<String, String>> itemsMap, String secLabel, String crfName) {
if (itemsMap == null)
return new ArrayList();
ArrayList<ItemBean> itemList = new ArrayList<ItemBean>();
ItemBean itemBean;
ItemFormMetadataBean metaBean;
Map<String, String> innerMap;
Map.Entry<Integer, Map<String, String>> me;
// SpreadsheetPreview returns doubles as Strings (such as "1.0")
// for "1" in a spreadsheet cell, so make sure only "1" is displayed
// using
// this NumberFormat object
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = itemsMap.entrySet().iterator(); iter.hasNext(); ) {
me = iter.next();
// iterate the internal Map, with all the item headers and values
innerMap = me.getValue();
// String itemPagNumber = innerMap.get("page_number");
String itemSectionLabel = innerMap.get("section_label");
if (itemSectionLabel.equalsIgnoreCase(secLabel)) {
itemBean = this.createItemBean(innerMap);
metaBean = createItemFormMetadataBean(me, crfName);
itemBean.setItemMeta(metaBean);
itemList.add(itemBean);
}
}
return itemList;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class BeanFactory method createDisplayItemBeansFromMap.
public List<DisplayItemBean> createDisplayItemBeansFromMap(Map<Integer, Map<String, String>> itemsMap, String crfName) {
List<DisplayItemBean> allDisplayItems = 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 = itemsMap.entrySet().iterator(); iter.hasNext(); ) {
displayItem = new DisplayItemBean();
// me is one row in the list of Items, indexed by the item number
me = iter.next();
itemMeta = this.createItemFormMetadataBean(me, crfName);
innerMap = me.getValue();
String labeltmp = innerMap.get("group_label");
if (labeltmp.length() < 1) {
itemMeta.setGroupLabel(UNGROUPED);
} else {
itemMeta.setGroupLabel(labeltmp);
}
displayItem.setMetadata(itemMeta);
displayItem.setItem(this.createItemBean(innerMap));
allDisplayItems.add(displayItem);
}
// Sort the List of DisplayItemBeans based on their ordinal; see
// getDisplayBean() in DataEntryServlet
Collections.sort(allDisplayItems);
return allDisplayItems;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryPreview method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// These numbers will be zero if the
// params are not present in the URL
int crfid = fp.getInt("crfId");
int tabNum = fp.getInt("tabId");
HttpSession session = request.getSession();
request.setAttribute("crfId", crfid);
String crfName = "";
String verNumber = "";
// All the data on the uploaded Excel file
// see org.akaza.openclinica.control.admin.SpreadsheetPreview
// createCrfMetaObject() method
Map<String, Map> crfMap = (Map) session.getAttribute("preview_crf");
if (crfMap == null) {
// addPageMessage
String msg = respage.getString("preview_data_has_timed_out");
this.addPageMessage(msg, request);
LOGGER.debug("The session attribute \"preview_crf\" has expired or gone out of scope in: " + this.getClass().getName());
this.forwardPage(Page.CRF_LIST_SERVLET, request, response);
}
Map<String, String> crfIdnameInfo = null;
if (crfMap != null) {
crfIdnameInfo = crfMap.get("crf_info");
}
// Get the CRF name and version String
if (crfIdnameInfo != null) {
Map.Entry mapEnt = null;
for (Object element : crfIdnameInfo.entrySet()) {
mapEnt = (Map.Entry) element;
if (((String) mapEnt.getKey()).equalsIgnoreCase("crf_name")) {
crfName = (String) mapEnt.getValue();
}
if (((String) mapEnt.getKey()).equalsIgnoreCase("version")) {
verNumber = (String) mapEnt.getValue();
}
}
}
// Set up the beans that DisplaySectionBean and the preview
// depend on
EventCRFBean ebean = new EventCRFBean();
CRFVersionBean crfverBean = new CRFVersionBean();
crfverBean.setName(verNumber);
CRFBean crfbean = new CRFBean();
crfbean.setId(crfid);
crfbean.setName(crfName);
ebean.setCrf(crfbean);
// This happens in ViewSectionDataEntry
// It's an assumption that it has to happen here as well
ecb = ebean;
// All the groups data, if it's present in the CRF
Map<Integer, Map<String, String>> groupsMap = null;
if (crfMap != null)
groupsMap = crfMap.get("groups");
// Find out whether this CRF involves groups
// At least one group is involved if the groups Map is not null or
// empty, and the first group entry (there may be only one) has a
// valid group label
boolean hasGroups = false;
/*
* if(groupsMap != null && (! groupsMap.isEmpty()) &&
* groupsMap.get(1).get("group_label").length() > 0) hasGroups = true;
*/
// A SortedMap containing the row number as the key, and the
// section headers/values (contained in a Map) as the value
Map<Integer, Map<String, String>> sectionsMap = null;
if (crfMap != null)
sectionsMap = crfMap.get("sections");
// The itemsMap contains the spreadsheet table items row number as a
// key,
// followed by a map of the column names/values; it contains values for
// display
// such as 'left item text'
Map<Integer, Map<String, String>> itemsMap = null;
if (crfMap != null)
itemsMap = crfMap.get("items");
// Create a list of FormGroupBeans from Maps of groups,
// items, and sections
BeanFactory beanFactory = new BeanFactory();
// FormBeanUtil formUtil = new FormBeanUtil();
// Set up sections for the preview
Map.Entry me = null;
SectionBean secbean = null;
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
String name_str = "";
String pageNum = "";
Map secMap = null;
// SpreadsheetPreviewNw returns doubles (via the
// HSSFCell API, which parses Excel files)
// as Strings (such as "1.0") for "1" in a spreadsheet cell,
// so make sure only "1" is displayed using
// this NumberFormat object
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
if (sectionsMap != null) {
for (Object element : sectionsMap.entrySet()) {
secbean = new SectionBean();
me = (Map.Entry) element;
secMap = (Map) me.getValue();
name_str = (String) secMap.get("section_label");
secbean.setName(name_str);
secbean.setTitle((String) secMap.get("section_title"));
secbean.setInstructions((String) secMap.get("instructions"));
secbean.setSubtitle((String) secMap.get("subtitle"));
pageNum = (String) secMap.get("page_number");
// type a number in that Spreadsheet cell
try {
pageNum = numFormatter.format(Double.parseDouble(pageNum));
} catch (NumberFormatException nfe) {
pageNum = "";
}
secbean.setPageNumberLabel(pageNum);
// Sift through the items to see if their section label matches
// the section's section_label column
secbean.setNumItems(this.getNumberOfItems(itemsMap, secbean.getName()));
allSectionBeans.add(secbean);
}
}
DisplayTableOfContentsBean dtocBean = new DisplayTableOfContentsBean();
// Methods should just take Lists, the interface, not
// ArrayList only!
dtocBean.setSections(allSectionBeans);
request.setAttribute("toc", dtocBean);
request.setAttribute("sectionNum", allSectionBeans.size() + "");
// Assuming that the super class' SectionBean sb variable must be
// initialized,
// since it happens in ViewSectionDataEntryServlet. TODO: verify this
sb = allSectionBeans.get(0);
// This is the StudySubjectBean
// Not sure if this is needed for a Preview, but leaving
// it in for safety/consisitency reasons
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
setupStudyBean(request);
// Create a DisplaySectionBean for the SectionBean specified by the
// tab number.
tabNum = tabNum == 0 ? 1 : tabNum;
String sectionTitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_TITLE);
String secLabel = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_LABEL);
String secSubtitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_SUBTITLE);
String instructions = getSectionColumnBySecNum(sectionsMap, tabNum, INSTRUCTIONS);
int secBorders = getSectionBordersBySecNum(sectionsMap, tabNum, BORDERS);
DisplaySectionBean displaySection = beanFactory.createDisplaySectionBean(itemsMap, sectionTitle, secLabel, secSubtitle, instructions, crfName, secBorders);
//
// the variable hasGroups should only be true if the group appears in
// this section
List<DisplayItemBean> disBeans = displaySection.getItems();
ItemFormMetadataBean metaBean;
String groupLabel;
hasGroups = false;
for (DisplayItemBean diBean : disBeans) {
metaBean = diBean.getMetadata();
groupLabel = metaBean.getGroupLabel();
if (groupLabel != null && groupLabel.length() > 0) {
hasGroups = true;
break;
}
}
// Create groups associated with this section
List<DisplayItemGroupBean> disFormGroupBeans = null;
if (hasGroups) {
disFormGroupBeans = beanFactory.createGroupBeans(itemsMap, groupsMap, secLabel, crfName);
displaySection.setDisplayFormGroups(disFormGroupBeans);
}
/*
* DisplaySectionBean displaySection =
* beanFactory.createDisplaySectionBean (itemsMap, sectionTitle,
* secLabel, secSubtitle, instructions, crfName);
*/
displaySection.setCrfVersion(crfverBean);
displaySection.setCrf(crfbean);
displaySection.setEventCRF(ebean);
// Not sure if this is needed? The JSPs pull it out
// as a request attribute
SectionBean aSecBean = new SectionBean();
request.setAttribute(BEAN_DISPLAY, displaySection);
// TODO: verify these attributes, from the original servlet, are
// necessary
request.setAttribute("sec", aSecBean);
request.setAttribute("EventCRFBean", ebean);
try {
request.setAttribute("tabId", Integer.toString(tabNum));
} catch (NumberFormatException nfe) {
request.setAttribute("tabId", new Integer("1"));
}
if (hasGroups) {
LOGGER.debug("has group, new_table is true");
request.setAttribute("new_table", true);
}
// YW 07-23-2007 << for issue 0000937
forwardPage(Page.CREATE_CRF_VERSION_CONFIRM, request, response);
// YW >>
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class TestRuleServlet method validate.
private HashMap<String, String> validate(Validator v) throws ParseException {
FormProcessor fp = new FormProcessor(request);
String targetString = fp.getString("target");
String ruleString = fp.getString("rule");
ruleString = ruleString.trim().replaceAll("(\n|\t|\r)", " ");
targetString = targetString.trim().replaceAll("(\n|\t|\r)", "");
HashMap<String, String> p = session.getAttribute("testValues") != null ? (HashMap<String, String>) session.getAttribute("testValues") : new HashMap<String, String>();
if (p != null) {
for (Map.Entry<String, String> entry : p.entrySet()) {
entry.setValue(fp.getString(entry.getKey()));
if (entry.getKey().startsWith(ExpressionService.STUDY_EVENT_OID_START_KEY) && (entry.getKey().endsWith(ExpressionService.STATUS) || entry.getKey().endsWith(ExpressionService.STARTDATE))) {
StudyEventDefinitionBean sed = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(entry.getKey(), currentStudy);
if (entry.getKey().endsWith(ExpressionService.STATUS)) {
// TODO add the logic for status
} else if (entry.getKey().endsWith(ExpressionService.STARTDATE)) {
try {
v.addValidation(entry.getKey(), Validator.IS_A_DATE);
SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"));
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
if (!entry.getValue().isEmpty()) {
java.util.Date date = sdf2.parse(entry.getValue());
entry.setValue(sdf.format(date));
}
} catch (Exception e) {
logger.error(e.toString());
// TODO: handle exception
}
}
} else {
ItemBean item = getExpressionService().getItemBeanFromExpression(entry.getKey());
List<ItemFormMetadataBean> itemFormMetadataBeans = getItemFormMetadataDAO().findAllByItemId(item.getId());
ItemFormMetadataBean itemFormMetadataBean = itemFormMetadataBeans.size() > 0 ? itemFormMetadataBeans.get(0) : null;
if (!entry.getValue().equals("") && NullValue.getByName(entry.getValue()) == NullValue.INVALID) {
if (itemFormMetadataBean != null) {
if (itemFormMetadataBean.getResponseSet().getResponseType() == ResponseType.SELECTMULTI || itemFormMetadataBean.getResponseSet().getResponseType() == ResponseType.CHECKBOX) {
v.addValidation(entry.getKey(), Validator.IN_RESPONSE_SET_COMMA_SEPERATED, itemFormMetadataBean.getResponseSet());
}
if (itemFormMetadataBean.getResponseSet().getResponseType() == ResponseType.SELECT || itemFormMetadataBean.getResponseSet().getResponseType() == ResponseType.RADIO) {
v.addValidation(entry.getKey(), Validator.IN_RESPONSE_SET_SINGLE_VALUE, itemFormMetadataBean.getResponseSet());
} else {
itemDataTypeToValidatorId(entry.getKey(), item, v);
}
}
}
if (item.getItemDataTypeId() == 9) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"));
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
if (!entry.getValue().isEmpty()) {
java.util.Date date = sdf.parse(entry.getValue());
entry.setValue(sdf2.format(date));
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
}
}
List<RuleActionBean> actions = session.getAttribute("testRuleActions") != null ? (List<RuleActionBean>) session.getAttribute("testRuleActions") : new ArrayList<RuleActionBean>();
if (actions != null) {
for (int i = 0; i < actions.size(); i++) {
actions.get(i).setExpressionEvaluatesTo(fp.getBoolean("actions" + i));
}
}
// Check Target if not valid report and return
try {
getExpressionService().ruleSetExpressionChecker(targetString);
} catch (OpenClinicaSystemException e) {
HashMap<String, String> result = new HashMap<String, String>();
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString(e.getErrorCode()));
Object[] arguments = e.getErrorParams();
result.put("ruleValidation", "target_invalid");
result.put("ruleValidationFailMessage", e.getErrorCode() + " : " + mf.format(arguments));
result.put("ruleEvaluatesTo", "");
request.setAttribute("targetFail", "on");
return result;
}
// Auto update itemName & itemDefinition based on target
ItemBean item = getExpressionService().getItemBeanFromExpression(targetString);
StudyEventDefinitionBean sed = null;
if (item != null) {
request.setAttribute("itemName", item.getName());
request.setAttribute("itemDefinition", item.getDescription());
} else {
sed = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(targetString, currentStudy);
if (sed != null) {
request.setAttribute("itemName", sed.getName());
request.setAttribute("itemDefinition", sed.getDescription());
}
}
RuleSetBean ruleSet = new RuleSetBean();
ExpressionBean target = new ExpressionBean();
target.setContext(Context.OC_RULES_V1);
target.setValue(targetString);
ruleSet.setTarget(target);
RuleSetBean persistentRuleSet = getRuleSetDao().findByExpressionAndStudy(ruleSet, currentStudy.getId());
if (persistentRuleSet != null) {
if (item != null)
request.setAttribute("ruleSetId", item.getId());
else
request.setAttribute("ruleSetId", sed.getId());
}
ExpressionBean rule = new ExpressionBean();
rule.setContext(Context.OC_RULES_V1);
rule.setValue(ruleString);
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(sm.getDataSource(), currentStudy, rule, ruleSet);
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
ep.setRespage(respage);
// Run expression with populated HashMap
DateTime start = new DateTime();
HashMap<String, String> result = ep.testEvaluateExpression(p);
DateTime end = new DateTime();
Duration dur = new Duration(start, end);
PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder().printZeroAlways().appendSecondsWithMillis().appendSuffix(" second", " seconds").toFormatter();
yearsAndMonths.print(dur.toPeriod());
// Run expression with empty HashMap to check rule validity, because
// using illegal test values will cause invalidity
HashMap<String, String> k = new HashMap<String, String>();
HashMap<String, String> theResult = ep.testEvaluateExpression(k);
if (theResult.get("ruleValidation").equals("rule_valid") && result.get("ruleValidation").equals("rule_invalid")) {
result.put("ruleValidation", "rule_valid");
result.put("ruleEvaluatesTo", resword.getString("test_rules_rule_fail") + " " + result.get("ruleValidationFailMessage"));
result.remove("ruleValidationFailMessage");
}
// Put on screen
request.setAttribute("duration", yearsAndMonths.print(dur.toPeriod()));
return result;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class PrintHorizontalFormBuilder method addResponseLayoutRow.
private void addResponseLayoutRow(ArrayList subHeadList, List<DisplayItemBean> displayBeans) {
Element thRow = new Element("tr");
String responseName;
String responseLayout;
ItemFormMetadataBean metaBean;
// Now create the th row
Element th2;
ResponseSetBean respBean;
ResponseOptionBean optBean;
int j = 0;
for (DisplayItemBean dBean : displayBeans) {
j++;
metaBean = dBean.getMetadata();
respBean = metaBean.getResponseSet();
responseName = respBean.getResponseType().getName();
if (responseName == null) {
responseName = "";
}
responseLayout = metaBean.getResponseLayout();
if (responseLayout == null) {
responseLayout = "";
}
// next to a rad or check *with* a horizontal layout.
if ((responseName.equalsIgnoreCase("radio") || responseName.equalsIgnoreCase("checkbox")) && responseLayout.equalsIgnoreCase("horizontal")) {
for (int i = 0; i < respBean.getOptions().size(); i++) {
optBean = (ResponseOptionBean) respBean.getOptions().get(i);
if (optBean != null) {
th2 = createThCell(optBean.getText(), 1);
// Add font for printing
String classNames = th2.getAttribute("class").getValue();
classNames = classNames + " general_font";
th2.setAttribute("class", classNames);
thRow.addContent(th2);
}
}
} else {
// create empty cells for non-radios or checks, or rads and
// checks
// without horizontal layout
th2 = createThCell("", 1);
thRow.addContent(th2);
}
if (j % maxColRow == 0) {
subHeadList.add(thRow);
thRow = new Element("tr");
}
}
if (j % maxColRow != 0)
subHeadList.add(thRow);
// now add the final empty th cell for the row
th2 = createThCell();
thRow.addContent(th2);
}
Aggregations