Search in sources :

Example 1 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.

the class ViewCRFServlet method populate.

private Collection<TableColumnHolder> populate(CRFBean crf, ArrayList<FormLayoutBean> versions) {
    HashMap<FormLayoutBean, ArrayList<TableColumnHolder>> hm = new HashMap<FormLayoutBean, ArrayList<TableColumnHolder>>();
    List<TableColumnHolder> tableColumnHolders = new ArrayList<TableColumnHolder>();
    for (FormLayoutBean versionBean : versions) {
        hm.put(versionBean, new ArrayList<TableColumnHolder>());
    }
    List<RuleSetBean> ruleSets = getRuleSetService().getRuleSetsByCrfAndStudy(crf, currentStudy);
    ruleSets = getRuleSetService().filterByStatusEqualsAvailable(ruleSets);
    for (RuleSetBean ruleSetBean : ruleSets) {
        if (ruleSetBean.getCrfVersion() == null) {
            for (FormLayoutBean version : versions) {
                hm.get(version).addAll(createFromRuleSet(ruleSetBean, version));
            }
        }
        if (ruleSetBean.getCrfVersion() != null) {
            hm.get(ruleSetBean.getCrfVersion()).addAll(createFromRuleSet(ruleSetBean, ruleSetBean.getFormLayout()));
        }
    }
    for (ArrayList<TableColumnHolder> list : hm.values()) {
        tableColumnHolders.addAll(list);
    }
    return tableColumnHolders;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 2 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean 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);
                    }
                }
            }
        }
    }
}
Also used : ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.

the class RuleSetAuditDaoTest method testFindAllByRuleSet.

public void testFindAllByRuleSet() {
    // RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
    // RuleSetAuditDao ruleSetAuditDao = (RuleSetAuditDao) getContext().getBean("ruleSetAuditDao");
    RuleSetBean ruleSet = ruleSetDao.findById(-1);
    List<RuleSetAuditBean> ruleSetAudits = ruleSetAuditDao.findAllByRuleSet(ruleSet);
    assertNotNull("ruleSetAudits is null", ruleSetAudits);
    assertEquals("The size of the ruleSetAudits is not 2", new Integer(2), Integer.valueOf(ruleSetAudits.size()));
}
Also used : RuleSetAuditBean(org.akaza.openclinica.domain.rule.RuleSetAuditBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 4 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.

the class RuleSetRuleAuditDaoTest method testFindAllByRuleSet.

public void testFindAllByRuleSet() {
    // RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
    // RuleSetRuleAuditDao ruleSetRuleAuditDao = (RuleSetRuleAuditDao) getContext().getBean("ruleSetRuleAuditDao");
    RuleSetBean ruleSet = ruleSetDao.findById(-1);
    List<RuleSetRuleAuditBean> ruleSetRuleAudits = ruleSetRuleAuditDao.findAllByRuleSet(ruleSet);
    assertNotNull("ruleSetAudits is null", ruleSetRuleAudits);
    assertEquals("The size of the ruleSetRuleAudits is not 2", new Integer(2), Integer.valueOf(ruleSetRuleAudits.size()));
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleAuditBean(org.akaza.openclinica.domain.rule.RuleSetRuleAuditBean)

Example 5 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.

the class RuleSetDaoTest method createStubRuleSetBean.

private RuleSetBean createStubRuleSetBean(RuleBean ruleBean) {
    RuleSetBean ruleSet = new RuleSetBean();
    ruleSet.setTarget(createExpression(Context.OC_RULES_V1, "SE_ED2REPEA.F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_N"));
    RuleSetRuleBean ruleSetRule = createRuleSetRule(ruleSet, ruleBean);
    ruleSet.addRuleSetRule(ruleSetRule);
    return ruleSet;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Aggregations

RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)68 ArrayList (java.util.ArrayList)30 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)26 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)19 HashMap (java.util.HashMap)15 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)15 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)11 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)9 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)8 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 Map (java.util.Map)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)5 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)5 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)5 Locale (java.util.Locale)4