Search in sources :

Example 36 with Resource

use of org.hl7.fhir.r5.model.Resource in project beneficiary-fhir-data by CMSgov.

the class CarrierClaimTransformerV2 method transform.

/**
 * @param metricRegistry the {@link MetricRegistry} to use
 * @param claim the CCW {@link CarrierClaim} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     CarrierClaim}
 */
@Trace
static ExplanationOfBenefit transform(MetricRegistry metricRegistry, Object claim, Optional<Boolean> includeTaxNumbers) {
    Timer.Context timer = metricRegistry.timer(MetricRegistry.name(CarrierClaimTransformerV2.class.getSimpleName(), "transform")).time();
    if (!(claim instanceof CarrierClaim)) {
        throw new BadCodeMonkeyException();
    }
    ExplanationOfBenefit eob = transformClaim((CarrierClaim) claim, includeTaxNumbers);
    timer.stop();
    return eob;
}
Also used : Timer(com.codahale.metrics.Timer) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Trace(com.newrelic.api.agent.Trace)

Example 37 with Resource

use of org.hl7.fhir.r5.model.Resource in project beneficiary-fhir-data by CMSgov.

the class CarrierClaimTransformerV2 method transformClaim.

/**
 * @param claimGroup the CCW {@link CarrierClaim} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     CarrierClaim}
 */
private static ExplanationOfBenefit transformClaim(CarrierClaim claimGroup, Optional<Boolean> includeTaxNumbers) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    // Required values not directly mapped
    eob.getMeta().addProfile(ProfileConstants.C4BB_EOB_NONCLINICIAN_PROFILE_URL);
    // TODO: ExplanationOfBenefit.outcome is a required field. Needs to be mapped.
    // eob.setOutcome(?)
    // Common group level fields between all claim types
    // Claim Type + Claim ID => ExplanationOfBenefit.id
    // CLM_ID => ExplanationOfBenefit.identifier
    // CLM_GRP_ID => ExplanationOfBenefit.identifier
    // BENE_ID + Coverage Type => ExplanationOfBenefit.insurance.coverage
    // (reference)
    // BENE_ID => ExplanationOfBenefit.patient (reference)
    // FINAL_ACTION => ExplanationOfBenefit.status
    // CLM_FROM_DT => ExplanationOfBenefit.billablePeriod.start
    // CLM_THRU_DT => ExplanationOfBenefit.billablePeriod.end
    // CLM_PMT_AMT => ExplanationOfBenefit.payment.amount
    TransformerUtilsV2.mapEobCommonClaimHeaderData(eob, claimGroup.getClaimId(), claimGroup.getBeneficiaryId(), ClaimTypeV2.CARRIER, claimGroup.getClaimGroupId().toPlainString(), MedicareSegment.PART_B, Optional.of(claimGroup.getDateFrom()), Optional.of(claimGroup.getDateThrough()), Optional.of(claimGroup.getPaymentAmount()), claimGroup.getFinalAction());
    // NCH_WKLY_PROC_DT => ExplanationOfBenefit.supportinginfo.timingDate
    TransformerUtilsV2.addInformation(eob, TransformerUtilsV2.createInformationRecievedDateSlice(eob, CcwCodebookVariable.NCH_WKLY_PROC_DT, Optional.of(claimGroup.getWeeklyProcessDate())));
    // map eob type codes into FHIR
    // NCH_CLM_TYPE_CD            => ExplanationOfBenefit.type.coding
    // EOB Type                   => ExplanationOfBenefit.type.coding
    // Claim Type (Professional)  => ExplanationOfBenefit.type.coding
    // NCH_NEAR_LINE_REC_IDENT_CD => ExplanationOfBenefit.extension
    TransformerUtilsV2.mapEobType(eob, ClaimTypeV2.CARRIER, Optional.of(claimGroup.getNearLineRecordIdCode()), Optional.of(claimGroup.getClaimTypeCode()));
    // CARR_CLM_PRMRY_PYR_PD_AMT => ExplanationOfBenefit.total.amount
    TransformerUtilsV2.addTotal(eob, TransformerUtilsV2.createTotalAdjudicationAmountSlice(eob, CcwCodebookVariable.CLM_TOT_CHRG_AMT, C4BBAdjudication.PRIOR_PAYER_PAID, claimGroup.getPrimaryPayerPaidAmount()));
    // Common group level fields between Carrier and DME
    // BENE_ID =>
    // CARR_NUM                       => ExplanationOfBenefit.extension
    // CLM_CLNCL_TRIL_NUM             => ExplanationOfBenefit.extension
    // CARR_CLM_CASH_DDCTBL_APLD_AMT  => ExplanationOfBenefit.benefitBalance.financial
    // CARR_CLM_PMT_DNL_CD            => ExplanationOfBenefit.extension
    // RFR_PHYSN_NPI                  => ExplanationOfBenefit.referral.identifier
    // => ExplanationOfBenefit.careteam.provider
    // RFR_PHYSN_UPIN                 => ExplanationOfBenefit.referral.identifier
    // => ExplanationOfBenefit.careteam.provider
    // CARR_CLM_PRVDR_ASGNMT_IND_SW   => ExplanationOfBenefit.extension
    // NCH_CLM_PRVDR_PMT_AMT          => ExplanationOfBenefit.benefitBalance.financial
    // NCH_CLM_BENE_PMT_AMT           => ExplanationOfBenefit.benefitBalance.financial
    // NCH_CARR_CLM_SBMTD_CHRG_AMT    => ExplanationOfBenefit.benefitBalance.financial
    // NCH_CARR_CLM_ALOWD_AMT         => ExplanationOfBenefit.benefitBalance.financial
    // CLM_DISP_CD                    => ExplanationOfBenefit.disposition
    // CARR_CLM_CNTL_NUM              => ExplanationOfBenefit.extension
    TransformerUtilsV2.mapEobCommonGroupCarrierDME(eob, claimGroup.getBeneficiaryId(), claimGroup.getCarrierNumber(), claimGroup.getClinicalTrialNumber(), claimGroup.getBeneficiaryPartBDeductAmount(), claimGroup.getPaymentDenialCode(), claimGroup.getReferringPhysicianNpi(), claimGroup.getReferringPhysicianUpin(), claimGroup.getProviderAssignmentIndicator(), claimGroup.getProviderPaymentAmount(), claimGroup.getBeneficiaryPaymentAmount(), claimGroup.getSubmittedChargeAmount(), claimGroup.getAllowedChargeAmount(), claimGroup.getClaimDispositionCode(), claimGroup.getClaimCarrierControlNumber());
    // ICD_DGNS_VRSN_CD(1-12) => diagnosis.diagnosisCodeableConcept
    for (Diagnosis diagnosis : DiagnosisUtilV2.extractDiagnoses(claimGroup)) {
        DiagnosisUtilV2.addDiagnosisCode(eob, diagnosis, ClaimTypeV2.CARRIER);
    }
    // CARR_CLM_RFRNG_PIN_NUM => ExplanationOfBenefit.careteam.provider
    TransformerUtilsV2.addCareTeamMember(eob, C4BBPractitionerIdentifierType.NPI, C4BBClaimProfessionalAndNonClinicianCareTeamRole.REFERRING, Optional.ofNullable(claimGroup.getReferringProviderIdNumber()));
    // CARR_CLM_ENTRY_CD => ExplanationOfBenefit.extension
    eob.addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.CARR_CLM_ENTRY_CD, claimGroup.getClaimEntryCode()));
    // Process line items
    for (CarrierClaimLine line : claimGroup.getLines()) {
        ItemComponent item = eob.addItem();
        // LINE_NUM => ExplanationOfBenefit.item.sequence
        item.setSequence(line.getLineNumber().intValue());
        // PRF_PHYSN_NPI => ExplanationOfBenefit.careTeam.provider
        Optional<CareTeamComponent> performing = TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.NPI, C4BBClaimProfessionalAndNonClinicianCareTeamRole.PERFORMING, line.getPerformingPhysicianNpi());
        // Fall back to UPIN if NPI not present
        if (!line.getPerformingPhysicianNpi().isPresent()) {
            performing = TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.UPIN, C4BBClaimProfessionalAndNonClinicianCareTeamRole.PERFORMING, line.getPerformingPhysicianUpin());
        }
        // Update the responsible flag
        performing.ifPresent(p -> {
            p.setResponsible(true);
            // PRVDR_SPCLTY => ExplanationOfBenefit.careTeam.qualification
            p.setQualification(TransformerUtilsV2.createCodeableConcept(eob, CcwCodebookVariable.PRVDR_SPCLTY, line.getProviderSpecialityCode()));
            // CARR_LINE_PRVDR_TYPE_CD => ExplanationOfBenefit.careTeam.extension
            p.addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.CARR_LINE_PRVDR_TYPE_CD, line.getProviderTypeCode()));
            // PRTCPTNG_IND_CD => ExplanationOfBenefit.careTeam.extension
            p.addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.PRTCPTNG_IND_CD, line.getProviderParticipatingIndCode()));
        });
        // ORG_NPI_NUM => ExplanationOfBenefit.careTeam.provider
        TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.NPI, C4BBClaimProfessionalAndNonClinicianCareTeamRole.PRIMARY, line.getOrganizationNpi());
        // CARR_LINE_RDCD_PMT_PHYS_ASTN_C => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationDenialReasonSlice(eob, CcwCodebookVariable.CARR_LINE_RDCD_PMT_PHYS_ASTN_C, String.valueOf(line.getReducedPaymentPhysicianAsstCode())));
        // HCPCS_CD               => ExplanationOfBenefit.item.productOrService
        // HCPCS_1ST_MDFR_CD      => ExplanationOfBenefit.item.modifier
        // HCPCS_2ND_MDFR_CD      => ExplanationOfBenefit.item.modifier
        // CARR_CLM_HCPCS_YR_CD   => ExplanationOfBenefit.item.modifier.version
        TransformerUtilsV2.mapHcpcs(eob, item, line.getHcpcsCode(), claimGroup.getHcpcsYearCode(), Arrays.asList(line.getHcpcsInitialModifierCode(), line.getHcpcsSecondModifierCode()));
        // tax num should be as a extension
        if (includeTaxNumbers.orElse(false)) {
            item.addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.TAX_NUM, line.getProviderTaxNumber()));
        }
        // CARR_LINE_ANSTHSA_UNIT_CNT => ExplanationOfBenefit.item.extension
        if (line.getAnesthesiaUnitCount().compareTo(BigDecimal.ZERO) > 0) {
            item.addExtension(TransformerUtilsV2.createExtensionQuantity(CcwCodebookVariable.CARR_LINE_ANSTHSA_UNIT_CNT, line.getAnesthesiaUnitCount()));
        }
        // CARR_LINE_MTUS_CNT => ExplanationOfBenefit.item.extension
        if (!line.getMtusCount().equals(BigDecimal.ZERO)) {
            item.addExtension(TransformerUtilsV2.createExtensionQuantity(CcwCodebookVariable.CARR_LINE_MTUS_CNT, line.getMtusCount()));
        }
        // CARR_LINE_MTUS_CD => ExplanationOfBenefit.item.extension
        line.getMtusCode().ifPresent(code -> item.addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.CARR_LINE_MTUS_CNT, code)));
        // Common item level fields between Carrier and DME
        // LINE_SRVC_CNT            => ExplanationOfBenefit.item.quantity
        // LINE_CMS_TYPE_SRVC_CD    => ExplanationOfBenefit.item.category
        // LINE_PLACE_OF_SRVC_CD    => ExplanationOfBenefit.item.location
        // BETOS_CD                 => ExplanationOfBenefit.item.extension
        // LINE_1ST_EXPNS_DT        => ExplanationOfBenefit.item.servicedPeriod
        // LINE_LAST_EXPNS_DT       => ExplanationOfBenefit.item.servicedPeriod
        // LINE_NCH_PMT_AMT         => ExplanationOfBenefit.item.adjudication
        // LINE_PMT_80_100_CD       => ExplanationOfBenefit.item.adjudication.extension
        // PAID_TO_PATIENT          => ExplanationOfBenefit.item.adjudication
        // LINE_PRVDR_PMT_AMT       => ExplanationOfBenefit.item.adjudication
        // LINE_BENE_PTB_DDCTBL_AMT => ExplanationOfBenefit.item.adjudication
        // LINE_BENE_PRMRY_PYR_CD   => ExplanationOfBenefit.item.extension
        // LINE_BENE_PRMRY_PYR_PD_AMT => ExplanationOfBenefit.item.adjudication
        // LINE_COINSRNC_AMT        => ExplanationOfBenefit.item.adjudication
        // LINE_SBMTD_CHRG_AMT      => ExplanationOfBenefit.item.adjudication
        // LINE_ALOWD_CHRG_AMT      => ExplanationOfBenefit.item.adjudication
        // LINE_BENE_PRMRY_PYR_CD   => ExplanationOfBenefit.item.extension
        // LINE_SERVICE_DEDUCTIBLE  => ExplanationOfBenefit.item.extension
        // LINE_HCT_HGB_TYPE_CD     => Observation.code
        // LINE_HCT_HGB_RSLT_NUM    => Observation.value
        // LINE_NDC_CD              => ExplanationOfBenefit.item.productOrService
        TransformerUtilsV2.mapEobCommonItemCarrierDME(item, eob, claimGroup.getClaimId(), item.getSequence(), line.getServiceCount(), line.getPlaceOfServiceCode(), line.getFirstExpenseDate(), line.getLastExpenseDate(), line.getBeneficiaryPaymentAmount(), line.getProviderPaymentAmount(), line.getBeneficiaryPartBDeductAmount(), line.getPrimaryPayerCode(), line.getPrimaryPayerPaidAmount(), line.getBetosCode(), line.getPaymentAmount(), line.getPaymentCode(), line.getCoinsuranceAmount(), line.getSubmittedChargeAmount(), line.getAllowedChargeAmount(), line.getProcessingIndicatorCode(), line.getServiceDeductibleCode(), line.getHctHgbTestTypeCode(), line.getHctHgbTestResult(), line.getCmsServiceTypeCode(), line.getNationalDrugCode());
        // LINE_ICD_DGNS_CD      => ExplanationOfBenefit.item.diagnosisSequence
        // LINE_ICD_DGNS_VRSN_CD => ExplanationOfBenefit.item.diagnosisSequence
        DiagnosisUtilV2.addDiagnosisLink(eob, item, Diagnosis.from(line.getDiagnosisCode(), line.getDiagnosisCodeVersion(), DiagnosisLabel.OTHER), ClaimTypeV2.CARRIER);
        // PRVDR_STATE_CD => ExplanationOfBenefit.item.location.extension
        line.getProviderStateCode().ifPresent(code -> item.getLocation().addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.PRVDR_STATE_CD, code)));
        // PRVDR_ZIP => ExplanationOfBenefit.item.location.extension
        line.getProviderZipCode().ifPresent(code -> item.getLocation().addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.PRVDR_ZIP, code)));
        // CARR_LINE_PRCNG_LCLTY_CD => ExplanationOfBenefit.item.location.extension
        item.getLocation().addExtension(TransformerUtilsV2.createExtensionCoding(eob, CcwCodebookVariable.CARR_LINE_PRCNG_LCLTY_CD, line.getLinePricingLocalityCode()));
        // CARR_LINE_CLIA_LAB_NUM => ExplanationOfBenefit.item.location.extension
        line.getCliaLabNumber().ifPresent(num -> item.getLocation().addExtension(TransformerUtilsV2.createExtensionIdentifier(CcwCodebookVariable.CARR_LINE_CLIA_LAB_NUM, num)));
    }
    TransformerUtilsV2.setLastUpdated(eob, claimGroup.getLastUpdated());
    return eob;
}
Also used : CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) CareTeamComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.CareTeamComponent)

Example 38 with Resource

use of org.hl7.fhir.r5.model.Resource in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProviderIT method readEobForExistingInpatientClaim.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * works as expected for an {@link InpatientClaim}-derived {@link ExplanationOfBenefit} that does
 * exist in the DB.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void readEobForExistingInpatientClaim() throws FHIRException {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    InpatientClaim claim = loadedRecords.stream().filter(r -> r instanceof InpatientClaim).map(r -> (InpatientClaim) r).findFirst().get();
    ExplanationOfBenefit eob = fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.INPATIENT, claim.getClaimId())).execute();
    assertNotNull(eob);
    // Compare result to transformed EOB
    compareEob(ClaimTypeV2.INPATIENT, eob, loadedRecords);
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Constants(ca.uhn.fhir.rest.api.Constants) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) BeforeAll(org.junit.jupiter.api.BeforeAll) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Triple(org.apache.commons.lang3.tuple.Triple) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) Resource(org.hl7.fhir.r4.model.Resource) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ExplanationOfBenefitResourceProvider(gov.cms.bfd.server.war.stu3.providers.ExplanationOfBenefitResourceProvider) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Money(org.hl7.fhir.r4.model.Money) ArrayList(java.util.ArrayList) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) ImmutableList(com.google.common.collect.ImmutableList) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) EntityManager(javax.persistence.EntityManager) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

Example 39 with Resource

use of org.hl7.fhir.r5.model.Resource 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)

Example 40 with Resource

use of org.hl7.fhir.r5.model.Resource in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProviderIT method readEobForExistingCarrierClaim.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
 * works as expected for a {@link CarrierClaim}-derived {@link ExplanationOfBenefit} that does
 * exist in the DB.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void readEobForExistingCarrierClaim() throws FHIRException {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    CarrierClaim claim = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get();
    ExplanationOfBenefit eob = fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.CARRIER, claim.getClaimId())).execute();
    // Compare result to transformed EOB
    compareEob(ClaimTypeV2.CARRIER, eob, loadedRecords);
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Constants(ca.uhn.fhir.rest.api.Constants) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) BeforeAll(org.junit.jupiter.api.BeforeAll) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Triple(org.apache.commons.lang3.tuple.Triple) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BenefitBalanceComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitBalanceComponent) Resource(org.hl7.fhir.r4.model.Resource) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ExplanationOfBenefitResourceProvider(gov.cms.bfd.server.war.stu3.providers.ExplanationOfBenefitResourceProvider) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Money(org.hl7.fhir.r4.model.Money) ArrayList(java.util.ArrayList) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) ImmutableList(com.google.common.collect.ImmutableList) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) EntityManager(javax.persistence.EntityManager) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)319 Resource (org.hl7.fhir.r4.model.Resource)312 Test (org.junit.jupiter.api.Test)297 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)270 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)230 FHIRException (org.hl7.fhir.exceptions.FHIRException)201 Test (org.junit.Test)190 IOException (java.io.IOException)181 Bundle (org.hl7.fhir.r4.model.Bundle)169 Date (java.util.Date)147 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)139 List (java.util.List)133 HashMap (java.util.HashMap)131 Patient (org.hl7.fhir.r4.model.Patient)118 FileOutputStream (java.io.FileOutputStream)110 Reference (org.hl7.fhir.r4.model.Reference)109 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)102 File (java.io.File)100 Collectors (java.util.stream.Collectors)95 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)92