use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method attachValidator.
private void attachValidator(DisplayItemBean displayItemBean, ImportHelper importHelper, DiscrepancyValidator discValidator, HashMap<String, String> hardv, javax.servlet.http.HttpServletRequest request, String eventCRFRepeatKey, String studySubjectOID) throws OpenClinicaException {
org.akaza.openclinica.bean.core.ResponseType rt = displayItemBean.getMetadata().getResponseSet().getResponseType();
String itemOid = displayItemBean.getItem().getOid() + "_" + eventCRFRepeatKey + "_" + displayItemBean.getData().getOrdinal() + "_" + studySubjectOID;
if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXT) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.TEXTAREA)) {
ItemFormMetadataBean ifm = displayItemBean.getMetadata();
String widthDecimal = ifm.getWidthDecimal();
// mm/dd/yyyy
if (displayItemBean.getItem().getDataType().equals(ItemDataType.DATE)) {
// pass it if it is blank, tbh
if (!"".equals(displayItemBean.getData().getValue())) {
String dateValue = displayItemBean.getData().getValue();
SimpleDateFormat sdf_sqldate = new SimpleDateFormat("yyyy-MM-dd");
sdf_sqldate.setLenient(false);
try {
// htaycher: database exspects format YYYY-MM-DD
Date originalDate = sdf_sqldate.parse(dateValue);
// String replacementValue = new SimpleDateFormat("MM/dd/yyyy").format(originalDate);
String replacementValue = new SimpleDateFormat("yyyy-MM-dd").format(originalDate);
displayItemBean.getData().setValue(replacementValue);
} catch (ParseException pe1) {
// next version; fail if it does not pass iso 8601
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("you_have_a_date_value_which_is_not"));
Object[] arguments = { displayItemBean.getItem().getOid() };
hardv.put(itemOid, mf.format(arguments));
}
}
} else if (displayItemBean.getItem().getDataType().equals(ItemDataType.ST)) {
int width = Validator.parseWidth(widthDecimal);
if (width > 0 && displayItemBean.getData().getValue().length() > width) {
hardv.put(itemOid, "This value exceeds required width=" + width);
}
} else // what if it's a number? should be only numbers
if (displayItemBean.getItem().getDataType().equals(ItemDataType.INTEGER)) {
try {
Integer testInt = new Integer(displayItemBean.getData().getValue());
int width = Validator.parseWidth(widthDecimal);
if (width > 0 && displayItemBean.getData().getValue().length() > width) {
hardv.put(itemOid, "This value exceeds required width=" + width);
}
// now, didn't check decimal for testInt.
} catch (Exception e) {
// pass if blank, tbh 07/2010
if (!"".equals(displayItemBean.getData().getValue())) {
hardv.put(itemOid, "This value is not an integer.");
}
}
} else // what if it's a float? should be only numbers
if (displayItemBean.getItem().getDataType().equals(ItemDataType.REAL)) {
try {
Float testFloat = new Float(displayItemBean.getData().getValue());
int width = Validator.parseWidth(widthDecimal);
if (width > 0 && displayItemBean.getData().getValue().length() > width) {
hardv.put(itemOid, "This value exceeds required width=" + width);
}
int decimal = Validator.parseDecimal(widthDecimal);
if (decimal > 0 && BigDecimal.valueOf(new Double(displayItemBean.getData().getValue()).doubleValue()).scale() > decimal) {
hardv.put(itemOid, "This value exceeds required decimal=" + decimal);
}
} catch (Exception ee) {
// pass if blank, tbh
if (!"".equals(displayItemBean.getData().getValue())) {
hardv.put(itemOid, "This value is not a real number.");
}
}
}
// what if it's a phone number? how often does that happen?
request.setAttribute(itemOid, displayItemBean.getData().getValue());
displayItemBean = importHelper.validateDisplayItemBeanText(discValidator, displayItemBean, itemOid);
// errors = v.validate();
} else if (rt.equals(ResponseType.CALCULATION) || rt.equals(ResponseType.GROUP_CALCULATION)) {
if (displayItemBean.getItem().getDataType().equals(ItemDataType.REAL)) {
ItemFormMetadataBean ifm = displayItemBean.getMetadata();
String widthDecimal = ifm.getWidthDecimal();
int decimal = Validator.parseDecimal(widthDecimal);
if (decimal > 0) {
try {
Double d = new Double(displayItemBean.getData().getValue());
if (BigDecimal.valueOf(d).scale() > decimal) {
hardv.put(itemOid, "This value exceeds required decimal=" + decimal);
}
} catch (Exception e) {
if (!"".equals(displayItemBean.getData().getValue())) {
hardv.put(itemOid, "This value is not a real number.");
}
}
}
}
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.RADIO) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECT)) {
// logger.info(itemOid + "is a RADIO or
// a SELECT ");
// adding a new hard edit check here; response_option mismatch
String theValue = matchValueWithOptions(displayItemBean, displayItemBean.getData().getValue(), displayItemBean.getMetadata().getResponseSet().getOptions());
request.setAttribute(itemOid, theValue);
logger.debug(" found the value for radio/single: " + theValue);
if (theValue == null && displayItemBean.getData().getValue() != null && !displayItemBean.getData().getValue().isEmpty()) {
// fail it here
logger.debug("-- theValue was NULL, the real value was " + displayItemBean.getData().getValue());
hardv.put(itemOid, "This is not in the correct response set.");
// throw new OpenClinicaException("One of your items did not
// have the correct response set. Please review Item OID "
// + displayItemBean.getItem().getOid() + " repeat key " +
// displayItemBean.getData().getOrdinal(), "");
}
displayItemBean = importHelper.validateDisplayItemBeanSingleCV(discValidator, displayItemBean, itemOid);
// errors = v.validate();
} else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CHECKBOX) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECTMULTI)) {
// logger.info(itemOid + "is a CHECKBOX
// or a SELECTMULTI ");
String theValue = matchValueWithManyOptions(displayItemBean, displayItemBean.getData().getValue(), displayItemBean.getMetadata().getResponseSet().getOptions());
request.setAttribute(itemOid, theValue);
// logger.debug(" found the value for checkbx/multi: " + theValue);
if (theValue == null && displayItemBean.getData().getValue() != null && !displayItemBean.getData().getValue().isEmpty()) {
// fail it here? found an 0,1 in the place of a NULL
// logger.debug("-- theValue was NULL, the real value was " + displayItemBean.getData().getValue());
hardv.put(itemOid, "This is not in the correct response set.");
}
displayItemBean = importHelper.validateDisplayItemBeanMultipleCV(discValidator, displayItemBean, itemOid);
// errors = v.validate();
}
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ImportHelper method validateDisplayItemBeanSingleCV.
/**
* Peform validation on a item which has a RADIO or SINGLESELECTresponse
* type. This function checks that the input isn't blank, and that its value
* comes from the controlled vocabulary (ResponseSetBean) in the
* DisplayItemBean.
*
* @param v
* The Validator to add validations to.
* @param dib
* The DisplayItemBean to validate.
* @return The DisplayItemBean which is validated.
*/
public DisplayItemBean validateDisplayItemBeanSingleCV(DiscrepancyValidator v, DisplayItemBean dib, String inputName) {
if (StringUtil.isBlank(inputName)) {
inputName = getInputName(dib);
}
ItemFormMetadataBean ibMeta = dib.getMetadata();
ItemDataBean idb = dib.getData();
if (StringUtil.isBlank(idb.getValue())) {
if (ibMeta.isRequired()) {
v.addValidation(inputName, Validator.IS_REQUIRED);
}
} else {
// commented out because it should be a hard edit check, tbh 05/2008
// v.addValidation(inputName,
// Validator.IN_RESPONSE_SET_SINGLE_VALUE,
// dib.getMetadata().getResponseSet());
}
return dib;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ImportHelper method validateDisplayItemBeanText.
/**
* Peform validation on a item which has a TEXT or TEXTAREA response type.
* If the item has a null value, it's automatically validated. Otherwise,
* it's checked against its data type.
*
* @param v
* The Validator to add validations to.
* @param dib
* The DisplayItemBean to validate.
* @return The DisplayItemBean which is validated.
*/
public DisplayItemBean validateDisplayItemBeanText(DiscrepancyValidator discValidator, DisplayItemBean dib, String inputName) {
if (StringUtil.isBlank(inputName)) {
// for single items
inputName = getInputName(dib);
}
ItemBean ib = dib.getItem();
ItemFormMetadataBean ibMeta = dib.getMetadata();
ItemDataType idt = ib.getDataType();
ItemDataBean idb = dib.getData();
boolean isNull = false;
if (!isNull) {
if (StringUtil.isBlank(idb.getValue())) {
// check required first
if (ibMeta.isRequired()) {
discValidator.addValidation(inputName, Validator.IS_REQUIRED);
}
} else {
if (idt.equals(ItemDataType.ST)) {
// a string's size could be more than 255, which is more
// than
// the db field length
discValidator.addValidation(inputName, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 3999);
} else if (idt.equals(ItemDataType.INTEGER)) {
// hard edit check, will comment out for now, tbh 05/2008
// v.addValidation(inputName, Validator.IS_AN_INTEGER);
// v.alwaysExecuteLastValidation(inputName);
} else if (idt.equals(ItemDataType.REAL)) {
// hard edit check, will comment out for now, tbh 05/08
// v.addValidation(inputName, Validator.IS_A_NUMBER);
// v.alwaysExecuteLastValidation(inputName);
} else if (idt.equals(ItemDataType.BL)) {
// there is no validation here since this data type is
// explicitly
// allowed to be null
// if the string input for this field parses to a non-zero
// number, the
// value will be true; otherwise, 0
} else if (idt.equals(ItemDataType.BN)) {
} else if (idt.equals(ItemDataType.SET)) {
// v.addValidation(inputName, Validator.NO_BLANKS_SET);
discValidator.addValidation(inputName, Validator.IN_RESPONSE_SET_SINGLE_VALUE, dib.getMetadata().getResponseSet());
} else if (idt.equals(ItemDataType.DATE)) {
// hard edit check, will comment out for now, tbh 05/08
// v.addValidation(inputName, Validator.IS_A_DATE);
// v.alwaysExecuteLastValidation(inputName);
}
String customValidationString = dib.getMetadata().getRegexp();
if (!StringUtil.isBlank(customValidationString)) {
Validation customValidation = null;
if (customValidationString.startsWith("func:")) {
try {
customValidation = Validator.processCRFValidationFunction(customValidationString);
} catch (Exception e) {
e.printStackTrace();
}
} else if (customValidationString.startsWith("regexp:")) {
try {
customValidation = Validator.processCRFValidationRegex(customValidationString);
} catch (Exception e) {
}
}
if (customValidation != null) {
customValidation.setErrorMessage(dib.getMetadata().getRegexpErrorMsg());
discValidator.addValidation(inputName, customValidation);
}
}
}
}
return dib;
}
Aggregations