@Test public void lookupConditionalReferenceUrlUnsupportedSystem() throws Exception { Mockito.when( bundleResourceProvider.getFhirVersion() ).thenReturn( FhirVersion.DSTU3 ); Mockito.when( fhirClientSystemRepository.findOneByFhirClientResourceType( Mockito.eq( FHIR_REST_INTERFACE_DSTU3_ID ), Mockito.eq( FhirResourceType.PATIENT ) ) ) .thenReturn( Optional.of( patientClientSystem ) ); final FhirOperation fhirOperation = new FhirOperation( FhirOperationType.POST, FhirResourceType.PATIENT, patientClientResource, null, baseResource3, new URI( "Patient?identifier=http%3A%2F%2Ftes.com%2Fpatient%7C8972" ) ); Assert.assertNull( bundleResourceProvider.lookupConditionalReferenceUrl( fhirOperation ) ); Assert.assertFalse( fhirOperation.isProcessed() ); Mockito.verifyZeroInteractions( dhisRepository ); Mockito.verifyZeroInteractions( fhirRepository ); }
@Nullable protected IBaseResource lookupConditionalReferenceUrl( @Nonnull FhirOperation operation ) { if ( operation.getUri() == null ) { return null; } final MultiValueMap<String, String> parameters = UriComponentsBuilder .fromUri( operation.getUri() ).build().getQueryParams(); if ( parameters.isEmpty() ) { return null; } final List<String> identifiers = parameters.get( SP_IDENTIFIER ); final String identifier; if ( identifiers == null ) { operation.getResult().badRequest( "Only identifiers are supported as conditional references in URLs." ); return null; } if ( identifiers.size() > 1 ) { operation.getResult().badRequest( "Conditional reference in URL must not contain more than one identifier." ); return null; } try { identifier = URLDecoder.decode( identifiers.get( 0 ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException( e ); } final FhirClientSystem fhirClientSystem = getFhirClientSystem( operation.getFhirResourceType() ); final TokenParam identifierParam = parseTokenParam( identifier ); if ( !fhirClientSystem.getSystem().getSystemUri().equals( identifierParam.getSystem() ) || StringUtils.isBlank( identifierParam.getValue() ) ) { return null; } return getDhisRepository().readByIdentifier( operation.getClientResource().getFhirClient(), operation.getFhirResourceType(), identifierParam.getValue() ).orElse( null ); }
AbstractBundleResourceProvider extends AbstractUntypedResourceProvider { @Nullable protected IBaseResource lookupConditionalReferenceUrl( @Nonnull FhirOperation operation ) { if ( operation.getUri() == null ) { return null; } final MultiValueMap<String, String> parameters = UriComponentsBuilder .fromUri( operation.getUri() ).build().getQueryParams(); if ( parameters.isEmpty() ) { return null; } final List<String> identifiers = parameters.get( SP_IDENTIFIER ); final String identifier; if ( identifiers == null ) { operation.getResult().badRequest( "Only identifiers are supported as conditional references in URLs." ); return null; } if ( identifiers.size() > 1 ) { operation.getResult().badRequest( "Conditional reference in URL must not contain more than one identifier." ); return null; } try { identifier = URLDecoder.decode( identifiers.get( 0 ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException( e ); } final FhirClientSystem fhirClientSystem = getFhirClientSystem( operation.getFhirResourceType() ); final TokenParam identifierParam = parseTokenParam( identifier ); if ( !fhirClientSystem.getSystem().getSystemUri().equals( identifierParam.getSystem() ) || StringUtils.isBlank( identifierParam.getValue() ) ) { return null; } return getDhisRepository().readByIdentifier( operation.getClientResource().getFhirClient(), operation.getFhirResourceType(), identifierParam.getValue() ).orElse( null ); } }
AbstractBundleResourceProvider extends AbstractUntypedResourceProvider { @Nullable protected IBaseResource lookupConditionalReferenceUrl( @Nonnull FhirOperation operation ) { if ( operation.getUri() == null ) { return null; } final MultiValueMap<String, String> parameters = UriComponentsBuilder .fromUri( operation.getUri() ).build().getQueryParams(); if ( parameters.isEmpty() ) { return null; } final List<String> identifiers = parameters.get( SP_IDENTIFIER ); final String identifier; if ( identifiers == null ) { operation.getResult().badRequest( "Only identifiers are supported as conditional references in URLs." ); return null; } if ( identifiers.size() > 1 ) { operation.getResult().badRequest( "Conditional reference in URL must not contain more than one identifier." ); return null; } try { identifier = URLDecoder.decode( identifiers.get( 0 ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException( e ); } final FhirClientSystem fhirClientSystem = getFhirClientSystem( operation.getFhirResourceType() ); final TokenParam identifierParam = parseTokenParam( identifier ); if ( !fhirClientSystem.getSystem().getSystemUri().equals( identifierParam.getSystem() ) || StringUtils.isBlank( identifierParam.getValue() ) ) { return null; } return getDhisRepository().readByIdentifier( operation.getClientResource().getFhirClient(), operation.getFhirResourceType(), identifierParam.getValue() ).orElse( null ); } AbstractBundleResourceProvider(
        @Nonnull FhirClientResourceRepository fhirClientResourceRepository,
        @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository,
        @Nonnull RequestCacheService requestCacheService ); }
AbstractBundleResourceProvider extends AbstractUntypedResourceProvider { @Nullable protected IBaseResource lookupConditionalReferenceUrl( @Nonnull FhirOperation operation ) { if ( operation.getUri() == null ) { return null; } final MultiValueMap<String, String> parameters = UriComponentsBuilder .fromUri( operation.getUri() ).build().getQueryParams(); if ( parameters.isEmpty() ) { return null; } final List<String> identifiers = parameters.get( SP_IDENTIFIER ); final String identifier; if ( identifiers == null ) { operation.getResult().badRequest( "Only identifiers are supported as conditional references in URLs." ); return null; } if ( identifiers.size() > 1 ) { operation.getResult().badRequest( "Conditional reference in URL must not contain more than one identifier." ); return null; } try { identifier = URLDecoder.decode( identifiers.get( 0 ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException( e ); } final FhirClientSystem fhirClientSystem = getFhirClientSystem( operation.getFhirResourceType() ); final TokenParam identifierParam = parseTokenParam( identifier ); if ( !fhirClientSystem.getSystem().getSystemUri().equals( identifierParam.getSystem() ) || StringUtils.isBlank( identifierParam.getValue() ) ) { return null; } return getDhisRepository().readByIdentifier( operation.getClientResource().getFhirClient(), operation.getFhirResourceType(), identifierParam.getValue() ).orElse( null ); } AbstractBundleResourceProvider(
        @Nonnull FhirClientResourceRepository fhirClientResourceRepository,
        @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository,
        @Nonnull RequestCacheService requestCacheService );  }
AbstractBundleResourceProvider extends AbstractUntypedResourceProvider { @Nullable protected IBaseResource lookupConditionalReferenceUrl( @Nonnull FhirOperation operation ) { if ( operation.getUri() == null ) { return null; } final MultiValueMap<String, String> parameters = UriComponentsBuilder .fromUri( operation.getUri() ).build().getQueryParams(); if ( parameters.isEmpty() ) { return null; } final List<String> identifiers = parameters.get( SP_IDENTIFIER ); final String identifier; if ( identifiers == null ) { operation.getResult().badRequest( "Only identifiers are supported as conditional references in URLs." ); return null; } if ( identifiers.size() > 1 ) { operation.getResult().badRequest( "Conditional reference in URL must not contain more than one identifier." ); return null; } try { identifier = URLDecoder.decode( identifiers.get( 0 ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { throw new IllegalStateException( e ); } final FhirClientSystem fhirClientSystem = getFhirClientSystem( operation.getFhirResourceType() ); final TokenParam identifierParam = parseTokenParam( identifier ); if ( !fhirClientSystem.getSystem().getSystemUri().equals( identifierParam.getSystem() ) || StringUtils.isBlank( identifierParam.getValue() ) ) { return null; } return getDhisRepository().readByIdentifier( operation.getClientResource().getFhirClient(), operation.getFhirResourceType(), identifierParam.getValue() ).orElse( null ); } AbstractBundleResourceProvider(
        @Nonnull FhirClientResourceRepository fhirClientResourceRepository,
        @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository,
        @Nonnull RequestCacheService requestCacheService );   }