use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class ClientsTest method testClientForEndpoint.
@Test
public void testClientForEndpoint() {
Endpoint endpoint = new Endpoint();
endpoint.setAddress("http://test.com");
endpoint.setHeader(Collections.singletonList(new StringType("Basic: XYZ123")));
IGenericClient client = Clients.forEndpoint(endpoint);
assertEquals("http://test.com", client.getServerBase());
List<Object> interceptors = client.getInterceptorService().getAllRegisteredInterceptors();
Object interceptor = interceptors.get(0);
assertTrue(interceptor instanceof HeaderInjectionInterceptor);
}
use of org.hl7.fhir.r4.model.Endpoint in project beneficiary-fhir-data by CMSgov.
the class ServerCapabilityStatementIT method getCapabilities.
/**
* Verifies that the server responds as expected to the <code>GET [base]/_metadata</code>
* endpoint.
*/
@Test
public void getCapabilities() {
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
CapabilityStatement capabilities = fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
assertNotNull(capabilities);
// Verify that our custom server metadata is correct.
assertEquals(V1Server.CAPABILITIES_PUBLISHER, capabilities.getPublisher());
assertEquals(V1Server.CAPABILITIES_SERVER_NAME, capabilities.getSoftware().getName());
assertEquals("gov.cms.bfd:bfd-server-war", capabilities.getImplementation().getDescription());
assertNotEquals(null, capabilities.getSoftware().getVersion());
assertNotEquals("", capabilities.getSoftware().getVersion());
// The default for this field is HAPI's version but we don't use that.
assertNotEquals(VersionUtil.getVersion(), capabilities.getSoftware().getVersion());
assertEquals(1, capabilities.getRest().size());
CapabilityStatementRestComponent restCapabilities = capabilities.getRestFirstRep();
assertEquals(RestfulCapabilityMode.SERVER, restCapabilities.getMode());
// Verify that Patient resource support looks like expected.
CapabilityStatementRestResourceComponent patientCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(Patient.class.getSimpleName())).findAny().get();
assertTrue(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
assertFalse(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.CREATE).findAny().isPresent());
// Verify that Coverage resource support looks like expected.
CapabilityStatementRestResourceComponent coverageCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(Coverage.class.getSimpleName())).findAny().get();
assertTrue(coverageCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(coverageCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
// Verify that EOB resource support looks like expected.
CapabilityStatementRestResourceComponent eobCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(ExplanationOfBenefit.class.getSimpleName())).findAny().get();
assertTrue(eobCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(eobCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
// Spot check that an arbitrary unsupported resource isn't listed.
assertFalse(restCapabilities.getResource().stream().filter(r -> r.getType().equals(DiagnosticReport.class.getSimpleName())).findAny().isPresent());
}
use of org.hl7.fhir.r4.model.Endpoint in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProvider method searchByCoverageContractAndYearMonth.
@Trace
private Bundle searchByCoverageContractAndYearMonth(// of relational search is more common.
TokenParam coverageId, LocalDate yearMonth, RequestDetails requestDetails) {
checkCoverageId(coverageId);
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
// requested.
if (!requestHeader.isMBIinIncludeIdentifiers() || requestHeader.isHICNinIncludeIdentifiers()) {
throw new InvalidRequestException(String.format("This endpoint requires the '%s: mbi' header.", CommonHeaders.HEADER_NAME_INCLUDE_IDENTIFIERS));
}
PatientLinkBuilder paging = new PatientLinkBuilder(requestDetails.getCompleteUrl());
Operation operation = new Operation(Operation.Endpoint.V1_PATIENT);
operation.setOption("by", "coverageContractForYearMonth");
requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
operation.publishOperationName();
List<Beneficiary> matchingBeneficiaries = fetchBeneficiariesByContractAndYearMonth(coverageId, yearMonth, paging);
boolean hasAnotherPage = matchingBeneficiaries.size() > paging.getPageSize();
if (hasAnotherPage) {
matchingBeneficiaries = matchingBeneficiaries.subList(0, paging.getPageSize());
paging = new PatientLinkBuilder(paging, hasAnotherPage);
}
List<IBaseResource> patients = matchingBeneficiaries.stream().map(b -> BeneficiaryTransformer.transform(metricRegistry, b, requestHeader)).collect(Collectors.toList());
Bundle bundle = TransformerUtils.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
TransformerUtils.workAroundHAPIIssue1585(requestDetails);
return bundle;
}
use of org.hl7.fhir.r4.model.Endpoint in project beneficiary-fhir-data by CMSgov.
the class AuthenticationIT method authenticationWorksForTrustedClient.
/**
* Verifies that authentication works for an SSL client certificate in the server's trust store.
*/
@Test
public void authenticationWorksForTrustedClient() {
// Construct a FHIR client using a trusted client identity certificate.
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient(Optional.of(ClientSslIdentity.TRUSTED));
/*
* Just check an arbitrary endpoint (all trusted clients have access to
* everything).
*/
CapabilityStatement capabilities = fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
assertNotNull(capabilities);
}
use of org.hl7.fhir.r4.model.Endpoint in project beneficiary-fhir-data by CMSgov.
the class AuthenticationIT method accessDeniedForClientCertThatIsNotTrusted.
/**
* Verifies that clients that present a client certificate that is not in the server's trust store
* receive an access denied error.
*/
@Test
public void accessDeniedForClientCertThatIsNotTrusted() {
/*
* Construct a FHIR client using a not-trusted client identity
* certificate.
*/
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient(Optional.of(ClientSslIdentity.UNTRUSTED));
/*
* Just check an arbitrary endpoint (all trusted clients have access to
* everything).
*/
assertThrows(FhirClientConnectionException.class, () -> {
fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
});
}
Aggregations