use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByMbiWithNoHistory.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for MBIs associated with {@link Beneficiary}s that have <strong>no</strong>
* {@link BeneficiaryHistory} records.
*/
@Test
public void searchForExistingPatientByMbiWithNoHistory() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
IGenericClient fhirClient = createFhirClient();
loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).forEach(h -> {
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, h.getMbiHash().get())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(1, searchResults.getTotal());
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
assertEquals(h.getBeneficiaryId(), patientFromSearchResult.getIdElement().getIdPart());
});
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByMbiHashWithBeneDups.
/**
* Verifies that the correct bene id or exception is returned when an MBI points to more than one
* bene id in either the Beneficiaries and/or BeneficiariesHistory table.
*/
@Test
public void searchForExistingPatientByMbiHashWithBeneDups() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
// load additional Beneficiary and Beneficiary History records for
// testing
loadedRecords.addAll(ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_HICN_MULT_BENES.getResources())));
IGenericClient fhirClient = createFhirClient();
Stream<Beneficiary> beneficiariesStream = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r);
List<Beneficiary> beneficiariesList = beneficiariesStream.collect(Collectors.toList());
Stream<BeneficiaryHistory> beneficiariesHistoryStream = loadedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r);
List<BeneficiaryHistory> beneficiariesHistoryList = beneficiariesHistoryStream.collect(Collectors.toList());
boolean useMbiFromBeneficiaryTable;
boolean expectsSingleBeneMatch;
/*
* The following scenario tests when the same mbi is in the
* Beneficiaries table but points to different bene ids.
*/
useMbiFromBeneficiaryTable = true;
expectsSingleBeneMatch = false;
assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "567834", "3456789", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
/*
* The following scenario tests when only one mbi is in the
* Beneficiaries table.
*/
useMbiFromBeneficiaryTable = true;
expectsSingleBeneMatch = true;
assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "123456NULLREFYR", "3456789N", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
/*
* The following scenario tests when the same mbi is in the
* Beneficiaries and also in the BeneficiariesHistory table. The bene id
* is different between the tables so the bene record from the
* Beneficiaries table should be used.
*
* bene id=BENE1234 mbi=SAMEMBI rfrnc_yr=2019 should be pulled back.
*/
useMbiFromBeneficiaryTable = true;
expectsSingleBeneMatch = false;
assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "BENE1234", "SAMEMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
/*
* The following scenario tests when the requested mbi is only in the
* BeneficiariesHistory table. Use the bene id from the
* BeneficiariesHistory table to then read the Beneficiaries table.
*/
useMbiFromBeneficiaryTable = false;
expectsSingleBeneMatch = true;
assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "55555", "HISTMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
/*
* The following scenario tests when the requested mbi is only in the
* BeneficiariesHistory table but this mbi points to more than one bene
* id in history.
*/
useMbiFromBeneficiaryTable = false;
expectsSingleBeneMatch = false;
assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "66666", "DUPHISTMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
/*
* The following scenario tests when a mbi is not found in the
* Beneficiaries and BeneficiariesHistory table.
*
*/
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, "notfoundmbi")).returnBundle(Bundle.class).execute();
assertEquals(0, searchResults.getTotal());
}
use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method assertPatientByHashTypeMatch.
/**
* The following method tests that a ResourceNotFoundException exception is thrown when there are
* instances of one hash value (hicn or mbi) pointing to more than bene id between the
* Beneficiaries and BeneficiariesHistory tables.
*
* <p>Or that single match is found when the expectsSingleBeneMatch param is = true.
*
* <p>The hashType param chooses which type of values/hash to use. This is either "hicn" or "mbi".
*
* @param fhirClient
* @param beneficiariesList
* @param beneficiariesHistoryList
* @param beneficiaryId
* @param unhashedValue
* @param useFromBeneficiaryTable
* @param hashType
* @param expectsSingleBeneMatch
*/
private void assertPatientByHashTypeMatch(IGenericClient fhirClient, List<Beneficiary> beneficiariesList, List<BeneficiaryHistory> beneficiariesHistoryList, String beneficiaryId, String unhashedValue, Boolean useFromBeneficiaryTable, String hashType, Boolean expectsSingleBeneMatch) {
Bundle searchResults = null;
String hicnHashed = "";
String mbiHash = "";
if (hashType != "hicn" && hashType != "mbi") {
fail("hashType value must be: hicn or mbi.");
}
if (useFromBeneficiaryTable) {
if (hashType.equals("hicn")) {
Beneficiary beneficiaryHicnToMatchTo = beneficiariesList.stream().filter(r -> unhashedValue.equals(r.getHicnUnhashed().get())).findFirst().get();
hicnHashed = beneficiaryHicnToMatchTo.getHicn();
} else if (hashType.equals("mbi")) {
Beneficiary beneficiaryMbiToMatchTo = beneficiariesList.stream().filter(r -> unhashedValue.equals(r.getMedicareBeneficiaryId().get())).findFirst().get();
mbiHash = beneficiaryMbiToMatchTo.getMbiHash().get();
}
} else {
if (hashType.equals("hicn")) {
BeneficiaryHistory beneficiaryHistoryHicnToMatchTo = beneficiariesHistoryList.stream().filter(r -> unhashedValue.equals(r.getHicnUnhashed().get())).findFirst().get();
hicnHashed = beneficiaryHistoryHicnToMatchTo.getHicn();
} else if (hashType.equals("mbi")) {
BeneficiaryHistory beneficiaryHistoryMbiToMatchTo = beneficiariesHistoryList.stream().filter(r -> unhashedValue.equals(r.getMedicareBeneficiaryId().get())).findFirst().get();
mbiHash = beneficiaryHistoryMbiToMatchTo.getMbiHash().get();
}
}
try {
// return bene record based on unhashedValue passed to this method
if (hashType.equals("hicn")) {
searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_HICN_HASH, hicnHashed)).returnBundle(Bundle.class).execute();
} else if (hashType.equals("mbi")) {
searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, mbiHash)).returnBundle(Bundle.class).execute();
}
if (!expectsSingleBeneMatch) {
// Should throw exception before here, so assert a failed test.
fail("An exception was expected when there are duplicate bene id matches.");
}
} catch (ResourceNotFoundException e) {
// Test passes if an exception was thrown.
}
// Validate result if a single match is expected for test.
if (expectsSingleBeneMatch) {
assertNotNull(searchResults);
assertEquals(1, searchResults.getTotal());
Beneficiary beneficiary = beneficiariesList.stream().filter(r -> beneficiaryId.equals(r.getBeneficiaryId())).findAny().get();
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
BeneficiaryTransformerTest.assertMatches(beneficiary, patientFromSearchResult, getRHwithIncldAddrFldHdr("false"));
}
}
Aggregations