use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class AuthenticationIT method accessDeniedForNoClientCert.
/**
* Verifies that clients that don't present a client certificate receive an access denied error.
*/
@Test
public void accessDeniedForNoClientCert() {
// Construct a FHIR client using no client identity certificate.
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient(Optional.empty());
/*
* Just check an arbitrary endpoint (all trusted clients have access to
* everything).
*/
assertThrows(FhirClientConnectionException.class, () -> {
fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
});
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class ServerTestUtils method createFhirClient.
/**
* @param versionId the {@link v1 or v2 identifier to use as a part of the URL for the FHIR server
* @param clientSslIdentity the {@link ClientSslIdentity} to use as a login for the FHIR server
* @return a new FHIR {@link IGenericClient} for use
*/
private IGenericClient createFhirClient(String versionId, Optional<ClientSslIdentity> clientSslIdentity, FhirContext ctx) {
// Figure out where the test server is running.
String fhirBaseUrl = String.format("%s/%s/fhir", getServerBaseUrl(), versionId);
/*
* We need to override the FHIR client's SSLContext. Unfortunately, that
* requires overriding the entire HttpClient that it uses. Otherwise,
* the settings used here mirror those that the default FHIR HttpClient
* would use.
*/
SSLContext sslContext = createSslContext(clientSslIdentity);
/*
* The default timeout is 10s, which was failing for batches of 100. A
* 300s timeout was failing for batches of 100 once Part B claims were
* mostly mapped, so batches were cut to 10, which ran at 12s or so,
* each.
*/
ctx.getRestfulClientFactory().setSocketTimeout((int) TimeUnit.MINUTES.toMillis(5));
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(sslContext)).build(), null, null, null, 5000, TimeUnit.MILLISECONDS);
@SuppressWarnings("deprecation") RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(ctx.getRestfulClientFactory().getSocketTimeout()).setConnectTimeout(ctx.getRestfulClientFactory().getConnectTimeout()).setConnectionRequestTimeout(ctx.getRestfulClientFactory().getConnectionRequestTimeout()).setStaleConnectionCheckEnabled(true).build();
HttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement().build();
ctx.getRestfulClientFactory().setHttpClient(httpClient);
IGenericClient client = ctx.newRestfulGenericClient(fhirBaseUrl);
/*
* The FHIR client logging (for tests) can be managed via the
* `src/test/resources/logback-test.xml` file.
*/
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLogRequestSummary(LOGGER.isDebugEnabled());
loggingInterceptor.setLogResponseSummary(LOGGER.isDebugEnabled());
loggingInterceptor.setLogRequestHeaders(LOGGER.isTraceEnabled());
loggingInterceptor.setLogResponseHeaders(LOGGER.isTraceEnabled());
loggingInterceptor.setLogRequestBody(LOGGER.isTraceEnabled());
loggingInterceptor.setLogResponseBody(LOGGER.isTraceEnabled());
client.registerInterceptor(loggingInterceptor);
return client;
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class ServerTestUtils method createFhirClientWithHeadersV2.
/**
* helper
*
* @return the client with extra params registered
*/
public IGenericClient createFhirClientWithHeadersV2(RequestHeaders requestHeader) {
IGenericClient fhirClient = createFhirClientV2();
if (requestHeader != null) {
ExtraParamsInterceptor extraParamsInterceptor = new ExtraParamsInterceptor();
extraParamsInterceptor.setHeaders(requestHeader);
fhirClient.registerInterceptor(extraParamsInterceptor);
}
return fhirClient;
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method readEobForExistingInpatientClaim.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
* works as expected for an {@link InpatientClaim}-derived {@link ExplanationOfBenefit} that does
* exist in the DB.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void readEobForExistingInpatientClaim() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
InpatientClaim claim = loadedRecords.stream().filter(r -> r instanceof InpatientClaim).map(r -> (InpatientClaim) r).findFirst().get();
ExplanationOfBenefit eob = fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.INPATIENT, claim.getClaimId())).execute();
assertNotNull(eob);
// Compare result to transformed EOB
compareEob(ClaimTypeV2.INPATIENT, eob, loadedRecords);
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForSamhsaEobsWithExcludeSamhsaTrue.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.R4ExplanationOfBenefitResourceProvider#findByPatient} with
* <code>excludeSAMHSA=true</code> properly filters out SAMHSA-related claims.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForSamhsaEobsWithExcludeSamhsaTrue() throws FHIRException {
Beneficiary beneficiary = loadSampleAWithSamhsa();
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary.getBeneficiaryId()))).and(new StringClientParam(EXCLUDE_SAMHSA_PARAM).matches().value("true")).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
for (ClaimTypeV2 claimType : ClaimTypeV2.values()) {
/*
* SAMHSA fields are present on all claim types except for PDE so we should not
* get any claims back in the results except for PDE.
*/
if (claimType == ClaimTypeV2.PDE) {
assertEquals(1, filterToClaimType(searchResults, claimType).size());
} else {
assertEquals(0, filterToClaimType(searchResults, claimType).size());
}
}
}
Aggregations