Search in sources :

Example 11 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class EndpointJsonResponseComparatorV2IT method eobReadCarrierWithTaxNumbers.

/**
 * @return the results of the {@link
 *     ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.dstu3.model.IdType)} operation for
 *     Carrier claims, with the {@link
 *     ExplanationOfBenefitResourceProvider#HEADER_NAME_INCLUDE_TAX_NUMBERS} set to <code>true
 *     </code>
 */
public static String eobReadCarrierWithTaxNumbers() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = createFhirClientAndSetEncoding();
    RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(CommonHeaders.HEADER_NAME_INCLUDE_TAX_NUMBERS, "true");
    ExtraParamsInterceptor extraParamsInterceptor = new ExtraParamsInterceptor();
    extraParamsInterceptor.setHeaders(requestHeader);
    fhirClient.registerInterceptor(extraParamsInterceptor);
    JsonInterceptor jsonInterceptor = createAndRegisterJsonInterceptor(fhirClient);
    CarrierClaim carrClaim = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get();
    fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.CARRIER, carrClaim.getClaimId())).execute();
    return jsonInterceptor.getResponse();
}
Also used : Arrays(java.util.Arrays) R4PatientResourceProvider(gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) Disabled(org.junit.jupiter.api.Disabled) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) TransformerUtilsV2(gov.cms.bfd.server.war.r4.providers.TransformerUtilsV2) Matcher(java.util.regex.Matcher) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) BeforeAll(org.junit.jupiter.api.BeforeAll) JsonNode(com.fasterxml.jackson.databind.JsonNode) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Path(java.nio.file.Path) Coverage(org.hl7.fhir.r4.model.Coverage) Patient(org.hl7.fhir.r4.model.Patient) MethodSource(org.junit.jupiter.params.provider.MethodSource) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) ImmutableSet(com.google.common.collect.ImmutableSet) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) ExplanationOfBenefitResourceProvider(gov.cms.bfd.server.war.stu3.providers.ExplanationOfBenefitResourceProvider) StandardCharsets(java.nio.charset.StandardCharsets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UncheckedIOException(java.io.UncheckedIOException) JsonArray(com.google.gson.JsonArray) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ClaimTypeV2(gov.cms.bfd.server.war.r4.providers.ClaimTypeV2) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) CoverageResourceProvider(gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Supplier(java.util.function.Supplier) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) Lists(com.google.common.collect.Lists) OutputStreamWriter(java.io.OutputStreamWriter) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) Iterator(java.util.Iterator) Files(java.nio.file.Files) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileOutputStream(java.io.FileOutputStream) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EncodingEnum(ca.uhn.fhir.rest.api.EncodingEnum) File(java.io.File) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Bundle(org.hl7.fhir.r4.model.Bundle) Comparator(java.util.Comparator) Collections(java.util.Collections) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor)

Example 12 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformBeneficiaryWithAllOptionalsEmpty.

/**
 * Verifies that {@link gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer} works
 * correctly when passed a {@link Beneficiary} where all {@link Optional} fields are set to {@link
 * Optional#empty()}.
 */
@Test
public void transformBeneficiaryWithAllOptionalsEmpty() {
    List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    Beneficiary beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    TransformerTestUtils.setAllOptionalsToEmpty(beneficiary);
    RequestHeaders requestHeader = getRHwithIncldIdntityHdr("");
    Patient patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
}
Also used : SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) Sex(gov.cms.bfd.server.war.commons.Sex) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) MetricRegistry(com.codahale.metrics.MetricRegistry) Set(java.util.Set) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Patient(org.hl7.fhir.dstu3.model.Patient) Optional(java.util.Optional) MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 13 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerTest method transformSampleARecordWithoutLastUpdated.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer#transform(Beneficiary)} works as
 * expected when run against the {@link StaticRifResource#SAMPLE_A_BENES} {@link Beneficiary} with
 * a lastUpdated field not set.
 */
@Test
public void transformSampleARecordWithoutLastUpdated() {
    Beneficiary beneficiary = loadSampleABeneficiary();
    beneficiary.setLastUpdated(Optional.empty());
    RequestHeaders requestHeader = getRHwithIncldIdntityHdr("");
    Patient patient = BeneficiaryTransformer.transform(new MetricRegistry(), beneficiary, requestHeader);
    assertMatches(beneficiary, patient, requestHeader);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Patient(org.hl7.fhir.dstu3.model.Patient) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 14 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProviderIT method assertExistingPatientIncludeIdentifiersExpected.

/**
 * Asserts that {@link
 * gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * contains expected/present identifiers for a {@link Patient}.
 *
 * @param includeIdentifiersValue header value
 * @param expectingMbi true if expecting a MBI
 * @param includeAddressValues header value
 */
public void assertExistingPatientIncludeIdentifiersExpected(boolean expectingMbi, RequestHeaders requestHeader) {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Patient expected = BeneficiaryTransformerV2.transform(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), beneficiary, requestHeader);
    IGenericClient fhirClient = createFhirClient(requestHeader);
    Patient patient = fhirClient.read().resource(Patient.class).withId(beneficiary.getBeneficiaryId()).execute();
    // Because of how transform doesn't go through R4PatientResourceProvider, `expected` won't have
    // the historical MBI data.
    // Also, SAMPLE_A does not have mbi history (it used to); however, what used to be denoted as
    // historical
    // is not provided as the 'current' MBI identifier (no historical).
    comparePatient(expected, patient);
    /*
     * Ensure the unhashed values for MBI are present.
     */
    Boolean mbiUnhashedPresent = false;
    Iterator<Identifier> identifiers = patient.getIdentifier().iterator();
    while (identifiers.hasNext()) {
        Identifier identifier = identifiers.next();
        if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_ID)) {
            mbiUnhashedPresent = true;
        }
    }
    // Unhashed MBI should always be present in V2
    assertTrue(mbiUnhashedPresent);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) Identifier(org.hl7.fhir.r4.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) 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) Patient(org.hl7.fhir.r4.model.Patient) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) 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) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Bundle(org.hl7.fhir.r4.model.Bundle) Identifier(org.hl7.fhir.r4.model.Identifier) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Patient(org.hl7.fhir.r4.model.Patient) Beneficiary(gov.cms.bfd.model.rif.Beneficiary)

Example 15 with RequestHeaders

use of gov.cms.bfd.server.war.commons.RequestHeaders 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)

Aggregations

RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)31 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)28 Patient (org.hl7.fhir.dstu3.model.Patient)20 Test (org.junit.jupiter.api.Test)18 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)17 Arrays (java.util.Arrays)17 List (java.util.List)17 Collectors (java.util.stream.Collectors)17 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)13 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)13 MetricRegistry (com.codahale.metrics.MetricRegistry)13 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)13 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)13 Optional (java.util.Optional)13 ArrayList (java.util.ArrayList)12 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)8 ServerTestUtils (gov.cms.bfd.server.war.ServerTestUtils)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)7 CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)7