Search in sources :

Example 96 with IGenericClient

use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.

the class R4CoverageResourceProviderIT method searchWithLastUpdated.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary} works as
 * expected for a search with a lastUpdated value.
 */
@Test
public void searchWithLastUpdated() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
    LOGGER.info("Bundle information: database {}, first {}", searchResults.getMeta().getLastUpdated(), searchResults.getEntry().get(0).getResource().getMeta().getLastUpdated());
    Date nowDate = new Date();
    Date secondsAgoDate = Date.from(Instant.now().minusSeconds(100));
    DateRangeParam inBoundsRange = new DateRangeParam().setLowerBoundInclusive(secondsAgoDate).setUpperBoundExclusive(nowDate);
    LOGGER.info("Query Date Range {}", inBoundsRange);
    Bundle searchInBoundsResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(inBoundsRange).returnBundle(Bundle.class).execute();
    assertNotNull(searchInBoundsResults);
    assertEquals(MedicareSegment.values().length, searchInBoundsResults.getTotal());
    Date hourAgoDate = Date.from(Instant.now().minusSeconds(3600));
    DateRangeParam outOfBoundsRange = new DateRangeParam(hourAgoDate, secondsAgoDate);
    Bundle searchOutOfBoundsResult = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(outOfBoundsRange).returnBundle(Bundle.class).execute();
    assertNotNull(searchOutOfBoundsResult);
    assertEquals(0, searchOutOfBoundsResult.getTotal());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Date(java.util.Date) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) LoggerFactory(org.slf4j.LoggerFactory) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Coverage(org.hl7.fhir.r4.model.Coverage) Logger(org.slf4j.Logger) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Coverage(org.hl7.fhir.r4.model.Coverage) Date(java.util.Date) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 97 with IGenericClient

use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.

the class R4CoverageResourceProviderIT method readCoveragesForMissingBeneficiary.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * works as expected for {@link Beneficiary}-derived {@link Coverage}s that do not exist in the DB
 * (with both positive and negative IDs).
 */
@Test
public void readCoveragesForMissingBeneficiary() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    // No data is loaded, so these should return nothing.
    ResourceNotFoundException exception;
    exception = null;
    try {
        fhirClient.read().resource(Coverage.class).withId(TransformerUtilsV2.buildCoverageId(MedicareSegment.PART_A, "1234")).execute();
    } catch (ResourceNotFoundException e) {
        exception = e;
    }
    assertNotNull(exception);
    exception = null;
    try {
        fhirClient.read().resource(Coverage.class).withId(TransformerUtilsV2.buildCoverageId(MedicareSegment.PART_B, "1234")).execute();
    } catch (ResourceNotFoundException e) {
        exception = e;
    }
    assertNotNull(exception);
    // Tests negative ID will pass regex pattern for valid coverageId.
    exception = null;
    try {
        fhirClient.read().resource(Coverage.class).withId(TransformerUtilsV2.buildCoverageId(MedicareSegment.PART_D, "-1234")).execute();
    } catch (ResourceNotFoundException e) {
        exception = e;
    }
    assertNotNull(exception);
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Test(org.junit.jupiter.api.Test)

Example 98 with IGenericClient

use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.

the class R4CoverageResourceProviderIT method searchByExistingBeneficiary.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
 * works as expected for a {@link Beneficiary} that does exist in the DB.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchByExistingBeneficiary() throws FHIRException {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    assertEquals(MedicareSegment.values().length, searchResults.getTotal());
    /*
     * Verify that no paging links exist within the bundle.
     */
    assertNull(searchResults.getLink(Constants.LINK_FIRST));
    assertNull(searchResults.getLink(Constants.LINK_NEXT));
    assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
    assertNull(searchResults.getLink(Constants.LINK_LAST));
    /*
     * Verify that each of the expected Coverages (one for every
     * MedicareSegment) is present and looks correct.
     */
    Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
    CoverageTransformerV2Test.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
    Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
    CoverageTransformerV2Test.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
    Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
    CoverageTransformerV2Test.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Date(java.util.Date) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) LoggerFactory(org.slf4j.LoggerFactory) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Coverage(org.hl7.fhir.r4.model.Coverage) Logger(org.slf4j.Logger) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Coverage(org.hl7.fhir.r4.model.Coverage) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 99 with IGenericClient

use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.

the class R4CoverageResourceProviderIT method readCoveragesForInvalidIdParam.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * works as expected for {@link Beneficiary}-derived {@link Coverage}s that has an invalid {@link
 * gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#IdParam} parameter.
 */
@Test
public void readCoveragesForInvalidIdParam() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    // Parameter is invalid, should throw exception
    InvalidRequestException exception;
    exception = null;
    try {
        fhirClient.read().resource(Coverage.class).withId(TransformerUtilsV2.buildCoverageId(MedicareSegment.PART_A, "1?234")).execute();
    } catch (InvalidRequestException e) {
        exception = e;
    }
    assertNotNull(exception);
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Test(org.junit.jupiter.api.Test)

Example 100 with IGenericClient

use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.

the class R4ClaimResponseResourceProviderIT method shouldGetCorrectFissClaimResponseResourceById.

@Test
void shouldGetCorrectFissClaimResponseResourceById() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    ClaimResponse claimResult = fhirClient.read().resource(ClaimResponse.class).withId("f-123456").execute();
    String expected = testUtils.expectedResponseFor("claimResponseFissRead");
    String actual = FhirContext.forR4().newJsonParser().encodeResourceToString(claimResult);
    AssertUtils.assertJsonEquals(expected, actual, IGNORE_PATTERNS);
}
Also used : ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Test(org.junit.jupiter.api.Test)

Aggregations

IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)288 Test (org.junit.jupiter.api.Test)166 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)141 List (java.util.List)133 Arrays (java.util.Arrays)127 BeforeAll (org.junit.jupiter.api.BeforeAll)126 ServerTestUtils (gov.cms.bfd.server.war.ServerTestUtils)125 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)124 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)123 PipelineTestUtils (gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils)123 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)123 AfterEach (org.junit.jupiter.api.AfterEach)123 Collectors (java.util.stream.Collectors)119 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)115 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)100 Bundle (org.hl7.fhir.r4.model.Bundle)92 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)91 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)90 Date (java.util.Date)88 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)85