Search in sources :

Example 11 with Beneficiary

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

the class R4PatientResourceProvider method selectBeneWithLatestReferenceYear.

/**
 * Following method will bring back the Beneficiary that has the most recent rfrnc_yr since there
 * may be more than bene id in the Beneficiaries table
 *
 * @param duplicateBenes of matching Beneficiary records the {@link
 *     Beneficiary#getBeneficiaryId()} value to match
 * @return a FHIR {@link Beneficiary} for the CCW {@link Beneficiary} that matches the specified
 *     {@link Beneficiary#getHicn()} hash value
 */
@Trace
private Beneficiary selectBeneWithLatestReferenceYear(List<Beneficiary> duplicateBenes) {
    BigDecimal maxReferenceYear = new BigDecimal(-0001);
    String maxReferenceYearMatchingBeneficiaryId = null;
    // loop through matching bene ids looking for max rfrnc_yr
    for (Beneficiary duplicateBene : duplicateBenes) {
        // bene record found but reference year is null - still process
        if (!duplicateBene.getBeneEnrollmentReferenceYear().isPresent()) {
            duplicateBene.setBeneEnrollmentReferenceYear(Optional.of(new BigDecimal(0)));
        }
        // bene reference year is > than prior reference year
        if (duplicateBene.getBeneEnrollmentReferenceYear().get().compareTo(maxReferenceYear) > 0) {
            maxReferenceYear = duplicateBene.getBeneEnrollmentReferenceYear().get();
            maxReferenceYearMatchingBeneficiaryId = duplicateBene.getBeneficiaryId();
        }
    }
    return entityManager.find(Beneficiary.class, maxReferenceYearMatchingBeneficiaryId);
}
Also used : BigDecimal(java.math.BigDecimal) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Trace(com.newrelic.api.agent.Trace)

Example 12 with Beneficiary

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

the class RifLoaderIT method loadInitialEnrollmentShouldCount21SinceThereIsAUpdateOf8MonthsAndAUpdateOf9Months.

/*
   * This test checks that all enrollment data for month july in its 2 year is updated when there is data
   * for august that comes in.
   */
@Test
public void loadInitialEnrollmentShouldCount21SinceThereIsAUpdateOf8MonthsAndAUpdateOf9Months() {
    // Load first year of data
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    // Load 8 months of data in year two
    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");
        assertEquals(20, beneficiaryFromDb.getBeneficiaryMonthlys().size());
        BeneficiaryMonthly augustMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(19);
        assertEquals("2019-08-01", augustMonthly.getYearMonth().toString());
        assertEquals("C", augustMonthly.getEntitlementBuyInInd().get().toString());
        assertEquals("AA", augustMonthly.getFipsStateCntyCode().get());
        assertFalse(augustMonthly.getHmoIndicatorInd().isPresent());
        assertEquals("AA", augustMonthly.getMedicaidDualEligibilityCode().get());
        assertEquals("AA", augustMonthly.getMedicareStatusCode().get());
        assertEquals("C", augustMonthly.getPartCContractNumberId().get());
        assertEquals("C", augustMonthly.getPartCPbpNumberId().get());
        assertEquals("C", augustMonthly.getPartCPlanTypeCode().get());
        assertEquals("C", augustMonthly.getPartDContractNumberId().get());
        assertEquals("AA", augustMonthly.getPartDLowIncomeCostShareGroupCode().get());
        assertFalse(augustMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", augustMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(augustMonthly.getPartDSegmentNumberId().isPresent());
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
    // Load 9 months of data in year two with some data updated in july
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_U_BENES_CHANGED_WITH_9_MONTHS.getResources()));
    entityManager = null;
    try {
        entityManager = entityManagerFactory.createEntityManager();
        Beneficiary beneficiaryFromDb = entityManager.find(Beneficiary.class, "567834");
        assertEquals(21, beneficiaryFromDb.getBeneficiaryMonthlys().size());
        BeneficiaryMonthly augustMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(19);
        assertEquals("2019-08-01", augustMonthly.getYearMonth().toString());
        assertEquals("C", augustMonthly.getEntitlementBuyInInd().get().toString());
        assertEquals("AA", augustMonthly.getFipsStateCntyCode().get());
        // Updated in file
        assertEquals("C", augustMonthly.getHmoIndicatorInd().get().toString());
        assertEquals("AA", augustMonthly.getMedicaidDualEligibilityCode().get());
        assertEquals("AA", augustMonthly.getMedicareStatusCode().get());
        assertEquals("C", augustMonthly.getPartCContractNumberId().get());
        assertEquals("C", augustMonthly.getPartCPbpNumberId().get());
        assertEquals("C", augustMonthly.getPartCPlanTypeCode().get());
        assertEquals("C", augustMonthly.getPartDContractNumberId().get());
        assertEquals("AA", augustMonthly.getPartDLowIncomeCostShareGroupCode().get());
        assertFalse(augustMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", augustMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(augustMonthly.getPartDSegmentNumberId().isPresent());
        BeneficiaryMonthly septMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(20);
        assertEquals("2019-09-01", septMonthly.getYearMonth().toString());
        assertFalse(septMonthly.getEntitlementBuyInInd().isPresent());
        assertFalse(septMonthly.getFipsStateCntyCode().isPresent());
        assertFalse(septMonthly.getHmoIndicatorInd().isPresent());
        assertEquals("AA", septMonthly.getMedicaidDualEligibilityCode().get());
        assertFalse(septMonthly.getMedicareStatusCode().isPresent());
        assertFalse(septMonthly.getPartCContractNumberId().isPresent());
        assertFalse(septMonthly.getPartCPbpNumberId().isPresent());
        assertFalse(septMonthly.getPartCPlanTypeCode().isPresent());
        assertFalse(septMonthly.getPartDContractNumberId().isPresent());
        assertFalse(septMonthly.getPartDLowIncomeCostShareGroupCode().isPresent());
        assertFalse(septMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", septMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(septMonthly.getPartDSegmentNumberId().isPresent());
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 13 with Beneficiary

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

the class RifFilesProcessorTest method process1BeneRecord.

/**
 * Ensures that {@link RifFilesProcessor} can correctly handle {@link
 * StaticRifResource#SAMPLE_A_BENES}.
 */
@Test
public void process1BeneRecord() {
    RifFilesEvent filesEvent = new RifFilesEvent(Instant.now(), StaticRifResource.SAMPLE_A_BENES.toRifFile());
    RifFilesProcessor processor = new RifFilesProcessor();
    RifFileRecords rifFileRecords = processor.produceRecords(filesEvent.getFileEvents().get(0));
    List<RifRecordEvent<?>> rifEventsList = rifFileRecords.getRecords().collect(Collectors.toList());
    assertEquals(StaticRifResource.SAMPLE_A_BENES.getRecordCount(), rifEventsList.size());
    RifRecordEvent<?> rifRecordEvent = rifEventsList.get(0);
    assertEquals(StaticRifResource.SAMPLE_A_BENES.getRifFileType(), rifRecordEvent.getFileEvent().getFile().getFileType());
    assertNotNull(rifRecordEvent.getRecord());
    assertTrue(rifRecordEvent.getRecord() instanceof Beneficiary);
    Beneficiary beneRow = (Beneficiary) rifRecordEvent.getRecord();
    assertEquals(beneRow.getBeneficiaryId(), rifRecordEvent.getBeneficiaryId());
    assertEquals(RecordAction.INSERT, rifRecordEvent.getRecordAction());
    assertEquals("567834", beneRow.getBeneficiaryId());
    assertEquals("MO", beneRow.getStateCode());
    assertEquals("123", beneRow.getCountyCode());
    assertEquals("12345", beneRow.getPostalCode());
    assertEquals(LocalDate.of(1981, Month.MARCH, 17), beneRow.getBirthDate());
    assertEquals(('1'), beneRow.getSex());
    assertEquals(new Character('1'), beneRow.getRace().get());
    assertEquals(new Character('1'), beneRow.getEntitlementCodeOriginal().get());
    assertEquals(new Character('1'), beneRow.getEntitlementCodeCurrent().get());
    assertEquals(new Character('N'), beneRow.getEndStageRenalDiseaseCode().get());
    assertEquals(new String("20"), beneRow.getMedicareEnrollmentStatusCode().get());
    assertEquals(new Character('0'), beneRow.getPartBTerminationCode().get());
    assertEquals(new Character('0'), beneRow.getPartBTerminationCode().get());
    assertEquals("543217066U", beneRow.getHicnUnhashed().orElse(null));
    assertEquals("Doe", beneRow.getNameSurname());
    assertEquals("John", beneRow.getNameGiven());
    assertEquals(new Character('A'), beneRow.getNameMiddleInitial().get());
    assertEquals("3456789", beneRow.getMedicareBeneficiaryId().get());
    assertEquals(LocalDate.of(1981, Month.MARCH, 17), beneRow.getBeneficiaryDateOfDeath().get());
    assertEquals(LocalDate.of(1963, Month.OCTOBER, 3), beneRow.getMedicareCoverageStartDate().get());
    assertEquals(new Character('1'), beneRow.getHmoIndicatorAprInd().get());
    assertEquals(new BigDecimal(5), beneRow.getPartDMonthsCount().get());
    assertEquals("00", beneRow.getPartDLowIncomeCostShareGroupFebCode().get());
    assertEquals(new Character('N'), beneRow.getPartDRetireeDrugSubsidyDecInd().get());
    assertEquals("204 SOUTH ST", beneRow.getDerivedMailingAddress1().get());
    assertEquals("7560 123TH ST", beneRow.getDerivedMailingAddress2().get());
    assertEquals("SURREY", beneRow.getDerivedMailingAddress3().get());
    assertEquals("DAEJEON SI 34867", beneRow.getDerivedMailingAddress4().get());
    assertEquals("COLOMBIA", beneRow.getDerivedMailingAddress5().get());
    assertEquals("SURREY", beneRow.getDerivedMailingAddress6().get());
    assertEquals("PODUNK", beneRow.getDerivedCityName().get());
    assertEquals("IA", beneRow.getDerivedStateCode().get());
    assertEquals("123456789", beneRow.getDerivedZipCode().get());
    assertEquals(LocalDate.of(2020, Month.JULY, 30), beneRow.getMbiEffectiveDate().get());
    assertEquals(new BigDecimal("1"), beneRow.getBeneLinkKey().get());
}
Also used : RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) BigDecimal(java.math.BigDecimal) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 14 with Beneficiary

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

the class R4ExplanationOfBenefitResourceProviderIT method searchForSamhsaEobsWithExcludeSamhsaTrue.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.R4ExplanationOfBenefitResourceProvider#findByPatient} with
 * <code>excludeSAMHSA=true</code> properly filters out SAMHSA-related claims.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchForSamhsaEobsWithExcludeSamhsaTrue() throws FHIRException {
    Beneficiary beneficiary = loadSampleAWithSamhsa();
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary.getBeneficiaryId()))).and(new StringClientParam(EXCLUDE_SAMHSA_PARAM).matches().value("true")).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    for (ClaimTypeV2 claimType : ClaimTypeV2.values()) {
        /*
       * SAMHSA fields are present on all claim types except for PDE so we should not
       * get any claims back in the results except for PDE.
       */
        if (claimType == ClaimTypeV2.PDE) {
            assertEquals(1, filterToClaimType(searchResults, claimType).size());
        } else {
            assertEquals(0, filterToClaimType(searchResults, claimType).size());
        }
    }
}
Also used : StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

Example 15 with Beneficiary

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

the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientAndType.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#findByPatient(ca.uhn.fhir.rest.param.ReferenceParam)}
 * works as expected for a {@link Patient} that does exist in the DB, with filtering by claim
 * type.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchForEobsByExistingPatientAndType() 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(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).where(new TokenClientParam("type").exactly().code(ClaimTypeV2.PDE.name())).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    /*
     * Verify the bundle contains a key for total and that the value matches the
     * number of entries in the bundle
     */
    assertEquals(loadedRecords.stream().filter(r -> (r instanceof PartDEvent)).filter(r -> !(r instanceof BeneficiaryHistory)).count(), searchResults.getTotal());
    PartDEvent partDEvent = loadedRecords.stream().filter(r -> r instanceof PartDEvent).map(r -> (PartDEvent) r).findFirst().get();
    // Compare result to transformed EOB
    assertEobEquals(PartDEventTransformerV2.transform(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), partDEvent, Optional.of(false)), filterToClaimType(searchResults, ClaimTypeV2.PDE).get(0));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Constants(ca.uhn.fhir.rest.api.Constants) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) BeforeAll(org.junit.jupiter.api.BeforeAll) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Triple(org.apache.commons.lang3.tuple.Triple) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) Resource(org.hl7.fhir.r4.model.Resource) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ExplanationOfBenefitResourceProvider(gov.cms.bfd.server.war.stu3.providers.ExplanationOfBenefitResourceProvider) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Money(org.hl7.fhir.r4.model.Money) ArrayList(java.util.ArrayList) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) ImmutableList(com.google.common.collect.ImmutableList) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) EntityManager(javax.persistence.EntityManager) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

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