class DhisRepositoryImpl implements DhisRepository {

    @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class, ForbiddenException.class } )
    @Override
    @Nonnull
    public Optional<IBaseResource> read( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisFhirResourceId dhisFhirResourceId )
    {
        final DhisResourceType dhisResourceType;
        final UUID ruleId;

        if ( dhisFhirResourceId.isQualified() )
        {
            dhisResourceType = dhisFhirResourceId.getType();
            ruleId = dhisFhirResourceId.getRuleId();
        }
        else
        {
            final RuleInfo<? extends AbstractRule> ruleInfo = dhisToFhirTransformerService.findSingleRule( fhirClient, fhirResourceType );

            if ( ruleInfo == null || !ruleInfo.getRule().isSimpleFhirId() )
            {
                return Optional.empty();
            }

            dhisResourceType = ruleInfo.getRule().getDhisResourceType();
            ruleId = ruleInfo.getRule().getId();
        }

        return new OneDhisResourceReader()
        {
            @Nonnull
            @Override
            protected UUID getRuleId()
            {
                return ruleId;
            }

            @Nullable
            @Override
            protected DhisToFhirTransformerRequest createTransformerRequest( @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisRequest dhisRequest, @Nonnull DhisResource dhisResource )
            {
                return dhisToFhirTransformerService.createTransformerRequest( fhirClient, dhisRequest, dhisResource, fhirResourceType, ruleId );
            }

            @Nullable
            @Override
            protected DhisResource getDhisResource()
            {
                return dhisResourceRepository.findRefreshed( dhisFhirResourceId.toQualified( dhisResourceType, ruleId ).getDhisResourceId() ).orElse( null );
            }
        }.read( fhirClient, fhirResourceType );
    }

    public  DhisRepositoryImpl(
        @Nonnull AuthorizationContext authorizationContext,
        @Nonnull Authorization systemDhis2Authorization,
        @Nonnull LockManager lockManager,
        @Nonnull RequestCacheService requestCacheService,
        @Nonnull StoredDhisResourceService storedItemService,
        @Nonnull DhisResourceRepository dhisResourceRepository,
        @Nonnull DhisToFhirTransformerService dhisToFhirTransformerService,
        @Nonnull FhirResourceRepository fhirResourceRepository,
        @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository,
        @Nonnull FhirRestInterfaceConfig fhirRestInterfaceConfig );

}