@Test public void readNonQualifiedId() { rule.setId( ruleId ); rule.setSimpleFhirId( true ); Mockito.doReturn( new RuleInfo<>( rule, Collections.emptyList() ) ).when( dhisToFhirTransformerService ).findSingleRule( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.PATIENT ) ); Mockito.doReturn( Optional.of( trackedEntityInstance ) ).when( dhisResourceRepository ) .findRefreshed( Mockito.eq( new DhisResourceId( DhisResourceType.TRACKED_ENTITY, "a1234567890" ) ) ); Mockito.doReturn( transformerRequest ).when( dhisToFhirTransformerService ) .createTransformerRequest( Mockito.same( fhirClient ), Mockito.any(), Mockito.same( trackedEntityInstance ), Mockito.eq( FhirResourceType.PATIENT ), Mockito.eq( ruleId ) ); Mockito.doReturn( ruleId ).when( transformerRequest ).getRuleId(); Mockito.doReturn( new DhisToFhirTransformOutcome<>( rule, resultResource ) ).when( dhisToFhirTransformerService ).transform( Mockito.same( transformerRequest ) ); final Optional<IBaseResource> result = repository.read( fhirClient, FhirResourceType.PATIENT, new DhisFhirResourceId( "a1234567890" ) ); Assert.assertTrue( result.isPresent() ); Assert.assertSame( resultResource, result.get() ); }
@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 ); }
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 ); } }
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 ); } 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 ); }
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 ); } 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 ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class } ) @Override @Transactional( propagation = Propagation.NOT_SUPPORTED ) void save( @Nonnull DhisSyncGroup syncGroup, @Nonnull DhisResource resource ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class, ForbiddenException.class } ) @Override @Nonnull Optional<IBaseResource> read( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisFhirResourceId dhisFhirResourceId ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class, ForbiddenException.class } ) @Nonnull @Override Optional<IBaseResource> readByIdentifier( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull String identifier ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, DhisToFhirDataProviderException.class, UnauthorizedException.class, ForbiddenException.class, DhisToFhirDataProviderException.class } ) @Nonnull @Override IBundleProvider search( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nullable Integer count, boolean unlimitedCount,
        @Nullable Set<SystemCodeValue> filteredCodes, @Nullable Map<String, List<String>> filter, @Nullable DateRangeParam lastUpdatedDateRange ); }
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 ); } 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 ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class } ) @Override @Transactional( propagation = Propagation.NOT_SUPPORTED ) void save( @Nonnull DhisSyncGroup syncGroup, @Nonnull DhisResource resource ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class, ForbiddenException.class } ) @Override @Nonnull Optional<IBaseResource> read( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull DhisFhirResourceId dhisFhirResourceId ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, UnauthorizedException.class, ForbiddenException.class } ) @Nonnull @Override Optional<IBaseResource> readByIdentifier( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nonnull String identifier ); @HystrixCommand( ignoreExceptions = { MissingDhisResourceException.class, TransformerDataException.class, TransformerMappingException.class, DhisToFhirDataProviderException.class, UnauthorizedException.class, ForbiddenException.class, DhisToFhirDataProviderException.class } ) @Nonnull @Override IBundleProvider search( @Nonnull FhirClient fhirClient, @Nonnull FhirResourceType fhirResourceType, @Nullable Integer count, boolean unlimitedCount,
        @Nullable Set<SystemCodeValue> filteredCodes, @Nullable Map<String, List<String>> filter, @Nullable DateRangeParam lastUpdatedDateRange );  }