Search in sources :

Example 16 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class CoverageTransformerV2 method transformPartC.

/**
 * @param metricRegistry the {@link MetricRegistry} to use
 * @param beneficiary the {@link Beneficiary} to generate a {@link MedicareSegment#PART_C} {@link
 *     Coverage} resource for
 * @return {@link MedicareSegment#PART_C} {@link Coverage} resource for the specified {@link
 *     Beneficiary}
 */
private static Coverage transformPartC(MetricRegistry metricRegistry, Beneficiary beneficiary) {
    Timer.Context timer = getTimerContext(metricRegistry, "part_c");
    Coverage coverage = new Coverage();
    coverage.getMeta().addProfile(ProfileConstants.C4BB_COVERAGE_URL);
    coverage.setId(TransformerUtilsV2.buildCoverageId(MedicareSegment.PART_C, beneficiary));
    coverage.setStatus(CoverageStatus.ACTIVE);
    beneficiary.getMedicareBeneficiaryId().ifPresent(value -> coverage.setSubscriberId(value));
    setTypeAndIssuer(coverage);
    setCoverageRelationship(coverage, SubscriberPolicyRelationship.SELF);
    createCoverageClass(coverage, CoverageClass.GROUP, TransformerConstants.COVERAGE_PLAN, Optional.empty());
    createCoverageClass(coverage, CoverageClass.PLAN, TransformerConstants.COVERAGE_PLAN_PART_C, Optional.empty());
    coverage.setBeneficiary(TransformerUtilsV2.referencePatient(beneficiary));
    // Contract Number
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_01, beneficiary.getPartCContractNumberJanId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_02, beneficiary.getPartCContractNumberFebId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_03, beneficiary.getPartCContractNumberMarId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_04, beneficiary.getPartCContractNumberAprId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_05, beneficiary.getPartCContractNumberMayId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_06, beneficiary.getPartCContractNumberJunId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_07, beneficiary.getPartCContractNumberJulId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_08, beneficiary.getPartCContractNumberAugId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_09, beneficiary.getPartCContractNumberSeptId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_10, beneficiary.getPartCContractNumberOctId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_11, beneficiary.getPartCContractNumberNovId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_CNTRCT_ID_12, beneficiary.getPartCContractNumberDecId());
    // PBP
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_01, beneficiary.getPartCPbpNumberJanId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_02, beneficiary.getPartCPbpNumberFebId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_03, beneficiary.getPartCPbpNumberMarId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_04, beneficiary.getPartCPbpNumberAprId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_05, beneficiary.getPartCPbpNumberMayId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_06, beneficiary.getPartCPbpNumberJunId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_07, beneficiary.getPartCPbpNumberJulId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_08, beneficiary.getPartCPbpNumberAugId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_09, beneficiary.getPartCPbpNumberSeptId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_10, beneficiary.getPartCPbpNumberOctId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_11, beneficiary.getPartCPbpNumberNovId());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PBP_ID_12, beneficiary.getPartCPbpNumberDecId());
    // Plan Type
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_01, beneficiary.getPartCPlanTypeJanCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_02, beneficiary.getPartCPlanTypeFebCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_03, beneficiary.getPartCPlanTypeMarCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_04, beneficiary.getPartCPlanTypeAprCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_05, beneficiary.getPartCPlanTypeMayCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_06, beneficiary.getPartCPlanTypeJunCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_07, beneficiary.getPartCPlanTypeJulCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_08, beneficiary.getPartCPlanTypeAugCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_09, beneficiary.getPartCPlanTypeSeptCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_10, beneficiary.getPartCPlanTypeOctCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_11, beneficiary.getPartCPlanTypeNovCode());
    addCoverageExtension(coverage, CcwCodebookVariable.PTC_PLAN_TYPE_CD_12, beneficiary.getPartCPlanTypeDecCode());
    // Monthly Medicare Advantage (MA) enrollment indicators:
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_01, beneficiary.getHmoIndicatorJanInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_02, beneficiary.getHmoIndicatorFebInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_03, beneficiary.getHmoIndicatorMarInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_04, beneficiary.getHmoIndicatorAprInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_05, beneficiary.getHmoIndicatorMayInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_06, beneficiary.getHmoIndicatorJunInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_07, beneficiary.getHmoIndicatorJulInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_08, beneficiary.getHmoIndicatorAugInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_09, beneficiary.getHmoIndicatorSeptInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_10, beneficiary.getHmoIndicatorOctInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_11, beneficiary.getHmoIndicatorNovInd());
    addCoverageCodeExtension(coverage, CcwCodebookVariable.HMO_IND_12, beneficiary.getHmoIndicatorDecInd());
    // The reference year of the enrollment data
    addCoverageDecimalExtension(coverage, CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear());
    // Monthly Medicare-Medicaid dual eligibility codes
    transformEntitlementDualEligibility(coverage, beneficiary);
    // update Coverage.meta.lastUpdated
    TransformerUtilsV2.setLastUpdated(coverage, beneficiary.getLastUpdated());
    timer.stop();
    return coverage;
}
Also used : Timer(com.codahale.metrics.Timer) Coverage(org.hl7.fhir.r4.model.Coverage)

Example 17 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class TransformerUtilsV2 method addProviderSlice.

/**
 * Looks up or adds a contained {@link Organization} object to the current {@link
 * ExplanationOfBenefit}. This is used to store Identifier slices related to the Provider
 * organization.
 *
 * @param eob The {@link ExplanationOfBenefit} to provider org details to
 * @param type The {@link C4BBIdentifierType} of the identifier slice
 * @param value The value of the identifier. If empty, this call is a no-op
 */
static void addProviderSlice(ExplanationOfBenefit eob, C4BBOrganizationIdentifierType type, Optional<String> value, Optional<Instant> lastUpdated) {
    if (value.isPresent()) {
        Resource providerResource = findOrCreateContainedOrg(eob, PROVIDER_ORG_ID);
        // We are assuming that the contained resource with an id of "provider-org" is an Organization
        if (!Organization.class.isInstance(providerResource)) {
            throw new BadCodeMonkeyException();
        }
        Organization provider = (Organization) providerResource;
        // Add the new Identifier to the Organization
        Identifier id = new Identifier().setType(createCodeableConcept(type.getSystem(), type.toCode())).setValue(value.get());
        // Certain types have specific systems
        if (type == C4BBOrganizationIdentifierType.NPI) {
            id.setSystem(TransformerConstants.CODING_NPI_US);
        }
        provider.addIdentifier(id);
        // Set active to value of true
        provider.setActive(true);
        setLastUpdated(provider, lastUpdated);
        // This gets updated for every call, but always set to the same value
        eob.getProvider().setReference(PROVIDER_ORG_REFERENCE);
    }
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) Identifier(org.hl7.fhir.r4.model.Identifier) CurrencyIdentifier(gov.cms.bfd.server.war.r4.providers.BeneficiaryTransformerV2.CurrencyIdentifier) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) Resource(org.hl7.fhir.r4.model.Resource)

Example 18 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class TransformerUtilsV2 method createCodeableConcept.

/**
 * @param rootResource the root FHIR {@link IAnyResource} that the resultant {@link
 *     CodeableConcept} will be contained in
 * @param ccwVariable the {@link CcwCodebookInterface} being coded
 * @param code the value to use for {@link Coding#getCode()} for the resulting (single) {@link
 *     Coding}, wrapped within the resulting {@link CodeableConcept}
 * @return the output {@link CodeableConcept} for the specified input values
 */
static CodeableConcept createCodeableConcept(IAnyResource rootResource, CcwCodebookInterface ccwVariable, Optional<?> code) {
    if (!code.isPresent()) {
        throw new IllegalArgumentException();
    }
    Coding coding = createCoding(rootResource, ccwVariable, code.get());
    CodeableConcept concept = new CodeableConcept();
    concept.addCoding(coding);
    return concept;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 19 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class TransformerUtilsV2 method addInformationWithCode.

/**
 * Returns a new {@link SupportingInformationComponent} that has been added to the specified
 * {@link ExplanationOfBenefit}. Unlike {@link #addInformation(ExplanationOfBenefit,
 * CcwCodebookInterface)}, this also sets the {@link SupportingInformationComponent#getCode()}
 * based on the values provided.
 *
 * @param eob the {@link ExplanationOfBenefit} to modify
 * @param categoryVariable {@link CcwCodebookInterface} to map to {@link
 *     SupportingInformationComponent#getCategory()}
 * @param codeSystemVariable the {@link CcwCodebookInterface} to map to the {@link
 *     Coding#getSystem()} used in the {@link SupportingInformationComponent#getCode()}
 * @param codeValue the value to map to the {@link Coding#getCode()} used in the {@link
 *     SupportingInformationComponent#getCode()}
 * @return the newly-added {@link SupportingInformationComponent} entry
 */
static SupportingInformationComponent addInformationWithCode(ExplanationOfBenefit eob, CcwCodebookInterface categoryVariable, CcwCodebookInterface codeSystemVariable, Optional<?> codeValue) {
    SupportingInformationComponent infoComponent = addInformation(eob, categoryVariable);
    CodeableConcept infoCode = new CodeableConcept().addCoding(createCoding(eob, codeSystemVariable, codeValue));
    infoComponent.setCode(infoCode);
    return infoComponent;
}
Also used : SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 20 with Value

use of org.hl7.fhir.utilities.graphql.Value 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));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) Money(org.hl7.fhir.r4.model.Money) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent)

Aggregations

Test (org.junit.jupiter.api.Test)222 ArrayList (java.util.ArrayList)183 FHIRException (org.hl7.fhir.exceptions.FHIRException)107 List (java.util.List)97 DisplayName (org.junit.jupiter.api.DisplayName)96 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)89 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)85 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)70 Identifier (org.hl7.fhir.r4.model.Identifier)69 Test (org.junit.Test)66 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)64 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)54 IOException (java.io.IOException)52 Bundle (org.hl7.fhir.r4.model.Bundle)49 Coding (org.hl7.fhir.r4.model.Coding)49 ValueSet (org.hl7.fhir.r5.model.ValueSet)48 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)46 Resource (org.hl7.fhir.r4.model.Resource)46 BigDecimal (java.math.BigDecimal)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)44