use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ImportDataRuleRunnerContainer method initRuleSetsAndTargets.
/**
* Populate importDataTrueRuleSets and variableAndValue.
* Precondition: import data file passed validation which means all OIDs are not empty.
* @param ds
* @param studyBean
* @param subjectDataBean
* @param ruleSetService
*/
@Transactional
public void initRuleSetsAndTargets(DataSource ds, StudyBean studyBean, SubjectDataBean subjectDataBean, RuleSetServiceInterface ruleSetService) {
this.shouldRunRules = this.shouldRunRules == null ? Boolean.FALSE : this.shouldRunRules;
this.importDataTrueRuleSets = this.importDataTrueRuleSets == null ? new ArrayList<RuleSetBean>() : this.importDataTrueRuleSets;
this.variableAndValue = this.variableAndValue == null ? new HashMap<String, String>() : this.variableAndValue;
studyOid = studyBean.getOid();
studySubjectOid = subjectDataBean.getSubjectOID();
StudySubjectBean studySubject = new StudySubjectDAO<String, ArrayList>(ds).findByOid(studySubjectOid);
HashMap<String, StudyEventDefinitionBean> seds = new HashMap<String, StudyEventDefinitionBean>();
HashMap<String, CRFVersionBean> cvs = new HashMap<String, CRFVersionBean>();
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
String sedOid = studyEventDataBean.getStudyEventOID();
StudyEventDefinitionBean sed;
if (seds.containsKey(sedOid))
sed = seds.get(sedOid);
else {
sed = new StudyEventDefinitionDAO<String, ArrayList>(ds).findByOid(sedOid);
seds.put(sedOid, sed);
}
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
for (FormDataBean formDataBean : formDataBeans) {
String cvOid = formDataBean.getFormOID();
CRFVersionBean crfVersion;
if (cvs.containsKey(cvOid))
crfVersion = cvs.get(cvOid);
else {
crfVersion = new CRFVersionDAO<String, ArrayList>(ds).findByOid(cvOid);
cvs.put(cvOid, crfVersion);
}
String sedOrd = studyEventDataBean.getStudyEventRepeatKey();
Integer sedOrdinal = sedOrd != null && !sedOrd.isEmpty() ? Integer.valueOf(sedOrd) : 1;
StudyEventBean studyEvent = (StudyEventBean) new StudyEventDAO(ds).findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubject.getId(), sed.getId(), sedOrdinal);
List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByCrfStudyAndStudyEventDefinition(studyBean, sed, crfVersion);
// Set<String> targetItemOids = new HashSet<String>();
if (ruleSets != null && !ruleSets.isEmpty()) {
ruleSets = filterByImportDataEntryTrue(ruleSets);
if (ruleSets != null && !ruleSets.isEmpty()) {
ruleSets = ruleSetService.filterByStatusEqualsAvailable(ruleSets);
ruleSets = ruleSetService.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEvent, crfVersion, sed);
// ruleSets = ruleSetService.filterRuleSetsByHiddenItems(ruleSets, eventCrfBean, crfVersion, new ArrayList<ItemBean>());
shouldRunRules = ruleSetService.shouldRunRulesForRuleSets(ruleSets, Phase.IMPORT);
if (shouldRunRules != null && shouldRunRules == Boolean.TRUE) {
// targetItemOids = collectTargetItemOids(ruleSets);
HashMap<String, Integer> grouped = new HashMap<String, Integer>();
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
for (ImportItemDataBean importItemDataBean : itemDataBeans) {
// if(targetItemOids.contains(importItemDataBean.getItemOID())) {
ItemBean item = new ItemDAO<String, ArrayList>(ds).findByOid(importItemDataBean.getItemOID()).get(0);
String igOid = itemGroupDataBean.getItemGroupOID();
String igOrd = itemGroupDataBean.getItemGroupRepeatKey();
Integer igOrdinal = igOrd != null && !igOrd.isEmpty() ? Integer.valueOf(igOrd) : 1;
// logic from DataEntryServlet method: populateRuleSpecificHashMaps()
if (isRepeatIGForSure(ds, crfVersion.getId(), igOid, igOrdinal, item.getId())) {
String key1 = igOid + "[" + igOrdinal + "]." + importItemDataBean.getItemOID();
String key = igOid + "." + importItemDataBean.getItemOID();
variableAndValue.put(key1, importItemDataBean.getValue());
if (grouped.containsKey(key)) {
grouped.put(key, grouped.get(key) + 1);
} else {
grouped.put(key, 1);
}
} else {
variableAndValue.put(importItemDataBean.getItemOID(), importItemDataBean.getValue());
grouped.put(importItemDataBean.getItemOID(), 1);
}
//
// }
}
}
ruleSets = ruleSetService.solidifyGroupOrdinalsUsingFormProperties(ruleSets, grouped);
importDataTrueRuleSets.addAll(ruleSets);
}
}
}
}
}
}
use of org.akaza.openclinica.dao.submit.ItemDAO 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.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class DataEntryServlet method getDisplayBean.
/**
* Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
* @param request TODO
* @param isSubmitted TODO
*/
protected DisplaySectionBean getDisplayBean(boolean hasGroup, boolean includeUngroupedItems, HttpServletRequest request, boolean isSubmitted) throws Exception {
DisplaySectionBean section = new DisplaySectionBean();
FormProcessor fp = new FormProcessor(request);
HttpSession session = request.getSession();
Locale loc = this.locale == null ? LocaleResolver.getLocale(request) : this.locale;
StudyBean study = (StudyBean) session.getAttribute("study");
SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
SectionDAO sdao;
// Find out whether there are ungrouped items in this section
boolean hasUngroupedItems = false;
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
if (eventDefinitionCRFId <= 0) {
// TODO: this block of code repeats
// many times, need to clean up
// synchronized(this)
{
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
eventDefinitionCRFId = edcBean.getId();
}
}
LOGGER.trace("eventDefinitionCRFId " + eventDefinitionCRFId);
// Use this class to find out whether there are ungrouped items in this
// section
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
if (hasGroup) {
DisplaySectionBean newDisplayBean = new DisplaySectionBean();
if (includeUngroupedItems) {
// Null values: this method adds null values to the
// displayitembeans
newDisplayBean = formBeanUtil.createDisplaySectionBWithFormGroups(sb.getId(), ecb.getCRFVersionId(), getDataSource(), eventDefinitionCRFId, ecb, getServletContext());
} else {
newDisplayBean = formBeanUtil.createDisplaySectionWithItemGroups(study, sb.getId(), ecb, ecb.getStudyEventId(), sm, eventDefinitionCRFId, getServletContext());
}
itemGroups = newDisplayBean.getDisplayFormGroups();
// setDataForDisplayItemGroups(itemGroups, sb,ecb,sm);
LOGGER.trace("found item group size: " + itemGroups.size() + " and to string: " + itemGroups.toString());
section.setDisplayFormGroups(itemGroups);
}
// Find out whether any display items are *not* grouped; see issue 1689
hasUngroupedItems = formBeanUtil.sectionHasUngroupedItems(getDataSource(), sb.getId(), itemGroups);
sdao = new SectionDAO(getDataSource());
//
sb.setHasSCDItem(hasUngroupedItems ? sdao.hasSCDItem(sb.getId()) : false);
section.setEventCRF(ecb);
if (sb.getParentId() > 0) {
SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
sb.setParent(parent);
}
section.setSection(sb);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
section.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(getDataSource());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
section.setCrf(cb);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
// EventDefinitionCRFBean edcb =
// edcdao.findByStudyEventIdAndCRFVersionId(study,
// ecb.getStudyEventId(), cvb.getId());
section.setEventDefinitionCRF(edcb);
// setup DAO's here to avoid creating too many objects
ItemDAO idao = new ItemDAO(getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), loc);
// Use itemGroups to determine if there are any ungrouped items
// get all the parent display item beans not in group
logMe("Entering getParentDisplayItems::: Thread is? " + Thread.currentThread());
ArrayList displayItems = getParentDisplayItems(hasGroup, sb, edcb, idao, ifmdao, iddao, hasUngroupedItems, request);
logMe("Entering getParentDisplayItems::: Done and Thread is? " + Thread.currentThread());
LOGGER.debug("just ran get parent display, has group " + hasGroup + " has ungrouped " + hasUngroupedItems);
// now sort them by ordinal,
// JN: Commenting out this logic, its wrong and will give erroneous results.
Collections.sort(displayItems);
// now get the child DisplayItemBeans
for (int i = 0; i < displayItems.size(); i++) {
DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
//
if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
if (shouldLoadDBValues(dib) && !isSubmitted) {
dib.loadDBValue();
}
} else {
if (shouldLoadDBValues(dib)) {
LOGGER.trace("should load db values is true, set value");
dib.loadDBValue();
LOGGER.trace("just got data loaded: " + dib.getData().getValue());
}
}
displayItems.set(i, dib);
}
section.setItems(displayItems);
return section;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class DataEntryServlet method loadItemsWithGroupRows.
protected void loadItemsWithGroupRows(DisplayItemWithGroupBean itemWithGroup, SectionBean sb, EventDefinitionCRFBean edcb, EventCRFBean ecb, HttpServletRequest request) {
// this method is a copy of the method: createItemWithGroups ,
// only modified for load one DisplayItemWithGroupBean.
//
ItemDAO idao = new ItemDAO(getDataSource());
// For adding null values to display items
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<String> nullValuesList = new ArrayList<String>();
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(edcb.getId(), getDataSource());
// >>BWP
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ArrayList data = iddao.findAllActiveBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
DisplayItemGroupBean itemGroup = itemWithGroup.getItemGroup();
// to arrange item groups and other single items, the ordinal of
// a item group will be the ordinal of the first item in this
// group
DisplayItemBean firstItem = itemGroup.getItems().get(0);
DisplayItemBean checkItem = firstItem;
// does not work if there is not any data in the first item of the group
// i.e. imports.
// does it make a difference if we take a last item?
boolean noNeedToSwitch = false;
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
if (idb.getItemId() == firstItem.getItem().getId()) {
noNeedToSwitch = true;
}
}
if (!noNeedToSwitch) {
checkItem = itemGroup.getItems().get(itemGroup.getItems().size() - 1);
}
// so we are either checking the first or the last item, BUT ONLY ONCE
itemWithGroup.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
itemWithGroup.setItemGroup(itemGroup);
itemWithGroup.setInGroup(true);
itemWithGroup.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
List<ItemBean> itBeans = idao.findAllItemsByGroupId(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
boolean hasData = false;
int checkAllColumns = 0;
// first item should be same as the row number
for (int i = 0; i < data.size(); i++) {
ItemDataBean idb = (ItemDataBean) data.get(i);
LOGGER.debug("check all columns: " + checkAllColumns);
if (idb.getItemId() == checkItem.getItem().getId()) {
hasData = true;
LOGGER.debug("set has data to --TRUE--");
checkAllColumns = 0;
// so that we only fire once a row
LOGGER.debug("has data set to true");
DisplayItemGroupBean digb = new DisplayItemGroupBean();
// always get a fresh copy for items, may use other
// better way to
// do deep copy, like clone
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), edcb, 0, getServletContext());
digb.setItems(dibs);
LOGGER.trace("set with dibs list of : " + dibs.size());
digb.setGroupMetaBean(runDynamicsCheck(itemGroup.getGroupMetaBean(), request));
digb.setItemGroupBean(itemGroup.getItemGroupBean());
itemWithGroup.getItemGroups().add(digb);
itemWithGroup.getDbItemGroups().add(digb);
}
}
List<DisplayItemGroupBean> groupRows = itemWithGroup.getItemGroups();
LOGGER.trace("how many group rows:" + groupRows.size());
LOGGER.trace("how big is the data:" + data.size());
if (hasData) {
// the group
for (int i = 0; i < groupRows.size(); i++) {
DisplayItemGroupBean displayGroup = groupRows.get(i);
for (DisplayItemBean dib : displayGroup.getItems()) {
for (int j = 0; j < data.size(); j++) {
ItemDataBean idb = (ItemDataBean) data.get(j);
if (idb.getItemId() == dib.getItem().getId() && !idb.isSelected()) {
idb.setSelected(true);
dib.setData(idb);
LOGGER.debug("--> set data " + idb.getId() + ": " + idb.getValue());
if (shouldLoadDBValues(dib)) {
LOGGER.debug("+++should load db values is true, set value");
dib.loadDBValue();
LOGGER.debug("+++data loaded: " + idb.getName() + ": " + idb.getOrdinal() + " " + idb.getValue());
LOGGER.debug("+++try dib OID: " + dib.getItem().getOid());
}
break;
}
}
}
}
} else {
// no data, still add a blank row for displaying
DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
digb2.setItems(dibs);
LOGGER.trace("set with nullValuesList of : " + nullValuesList);
digb2.setEditFlag("initial");
digb2.setGroupMetaBean(itemGroup.getGroupMetaBean());
digb2.setItemGroupBean(itemGroup.getItemGroupBean());
itemWithGroup.getItemGroups().add(digb2);
itemWithGroup.getDbItemGroups().add(digb2);
}
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class DataEntryServlet method saveItemsToMarkComplete.
/**
* 06/13/2007- jxu Since we don't require users to review each section before mark a CRF as complete, we need to create item data in the database because
* items will not be created unless the section which contains the items is reviewed by users
* @param request TODO
*/
private boolean saveItemsToMarkComplete(Status completeStatus, HttpServletRequest request) throws Exception {
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionDAO sdao = new SectionDAO(getDataSource());
ArrayList sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ItemDAO idao = new ItemDAO(getDataSource());
for (int i = 0; i < sections.size(); i++) {
SectionBean sb = (SectionBean) sections.get(i);
if (!isCreateItemReqd(sb, request)) {
// ArrayList requiredItems =
// idao.findAllRequiredBySectionId(sb.getId());
// if (!requiredItems.isEmpty()) {
// return false;
// }
ArrayList items = idao.findAllBySectionId(sb.getId());
for (int j = 0; j < items.size(); j++) {
ItemBean item = (ItemBean) items.get(j);
ArrayList<ItemDataBean> itemBean = iddao.findAllByEventCRFIdAndItemIdNoStatus(ecb.getId(), item.getId());
ItemDataBean idb = new ItemDataBean();
idb.setItemId(item.getId());
idb.setEventCRFId(ecb.getId());
idb.setCreatedDate(new Date());
idb.setOrdinal(1);
idb.setOwner(ub);
if (completeStatus != null) {
// to avoid null exception
idb.setStatus(completeStatus);
} else {
idb.setStatus(Status.UNAVAILABLE);
}
idb.setValue("");
boolean save = true;
if (itemBean.size() > 0)
save = false;
/* while(itemBean.iterator().hasNext())
{
ItemDataBean temp = itemBean.iterator().next();
if(idb.getEventCRFId()==(temp.getEventCRFId()))
{
if(idb.getItemId()==(temp.getItemId())){
save = false;
}
}
}*/
if (save) {
iddao.create(idb);
}
}
}
}
return true;
}
Aggregations