use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class CRFVersionMetadataUtil method retrieveFormMetadata.
/**
* Builds and returns an ArrayList of SectionBeans that comprise the metadata of a CRFVersion.
*/
public ArrayList<SectionBean> retrieveFormMetadata(CRFVersionBean version) throws Exception {
ItemDAO idao = new ItemDAO(dataSource);
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(dataSource);
// tbh, 102007
SectionDAO sdao = new SectionDAO(dataSource);
ItemGroupDAO igdao = new ItemGroupDAO(dataSource);
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO(dataSource);
ArrayList sections = (ArrayList) sdao.findByVersionId(version.getId());
HashMap versionMap = new HashMap();
for (int i = 0; i < sections.size(); i++) {
SectionBean section = (SectionBean) sections.get(i);
versionMap.put(new Integer(section.getId()), section.getItems());
// YW 08-21-2007, add group metadata
ArrayList<ItemGroupBean> igs = (ArrayList<ItemGroupBean>) igdao.findGroupBySectionId(section.getId());
for (int j = 0; j < igs.size(); ++j) {
ArrayList<ItemGroupMetadataBean> igms = (ArrayList<ItemGroupMetadataBean>) igmdao.findMetaByGroupAndSection(igs.get(j).getId(), section.getCRFVersionId(), section.getId());
if (!igms.isEmpty()) {
// Note, the following logic has been adapted here -
// "for a given crf version,
// all the items in the same group have the same group
// metadata
// so we can get one of them and set metadata for the
// group"
igs.get(j).setMeta(igms.get(0));
igs.get(j).setItemGroupMetaBeans(igms);
}
}
((SectionBean) sections.get(i)).setGroups(igs);
// YW >>
}
ArrayList items = idao.findAllItemsByVersionId(version.getId());
// then different query will be used
if (igmdao.versionIncluded(version.getId())) {
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), version.getId());
item.setItemMeta(ifm);
// logger.info("option******" +
// ifm.getResponseSet().getOptions().size());
ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
its.add(item);
}
} else {
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionIdNotInIGM(item.getId(), version.getId());
item.setItemMeta(ifm);
// logger.info("option******" +
// ifm.getResponseSet().getOptions().size());
ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
its.add(item);
}
}
for (int i = 0; i < sections.size(); i++) {
SectionBean section = (SectionBean) sections.get(i);
section.setItems((ArrayList) versionMap.get(new Integer(section.getId())));
}
return sections;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class CreateFiltersTwoServlet method processRequest.
// < ResourceBundle restext,resword,respage,resexception;
@Override
public void processRequest() throws Exception {
// we can't get to here without an action:
// begin--takes us to specify parameters,
// where the user will select CRF, then section,
// then parameters of the section: a little tricky
// to do entirely with javascript, but can be done.
// possible to set up the CRF-section relationship,
// and then have a screen 3.5 with the parameters?
// criteria--takes us to specify criteria, that is,
// to specify and, or, not and, etc. here we'll take the
// list we just generated online and generate a chain
// of filterobjectbeans, which will in turn,
// generate the SQL add on for the dataset.
String action = request.getParameter("action");
StudyBean studyWithEventDefs = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefs = new StudyBean();
studyWithEventDefs.setId(currentStudy.getParentStudyId());
}
if (StringUtil.isBlank(action)) {
// throw an error
} else if ("begin".equalsIgnoreCase(action)) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
HashMap events = sedao.findCRFsByStudy(studyWithEventDefs);
// if events are empty -- resend to first filter page with message
if (events.isEmpty()) {
addPageMessage(respage.getString("no_CRF_assigned_pick_another"));
FormProcessor fp = new FormProcessor(request);
FilterDAO fdao = new FilterDAO(sm.getDataSource());
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList filters = (ArrayList) fdao.findAll();
ArrayList filterRows = FilterRow.generateRowsFromBeans(filters);
String[] columns = { resword.getString("filter_name"), resword.getString("description"), resword.getString("created_by"), resword.getString("created_date"), resword.getString("status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(5);
table.addLink(resword.getString("create_new_filter"), "CreateFiltersOne?action=begin");
table.setQuery("CreateFiltersOne", new HashMap());
table.setRows(filterRows);
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.CREATE_FILTER_SCREEN_1);
} else {
// else, send to the following page:
request.setAttribute("events", events);
forwardPage(Page.CREATE_FILTER_SCREEN_3);
}
} else if ("crfselected".equalsIgnoreCase(action)) {
// get the crf id, return to a new page with sections
// and parameters attached, tbh
FormProcessor fp = new FormProcessor(request);
HashMap errors = new HashMap();
int crfId = fp.getInt("crfId");
if (crfId > 0) {
CRFVersionDAO cvDAO = new CRFVersionDAO(sm.getDataSource());
CRFDAO cDAO = new CRFDAO(sm.getDataSource());
SectionDAO secDAO = new SectionDAO(sm.getDataSource());
Collection sections = secDAO.findByVersionId(crfId);
CRFVersionBean cvBean = (CRFVersionBean) cvDAO.findByPK(crfId);
CRFBean cBean = (CRFBean) cDAO.findByPK(cvBean.getCrfId());
request.setAttribute("sections", sections);
session.setAttribute("cBean", cBean);
// for further pages,
session.setAttribute("cvBean", cvBean);
// tbh
forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
} else {
addPageMessage(respage.getString("select_a_CRF_before_picking"));
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
HashMap events = sedao.findCRFsByStudy(studyWithEventDefs);
request.setAttribute("events", events);
forwardPage(Page.CREATE_FILTER_SCREEN_3);
}
} else if ("sectionselected".equalsIgnoreCase(action)) {
// TODO set the crf and the section into session,
// allow for the user to go back and forth,
// set up the questions to be picked,
// allow the user to move on to create_filter_screen_4
FormProcessor fp = new FormProcessor(request);
int sectionId = fp.getInt("sectionId");
if (sectionId > 0) {
SectionDAO secDAO = new SectionDAO(sm.getDataSource());
SectionBean secBean = (SectionBean) secDAO.findByPK(sectionId);
session.setAttribute("secBean", secBean);
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
Collection metadatas = ifmDAO.findAllBySectionId(sectionId);
if (metadatas.size() > 0) {
request.setAttribute("metadatas", metadatas);
forwardPage(Page.CREATE_FILTER_SCREEN_3_2);
} else {
CRFVersionBean cvBean = (CRFVersionBean) session.getAttribute("cvBean");
addPageMessage(respage.getString("section_not_have_questions_select_another"));
// SectionDAO secDAO = new SectionDAO(sm.getDataSource());
Collection sections = secDAO.findByVersionId(cvBean.getId());
request.setAttribute("sections", sections);
forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
}
} else {
CRFVersionBean cvBean = (CRFVersionBean) session.getAttribute("cvBean");
addPageMessage(respage.getString("select_section_before_select_question"));
SectionDAO secDAO = new SectionDAO(sm.getDataSource());
Collection sections = secDAO.findByVersionId(cvBean.getId());
request.setAttribute("sections", sections);
forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
}
} else if ("questionsselected".equalsIgnoreCase(action)) {
ArrayList alist = this.extractIdsFromForm();
// and send the user to create_filter_screen_4
if (alist.size() > 0) {
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
Collection questions = ifmDAO.findByMultiplePKs(alist);
session.setAttribute("questions", questions);
forwardPage(Page.CREATE_FILTER_SCREEN_4);
} else {
SectionBean secBean = (SectionBean) session.getAttribute("secBean");
addPageMessage(respage.getString("select_questions_before_set_parameters"));
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
Collection metadatas = ifmDAO.findAllBySectionId(secBean.getId());
request.setAttribute("metadatas", metadatas);
forwardPage(Page.CREATE_FILTER_SCREEN_3_2);
}
} else if ("validatecriteria".equalsIgnoreCase(action)) {
// TODO look at the criteria and create a list of filterobjectdata
// beans, so that we can create the SQL later on in
// the process.
// also, throw the user back to the process or throw
// them forward into the createServletThree process
FormProcessor fp = new FormProcessor(request);
String logical = fp.getString("logical");
ArrayList questions = (ArrayList) session.getAttribute("questions");
ArrayList filterobjects = new ArrayList();
// (ArrayList)session.getAttribute("filterobjects");
Iterator q_it = questions.iterator();
int arrCnt = 0;
while (q_it.hasNext()) {
ItemFormMetadataBean ifmBean = (ItemFormMetadataBean) q_it.next();
String opString = "operator:" + ifmBean.getId();
String valString = "value:" + ifmBean.getId();
String remString = "remove:" + ifmBean.getId();
if ("remove".equals(fp.getString(remString))) {
logger.info("found the string: " + remString);
// TODO remove the question from from the list,
// redirect to that page again????? <--maybe not?
// questions.remove(arrCnt);
// shouldn't have to remove the above, just do nothing
arrCnt++;
} else {
String operator = fp.getString(opString);
String value = fp.getString(valString);
FilterObjectBean fob = new FilterObjectBean();
fob.setItemId(ifmBean.getId());
fob.setItemName(ifmBean.getHeader() + " " + ifmBean.getLeftItemText() + " " + ifmBean.getRightItemText());
// case operator:
if ("equal to".equalsIgnoreCase(operator)) {
fob.setOperand("=");
} else if ("greater than".equalsIgnoreCase(operator)) {
fob.setOperand(">");
} else if ("less than".equalsIgnoreCase(operator)) {
fob.setOperand("<");
} else if ("greater than or equal".equalsIgnoreCase(operator)) {
fob.setOperand(">=");
} else if ("less than or equal".equalsIgnoreCase(operator)) {
fob.setOperand("<=");
} else if ("like".equalsIgnoreCase(operator)) {
fob.setOperand(" like ");
} else if ("not like".equalsIgnoreCase(operator)) {
fob.setOperand(" not like ");
} else {
fob.setOperand("!=");
}
fob.setValue(value);
filterobjects.add(fob);
}
// end else
//
}
// end while
session.setAttribute("questions", questions);
// TODO where does the connector come into play?
// session.setAttribute("filterobjects",filterobjects);
FilterDAO fDAO = new FilterDAO(sm.getDataSource());
String newSQL = (String) session.getAttribute("newSQL");
ArrayList newExp = (ArrayList) session.getAttribute("newExp");
// human readable explanation
String newNewSQL = fDAO.genSQLStatement(newSQL, logical, filterobjects);
ArrayList newNewExp = fDAO.genExplanation(newExp, logical, filterobjects);
if (arrCnt == questions.size()) {
newNewSQL = newSQL;
newNewExp = newExp;
// don't change anything, if we've removed everything from this
// list
}
logger.info("new SQL Generated: " + newNewSQL);
String sub = fp.getString("submit");
if ("Specify Filter Metadata".equals(sub)) {
// add new params, create the filter object,
// and go to create metadata
FilterBean fb = new FilterBean();
fb.setSQLStatement(newNewSQL + ")");
// adding parens here to finish off other
// statement--might add first part of statement here
// for legibility's sake
// tbh 06-02-2005
session.removeAttribute("newSQL");
// end of the road
session.setAttribute("newFilter", fb);
request.setAttribute("statuses", getStatuses());
forwardPage(Page.CREATE_FILTER_SCREEN_5);
} else {
// replace the 'old' sql with the new sql gathered from the
// session
session.setAttribute("newSQL", newNewSQL);
session.setAttribute("newExp", newNewExp);
// add new params, and go back
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
HashMap events = sedao.findCRFsByStudy(currentStudy);
//
request.setAttribute("events", events);
forwardPage(Page.CREATE_FILTER_SCREEN_3);
}
}
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method isEachRequiredFieldFillout.
protected boolean isEachRequiredFieldFillout(HttpServletRequest request) {
HttpSession session = request.getSession();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
// need to update this method to accomodate dynamics, tbh
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ItemDAO idao = new ItemDAO(getDataSource());
ItemFormMetadataDAO itemFormMetadataDao = new ItemFormMetadataDAO(getDataSource());
// Below code will iterate all shown and hidden required fields/items in a crf version and verify if the data field is filled up with value or if not , then it is a hidden field with no show rule triggered for the item.
ArrayList<ItemFormMetadataBean> shownRequiredAllItemsInCrfVersion = itemFormMetadataDao.findAllItemsRequiredAndShownByCrfVersionId(ecb.getCRFVersionId());
ArrayList<ItemFormMetadataBean> hiddenRequiredAllItemsInCrfVersion = itemFormMetadataDao.findAllItemsRequiredAndHiddenByCrfVersionId(ecb.getCRFVersionId());
ItemGroupMetadataDAO<String, ArrayList> igdao = new ItemGroupMetadataDAO<String, ArrayList>(dataSource);
ArrayList<ItemDataBean> itemdatas = null;
for (ItemFormMetadataBean shownItemMeta : shownRequiredAllItemsInCrfVersion) {
ItemGroupMetadataBean igBean = (ItemGroupMetadataBean) igdao.findByItemAndCrfVersion(shownItemMeta.getItemId(), ecb.getCRFVersionId());
// verifies if the group that the item belongs to is not hidden.
if (igBean != null && igBean.isShowGroup()) {
itemdatas = iddao.findAllByEventCRFIdAndItemId(ecb.getId(), shownItemMeta.getItemId());
if (itemdatas == null || itemdatas.size() == 0)
return false;
for (ItemDataBean itemdata : itemdatas) {
System.out.println(itemdata.getItemId() + " : " + itemdata.getValue());
if ((itemdata.getValue() == null || itemdata.getValue().equals("") || itemdata.getValue().trim().length() == 0) && dndao.findNumExistingNotesForItem(itemdata.getId()) < 1) {
return false;
}
}
}
ArrayList<DynamicsItemFormMetadataBean> dynamicsItemFormMetadataBeans = null;
for (ItemFormMetadataBean hiddenItemMeta : hiddenRequiredAllItemsInCrfVersion) {
itemdatas = iddao.findAllByEventCRFIdAndItemId(ecb.getId(), hiddenItemMeta.getItemId());
dynamicsItemFormMetadataBeans = getItemMetadataService().getDynamicsItemFormMetadataDao().findByItemAndEventCrfShown(ecb, hiddenItemMeta.getItemId());
if (itemdatas.size() == 0 && dynamicsItemFormMetadataBeans.size() > 0) {
return false;
}
for (ItemDataBean itemdata : itemdatas) {
if ((itemdata.getValue() == null || itemdata.getValue().equals("") || itemdata.getValue().trim().length() == 0) && dndao.findNumExistingNotesForItem(itemdata.getId()) < 1 && dynamicsItemFormMetadataBeans.size() > 0) {
return false;
}
}
}
}
// had to change the query below to allow for hidden items here, tbh 04/2010
ArrayList allFilled = iddao.findAllBlankRequiredByEventCRFId(ecb.getId(), ecb.getCRFVersionId());
int numNotes = 0;
if (!allFilled.isEmpty()) {
LOGGER.trace("allFilled is not empty");
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
HashMap idNotes = fdn.getIdNotes();
for (int i = 0; i < allFilled.size(); i++) {
ItemDataBean idb = (ItemDataBean) allFilled.get(i);
int exsitingNotes = dndao.findNumExistingNotesForItem(idb.getId());
if (exsitingNotes > 0) {
LOGGER.trace("has existing note");
numNotes++;
} else if (idNotes.containsKey(idb.getId())) {
LOGGER.trace("has note in session");
numNotes++;
}
}
LOGGER.trace("numNotes allFilled.size:" + numNotes + " " + allFilled.size());
if (numNotes >= allFilled.size()) {
LOGGER.trace("all required are filled out");
return true;
} else {
LOGGER.debug("numNotes < allFilled.size() " + numNotes + ": " + allFilled.size());
return false;
}
}
return true;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method buildMatrixForRepeatingGroups.
// @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method buildMatrixForRepeatingGroups
protected DisplayItemWithGroupBean buildMatrixForRepeatingGroups(DisplayItemWithGroupBean diwgb, DisplayItemGroupBean itemGroup, EventCRFBean ecb, SectionBean sb, List<ItemBean> itBeans, Map<String, ItemDataBean> dataMap, List<String> nullValuesList, boolean isSubmitted) {
int tempOrdinal = 1;
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
int maxOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, itemGroup.getItemGroupBean());
// Incase of no data
if (maxOrdinal == 0)
maxOrdinal = 1;
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO<String, ArrayList>(getDataSource());
List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
boolean groupHasData = false;
for (int i = 1; i <= maxOrdinal; i++) {
List<DisplayItemBean> displayItemBeans = new ArrayList<DisplayItemBean>();
DisplayItemGroupBean dig = new DisplayItemGroupBean();
for (ItemBean itBean : itBeans) {
DisplayItemBean displayItemBean = new DisplayItemBean();
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(itBean.getId(), ecb.getCRFVersionId());
// itBean.setItemMeta(ifm);//TODO:remove this or the one down displayItemBean.setMetadata(ifm);
displayItemBean.setMetadata(ifm);
displayItemBean.setItem(itBean);
ItemDataBean itemData = dataMap.get(itBean.getId() + "," + i);
if (itemData != null) {
// to indicate any item in the group has data;
groupHasData = true;
displayItemBean.setIsNewItem(false);
}
if (itemData == null) {
itemData = displayItemBean.getData();
itemData.setValue("");
itemData.setOrdinal(i);
}
addNullValues(displayItemBean, nullValuesList);
displayItemBean.setData(itemData);
// displayItemBean.loadDBValue();
if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
if (shouldLoadDBValues(displayItemBean) && !isSubmitted) {
displayItemBean.loadDBValue();
}
} else {
if (shouldLoadDBValues(displayItemBean)) {
LOGGER.trace("should load db values is true, set value");
displayItemBean.loadDBValue();
LOGGER.trace("just got data loaded: " + displayItemBean.getData().getValue());
}
}
displayItemBeans.add(displayItemBean);
}
Collections.sort(displayItemBeans);
dig.setItems(displayItemBeans);
dig.setHasData(groupHasData);
itemGroups.add(dig);
}
diwgb.setItemGroups(itemGroups);
diwgb.setDbItemGroups(itemGroups);
return diwgb;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class DataEntryServlet 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.
*/
protected 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() && ibMeta.isShowItem()) {
v.addValidation(inputName, Validator.IS_REQUIRED);
}
} else {
v.addValidation(inputName, Validator.IN_RESPONSE_SET_SINGLE_VALUE, dib.getMetadata().getResponseSet());
}
customValidation(v, dib, inputName);
return dib;
}
Aggregations