@Test public void createBatchResponseError() { final List<FhirOperation> operations = new ArrayList<>(); operations.add( new FhirOperation( FhirOperationType.PUT, FhirResourceType.PATIENT, patientClientResource, "4711", new Patient(), null ) ); operations.get( 0 ).getResult().unprocessableEntity( "Invalid data included" ); final FhirBatchRequest batchRequest = new FhirBatchRequest( operations, false ); final Bundle bundle = provider.createBatchResponse( batchRequest ); Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, bundle.getType() ); Assert.assertEquals( 1, bundle.getEntry().size() ); Assert.assertNull( bundle.getEntry().get( 0 ).getResponse().getLocation() ); Assert.assertEquals( "422 Unprocessable entity", bundle.getEntry().get( 0 ).getResponse().getStatus() ); Assert.assertNotNull( bundle.getEntry().get( 0 ).getResponse().getOutcome() ); Assert.assertNotNull( ( (OperationOutcome) bundle.getEntry().get( 0 ).getResponse().getOutcome() ).getIssue() ); Assert.assertEquals( 1, ( (OperationOutcome) bundle.getEntry().get( 0 ).getResponse().getOutcome() ).getIssue().size() ); Assert.assertEquals( "Invalid data included", ( (OperationOutcome) bundle.getEntry().get( 0 ).getResponse().getOutcome() ).getIssueFirstRep().getDiagnostics() ); }
@Nonnull @Override protected Bundle createBatchResponse( @Nonnull FhirBatchRequest batchRequest ) { final Bundle bundle = new Bundle(); bundle.setType( batchRequest.isTransactional() ? Bundle.BundleType.TRANSACTIONRESPONSE : Bundle.BundleType.BATCHRESPONSE ); batchRequest.getOperations().forEach( operation -> { if ( !operation.isProcessed() ) { operation.getResult().internalServerError( "Operation has not been processed." ); } final Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getResponse().setStatus( getStatus( operation.getResult() ) ); if ( operation.getResult().getId() != null && !operation.getResult().getId().isEmpty() ) { entry.getResponse().setLocation( operation.getFhirResourceType().getResourceTypeName() + "/" + operation.getResult().getId().getIdPart() ); } if ( operation.getResult().getIssue() != null ) { final OperationOutcome outcome = new OperationOutcome(); final OperationOutcome.OperationOutcomeIssueComponent issue = outcome.addIssue(); issue.setSeverity( convert( operation.getResult().getIssue().getSeverity() ) ); issue.setCode( convert( operation.getResult().getIssue().getType() ) ); issue.setDiagnostics( operation.getResult().getIssue().getDiagnostics() ); entry.getResponse().setOutcome( outcome ); } } ); return bundle; }
R4BundleResourceProvider extends AbstractBundleResourceProvider<Bundle> { @Nonnull @Override protected Bundle createBatchResponse( @Nonnull FhirBatchRequest batchRequest ) { final Bundle bundle = new Bundle(); bundle.setType( batchRequest.isTransactional() ? Bundle.BundleType.TRANSACTIONRESPONSE : Bundle.BundleType.BATCHRESPONSE ); batchRequest.getOperations().forEach( operation -> { if ( !operation.isProcessed() ) { operation.getResult().internalServerError( "Operation has not been processed." ); } final Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getResponse().setStatus( getStatus( operation.getResult() ) ); if ( operation.getResult().getId() != null && !operation.getResult().getId().isEmpty() ) { entry.getResponse().setLocation( operation.getFhirResourceType().getResourceTypeName() + "/" + operation.getResult().getId().getIdPart() ); } if ( operation.getResult().getIssue() != null ) { final OperationOutcome outcome = new OperationOutcome(); final OperationOutcome.OperationOutcomeIssueComponent issue = outcome.addIssue(); issue.setSeverity( convert( operation.getResult().getIssue().getSeverity() ) ); issue.setCode( convert( operation.getResult().getIssue().getType() ) ); issue.setDiagnostics( operation.getResult().getIssue().getDiagnostics() ); entry.getResponse().setOutcome( outcome ); } } ); return bundle; } }
R4BundleResourceProvider extends AbstractBundleResourceProvider<Bundle> { @Nonnull @Override protected Bundle createBatchResponse( @Nonnull FhirBatchRequest batchRequest ) { final Bundle bundle = new Bundle(); bundle.setType( batchRequest.isTransactional() ? Bundle.BundleType.TRANSACTIONRESPONSE : Bundle.BundleType.BATCHRESPONSE ); batchRequest.getOperations().forEach( operation -> { if ( !operation.isProcessed() ) { operation.getResult().internalServerError( "Operation has not been processed." ); } final Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getResponse().setStatus( getStatus( operation.getResult() ) ); if ( operation.getResult().getId() != null && !operation.getResult().getId().isEmpty() ) { entry.getResponse().setLocation( operation.getFhirResourceType().getResourceTypeName() + "/" + operation.getResult().getId().getIdPart() ); } if ( operation.getResult().getIssue() != null ) { final OperationOutcome outcome = new OperationOutcome(); final OperationOutcome.OperationOutcomeIssueComponent issue = outcome.addIssue(); issue.setSeverity( convert( operation.getResult().getIssue().getSeverity() ) ); issue.setCode( convert( operation.getResult().getIssue().getType() ) ); issue.setDiagnostics( operation.getResult().getIssue().getDiagnostics() ); entry.getResponse().setOutcome( outcome ); } } ); return bundle; } R4BundleResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository, @Nonnull RequestCacheService requestCacheService ); }
R4BundleResourceProvider extends AbstractBundleResourceProvider<Bundle> { @Nonnull @Override protected Bundle createBatchResponse( @Nonnull FhirBatchRequest batchRequest ) { final Bundle bundle = new Bundle(); bundle.setType( batchRequest.isTransactional() ? Bundle.BundleType.TRANSACTIONRESPONSE : Bundle.BundleType.BATCHRESPONSE ); batchRequest.getOperations().forEach( operation -> { if ( !operation.isProcessed() ) { operation.getResult().internalServerError( "Operation has not been processed." ); } final Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getResponse().setStatus( getStatus( operation.getResult() ) ); if ( operation.getResult().getId() != null && !operation.getResult().getId().isEmpty() ) { entry.getResponse().setLocation( operation.getFhirResourceType().getResourceTypeName() + "/" + operation.getResult().getId().getIdPart() ); } if ( operation.getResult().getIssue() != null ) { final OperationOutcome outcome = new OperationOutcome(); final OperationOutcome.OperationOutcomeIssueComponent issue = outcome.addIssue(); issue.setSeverity( convert( operation.getResult().getIssue().getSeverity() ) ); issue.setCode( convert( operation.getResult().getIssue().getType() ) ); issue.setDiagnostics( operation.getResult().getIssue().getDiagnostics() ); entry.getResponse().setOutcome( outcome ); } } ); return bundle; } R4BundleResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository, @Nonnull RequestCacheService requestCacheService ); @Nonnull @Override FhirVersion getFhirVersion(); @Nonnull @Transaction Bundle process( @Nonnull RequestDetails requestDetails, @TransactionParam Bundle bundle ); }
R4BundleResourceProvider extends AbstractBundleResourceProvider<Bundle> { @Nonnull @Override protected Bundle createBatchResponse( @Nonnull FhirBatchRequest batchRequest ) { final Bundle bundle = new Bundle(); bundle.setType( batchRequest.isTransactional() ? Bundle.BundleType.TRANSACTIONRESPONSE : Bundle.BundleType.BATCHRESPONSE ); batchRequest.getOperations().forEach( operation -> { if ( !operation.isProcessed() ) { operation.getResult().internalServerError( "Operation has not been processed." ); } final Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getResponse().setStatus( getStatus( operation.getResult() ) ); if ( operation.getResult().getId() != null && !operation.getResult().getId().isEmpty() ) { entry.getResponse().setLocation( operation.getFhirResourceType().getResourceTypeName() + "/" + operation.getResult().getId().getIdPart() ); } if ( operation.getResult().getIssue() != null ) { final OperationOutcome outcome = new OperationOutcome(); final OperationOutcome.OperationOutcomeIssueComponent issue = outcome.addIssue(); issue.setSeverity( convert( operation.getResult().getIssue().getSeverity() ) ); issue.setCode( convert( operation.getResult().getIssue().getType() ) ); issue.setDiagnostics( operation.getResult().getIssue().getDiagnostics() ); entry.getResponse().setOutcome( outcome ); } } ); return bundle; } R4BundleResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository, @Nonnull RequestCacheService requestCacheService ); @Nonnull @Override FhirVersion getFhirVersion(); @Nonnull @Transaction Bundle process( @Nonnull RequestDetails requestDetails, @TransactionParam Bundle bundle );  }