class EnrollmentServiceImpl implements EnrollmentService, LocalDhisRepositoryPersistCallback<Enrollment> {

    @HystrixCommand( ignoreExceptions = { DhisConflictException.class, UnauthorizedException.class } )
    @Nonnull
    @Override
    @CacheEvict( key = "{'findLatestActive', #a0.programId, #a0.trackedEntityInstanceId}", cacheManager = "dhisCacheManager", cacheNames = "enrollments" )
    public Enrollment createOrUpdate( @Nonnull Enrollment enrollment )
    {
        return resourceRepositoryTemplate.save( enrollment, e -> {
            if ( e.getEvents() != null )
            {
                // local IDs must be created for each included event
                e.getEvents().forEach( event -> {
                    // force update of included enrollment ID
                    event.setEnrollment( e );
                    eventService.createOrMinimalUpdate( event );
                } );
            }
        } );
    }

    @Autowired public  EnrollmentServiceImpl( @Nonnull @Qualifier( "userDhis2RestTemplate" ) RestTemplate restTemplate, @Nonnull EventService eventService, @Nonnull RequestCacheService requestCacheService );

}