use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class ImportHelper method getInputName.
/**
* @param dib
* A DisplayItemBean representing an input on the CRF.
* @return The name of the input in the HTML form.
*/
public final String getInputName(DisplayItemBean dib) {
ItemBean ib = dib.getItem();
String inputName = "input" + ib.getId();
return inputName;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean 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;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean 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.DisplayItemBean in project OpenClinica by OpenClinica.
the class BeanFactory method createGroupBeans.
/**
* This method creates a List of DisplayItemGroupBeans. The
* DisplayItemGroupBeans are listed in the order their items are defined in
* the CRF spreadsheet. These beans include the items that are and are not
* associated with a group. If an item is defined in a spreadsheet but does
* not have a group label, that item is included in a DisplayItemGroupBean,
* but not linked to any groups (i.e., that DisplayItemGroupBean has an
* empty FormGroupBean object, with an empty String for a group label). For
* example, if the spreadsheet defines two items first, but does not assign
* them a group, then those items will make up the first
* DisplayItemGroupBean. The spreadsheet then might define a <em>group</em>
* of items followed by more items that are not part of a group. The former
* items will represent the second DisplayItemGroupBean. The third
* DisplayItemGroupBean will include the last collection of "orphaned"
* items, accompanied by an empty FormGroupBean object.
*
* @param itemsMap
* A Map containing rows of Item information from the
* spreadsheet. The items are in the order they were defined in
* the spreadsheet.
* @param sectionLabel
* A String specifying the name of the section we are displaying.
* @param groupsMap
* A Map containing rows of Group information from the
* spreadsheet.
* @param crfName
* The name of the CRF, a String.
* @see org.akaza.openclinica.bean.submit.ItemGroupBean
* @return A List of DisplayItemGroupBeans
*/
public List<DisplayItemGroupBean> createGroupBeans(Map<Integer, Map<String, String>> itemsMap, Map<Integer, Map<String, String>> groupsMap, String sectionLabel, String crfName) {
List<DisplayItemGroupBean> groupBeans = new ArrayList<DisplayItemGroupBean>();
// properly build group beans
if (groupsMap == null || groupsMap.isEmpty() || sectionLabel == null || sectionLabel.length() < 1 || sectionLabel.equalsIgnoreCase(UNGROUPED) || itemsMap == null || itemsMap.isEmpty()) {
return groupBeans;
}
// First, separate the items into those only associated with this
// section
Map<String, String> innermap;
List<DisplayItemBean> displayItems;
Map.Entry<Integer, Map<String, String>> me;
// This Map will hold the DisplayitemBeans that are associated with this
// section
Map<Integer, Map<String, String>> newMap = new HashMap<Integer, Map<String, String>>();
String lab;
for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = itemsMap.entrySet().iterator(); iter.hasNext(); ) {
me = iter.next();
innermap = me.getValue();
lab = innermap.get("section_label");
if (lab != null && lab.equalsIgnoreCase(sectionLabel)) {
newMap.put(me.getKey(), innermap);
}
}
displayItems = this.createDisplayItemBeansFromMap(newMap, crfName);
// Now, separate the DisplayItemBeans into those associated with groups,
// and any others that do not have groups
ItemGroupBean fgBean;
DisplayItemGroupBean disFgBean;
String latestGroupLabel;
boolean validGroupFlag = false;
int ordinal = 0;
// the List.
for (DisplayItemBean disBean : displayItems) {
latestGroupLabel = disBean.getMetadata().getGroupLabel();
// to a group. Store it in a FormGroupBean.
if (latestGroupLabel != null && latestGroupLabel.length() > 0 && !latestGroupLabel.equalsIgnoreCase(UNGROUPED)) {
// set this flag to true, indicating that the items being
// processed now
// are associated with a valid group
validGroupFlag = true;
// If lastGroupLabel is not yet stored in the List of
// DisplayGroupBeans
// then the beans associated with that label (DisplayGroupBeans
// and
// FormGroupBeans) have to be initialized.
// Otherwise, just store the new displayitembean in the existing
// FormGroupBean/DisplayFormGroupBean
disFgBean = getGroupFromLabel(latestGroupLabel, groupBeans);
// then a new one has to be initialized for this DisplayItemBean
if (!(disFgBean.getItemGroupBean().getName().length() > 0)) {
// Get FormGroupBean from group label
fgBean = initFormGroupFromMap(latestGroupLabel, groupsMap);
ordinal++;
fgBean.getMeta().setOrdinal(ordinal);
disFgBean.setItemGroupBean(fgBean);
disFgBean.setGroupMetaBean(fgBean.getMeta());
groupBeans.add(disFgBean);
}
} else {
// if there is no group label associated with the
// DisplayItemBean, then it
// does not have a group; it is an "orphaned" item. In this
// case, create a
// DisplayFormGroup with a group label signified with an empty
// string. This
// "group" will hold the orphaned items. What if there are
// orphaned items
// in the spreadsheet that are divided by grouped items? Then
// these orphaned
// items have to be in separate DisplayFormGroups. To handle
// this case, the
// code checks the validGroupFlag boolean variable. if "true,"
// indicating that
// non-orphaned beans have just been processed, then create a
// new
// DisplayFormGroup for these orphaned items.
boolean isFirst = isFirstUngroupedItem(groupBeans);
if (validGroupFlag || isFirst) {
disFgBean = new DisplayItemGroupBean();
fgBean = new ItemGroupBean();
ordinal++;
fgBean.getMeta().setOrdinal(ordinal);
fgBean.setName(UNGROUPED);
disFgBean.setItemGroupBean(fgBean);
disFgBean.setGroupMetaBean(fgBean.getMeta());
groupBeans.add(disFgBean);
} else {
// The existing DisplayFormGroupBean for orphaned items
// is the FormGroupBean containing the highest ordinal, and
// with a group label
// containing an empty string
disFgBean = getLatestDisFormBeanForOrphanedItems(groupBeans);
}
validGroupFlag = false;
}
disFgBean.getItems().add(disBean);
}
return groupBeans;
}
use of org.akaza.openclinica.bean.submit.DisplayItemBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method reshuffleReasonForChangeHashAndDiscrepancyNotes.
private void reshuffleReasonForChangeHashAndDiscrepancyNotes(List<DisplayItemWithGroupBean> allItems, HttpServletRequest request, EventCRFBean ecb) {
int manualRows = 0;
HashMap<String, Boolean> noteSubmitted = (HashMap<String, Boolean>) request.getSession().getAttribute(DataEntryServlet.NOTE_SUBMITTED);
FormDiscrepancyNotes noteTree = (FormDiscrepancyNotes) request.getSession().getAttribute(CreateDiscrepancyNoteServlet.FLAG_DISCREPANCY_RFC);
ArrayList<DiscrepancyNoteBean> fieldNote = null;
String intendedKey = null;
String replacementKey = null;
if ((noteSubmitted == null || noteSubmitted.size() < 1) && (noteTree == null || noteTree.getFieldNotes() == null || noteTree.getFieldNotes().size() < 1)) {
return;
}
for (int i = 0; i < allItems.size(); i++) {
DisplayItemWithGroupBean diwb = allItems.get(i);
if (diwb.isInGroup()) {
List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
for (int j = 0; j < dgbs.size(); j++) {
DisplayItemGroupBean digb = dgbs.get(j);
ItemGroupBean igb = digb.getItemGroupBean();
List<DisplayItemBean> dibs = digb.getItems();
if (j == 0) {
// first repeat
for (DisplayItemBean dib : dibs) {
intendedKey = ecb.getId() + "_" + digb.getInputId() + getInputName(dib);
replacementKey = ecb.getId() + "_" + digb.getItemGroupBean().getOid() + "_" + j + getInputName(dib);
if (!replacementKey.equals(intendedKey)) {
if (noteSubmitted.containsKey(intendedKey)) {
noteSubmitted.put(replacementKey, Boolean.TRUE);
noteSubmitted.remove(intendedKey);
}
if (noteTree.getNotes(intendedKey) != null) {
fieldNote = (ArrayList<DiscrepancyNoteBean>) noteTree.getNotes(intendedKey);
if (fieldNote != null && fieldNote.size() > 0) {
noteTree.getFieldNotes().put(replacementKey, fieldNote);
noteTree.getFieldNotes().remove(intendedKey);
}
//not changing here because this hash should not be used
// noteTree.addIdNote(note.getEntityId(), field);
//
}
}
}
} else {
// everything in between
manualRows++;
for (DisplayItemBean dib : dibs) {
intendedKey = ecb.getId() + "_" + digb.getInputId() + getInputName(dib);
replacementKey = ecb.getId() + "_" + digb.getItemGroupBean().getOid() + "_manual" + (j) + getInputName(dib);
if (!replacementKey.equals(intendedKey)) {
if (noteSubmitted != null && noteSubmitted.containsKey(intendedKey)) {
noteSubmitted.put(replacementKey, Boolean.TRUE);
noteSubmitted.remove(intendedKey);
}
if (noteTree != null && noteTree.getNotes(intendedKey) != null) {
fieldNote = (ArrayList<DiscrepancyNoteBean>) noteTree.getNotes(intendedKey);
if (fieldNote != null && fieldNote.size() > 0) {
noteTree.getFieldNotes().put(replacementKey, fieldNote);
noteTree.getFieldNotes().remove(intendedKey);
}
}
}
}
}
LOGGER.debug("removing: " + intendedKey + " and replacing it with " + replacementKey);
}
}
}
request.getSession().setAttribute(DataEntryServlet.NOTE_SUBMITTED, noteSubmitted);
}
Aggregations