use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class CreateCRFVersionServlet method isResponseValid.
private ItemBean isResponseValid(HashMap items, CRFVersionBean version) {
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO metadao = new ItemFormMetadataDAO(sm.getDataSource());
Set names = items.keySet();
Iterator it = names.iterator();
while (it.hasNext()) {
String name = (String) it.next();
ItemBean oldItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
ItemBean item = (ItemBean) items.get(name);
if (oldItem.getId() > 0) {
// found same item in DB
ArrayList metas = metadao.findAllByItemId(oldItem.getId());
for (int i = 0; i < metas.size(); i++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(i);
ResponseSetBean rsb = ifmb.getResponseSet();
if (hasDifferentOption(rsb, item.getItemMeta().getResponseSet()) != null) {
return item;
}
}
}
}
return null;
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean 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.ResponseSetBean in project OpenClinica by OpenClinica.
the class BeanFactory method createResponseSetBean.
/* Create a ResponseSetBean from a Map of property/value pairs */
public ResponseSetBean createResponseSetBean(Map<String, String> itemValuesMap, String crfName) {
ResponseSetBean rBean = new ResponseSetBean();
// If an item has a response label that has already been defined (by
// previous
// item definitions) then use the response_options_text and
// response_values associated
// with that response label
String[] innerArray = new String[2];
String responseType = itemValuesMap.get("response_type");
String responseLab = itemValuesMap.get("response_label");
String optionsTxt = itemValuesMap.get("response_options_text");
String optionsVals = itemValuesMap.get("response_values");
rBean.setResponseType(ResponseType.getByName(responseType));
rBean.setLabel(itemValuesMap.get("response_label"));
// Find out if the response text and option values are already cached
// for
// this CRF. The String index is the CRF name; the String array refrs to
// the options text and options values.
Map<String, String[]> responseLabels = cachedResponseLabels.get(crfName);
if (responseLabels == null) {
responseLabels = new HashMap<String, String[]>();
cachedResponseLabels.put(crfName, responseLabels);
}
if (responseLabels.get(responseLab) == null) {
innerArray[0] = optionsTxt;
innerArray[1] = optionsVals;
responseLabels.put(responseLab, innerArray);
}
// if the item has a response label but no values for
// response_options_text
// or response_values, provide the item with the cached values for these
// properties
String[] tmpArr;
if (responseLab != null && responseLab.length() != 0 && optionsTxt != null && optionsTxt.length() == 0 && optionsVals != null && optionsVals.length() == 0) {
tmpArr = responseLabels.get(responseLab);
// The responseLabel is stored in the Map
if (tmpArr != null) {
rBean.setOptions(tmpArr[0], tmpArr[1]);
return rBean;
}
}
rBean.setOptions(optionsTxt, optionsVals);
return rBean;
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class BeanFactory method createItemFormMetadataBean.
/*
* Create an ItemFormMetadataBean from the values referred to by a Map.Entry
* object. The Map.Entry contains an integer pointing to a Map of Item
* values from the Sreadsheet template, as in (item_name: Item1, etc...}
*/
public ItemFormMetadataBean createItemFormMetadataBean(Map.Entry<Integer, Map<String, String>> me, String crfName) {
if (me == 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(me.getKey());
Map<String, String> map = me.getValue();
// response_layout property for checkboxes and radio buttons
metadataBean.setResponseLayout(map.get("response_layout"));
metadataBean.setDefaultValue(map.get("default_value"));
metadataBean.setParentLabel(map.get("parent_item"));
metadataBean.setLeftItemText(map.get("left_item_text"));
metadataBean.setRightItemText(map.get("right_item_text"));
metadataBean.setHeader(map.get("header"));
metadataBean.setSubHeader(map.get("subheader"));
metadataBean.setGroupLabel(map.get("group_label"));
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");
//We support any character in QUESTION_NUMBER field. So there is no need to do this number formatting.
// 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.ResponseSetBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method addAttachedFilePath.
protected String addAttachedFilePath(DisplayItemBean dib, String attachedFilePath) {
String fileName = "";
ItemDataBean idb = dib.getData();
String itemDataValue = idb.getValue();
String dbValue = dib.getDbData().getValue();
ResponseSetBean rsb = dib.getMetadata().getResponseSet();
org.akaza.openclinica.bean.core.ResponseType rt = rsb.getResponseType();
if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.FILE) && itemDataValue.length() > 0) {
File file = new File(itemDataValue);
fileName = file.getName();
if (itemDataValue.length() > fileName.length()) {
// itemDataValue includes file path
idb.setValue(itemDataValue);
} else {
File f = new File(dbValue);
fileName = f.getName();
if (fileName.equals(itemDataValue) && dbValue.length() > itemDataValue.length()) {
// since filename is unique by timestamp, re-upload will
// append
// another timestamp to the same filename
idb.setValue(dbValue);
} else {
idb.setValue(attachedFilePath + itemDataValue);
fileName = itemDataValue;
}
}
}
return fileName;
}
Aggregations