Search in sources :

Example 61 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class DataImportService method submitData.

public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
    boolean discNotesGenerated = false;
    ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
    itemDataDao.setFormatDates(false);
    EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
    StringBuffer auditMsg = new StringBuffer();
    int eventCrfBeanId = -1;
    EventCRFBean eventCrfBean = null;
    ArrayList<Integer> eventCrfInts;
    ItemDataBean itemDataBean;
    CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
    for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
        boolean resetSDV = false;
        logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
        if (wrapper.isSavable()) {
            eventCrfInts = new ArrayList<Integer>();
            logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
            if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
                return getReturnList("fail", "", "No items to submit. Please check your XML.");
            }
            for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
                eventCrfBeanId = displayItemBean.getData().getEventCRFId();
                eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
                logger.debug("found value here: " + displayItemBean.getData().getValue());
                logger.debug("found status here: " + eventCrfBean.getStatus().getName());
                itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
                    if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
                        resetSDV = true;
                    logger.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
                    itemDataBean.setUpdatedDate(new Date());
                    itemDataBean.setUpdater(userBean);
                    itemDataBean.setValue(displayItemBean.getData().getValue());
                    // set status?
                    itemDataDao.update(itemDataBean);
                    logger.debug("updated: " + itemDataBean.getItemId());
                    // need to set pk here in order to create dn
                    displayItemBean.getData().setId(itemDataBean.getId());
                } else {
                    resetSDV = true;
                    itemDataDao.create(displayItemBean.getData());
                    logger.debug("created: " + displayItemBean.getData().getItemId());
                    itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                    // logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
                    displayItemBean.getData().setId(itemDataBean.getId());
                }
                ItemDAO idao = new ItemDAO(dataSource);
                ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
                // logger.debug("*** checking for validation errors: " + ibean.getName());
                String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
                // wrapper.getValidationErrors().toString());
                if (wrapper.getValidationErrors().containsKey(itemOid)) {
                    ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
                    for (String message : messageList) {
                        DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
                        createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
                        discNotesGenerated = true;
                        logger.debug("*** created disc note with message: " + message);
                        auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
                    // split by this ? later, tbh
                    // displayItemBean);
                    }
                }
                if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
                    String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
                    if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
                        crfBusinessLogicHelper.markCRFStarted(eventCrfBean, userBean, true);
                    } else {
                        crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
                    }
                    eventCrfInts.add(new Integer(eventCrfBean.getId()));
                }
            }
            // Reset the SDV status if item data has been changed or added
            if (eventCrfBean != null && resetSDV)
                eventCrfDao.setSDVStatus(false, userBean.getId(), eventCrfBean.getId());
        }
    }
    if (!discNotesGenerated) {
        return getReturnList("success", "", auditMsg.toString());
    } else {
        return getReturnList("warn", "", auditMsg.toString());
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) CrfBusinessLogicHelper(org.akaza.openclinica.web.job.CrfBusinessLogicHelper) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)

Example 62 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class ImportHelper method validateDisplayItemBeanMultipleCV.

/**
     * 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 validateDisplayItemBeanMultipleCV(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 {
    // comment this out since it should be a hard edit check, tbh
    // 05/2008
    // v.addValidation(inputName, Validator.IN_RESPONSE_SET,
    // dib.getMetadata().getResponseSet());
    }
    return dib;
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 63 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class ExpressionService method getValueFromDb.

private String getValueFromDb(String expression, List<ItemDataBean> itemData, Map<Integer, ItemBean> itemBeans) throws OpenClinicaSystemException {
    if (isExpressionPartial(expression)) {
        throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
    }
    try {
        Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
        ItemDataBean itemDataBean = itemData.get(index);
        String value = itemData.get(index).getValue();
        if (itemBeans.containsKey(itemDataBean.getItemId())) {
            value = ifValueIsDate(itemBeans.get(itemDataBean.getItemId()), value);
        }
        return value;
    } catch (NullPointerException npe) {
        logger.error("NullPointerException was thrown ");
        return null;
    } catch (IndexOutOfBoundsException ioobe) {
        logger.error("IndexOutOfBoundsException was thrown ");
        return null;
    }
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 64 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class ItemDataDAOTest method test_itemDataDaoTest_.

// Scenario
// Cannot insert a value using rule into a PDATE field from another PDATE field
public void test_itemDataDaoTest_() {
    ResourceBundleProvider.updateLocale(new Locale("en"));
    ItemDataDAO itemDataDAO = new ItemDataDAO(null);
    ItemDataBean idb = new ItemDataBean();
    idb.setValue("05-Sep-2014");
    ItemDataBean result1 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "dd-MMM-yyyy", ItemDataType.DATE);
    assertEquals("2014-09-05", result1.getValue());
    idb.setValue("2014-09-05");
    ItemDataBean result2 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "yyyy-MM-dd", ItemDataType.DATE);
    assertEquals("2014-09-05", result2.getValue());
    idb.setValue("05-Sep-2014");
    ItemDataBean result3 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "PDATE DOES NOT USE FORMAT", ItemDataType.PDATE);
    assertEquals("2014-09-05", result3.getValue());
    idb.setValue("2014-09-05");
    ItemDataBean result4 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "PDATE DOES NOT USE FORMAT", ItemDataType.PDATE);
    assertNotSame("2014-09-05", result4.getValue());
    idb.setValue("Sep-2014");
    ItemDataBean result5 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "PDATE DOES NOT USE FORMAT", ItemDataType.PDATE);
    assertEquals("2014-09", result5.getValue());
    idb.setValue("2014-09");
    ItemDataBean result6 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "PDATE DOES NOT USE FORMAT", ItemDataType.PDATE);
    assertNotSame("2014-09", result6.getValue());
    idb.setValue("2014");
    ItemDataBean result7 = itemDataDAO.setItemDataBeanIfDateOrPdate(idb, "PDATE DOES NOT USE FORMAT", ItemDataType.PDATE);
    assertEquals("2014", result7.getValue());
}
Also used : Locale(java.util.Locale) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 65 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class RuleExecutionBusinessObject method initializeRule.

public void initializeRule(RuleBean rule) {
    // source data
    // ItemDataBean sourceItemDataBean = rule.getSourceItemDataBean();
    ItemDataBean sourceItemDataBean = null;
    // target data
    // ItemDataBean targetItemDataBean = rule.getTargetItemDataBean();
    ItemDataBean targetItemDataBean = null;
    // fireRules on source & target
    // TODO KK FIX HERE
    // fireRule(sourceItemDataBean,rule.getSourceItemValue(),sourceItemFormMetadataBean,rule.getSourceOperator());
    boolean sourceResult = true;
    // fireRule(targetItemDataBean,rule.getTargetItemValue(),targetItemFormMetadataBean,rule.getTargetOperator());
    boolean targetResult = true;
    if (sourceResult && targetResult) {
    // We are good
    }
    if (sourceResult == true && targetResult == false) {
        // file a descrepancy Note
        createDiscrepancyNote(rule.toString(), targetItemDataBean, sourceItemDataBean);
    }
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Aggregations

ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)133 ArrayList (java.util.ArrayList)74 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)64 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)61 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)42 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)41 HashMap (java.util.HashMap)39 Date (java.util.Date)37 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)37 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)33 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)33 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)26 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)26 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)26 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)21 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)20 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)20 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)18