Search in sources :

Example 1 with EnrollmentEvaluationEvent

use of org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent in project dhis2-core by dhis2.

the class AbstractEnrollmentService method addEnrollment.

private ImportSummary addEnrollment(Enrollment enrollment, ImportOptions importOptions, org.hisp.dhis.trackedentity.TrackedEntityInstance daoTrackedEntityInstance, boolean handleEvents) {
    importOptions = updateImportOptions(importOptions);
    String storedBy = !StringUtils.isEmpty(enrollment.getStoredBy()) && enrollment.getStoredBy().length() < 31 ? enrollment.getStoredBy() : (importOptions.getUser() == null || StringUtils.isEmpty(importOptions.getUser().getUsername()) ? "system-process" : importOptions.getUser().getUsername());
    if (daoTrackedEntityInstance == null) {
        daoTrackedEntityInstance = getTrackedEntityInstance(enrollment.getTrackedEntityInstance(), importOptions.getUser());
    }
    Program program = getProgram(importOptions.getIdSchemes(), enrollment.getProgram());
    OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), enrollment.getOrgUnit());
    ImportSummary importSummary = validateRequest(program, daoTrackedEntityInstance, enrollment, organisationUnit, importOptions);
    if (importSummary.getStatus() != ImportStatus.SUCCESS) {
        return importSummary;
    }
    List<String> errors = trackerAccessManager.canCreate(importOptions.getUser(), new ProgramInstance(program, daoTrackedEntityInstance, organisationUnit), false);
    if (!errors.isEmpty()) {
        return new ImportSummary(ImportStatus.ERROR, errors.toString()).incrementIgnored();
    }
    if (enrollment.getStatus() == null) {
        enrollment.setStatus(EnrollmentStatus.ACTIVE);
    }
    ProgramStatus programStatus = enrollment.getStatus() == EnrollmentStatus.ACTIVE ? ProgramStatus.ACTIVE : enrollment.getStatus() == EnrollmentStatus.COMPLETED ? ProgramStatus.COMPLETED : ProgramStatus.CANCELLED;
    ProgramInstance programInstance = programInstanceService.prepareProgramInstance(daoTrackedEntityInstance, program, programStatus, enrollment.getEnrollmentDate(), enrollment.getIncidentDate(), organisationUnit, enrollment.getEnrollment());
    if (programStatus == ProgramStatus.COMPLETED || programStatus == ProgramStatus.CANCELLED) {
        Date date = enrollment.getCompletedDate();
        if (date == null) {
            date = new Date();
        }
        String user = enrollment.getCompletedBy();
        if (user == null) {
            user = importOptions.getUser().getUsername();
        }
        programInstance.setCompletedBy(user);
        programInstance.setEndDate(date);
    }
    programInstanceService.addProgramInstance(programInstance, importOptions.getUser());
    importSummary = validateProgramInstance(program, programInstance, enrollment, importSummary);
    if (importSummary.getStatus() != ImportStatus.SUCCESS) {
        return importSummary;
    }
    // -----------------------------------------------------------------
    // Send enrollment notifications (if any)
    // -----------------------------------------------------------------
    eventPublisher.publishEvent(new ProgramEnrollmentNotificationEvent(this, programInstance.getId()));
    eventPublisher.publishEvent(new EnrollmentEvaluationEvent(this, programInstance.getId()));
    eventPublisher.publishEvent(new TrackerEnrollmentWebHookEvent(this, programInstance.getUid()));
    updateFeatureType(program, enrollment, programInstance);
    updateAttributeValues(enrollment, importOptions);
    updateDateFields(enrollment, programInstance);
    programInstance.setFollowup(enrollment.getFollowup());
    programInstance.setStoredBy(storedBy);
    programInstanceService.updateProgramInstance(programInstance, importOptions.getUser());
    trackerOwnershipAccessManager.assignOwnership(daoTrackedEntityInstance, program, organisationUnit, true, true);
    saveTrackedEntityComment(programInstance, enrollment, importOptions.getUser());
    importSummary.setReference(programInstance.getUid());
    enrollment.setEnrollment(programInstance.getUid());
    importSummary.getImportCount().incrementImported();
    if (handleEvents) {
        importSummary.setEvents(handleEvents(enrollment, programInstance, importOptions));
    } else {
        for (Event event : enrollment.getEvents()) {
            event.setEnrollment(enrollment.getEnrollment());
            event.setProgram(programInstance.getProgram().getUid());
            event.setTrackedEntityInstance(enrollment.getTrackedEntityInstance());
        }
    }
    return importSummary;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) TrackerEnrollmentWebHookEvent(org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) Event(org.hisp.dhis.dxf2.events.event.Event) TrackerEnrollmentWebHookEvent(org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) Date(java.util.Date) ProgramStatus(org.hisp.dhis.program.ProgramStatus)

Example 2 with EnrollmentEvaluationEvent

use of org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent in project dhis2-core by dhis2.

the class DefaultProgramInstanceService method enrollTrackedEntityInstance.

@Override
@Transactional
public ProgramInstance enrollTrackedEntityInstance(TrackedEntityInstance trackedEntityInstance, Program program, Date enrollmentDate, Date incidentDate, OrganisationUnit organisationUnit, String uid) {
    // ---------------------------------------------------------------------
    // Add program instance
    // ---------------------------------------------------------------------
    ProgramInstance programInstance = prepareProgramInstance(trackedEntityInstance, program, ProgramStatus.ACTIVE, enrollmentDate, incidentDate, organisationUnit, uid);
    addProgramInstance(programInstance);
    // ---------------------------------------------------------------------
    // Add program owner and overwrite if already exists.
    // ---------------------------------------------------------------------
    trackerOwnershipAccessManager.assignOwnership(trackedEntityInstance, program, organisationUnit, true, true);
    // -----------------------------------------------------------------
    // Send enrollment notifications (if any)
    // -----------------------------------------------------------------
    eventPublisher.publishEvent(new ProgramEnrollmentNotificationEvent(this, programInstance.getId()));
    eventPublisher.publishEvent(new EnrollmentEvaluationEvent(this, programInstance.getId()));
    // -----------------------------------------------------------------
    // Update ProgramInstance and TEI
    // -----------------------------------------------------------------
    updateProgramInstance(programInstance);
    trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance);
    return programInstance;
}
Also used : EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) ProgramEnrollmentNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EnrollmentEvaluationEvent

use of org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent in project dhis2-core by dhis2.

the class DefaultProgramInstanceService method completeProgramInstanceStatus.

@Override
@Transactional
public void completeProgramInstanceStatus(ProgramInstance programInstance) {
    // -----------------------------------------------------------------
    // Update program-instance
    // -----------------------------------------------------------------
    programInstance.setStatus(ProgramStatus.COMPLETED);
    updateProgramInstance(programInstance);
    // ---------------------------------------------------------------------
    // Send sms-message after program completion
    // ---------------------------------------------------------------------
    eventPublisher.publishEvent(new ProgramEnrollmentCompletionNotificationEvent(this, programInstance.getId()));
    eventPublisher.publishEvent(new EnrollmentEvaluationEvent(this, programInstance.getId()));
}
Also used : EnrollmentEvaluationEvent(org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent) ProgramEnrollmentCompletionNotificationEvent(org.hisp.dhis.program.notification.event.ProgramEnrollmentCompletionNotificationEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EnrollmentEvaluationEvent (org.hisp.dhis.programrule.engine.EnrollmentEvaluationEvent)3 ProgramEnrollmentNotificationEvent (org.hisp.dhis.program.notification.event.ProgramEnrollmentNotificationEvent)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Date (java.util.Date)1 Event (org.hisp.dhis.dxf2.events.event.Event)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramStatus (org.hisp.dhis.program.ProgramStatus)1 ProgramEnrollmentCompletionNotificationEvent (org.hisp.dhis.program.notification.event.ProgramEnrollmentCompletionNotificationEvent)1 TrackerEnrollmentWebHookEvent (org.hisp.dhis.programrule.engine.TrackerEnrollmentWebHookEvent)1