/** * Activate rules for accruals. Called for new registrations only. Checks if accrual notifications * are configured. Fires rules if thresholds are met. * * @param studySubjectObj the study subject obj */ private void activateRulesForAccruals(Object studySubjectObj) { StudySubject studySubject = null; StudyOrganization studyOrg = null; StudySite studySite = null; if (studySubjectObj instanceof StudySubject) { studySubject = (StudySubject) studySubjectObj; } else { return; } List<Object> objects = new ArrayList<Object>(); objects.add(studySubject); int studyAccruals = 0; int threshold = 0; List<HealthcareSite> hcsList = getSites(studySubject); for (PlannedNotification pn : getPlannedNotifications(hcsList)) { if (pn.getEventName().equals(NotificationEventTypeEnum.STUDY_ACCRUAL_EVENT)) { Iterator<StudyOrganization> iter = studySubject.getStudySite().getStudy().getStudyOrganizations().iterator(); while (iter.hasNext()) { studyOrg = iter.next(); // ensure that the host org is in the studyOrg list for the study if (studyOrg .getHealthcareSite() .getPrimaryIdentifier() .equalsIgnoreCase(configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE))) { studyAccruals = calculateStudyAccrual(studySubject); threshold = studySubject.getStudySite().getStudy().getTargetAccrualNumber().intValue(); // if accruals exceed specified threshold value then send out email if (studyAccruals * 100 / threshold >= pn.getStudyThreshold()) { objects.add(pn); rulesDelegationService.activateRules( NotificationEventTypeEnum.STUDY_ACCRUAL_EVENT, objects); } } } } if (pn.getEventName().equals(NotificationEventTypeEnum.STUDY_SITE_ACCRUAL_EVENT)) { studySite = studySubject.getStudySite(); // ensure that the host org is in the studySite list for the study if (studySite .getHealthcareSite() .getPrimaryIdentifier() .equalsIgnoreCase(configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE))) { studyAccruals = calculateStudySiteAccrual(studySubject); threshold = studySubject.getStudySite().getTargetAccrualNumber().intValue(); // if accruals exceed specified threshold value then send out email if ((studyAccruals / threshold) * 100 >= pn.getStudySiteThreshold()) { objects.add(pn); rulesDelegationService.activateRules( NotificationEventTypeEnum.STUDY_SITE_ACCRUAL_EVENT, objects); } } } } }