Search in sources :

Example 96 with Beneficiary

use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.

the class RifLoaderIT method failOnUpdateBeneficiaryBeforeInsert.

/**
 * Runs {@link RifLoader} against the {@link StaticRifResourceGroup#SAMPLE_A} data for an <code>
 * UPDATE</code> {@link Beneficiary} record that there hasn't been a previous <code>INSERT</code>
 * on, to verify that this fails as expected.
 */
@Test
public void failOnUpdateBeneficiaryBeforeInsert() {
    // Tweak the SAMPLE_A beneficiary to be an UPDATE.
    Stream<RifFile> samplesStream = filterSamples(r -> r.getFileType() == RifFileType.BENEFICIARY, StaticRifResourceGroup.SAMPLE_A.getResources());
    Function<RifRecordEvent<?>, List<List<String>>> recordEditor = rifRecordEvent -> {
        CSVRecord beneCsvRow = rifRecordEvent.getRawCsvRecords().get(0);
        List<String> beneCsvValues = StreamSupport.stream(beneCsvRow.spliterator(), false).collect(Collectors.toList());
        beneCsvValues.set(0, "UPDATE");
        return List.of(beneCsvValues);
    };
    Function<RifFile, RifFile> fileEditor = sample -> editSampleRecords(sample, recordEditor);
    Stream<RifFile> editedSample = editSamples(samplesStream, fileEditor);
    // Load the edited sample to verify that it fails, as expected.
    AssertionFailedError thrown = assertThrows(AssertionFailedError.class, () -> {
        loadSample("SAMPLE_A, bene only, UPDATE", CcwRifLoadTestUtils.getLoadOptions(), editedSample);
    });
    assertTrue(thrown.getMessage().contains("Load errors encountered"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) RifFileType(gov.cms.bfd.model.rif.RifFileType) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) CSVRecord(org.apache.commons.csv.CSVRecord) LoggerFactory(org.slf4j.LoggerFactory) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) Disabled(org.junit.jupiter.api.Disabled) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CSVFormat(org.apache.commons.csv.CSVFormat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertionFailedError(org.opentest4j.AssertionFailedError) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Path(java.nio.file.Path) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Predicate(java.util.function.Predicate) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFile(gov.cms.bfd.model.rif.RifFile) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) TestInfo(org.junit.jupiter.api.TestInfo) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) LoadedBatch(gov.cms.bfd.model.rif.LoadedBatch) List(java.util.List) BeneficiaryHistory_(gov.cms.bfd.model.rif.BeneficiaryHistory_) Stream(java.util.stream.Stream) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) LocalDate(java.time.LocalDate) Slf4jReporter(com.codahale.metrics.Slf4jReporter) LoadedFile(gov.cms.bfd.model.rif.LoadedFile) Optional(java.util.Optional) RifParsingUtils(gov.cms.bfd.model.rif.parse.RifParsingUtils) BeneficiaryColumn(gov.cms.bfd.model.rif.BeneficiaryColumn) RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) CSVPrinter(org.apache.commons.csv.CSVPrinter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) LocalRifFile(gov.cms.bfd.pipeline.ccw.rif.extract.LocalRifFile) Function(java.util.function.Function) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) Root(javax.persistence.criteria.Root) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Month(java.time.Month) FileWriter(java.io.FileWriter) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) EntityTransaction(javax.persistence.EntityTransaction) RifFile(gov.cms.bfd.model.rif.RifFile) LocalRifFile(gov.cms.bfd.pipeline.ccw.rif.extract.LocalRifFile) RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) List(java.util.List) CSVRecord(org.apache.commons.csv.CSVRecord) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 97 with Beneficiary

use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.

the class RifLoaderIT method loadInitialEnrollmentShouldCount20SinceThereIsAUpdateOf8Months.

/*
   * This test checks that all enrollment data for 2 years has been loaded into the beneficiary
   * monthly table and than does an update of 8 years without the 4 other months for the year
   */
@Test
public void loadInitialEnrollmentShouldCount20SinceThereIsAUpdateOf8Months() {
    // Loads first year of data
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    // Loads second year of data
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_U.getResources()));
    // Loads  second year of data with only 8 months
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_U_BENES_CHANGED_WITH_8_MONTHS.getResources()));
    EntityManagerFactory entityManagerFactory = PipelineTestUtils.get().getPipelineApplicationState().getEntityManagerFactory();
    EntityManager entityManager = null;
    try {
        entityManager = entityManagerFactory.createEntityManager();
        Beneficiary beneficiaryFromDb = entityManager.find(Beneficiary.class, "567834");
        // Checks to make sure we only have 20 months of data
        assertEquals(20, beneficiaryFromDb.getBeneficiaryMonthlys().size());
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 98 with Beneficiary

use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.

the class RifLoaderTest method isBeneficiaryHistoryEqual.

/**
 * Runs a couple of fake HICNs through {@link RifLoader#computeHicnHash(LoadAppOptions,
 * SecretKeyFactory, String)} to verify that the expected result is produced.
 */
@Test
public void isBeneficiaryHistoryEqual() {
    Beneficiary newBene = new Beneficiary();
    LocalDate birthDate = LocalDate.of(1960, 1, 8);
    String hicn = "2332j3l2";
    Optional<String> hicnUnhased = Optional.of("323232");
    char sex = 'M';
    Optional<String> medicareBeneficiaryId = Optional.of("beneficiaryId");
    Optional<String> mbiHash = Optional.of("mbiHash");
    Optional<LocalDate> mbiEffectiveDate = Optional.of(LocalDate.of(2020, 1, 1));
    Optional<LocalDate> mbiObsoleteDate = Optional.of(LocalDate.of(2020, 1, 8));
    newBene.setBirthDate(birthDate);
    newBene.setHicn(hicn);
    newBene.setHicnUnhashed(hicnUnhased);
    newBene.setSex(sex);
    newBene.setMedicareBeneficiaryId(medicareBeneficiaryId);
    newBene.setMbiHash(mbiHash);
    newBene.setMbiEffectiveDate(mbiEffectiveDate);
    newBene.setMbiObsoleteDate(mbiObsoleteDate);
    Beneficiary oldBene = new Beneficiary();
    oldBene.setBirthDate(birthDate);
    oldBene.setHicn(hicn);
    oldBene.setHicnUnhashed(hicnUnhased);
    oldBene.setSex(sex);
    oldBene.setMedicareBeneficiaryId(medicareBeneficiaryId);
    oldBene.setMbiHash(mbiHash);
    oldBene.setMbiEffectiveDate(mbiEffectiveDate);
    oldBene.setMbiObsoleteDate(mbiObsoleteDate);
    // Both old and new beneficiary have the same values return true
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary birth date is not the same as old should assert false
    newBene.setBirthDate(LocalDate.of(1950, 1, 8));
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary birth date and set it back to old should assert true
    newBene.setBirthDate(birthDate);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary hicn is not the same as old should assert false
    newBene.setHicn("difHicn");
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary hicn and set it back to old should assert true
    newBene.setHicn(hicn);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary hicnunHashed is not the same as old should assert false
    newBene.setHicnUnhashed(Optional.of("difHicn"));
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary hicnUnhased and set it back to old should assert true
    newBene.setHicnUnhashed(hicnUnhased);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary sex is not the same as old should assert false
    newBene.setSex('F');
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary sex and set it back to old should assert true
    newBene.setSex(sex);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mediciarybeneficiaryid is not the same as old should assert false
    newBene.setMedicareBeneficiaryId(Optional.of("diff"));
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary mediciarybeneficiaryid and set it back to old should assert true
    newBene.setMedicareBeneficiaryId(medicareBeneficiaryId);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mbihash is not the same as old should assert false
    newBene.setMbiHash(Optional.of("mbihashdiff"));
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary mbihash and set it back to old should assert true
    newBene.setMbiHash(mbiHash);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mbiEffectiveDate is not the same as old should assert false
    newBene.setMbiEffectiveDate(Optional.of(LocalDate.of(2020, 1, 8)));
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary mbiEffectiveDate and set it back to old should assert true
    newBene.setMbiEffectiveDate(mbiEffectiveDate);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mbiObsoleteDate is not the same as old should assert true
    // becasue mbiObsoleteDate is no longer part of the equality check.
    newBene.setMbiObsoleteDate(Optional.of(LocalDate.of(2020, 1, 2)));
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary mbiObsoleteDate and set it back to old should assert true
    newBene.setMbiObsoleteDate(mbiObsoleteDate);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Check for nulls on fields
    // New beneficiary hicnUnhashed is null and the return result should assert false
    newBene.setHicnUnhashed(Optional.empty());
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary hicnUnhashed and set it back to old should assert true
    newBene.setHicnUnhashed(hicnUnhased);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary sex is null and the return result should assert false
    newBene.setSex(Character.MIN_VALUE);
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo New beneficiary sex and set it back to old should assert true
    newBene.setSex(sex);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mediciarybeneficiaryid is null and the return result should assert false
    newBene.setMedicareBeneficiaryId(Optional.empty());
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // Undo beneficiary mediciarybeneficiaryid and set it back to old should assert true
    newBene.setMedicareBeneficiaryId(medicareBeneficiaryId);
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mbiEffectiveDate is null and the return result should assert false
    newBene.setMbiEffectiveDate(Optional.empty());
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // old beneficiary mbiEffectiveDate was empty and new beneficiary has mbiEffectiveDate
    newBene.setMbiEffectiveDate(mbiEffectiveDate);
    oldBene.setMbiEffectiveDate(Optional.empty());
    assertFalse(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
    // New beneficiary mbiObsoleteDate is null and the return result should assert true
    // since the test will ignore empty setMbiObsoleteDate.
    oldBene.setMbiEffectiveDate(mbiEffectiveDate);
    newBene.setMbiObsoleteDate(Optional.empty());
    assertTrue(RifLoader.isBeneficiaryHistoryEqual(newBene, oldBene));
}
Also used : LocalDate(java.time.LocalDate) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 99 with Beneficiary

use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProvider method findClaimTypeByPatient.

/**
 * @param claimType the {@link ClaimTypeV2} to find
 * @param patientId the {@link Beneficiary#getBeneficiaryId()} to filter by
 * @param lastUpdated the update time to filter by
 * @return the matching claim/event entities
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Trace
private <T> List<T> findClaimTypeByPatient(ClaimTypeV2 claimType, String patientId, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = builder.createQuery((Class) claimType.getEntityClass());
    Root root = criteria.from(claimType.getEntityClass());
    claimType.getEntityLazyAttributes().stream().forEach(a -> root.fetch(a));
    criteria.select(root).distinct(true);
    // Search for a beneficiary's records. Use lastUpdated if present
    Predicate wherePredicate = builder.equal(root.get(claimType.getEntityBeneficiaryIdAttribute()), patientId);
    if (lastUpdated != null && !lastUpdated.isEmpty()) {
        Predicate predicate = QueryUtils.createLastUpdatedPredicate(builder, root, lastUpdated);
        wherePredicate = builder.and(wherePredicate, predicate);
    }
    criteria.where(wherePredicate);
    List<T> claimEntities = null;
    Long eobsByBeneIdQueryNanoSeconds = null;
    Timer.Context timerEobQuery = metricRegistry.timer(MetricRegistry.name(metricRegistry.getClass().getSimpleName(), "query", "eobs_by_bene_id", claimType.name().toLowerCase())).time();
    try {
        claimEntities = entityManager.createQuery(criteria).getResultList();
    } finally {
        eobsByBeneIdQueryNanoSeconds = timerEobQuery.stop();
        TransformerUtilsV2.recordQueryInMdc(String.format("eobs_by_bene_id.%s", claimType.name().toLowerCase()), eobsByBeneIdQueryNanoSeconds, claimEntities == null ? 0 : claimEntities.size());
    }
    if (claimEntities != null && serviceDate != null && !serviceDate.isEmpty()) {
        final Instant lowerBound = serviceDate.getLowerBoundAsInstant() != null ? serviceDate.getLowerBoundAsInstant().toInstant() : null;
        final Instant upperBound = serviceDate.getUpperBoundAsInstant() != null ? serviceDate.getUpperBoundAsInstant().toInstant() : null;
        final java.util.function.Predicate<LocalDate> lowerBoundCheck = lowerBound == null ? (date) -> true : (date) -> compareLocalDate(date, lowerBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getLowerBound().getPrefix());
        final java.util.function.Predicate<LocalDate> upperBoundCheck = upperBound == null ? (date) -> true : (date) -> compareLocalDate(date, upperBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getUpperBound().getPrefix());
        return claimEntities.stream().filter(entity -> lowerBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity)) && upperBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity))).collect(Collectors.toList());
    }
    return claimEntities;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) ListIterator(java.util.ListIterator) Description(ca.uhn.fhir.model.api.annotation.Description) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) Matcher(java.util.regex.Matcher) 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) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ParamPrefixEnum(ca.uhn.fhir.rest.param.ParamPrefixEnum) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Pattern(java.util.regex.Pattern) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Nullable(javax.annotation.Nullable) 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) Logger(org.slf4j.Logger) Operation(gov.cms.bfd.server.war.Operation) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Bundle(org.hl7.fhir.r4.model.Bundle) Comparator(java.util.Comparator) Root(javax.persistence.criteria.Root) Instant(java.time.Instant) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) LocalDate(java.time.LocalDate) Predicate(javax.persistence.criteria.Predicate) Timer(com.codahale.metrics.Timer) Trace(com.newrelic.api.agent.Trace)

Example 100 with Beneficiary

use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProvider 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.V2_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 -> BeneficiaryTransformerV2.transform(metricRegistry, b, requestHeader)).collect(Collectors.toList());
    Bundle bundle = TransformerUtilsV2.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
    TransformerUtilsV2.workAroundHAPIIssue1585(requestDetails);
    return bundle;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Description(ca.uhn.fhir.model.api.annotation.Description) Identifier(org.hl7.fhir.r4.model.Identifier) 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) Patient(org.hl7.fhir.r4.model.Patient) 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) TypedQuery(javax.persistence.TypedQuery) 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) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) MDC(org.slf4j.MDC) YearMonth(java.time.YearMonth) Bundle(org.hl7.fhir.r4.model.Bundle) Collections(java.util.Collections) PatientLinkBuilder(gov.cms.bfd.server.war.commons.PatientLinkBuilder) Bundle(org.hl7.fhir.r4.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

Beneficiary (gov.cms.bfd.model.rif.Beneficiary)152 Test (org.junit.jupiter.api.Test)105 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)102 List (java.util.List)97 Arrays (java.util.Arrays)96 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)94 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)93 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)90 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)90 ServerTestUtils (gov.cms.bfd.server.war.ServerTestUtils)89 Collectors (java.util.stream.Collectors)87 PipelineTestUtils (gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils)85 AfterEach (org.junit.jupiter.api.AfterEach)84 BeforeAll (org.junit.jupiter.api.BeforeAll)83 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)77 Instant (java.time.Instant)73 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)68 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)68 Date (java.util.Date)67 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)67