use of org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent in project beneficiary-fhir-data by CMSgov.
the class TransformerUtilsV2 method findOrAddBenefitBalance.
/**
* @param eob the {@link ExplanationOfBenefit} that the {@link BenefitComponent} should be part of
* @param benefitCategory the {@link BenefitCategory} to map to {@link
* BenefitBalanceComponent#getCategory()}
* @return the already-existing {@link BenefitBalanceComponent} that matches the specified
* parameters, or a new one
*/
private static BenefitBalanceComponent findOrAddBenefitBalance(ExplanationOfBenefit eob, ExBenefitcategory benefitCategory) {
Optional<BenefitBalanceComponent> matchingBenefitBalance = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), benefitCategory.getSystem(), benefitCategory.toCode())).findAny();
// Found an existing BenefitBalance that matches the coding system
if (matchingBenefitBalance.isPresent()) {
return matchingBenefitBalance.get();
}
CodeableConcept benefitCategoryConcept = new CodeableConcept();
benefitCategoryConcept.addCoding().setSystem(benefitCategory.getSystem()).setCode(benefitCategory.toCode()).setDisplay(benefitCategory.getDisplay());
BenefitBalanceComponent newBenefitBalance = new BenefitBalanceComponent(benefitCategoryConcept);
eob.addBenefitBalance(newBenefitBalance);
return newBenefitBalance;
}
use of org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent 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.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent in project beneficiary-fhir-data by CMSgov.
the class TransformerTestUtils method assertBenefitBalanceUsedIntEquals.
/**
* @param expectedBenefitCategory the {@link BenefitCategory} for the expected {@link
* BenefitBalanceComponent#getCategory()}
* @param expectedFinancialType the {@link CcwCodebookVariable} for the expected {@link
* BenefitComponent#getType()}
* @param expectedUsedInt the expected {@link BenefitComponent#getUsedUnsignedIntType()} value
* @param eob the {@link ExplanationOfBenefit} to verify the actual {@link BenefitComponent}
* within
*/
static void assertBenefitBalanceUsedIntEquals(BenefitCategory expectedBenefitCategory, CcwCodebookVariable expectedFinancialType, Integer expectedUsedInt, ExplanationOfBenefit eob) {
Optional<BenefitBalanceComponent> benefitBalanceComponent = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), expectedBenefitCategory.getSystem(), expectedBenefitCategory.toCode())).findAny();
assertTrue(benefitBalanceComponent.isPresent());
Optional<BenefitComponent> benefitBalanceFinancialEntry = benefitBalanceComponent.get().getFinancial().stream().filter(f -> isCodeInConcept(f.getType(), TransformerConstants.CODING_BBAPI_BENEFIT_BALANCE_TYPE, CCWUtils.calculateVariableReferenceUrl(expectedFinancialType))).findAny();
assertTrue(benefitBalanceFinancialEntry.isPresent());
try {
assertEquals(expectedUsedInt, benefitBalanceFinancialEntry.get().getUsedUnsignedIntType().getValue());
} catch (FHIRException e) {
throw new BadCodeMonkeyException(e);
}
}
use of org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method findOrAddBenefitBalance.
/**
* @param eob the {@link ExplanationOfBenefit} that the {@link BenefitComponent} should be part of
* @param benefitCategory the {@link BenefitCategory} to map to {@link
* BenefitBalanceComponent#getCategory()}
* @return the already-existing {@link BenefitBalanceComponent} that matches the specified
* parameters, or a new one
*/
private static BenefitBalanceComponent findOrAddBenefitBalance(ExplanationOfBenefit eob, BenefitCategory benefitCategory) {
Optional<BenefitBalanceComponent> matchingBenefitBalance = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), benefitCategory.getSystem(), benefitCategory.toCode())).findAny();
if (matchingBenefitBalance.isPresent())
return matchingBenefitBalance.get();
CodeableConcept benefitCategoryConcept = new CodeableConcept();
benefitCategoryConcept.addCoding().setSystem(benefitCategory.getSystem()).setCode(benefitCategory.toCode()).setDisplay(benefitCategory.getDisplay());
BenefitBalanceComponent newBenefitBalance = new BenefitBalanceComponent(benefitCategoryConcept);
eob.addBenefitBalance(newBenefitBalance);
return newBenefitBalance;
}
use of org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addBenefitBalanceFinancial.
/**
* @param eob the {@link ExplanationOfBenefit} that the {@link BenefitComponent} should be part of
* @param benefitCategory the {@link BenefitCategory} (see {@link
* BenefitBalanceComponent#getCategory()}) for the {@link BenefitBalanceComponent} that the
* new {@link BenefitComponent} should be part of
* @param financialType the {@link CcwCodebookInterface} to map to {@link
* BenefitComponent#getType()}
* @return the new {@link BenefitBalanceComponent}, which will have already been added to the
* appropriate {@link ExplanationOfBenefit#getBenefitBalance()} entry
*/
static BenefitComponent addBenefitBalanceFinancial(ExplanationOfBenefit eob, BenefitCategory benefitCategory, CcwCodebookInterface financialType) {
BenefitBalanceComponent eobPrimaryBenefitBalance = findOrAddBenefitBalance(eob, benefitCategory);
CodeableConcept financialTypeConcept = TransformerUtils.createCodeableConcept(TransformerConstants.CODING_BBAPI_BENEFIT_BALANCE_TYPE, CCWUtils.calculateVariableReferenceUrl(financialType));
financialTypeConcept.getCodingFirstRep().setDisplay(financialType.getVariable().getLabel());
BenefitComponent financialEntry = new BenefitComponent(financialTypeConcept);
eobPrimaryBenefitBalance.getFinancial().add(financialEntry);
return financialEntry;
}
Aggregations