use of org.hl7.fhir.dstu2.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method assertEobEquals.
/**
* Compares two ExplanationOfBenefit objects in detail while working around serialization issues
* like comparing "0" and "0.0" or creation differences like using "Quantity" vs "SimpleQuantity"
*
* @param expected the expected
* @param actual the actual
*/
private static void assertEobEquals(ExplanationOfBenefit expected, ExplanationOfBenefit actual) {
// ID in the bundle will have `ExplanationOfBenefit/` in front, so make sure the last bit
// matches up
assertTrue(actual.getId().endsWith(expected.getId()));
// Clean them out so we can do a deep compare later
actual.setId("");
expected.setId("");
// If there are any contained resources, they might have lastupdate times in them too
assertEquals(expected.getContained().size(), actual.getContained().size());
for (int i = 0; i < expected.getContained().size(); i++) {
Resource expectedContained = expected.getContained().get(i);
Resource actualContained = actual.getContained().get(i);
expectedContained.getMeta().setLastUpdated(null);
actualContained.getMeta().setLastUpdated(null);
// TODO: HAPI seems to be inserting the `#` in the ID of the contained element.
// This is incorrect according to the FHIR spec:
// https://build.fhir.org/references.html#contained
// This works around that problem
assertEquals("#" + expectedContained.getId(), actualContained.getId());
expectedContained.setId("");
actualContained.setId("");
}
// Dates are not easy to compare so just make sure they are there
assertNotNull(actual.getMeta().getLastUpdated());
// We compared all of meta that we care about so get it out of the way
expected.getMeta().setLastUpdated(null);
actual.getMeta().setLastUpdated(null);
// Created is required, but can't be compared
assertNotNull(actual.getCreated());
expected.setCreated(null);
actual.setCreated(null);
// Extensions may have `valueMoney` elements
assertEquals(expected.getExtension().size(), actual.getExtension().size());
for (int i = 0; i < expected.getExtension().size(); i++) {
Extension expectedEx = expected.getExtension().get(i);
Extension actualEx = actual.getExtension().get(i);
// We have to deal with Money objects separately
if (expectedEx.hasValue() && expectedEx.getValue() instanceof Money) {
assertTrue(actualEx.getValue() instanceof Money);
assertCurrencyEquals((Money) expectedEx.getValue(), (Money) actualEx.getValue());
// Now remove since we validated so we can compare the rest directly
expectedEx.setValue(null);
actualEx.setValue(null);
}
}
// SupportingInfo can have `valueQuantity` that has the 0 vs 0.0 issue
assertEquals(expected.getSupportingInfo().size(), actual.getSupportingInfo().size());
for (int i = 0; i < expected.getSupportingInfo().size(); i++) {
SupportingInformationComponent expectedSup = expected.getSupportingInfo().get(i);
SupportingInformationComponent actualSup = actual.getSupportingInfo().get(i);
// We have to deal with Money objects separately
if (expectedSup.hasValueQuantity()) {
assertTrue(actualSup.hasValueQuantity());
assertEquals(expectedSup.getValueQuantity().getValue().floatValue(), actualSup.getValueQuantity().getValue().floatValue(), 0.0);
// Now remove since we validated so we can compare the rest directly
expectedSup.setValue(null);
actualSup.setValue(null);
}
}
// line items
assertEquals(expected.getItem().size(), actual.getItem().size());
for (int i = 0; i < expected.getItem().size(); i++) {
ItemComponent expectedItem = expected.getItem().get(i);
ItemComponent actualItem = actual.getItem().get(i);
// Compare value directly because SimpleQuantity vs Quantity can't be compared
assertEquals(expectedItem.getQuantity().getValue().floatValue(), actualItem.getQuantity().getValue().floatValue(), 0.0);
expectedItem.setQuantity(null);
actualItem.setQuantity(null);
assertEquals(expectedItem.getAdjudication().size(), actualItem.getAdjudication().size());
for (int j = 0; j < expectedItem.getAdjudication().size(); j++) {
AdjudicationComponent expectedAdj = expectedItem.getAdjudication().get(j);
AdjudicationComponent actualAdj = actualItem.getAdjudication().get(j);
// Here is where we start getting into trouble with "0" vs "0.0", so we do this manually
if (expectedAdj.hasAmount()) {
assertNotNull(actualAdj.getAmount());
assertCurrencyEquals(expectedAdj.getAmount(), actualAdj.getAmount());
} else {
// If expected doesn't have an amount, actual shouldn't
assertFalse(actualAdj.hasAmount());
}
// We just checked manually, so null them out and check the rest of the fields
expectedAdj.setAmount(null);
actualAdj.setAmount(null);
}
}
// Total has the same problem with values
assertEquals(expected.getTotal().size(), actual.getTotal().size());
for (int i = 0; i < expected.getTotal().size(); i++) {
TotalComponent expectedTot = expected.getTotal().get(i);
TotalComponent actualTot = actual.getTotal().get(i);
if (expectedTot.hasAmount()) {
assertNotNull(actualTot.getAmount());
assertCurrencyEquals(expectedTot.getAmount(), actualTot.getAmount());
} else {
// If expected doesn't have an amount, actual shouldn't
assertFalse(actualTot.hasAmount());
}
expectedTot.setAmount(null);
actualTot.setAmount(null);
}
// Benefit Balance Financial components
assertEquals(expected.getBenefitBalance().size(), actual.getBenefitBalance().size());
for (int i = 0; i < expected.getBenefitBalance().size(); i++) {
BenefitBalanceComponent expectedBen = expected.getBenefitBalance().get(i);
BenefitBalanceComponent actualBen = actual.getBenefitBalance().get(i);
assertEquals(expectedBen.getFinancial().size(), actualBen.getFinancial().size());
for (int j = 0; j < expectedBen.getFinancial().size(); j++) {
BenefitComponent expectedFinancial = expectedBen.getFinancial().get(j);
BenefitComponent actualFinancial = actualBen.getFinancial().get(j);
// Are we dealing with Money?
if (expectedFinancial.hasUsedMoney()) {
assertNotNull(actualFinancial.getUsedMoney());
assertCurrencyEquals(expectedFinancial.getUsedMoney(), actualFinancial.getUsedMoney());
// Clean up
expectedFinancial.setUsed(null);
actualFinancial.setUsed(null);
}
}
}
// As does payment
if (expected.hasPayment()) {
assertTrue(actual.hasPayment());
assertCurrencyEquals(expected.getPayment().getAmount(), actual.getPayment().getAmount());
} else {
// If expected doesn't have an amount, actual shouldn't
assertFalse(actual.hasPayment());
}
expected.getPayment().setAmount(null);
actual.getPayment().setAmount(null);
// Now for the grand finale, we can do an `equalsDeep` on the rest
assertTrue(expected.equalsDeep(actual));
}
use of org.hl7.fhir.dstu2.model.Bundle 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 org.hl7.fhir.dstu2.model.Bundle 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));
}
use of org.hl7.fhir.dstu2.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsByMissingPatient.
/**
* 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 not exist in the DB.
*/
@Test
public void searchForEobsByMissingPatient() {
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
// No data is loaded, so this should return 0 matches.
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(new IdDt("Patient", "1234"))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(0, searchResults.getTotal());
}
use of org.hl7.fhir.dstu2.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithPageSizeNotProvided.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#findByPatient} works
* as expected for a {@link Patient} that does exist in the DB, with paging, providing the
* startIndex but not the pageSize (count).
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatientWithPageSizeNotProvided() 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))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Verify that no paging links exist in the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Access a created link of this bundle, providing the startIndex but not the
* pageSize (count).
*/
Bundle pagedResults = fhirClient.loadPage().byUrl(searchResults.getLink(Bundle.LINK_SELF).getUrl() + "&startIndex=4").andReturnBundle(Bundle.class).execute();
assertNotNull(pagedResults);
/*
* Verify that paging links exist in this paged bundle.
*/
assertNull(pagedResults.getLink(Constants.LINK_NEXT));
assertNotNull(pagedResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(pagedResults.getLink(Constants.LINK_FIRST));
assertNotNull(pagedResults.getLink(Constants.LINK_LAST));
/*
* Add the entries in the paged results to a list and verify that only the last
* 4 entries in the original searchResults were returned in the pagedResults.
*/
List<IBaseResource> pagedEntries = new ArrayList<>();
pagedResults.getEntry().forEach(e -> pagedEntries.add(e.getResource()));
assertEquals(4, pagedEntries.size());
}
Aggregations