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);
}
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();
}
}
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());
}
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());
}
}
}
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));
}
Aggregations