use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method ensureSelectedOption.
private void ensureSelectedOption(DisplayItemBean displayItemBean) {
if (displayItemBean == null || displayItemBean.getData() == null) {
return;
}
ItemDataBean itemDataBean = displayItemBean.getData();
String dataName = itemDataBean.getName();
String dataValue = itemDataBean.getValue();
if ("".equalsIgnoreCase(dataValue)) {
return;
}
List<ResponseOptionBean> responseOptionBeans = new ArrayList<ResponseOptionBean>();
ResponseSetBean responseSetBean = displayItemBean.getMetadata().getResponseSet();
if (responseSetBean == null) {
return;
}
responseOptionBeans = responseSetBean.getOptions();
String tempVal = "";
for (ResponseOptionBean responseOptionBean : responseOptionBeans) {
tempVal = responseOptionBean.getValue();
if (tempVal != null && tempVal.equalsIgnoreCase(dataValue)) {
responseOptionBean.setSelected(true);
}
}
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class Validator method validate.
protected HashMap validate(String fieldName, Validation v) {
switch(v.getType()) {
case NO_BLANKS:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_NUMBER:
if (!isNumber(fieldName)) {
addError(fieldName, v);
}
break;
case IS_IN_RANGE:
float lowerBound = v.getFloat(0);
float upperBound = v.getFloat(1);
if (!isInRange(fieldName, lowerBound, upperBound)) {
addError(fieldName, v);
}
break;
case IS_A_DATE:
if (!isDate(fieldName)) {
addError(fieldName, v);
}
break;
case IS_DATE_TIME:
if (!isDateTime(fieldName)) {
addError(fieldName, v);
}
break;
case CHECK_SAME:
String compareField = v.getString(0);
if (!isSame(fieldName, compareField)) {
addError(fieldName, v);
}
break;
case IS_A_EMAIL:
if (!isEmail(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_PHONE_NUMBER:
if (!isPhoneNumber(fieldName)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS:
EntityDAO edao = (EntityDAO) v.getArg(0);
if (!entityExists(fieldName, edao)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS_IN_STUDY:
AuditableEntityDAO dao = (AuditableEntityDAO) v.getArg(0);
StudyBean study = (StudyBean) v.getArg(1);
if (!entityExistsInStudy(fieldName, dao, study)) {
addError(fieldName, v);
}
break;
case USERNAME_UNIQUE:
UserAccountDAO udao = (UserAccountDAO) v.getArg(0);
if (!usernameUnique(fieldName, udao)) {
addError(fieldName, v);
}
break;
case IS_AN_INTEGER:
if (!isInteger(fieldName)) {
addError(fieldName, v);
}
break;
// break;
case IS_IN_SET:
ArrayList set = (ArrayList) v.getArg(0);
if (!isInSet(fieldName, set)) {
addError(fieldName, v);
}
break;
case IS_A_PASSWORD:
if (!lengthComparesToStaticValue(fieldName, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, PASSWORD_MINIMUM_LENGTH)) {
addError(fieldName, v);
}
break;
case IS_A_USERNAME:
if (!isUsername(fieldName)) {
addError(fieldName, v);
}
break;
case IS_VALID_TERM:
TermType termType = (TermType) v.getArg(0);
if (!isValidTerm(fieldName, termType)) {
addError(fieldName, v);
}
break;
case COMPARES_TO_STATIC_VALUE:
NumericComparisonOperator operator = (NumericComparisonOperator) v.getArg(0);
float compareTo = v.getFloat(1);
if (!comparesToStaticValue(fieldName, operator, compareTo)) {
addError(fieldName, v);
}
break;
case LENGTH_NUMERIC_COMPARISON:
NumericComparisonOperator operator2 = (NumericComparisonOperator) v.getArg(0);
int compareTo2 = v.getInt(1);
if (!lengthComparesToStaticValue(fieldName, operator2, compareTo2)) {
addError(fieldName, v);
}
break;
case DATE_IS_AFTER_OR_EQUAL:
String earlierDateFieldName = v.getString(0);
if (!isDateAfterOrEqual(fieldName, earlierDateFieldName)) {
addError(fieldName, v);
}
break;
case NO_BLANKS_SET:
if (isSetBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET:
ResponseSetBean rsb = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsb, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_COMMA_SEPERATED:
ResponseSetBean rsbs = (ResponseSetBean) v.getArg(0);
if (!isInResponseSetCommaSeperated(fieldName, rsbs, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_SINGLE_VALUE:
ResponseSetBean rsbSingle = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsbSingle, false)) {
addError(fieldName, v);
}
break;
case MATCHES_INITIAL_DATA_ENTRY_VALUE:
String oldValue = v.getString(0);
boolean isMultiple = v.getBoolean(1);
if (!valueMatchesInitialValue(fieldName, oldValue, isMultiple)) {
addError(fieldName, v);
}
break;
case DIFFERENT_NUMBER_OF_GROUPS_IN_DDE:
addError(fieldName, v);
break;
case IS_REQUIRED:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case DATE_IN_PAST:
if (!isDateInPast(fieldName)) {
addError(fieldName, v);
}
break;
case MATCHES_REGULAR_EXPRESSION:
if (!matchesRegex(fieldName, v.getString(0))) {
addError(fieldName, v);
}
break;
case CHECK_DIFFERENT:
String old = v.getString(0);
if (isSame(fieldName, old)) {
addError(fieldName, v);
}
break;
case IS_A_DATE_WITHOUT_REQUIRED_CHECK:
if (!isDateWithoutRequiredCheck(fieldName)) {
addError(fieldName, v);
}
break;
case CALCULATION_FAILED:
addError(fieldName, v);
break;
case IS_AN_RULE:
ArrayList<String> messages = (ArrayList<String>) v.getArg(0);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < messages.size(); i++) {
sb.append(messages.get(i));
if (i != messages.size() - 1)
sb.append(" , ");
logger.debug(messages.get(i));
}
v.setErrorMessage(sb.toString());
addError(fieldName, v);
break;
case IS_PARTIAL_DATE:
boolean isPDate = Boolean.FALSE;
String fieldValue = getFieldValue(fieldName);
if (fieldValue != null) {
// resformat.getString("date_format_string"))) {
if (StringUtil.isFormatDate(fieldValue, resformat.getString("date_format_string")) || StringUtil.isPartialYear(fieldValue, "yyyy") || StringUtil.isPartialYearMonth(fieldValue, resformat.getString("date_format_year_month"))) {
isPDate = true;
}
}
if (!isPDate) {
addError(fieldName, v);
}
break;
case IS_VALID_WIDTH_DECIMAL:
ArrayList<String> params = (ArrayList<String>) v.getArg(0);
String dataType = params.get(0);
String widthDecimal = params.get(1);
StringBuffer error = this.validateFieldWidthDecimal(fieldName, dataType, widthDecimal);
if (error.length() > 0) {
addError(fieldName, error.toString());
}
break;
case BARCODE_EAN_13:
EanCheckDigit eanChk = new EanCheckDigit();
if (!eanChk.isValid(getFieldValue(fieldName))) {
addError(fieldName, v);
}
break;
case TO_HIDE_CONDITIONAL_DISPLAY:
addError(fieldName, v);
break;
}
return errors;
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class SPSSReportBean method isIntType.
// YW
private boolean isIntType(ItemBean ib) {
ArrayList metas = ib.getItemMetas();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.TEXT) || rsb.getResponseType().equals(ResponseType.TEXTAREA)) {
return true;
}
}
return false;
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class SPSSReportBean method getMetadataFile.
public StringBuffer getMetadataFile(SPSSVariableNameValidator svnv, ExtractBean eb) {
itemNames.clear();
// Is it necessary to
String[] attributes = createAttributes(eb);
// validate
// StudyGroupClassBean
// names? YW
String[] attributeTypes = createAttributeTypes(eb);
StringBuffer answer = new StringBuffer();
answer.append("* NOTE: If you have put this file in a different folder \n" + "* from the associated data file, you will have to change the FILE \n" + "* location on the line below to point to the physical location of your data file.\n");
answer.append("GET DATA " + "/TYPE = TXT" + "/FILE = '" + getDatFileName() + "' " + "/DELCASE = LINE " + "/DELIMITERS = \"\\t\" " + "/ARRANGEMENT = DELIMITED " + "/FIRSTCASE = " + FIRSTCASE + " " + // since
"/IMPORTCASE = ALL ");
if (data.size() <= 0) {
answer.append(".\n");
} else {
ArrayList columns = (ArrayList) data.get(this.COLUMNS_IND);
int startItem = columns.size() - items.size();
logger.debug("--> generated start item " + startItem + " from " + columns.size() + " minus " + items.size());
answer.append("/VARIABLES = \n");
int index;
for (int i = 0; i < columns.size(); i++) {
String itemName = (String) columns.get(i);
// YW << Why do we need "V_" here? Right now it has been
// removed, because:
// This "V_" exists in .sps file but not exists in .dat file.
// String varLabel = "V_" + itemName;
String varLabel = svnv.getValidName(itemName);
itemNames.add(varLabel);
// builtin attributes
if (i < startItem) {
if (varLabel.startsWith("Gender")) {
gender = true;
}
index = builtinIndex(varLabel, attributes);
logger.debug("varLabel[" + varLabel + "] index[" + index + "] attributeTypes[" + attributeTypes[1] + "]");
answer.append("\t" + varLabel + " " + attributeTypes[index]);
// >> tbh #5524
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
ItemBean ib = dih.getItem();
// << tbh
if (attributeTypes[index].equals("A")) {
int len = getDataColumnMaxLen(i);
if (len == 0) {
// mininum length required by spss
len = 1;
}
// >> tbh #5524
ArrayList metas = ib.getItemMetas();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
ArrayList options = rsb.getOptions();
for (int l = 0; l < options.size(); l++) {
ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
if (ro.getText().length() > len) {
len = ro.getText().length();
}
}
}
// << tbh
if (len > 8) {
len = 8;
}
answer.append(len);
}
answer.append("\n");
}
// YW >>
}
// items
logger.debug("--> looking at " + startItem + " out of " + columns.size());
for (int i = startItem; i < columns.size(); i++) {
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
ItemBean ib = dih.getItem();
// YW <<
String varLabel = (String) itemNames.get(i);
int dataTypeId = ib.getItemDataTypeId();
// String.
if (dataTypeId == 9) {
// date
answer.append("\t" + varLabel + " ADATE10\n");
} else if (dataTypeId == 7) {
// float
answer.append("\t" + varLabel + " F8.2\n");
} else if (dataTypeId == 6 && isIntType(ib)) {
// pure int data
// type for one
// item.
answer.append("\t" + varLabel + " F8.0\n");
} else {
// string
// YW >>
int len = getDataColumnMaxLen(i);
if (len == 0) {
// mininum length required by spss
len = 1;
}
ArrayList metas = ib.getItemMetas();
int optionCount = 0;
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.CHECKBOX) || rsb.getResponseType().equals(ResponseType.RADIO) || rsb.getResponseType().equals(ResponseType.SELECT) || rsb.getResponseType().equals(ResponseType.SELECTMULTI)) {
optionCount++;
}
// tbh >> #5524: all possible response value options should be reviewed so that length is OK
ArrayList options = rsb.getOptions();
for (int l = 0; l < options.size(); l++) {
ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
if (ro.getText().length() > len) {
len = ro.getText().length();
}
}
// << tbh
}
if (optionCount == metas.size()) {
// value labels
if (len > 8) {
len = 8;
}
}
answer.append("\t" + varLabel + " A" + len + "\n");
}
}
answer.append(".\n");
answer.append("VARIABLE LABELS\n");
// builtin attributes
for (int i = 0; i < startItem; ++i) {
String varLabel = (String) itemNames.get(i);
if ((String) descriptions.get(itemNames.get(i)) != null) {
answer.append("\t" + varLabel + " \"" + (String) descriptions.get(itemNames.get(i)) + "\"\n");
} else {
for (int j = 0; j < eb.getStudyGroupClasses().size(); ++j) {
answer.append("\t" + varLabel + " \"" + (String) descriptions.get(((StudyGroupClassBean) eb.getStudyGroupClasses().get(j)).getName()) + "\"\n");
}
}
}
// items
for (int i = startItem; i < itemNames.size(); i++) {
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
ItemBean ib = dih.getItem();
String varLabel = (String) itemNames.get(i);
answer.append("\t" + varLabel + " \"" + ib.getDescription() + "\"\n");
}
answer.append(".\n");
answer.append("VALUE LABELS\n");
if (isGender()) {
answer.append("\t" + "Gender" + "\n");
answer.append("\t" + "'M'" + " \"" + "Male" + "\"\n");
answer.append("\t" + "'F'" + " \"" + "Female" + "\"\n\t/\n");
}
for (int i = 0; i < items.size(); i++) {
String temp = "";
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
ItemBean ib = dih.getItem();
String varLabel = (String) itemNames.get(i + startItem);
temp += "\t" + varLabel + "\n";
boolean allOption = true;
ArrayList metas = ib.getItemMetas();
HashMap optionMap = new LinkedHashMap();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.TEXT) || rsb.getResponseType().equals(ResponseType.FILE) || rsb.getResponseType().equals(ResponseType.TEXTAREA)) {
// has text response, dont show value labels
allOption = false;
break;
} else {
for (int j = 0; j < rsb.getOptions().size(); j++) {
ResponseOptionBean ob = (ResponseOptionBean) rsb.getOptions().get(j);
String key = ob.getValue();
if (optionMap.containsKey(key)) {
ArrayList a = (ArrayList) optionMap.get(key);
if (!a.contains(ob.getText())) {
a.add(ob.getText());
optionMap.put(key, a);
}
} else {
ArrayList a = new ArrayList();
a.add(ob.getText());
optionMap.put(key, a);
}
}
}
}
Iterator it = optionMap.keySet().iterator();
while (it.hasNext()) {
String value = (String) it.next();
ArrayList a = (ArrayList) optionMap.get(value);
String texts = "";
if (a.size() > 1) {
for (int n = 0; n < a.size(); n++) {
texts += (String) a.get(n);
if (n < a.size() - 1) {
texts += "/";
}
}
} else {
texts = (String) a.get(0);
}
if (value.length() > 8) {
value = value.substring(0, 8);
}
if (isValueText(value)) {
temp += "\t'" + value + "' \"" + texts + "\"\n";
} else {
temp += "\t" + value + " \"" + texts + "\"\n";
}
}
if (allOption) {
answer.append(temp + "\t/\n");
}
}
}
answer.append(".\n EXECUTE.\n");
return answer;
}
use of org.akaza.openclinica.bean.submit.ResponseSetBean in project OpenClinica by OpenClinica.
the class ItemFormMetadataDAO method getEntityFromHashMap.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.dao.core.DAOInterface#getEntityFromHashMap(java.util.HashMap)
*/
public Object getEntityFromHashMap(HashMap hm) {
ItemFormMetadataBean answer = new ItemFormMetadataBean();
answer.setId(getIntFromRow(hm, "item_form_metadata_id"));
answer.setItemId(getIntFromRow(hm, "item_id"));
answer.setCrfVersionId(getIntFromRow(hm, "crf_version_id"));
answer.setHeader(getStringFromRow(hm, "header"));
answer.setSubHeader(getStringFromRow(hm, "subheader"));
answer.setParentId(getIntFromRow(hm, "parent_id"));
answer.setParentLabel(getStringFromRow(hm, "parent_label"));
answer.setColumnNumber(getIntFromRow(hm, "column_number"));
answer.setPageNumberLabel(getStringFromRow(hm, "page_number_label"));
answer.setQuestionNumberLabel(getStringFromRow(hm, "question_number_label"));
answer.setLeftItemText(getStringFromRow(hm, "left_item_text"));
answer.setRightItemText(getStringFromRow(hm, "right_item_text"));
answer.setSectionId(getIntFromRow(hm, "section_id"));
answer.setDescisionConditionId(getIntFromRow(hm, "decision_condition_id"));
answer.setResponseSetId(getIntFromRow(hm, "response_set_id"));
answer.setRegexp(getStringFromRow(hm, "regexp"));
answer.setRegexpErrorMsg(getStringFromRow(hm, "regexp_error_msg"));
answer.setOrdinal(getIntFromRow(hm, "ordinal"));
answer.setRequired(getBooleanFromRow(hm, "required"));
// YW 08-02-2007, default_value column has been added
answer.setDefaultValue(getStringFromRow(hm, "default_value"));
answer.setResponseLayout(getStringFromRow(hm, "response_layout"));
answer.setWidthDecimal(getStringFromRow(hm, "width_decimal"));
// answer.setShowItem(((Boolean) hm.get("show_item")).booleanValue());
answer.setShowItem(getBooleanFromRow(hm, "show_item"));
// System.out.println("found show item: " + getBooleanFromRow(hm, "show_item"));
// now get the response set
ResponseSetBean rsb = new ResponseSetBean();
rsb.setId(getIntFromRow(hm, "response_set_id"));
rsb.setLabel(getStringFromRow(hm, "label"));
rsb.setResponseTypeId(getIntFromRow(hm, "response_type_id"));
String optionsText = getStringFromRow(hm, "options_text");
String optionsValues = getStringFromRow(hm, "options_values");
rsb.setOptions(optionsText, optionsValues);
answer.setResponseSet(rsb);
return answer;
}
Aggregations