Search in sources :

Example 71 with Endpoint

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);
}
Also used : Endpoint(org.hl7.fhir.dstu3.model.Endpoint) StringType(org.hl7.fhir.dstu3.model.StringType) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Test(org.junit.jupiter.api.Test)

Example 72 with Endpoint

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());
}
Also used : Coverage(org.hl7.fhir.dstu3.model.Coverage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) RestfulCapabilityMode(org.hl7.fhir.dstu3.model.CapabilityStatement.RestfulCapabilityMode) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) CapabilityStatementRestComponent(org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent) Test(org.junit.jupiter.api.Test) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Patient(org.hl7.fhir.dstu3.model.Patient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VersionUtil(ca.uhn.fhir.util.VersionUtil) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) TypeRestfulInteraction(org.hl7.fhir.dstu3.model.CapabilityStatement.TypeRestfulInteraction) CapabilityStatementRestResourceComponent(org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) CapabilityStatementRestComponent(org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent) CapabilityStatementRestResourceComponent(org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent) Test(org.junit.jupiter.api.Test)

Example 73 with Endpoint

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;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Identifier(org.hl7.fhir.dstu3.model.Identifier) Description(ca.uhn.fhir.model.api.annotation.Description) IdType(org.hl7.fhir.dstu3.model.IdType) NoResultException(javax.persistence.NoResultException) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Predicate(javax.persistence.criteria.Predicate) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) SingularAttribute(javax.persistence.metamodel.SingularAttribute) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) QueryHints(org.hibernate.jpa.QueryHints) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) BeneficiaryHistory_(gov.cms.bfd.model.rif.BeneficiaryHistory_) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Year(java.time.Year) LocalDate(java.time.LocalDate) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) HashMap(java.util.HashMap) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary_(gov.cms.bfd.model.rif.Beneficiary_) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) LinkedList(java.util.LinkedList) Root(javax.persistence.criteria.Root) Read(ca.uhn.fhir.rest.annotation.Read) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) Operation(gov.cms.bfd.server.war.Operation) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) Patient(org.hl7.fhir.dstu3.model.Patient) MDC(org.slf4j.MDC) YearMonth(java.time.YearMonth) Collections(java.util.Collections) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Bundle(org.hl7.fhir.dstu3.model.Bundle) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Operation(gov.cms.bfd.server.war.Operation) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Trace(com.newrelic.api.agent.Trace)

Example 74 with Endpoint

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);
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) Test(org.junit.jupiter.api.Test)

Example 75 with Endpoint

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();
    });
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)36 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)21 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)18 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)16 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)15 Endpoint (org.hl7.fhir.r4.model.Endpoint)15 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 Bundle (org.hl7.fhir.r4.model.Bundle)12 Organization (org.hl7.fhir.dstu3.model.Organization)11 Resource (org.hl7.fhir.r4.model.Resource)10 Resource (org.hl7.fhir.dstu3.model.Resource)9 Operation (ca.uhn.fhir.rest.annotation.Operation)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Description (ca.uhn.fhir.model.api.annotation.Description)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 ArrayList (java.util.ArrayList)6