use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class RifLoader method updateBeneficaryHistory.
/**
* Ensures that a {@link BeneficiaryHistory} record is created for the specified {@link
* Beneficiary}, if that {@link Beneficiary} already exists and is just being updated.
*
* @param entityManager the {@link EntityManager} to use
* @param newBeneficiaryRecord the {@link Beneficiary} record being processed
* @param oldBeneficiaryRecord the previous/current version of the {@link Beneficiary} (as it
* exists in the database before applying the specified {@link RifRecordEvent})
* @param batchTimestamp the timestamp of the batch
*/
private static void updateBeneficaryHistory(EntityManager entityManager, Beneficiary newBeneficiaryRecord, Optional<Beneficiary> oldBeneficiaryRecord, Instant batchTimestamp) {
if (oldBeneficiaryRecord.isPresent() && !isBeneficiaryHistoryEqual(newBeneficiaryRecord, oldBeneficiaryRecord.get())) {
BeneficiaryHistory oldBeneCopy = new BeneficiaryHistory();
oldBeneCopy.setBeneficiaryId(oldBeneficiaryRecord.get().getBeneficiaryId());
oldBeneCopy.setBirthDate(oldBeneficiaryRecord.get().getBirthDate());
oldBeneCopy.setHicn(oldBeneficiaryRecord.get().getHicn());
oldBeneCopy.setHicnUnhashed(oldBeneficiaryRecord.get().getHicnUnhashed());
oldBeneCopy.setSex(oldBeneficiaryRecord.get().getSex());
oldBeneCopy.setMedicareBeneficiaryId(oldBeneficiaryRecord.get().getMedicareBeneficiaryId());
oldBeneCopy.setMbiHash(oldBeneficiaryRecord.get().getMbiHash());
oldBeneCopy.setMbiEffectiveDate(oldBeneficiaryRecord.get().getMbiEffectiveDate());
oldBeneCopy.setMbiObsoleteDate(oldBeneficiaryRecord.get().getMbiObsoleteDate());
oldBeneCopy.setLastUpdated(Optional.of(batchTimestamp));
entityManager.persist(oldBeneCopy);
}
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class RifLoader method hashBeneficiaryHistoryHicn.
/**
* For {@link RifRecordEvent}s where the {@link RifRecordEvent#getRecord()} is a {@link
* BeneficiaryHistory}, switches the {@link BeneficiaryHistory#getHicn()} property to a
* cryptographic hash of its current value. This is done for security purposes, and the Blue
* Button API frontend applications know how to compute the exact same hash, which allows the two
* halves of the system to interoperate.
*
* <p>All other {@link RifRecordEvent}s are left unmodified.
*
* @param rifRecordEvent the {@link RifRecordEvent} to (possibly) modify
*/
private void hashBeneficiaryHistoryHicn(RifRecordEvent<?> rifRecordEvent) {
if (rifRecordEvent.getFileEvent().getFile().getFileType() != RifFileType.BENEFICIARY_HISTORY)
return;
Timer.Context timerHashing = rifRecordEvent.getFileEvent().getEventMetrics().timer(MetricRegistry.name(getClass().getSimpleName(), "hicnsHashed")).time();
BeneficiaryHistory beneficiaryHistory = (BeneficiaryHistory) rifRecordEvent.getRecord();
// set the unhashed Hicn
beneficiaryHistory.setHicnUnhashed(Optional.of(beneficiaryHistory.getHicn()));
// set the hashed Hicn
beneficiaryHistory.setHicn(computeHicnHash(idHasher, beneficiaryHistory.getHicn()));
timerHashing.stop();
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsWithLargePageSizesOnFewerResults.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with a page size of 50 with fewer (8) results.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsWithLargePageSizesOnFewerResults() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
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(TransformerUtils.buildPatientId(beneficiary))).count(50).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 Beneficiary)).filter(r -> !(r instanceof BeneficiaryHistory)).filter(r -> !(r instanceof MedicareBeneficiaryIdHistory)).count(), searchResults.getTotal());
/*
* Verify that only the first and last links exist as there are no previous or
* next pages.
*/
assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
assertNotNull(searchResults.getLink(Constants.LINK_LAST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
/*
* Verify that each of the expected claims (one for every claim type) is present
* and looks correct.
*/
CarrierClaim carrierClaim = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get();
assertEquals(1, filterToClaimType(searchResults, ClaimType.CARRIER).size());
CarrierClaimTransformerTest.assertMatches(carrierClaim, filterToClaimType(searchResults, ClaimType.CARRIER).get(0), Optional.empty());
DMEClaim dmeClaim = loadedRecords.stream().filter(r -> r instanceof DMEClaim).map(r -> (DMEClaim) r).findFirst().get();
DMEClaimTransformerTest.assertMatches(dmeClaim, filterToClaimType(searchResults, ClaimType.DME).get(0), Optional.empty());
HHAClaim hhaClaim = loadedRecords.stream().filter(r -> r instanceof HHAClaim).map(r -> (HHAClaim) r).findFirst().get();
HHAClaimTransformerTest.assertMatches(hhaClaim, filterToClaimType(searchResults, ClaimType.HHA).get(0));
HospiceClaim hospiceClaim = loadedRecords.stream().filter(r -> r instanceof HospiceClaim).map(r -> (HospiceClaim) r).findFirst().get();
HospiceClaimTransformerTest.assertMatches(hospiceClaim, filterToClaimType(searchResults, ClaimType.HOSPICE).get(0));
InpatientClaim inpatientClaim = loadedRecords.stream().filter(r -> r instanceof InpatientClaim).map(r -> (InpatientClaim) r).findFirst().get();
InpatientClaimTransformerTest.assertMatches(inpatientClaim, filterToClaimType(searchResults, ClaimType.INPATIENT).get(0));
OutpatientClaim outpatientClaim = loadedRecords.stream().filter(r -> r instanceof OutpatientClaim).map(r -> (OutpatientClaim) r).findFirst().get();
OutpatientClaimTransformerTest.assertMatches(outpatientClaim, filterToClaimType(searchResults, ClaimType.OUTPATIENT).get(0));
PartDEvent partDEvent = loadedRecords.stream().filter(r -> r instanceof PartDEvent).map(r -> (PartDEvent) r).findFirst().get();
PartDEventTransformerTest.assertMatches(partDEvent, filterToClaimType(searchResults, ClaimType.PDE).get(0));
SNFClaim snfClaim = loadedRecords.stream().filter(r -> r instanceof SNFClaim).map(r -> (SNFClaim) r).findFirst().get();
SNFClaimTransformerTest.assertMatches(snfClaim, filterToClaimType(searchResults, ClaimType.SNF).get(0));
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientAndType.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient(ReferenceParam,
* TokenAndListParam, String, String, DateRangeParam, DateRangeParam, RequestDetails)} 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().createFhirClient();
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(TransformerUtils.buildPatientId(beneficiary))).where(new TokenClientParam("type").exactly().code(ClaimType.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();
PartDEventTransformerTest.assertMatches(partDEvent, filterToClaimType(searchResults, ClaimType.PDE).get(0));
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerTest method loadSampleABeneficiary.
/**
* @return the {@link StaticRifResourceGroup#SAMPLE_A} {@link Beneficiary} record, with the {@link
* Beneficiary#getBeneficiaryHistories()} and {@link
* Beneficiary#getMedicareBeneficiaryIdHistories()} fields populated.
*/
private static Beneficiary loadSampleABeneficiary() {
List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
// Pull out the base Beneficiary record and fix its HICN and MBI-HASH fields.
Beneficiary beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
beneficiary.setHicn("someHICNhash");
beneficiary.setMbiHash(Optional.of("someMBIhash"));
// Add the HICN history records to the Beneficiary, and fix their HICN fields.
Set<BeneficiaryHistory> beneficiaryHistories = parsedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId())).collect(Collectors.toSet());
beneficiary.getBeneficiaryHistories().addAll(beneficiaryHistories);
for (BeneficiaryHistory beneficiaryHistory : beneficiary.getBeneficiaryHistories()) {
beneficiaryHistory.setHicnUnhashed(Optional.of(beneficiaryHistory.getHicn()));
beneficiaryHistory.setHicn("someHICNhash");
}
// Add the MBI history records to the Beneficiary.
Set<MedicareBeneficiaryIdHistory> beneficiaryMbis = parsedRecords.stream().filter(r -> r instanceof MedicareBeneficiaryIdHistory).map(r -> (MedicareBeneficiaryIdHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId().orElse(null))).collect(Collectors.toSet());
beneficiary.getMedicareBeneficiaryIdHistories().addAll(beneficiaryMbis);
return beneficiary;
}
Aggregations