Search in sources :

Example 1 with FINAL

use of org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addCareTeamPractitioner.

/**
 * Ensures that the specified {@link ExplanationOfBenefit} has the specified {@link
 * CareTeamComponent}, and links the specified {@link ItemComponent} to that {@link
 * CareTeamComponent} (via {@link ItemComponent#addCareTeamLinkId(int)}).
 *
 * @param eob the {@link ExplanationOfBenefit} that the {@link CareTeamComponent} should be part
 *     of
 * @param eobItem the {@link ItemComponent} that should be linked to the {@link CareTeamComponent}
 * @param practitionerIdSystem the {@link Identifier#getSystem()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param practitionerIdValue the {@link Identifier#getValue()} of the practitioner to reference
 *     in {@link CareTeamComponent#getProvider()}
 * @param careTeamRole the {@link ClaimCareteamrole} to use for the {@link
 *     CareTeamComponent#getRole()}
 * @return the {@link CareTeamComponent} that was created/linked
 */
static CareTeamComponent addCareTeamPractitioner(ExplanationOfBenefit eob, ItemComponent eobItem, String practitionerIdSystem, String practitionerIdValue, ClaimCareteamrole careTeamRole) {
    // Try to find a matching pre-existing entry.
    CareTeamComponent careTeamEntry = eob.getCareTeam().stream().filter(ctc -> ctc.getProvider().hasIdentifier()).filter(ctc -> practitionerIdSystem.equals(ctc.getProvider().getIdentifier().getSystem()) && practitionerIdValue.equals(ctc.getProvider().getIdentifier().getValue())).filter(ctc -> ctc.hasRole()).filter(ctc -> careTeamRole.toCode().equals(ctc.getRole().getCodingFirstRep().getCode()) && careTeamRole.getSystem().equals(ctc.getRole().getCodingFirstRep().getSystem())).findAny().orElse(null);
    // If no match was found, add one to the EOB.
    if (careTeamEntry == null) {
        careTeamEntry = eob.addCareTeam();
        careTeamEntry.setSequence(eob.getCareTeam().size() + 1);
        careTeamEntry.setProvider(createIdentifierReference(practitionerIdSystem, practitionerIdValue));
        CodeableConcept careTeamRoleConcept = createCodeableConcept(ClaimCareteamrole.OTHER.getSystem(), careTeamRole.toCode());
        careTeamRoleConcept.getCodingFirstRep().setDisplay(careTeamRole.getDisplay());
        careTeamEntry.setRole(careTeamRoleConcept);
    }
    // care team entry is at eob level so no need to create item link id
    if (eobItem == null) {
        return careTeamEntry;
    }
    // Link the EOB.item to the care team entry (if it isn't already).
    final int careTeamEntrySequence = careTeamEntry.getSequence();
    if (eobItem.getCareTeamLinkId().stream().noneMatch(id -> id.getValue() == careTeamEntrySequence)) {
        eobItem.addCareTeamLinkId(careTeamEntrySequence);
    }
    return careTeamEntry;
}
Also used : Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Constants(ca.uhn.fhir.rest.api.Constants) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) StringUtils(org.apache.commons.lang3.StringUtils) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Map(java.util.Map) ProcedureComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ProcedureComponent) CcwCodebookMissingVariable(gov.cms.bfd.model.codebook.data.CcwCodebookMissingVariable) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Value(gov.cms.bfd.model.codebook.model.Value) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) Coverage(org.hl7.fhir.dstu3.model.Coverage) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) UncheckedIOException(java.io.UncheckedIOException) ReferralRequestStatus(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestStatus) Stream(java.util.stream.Stream) ReferralRequestRequesterComponent(org.hl7.fhir.dstu3.model.ReferralRequest.ReferralRequestRequesterComponent) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) Money(org.hl7.fhir.dstu3.model.Money) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) CurrencyIdentifier(gov.cms.bfd.server.war.stu3.providers.BeneficiaryTransformer.CurrencyIdentifier) CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MetricRegistry(com.codahale.metrics.MetricRegistry) LinkBuilder(gov.cms.bfd.server.war.commons.LinkBuilder) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) InputStreamReader(java.io.InputStreamReader) FDADrugDataUtilityApp(gov.cms.bfd.server.war.FDADrugDataUtilityApp) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) Patient(org.hl7.fhir.dstu3.model.Patient) MDC(org.slf4j.MDC) BufferedReader(java.io.BufferedReader) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) LoggerFactory(org.slf4j.LoggerFactory) Extension(org.hl7.fhir.dstu3.model.Extension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) Organization(org.hl7.fhir.dstu3.model.Organization) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) Collection(java.util.Collection) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DiagnosisLabel(gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel) Quantity(org.hl7.fhir.dstu3.model.Quantity) UnsignedIntType(org.hl7.fhir.dstu3.model.UnsignedIntType) Objects(java.util.Objects) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateType(org.hl7.fhir.dstu3.model.DateType) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) DataFormatException(ca.uhn.fhir.parser.DataFormatException) HashMap(java.util.HashMap) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) HashSet(java.util.HashSet) ExplanationOfBenefitStatus(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ExplanationOfBenefitStatus) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) ObservationStatus(org.hl7.fhir.dstu3.model.Observation.ObservationStatus) InvalidRifValueException(gov.cms.bfd.model.rif.parse.InvalidRifValueException) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) Logger(org.slf4j.Logger) Resource(org.hl7.fhir.dstu3.model.Resource) Variable(gov.cms.bfd.model.codebook.model.Variable) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) Consumer(java.util.function.Consumer) URLEncoder(java.net.URLEncoder) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) InputStream(java.io.InputStream) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 2 with FINAL

use of org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class ExplanationOfBenefitResourceProvider method findClaimTypeByPatient.

/**
 * @param claimType the {@link ClaimType} to find
 * @param patientId the {@link Beneficiary#getBeneficiaryId()} to filter by
 * @param lastUpdated the update time to filter by
 * @return the matching claim/event entities
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Trace
private <T> List<T> findClaimTypeByPatient(ClaimType claimType, String patientId, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = builder.createQuery((Class) claimType.getEntityClass());
    Root root = criteria.from(claimType.getEntityClass());
    claimType.getEntityLazyAttributes().stream().forEach(a -> root.fetch(a));
    criteria.select(root).distinct(true);
    // Search for a beneficiary's records. Use lastUpdated if present
    Predicate wherePredicate = builder.equal(root.get(claimType.getEntityBeneficiaryIdAttribute()), patientId);
    if (lastUpdated != null && !lastUpdated.isEmpty()) {
        Predicate predicate = QueryUtils.createLastUpdatedPredicate(builder, root, lastUpdated);
        wherePredicate = builder.and(wherePredicate, predicate);
    }
    criteria.where(wherePredicate);
    List<T> claimEntities = null;
    Long eobsByBeneIdQueryNanoSeconds = null;
    Timer.Context timerEobQuery = metricRegistry.timer(MetricRegistry.name(metricRegistry.getClass().getSimpleName(), "query", "eobs_by_bene_id", claimType.name().toLowerCase())).time();
    try {
        claimEntities = entityManager.createQuery(criteria).getResultList();
    } finally {
        eobsByBeneIdQueryNanoSeconds = timerEobQuery.stop();
        TransformerUtils.recordQueryInMdc(String.format("eobs_by_bene_id.%s", claimType.name().toLowerCase()), eobsByBeneIdQueryNanoSeconds, claimEntities == null ? 0 : claimEntities.size());
    }
    if (claimEntities != null && serviceDate != null && !serviceDate.isEmpty()) {
        final Instant lowerBound = serviceDate.getLowerBoundAsInstant() != null ? serviceDate.getLowerBoundAsInstant().toInstant() : null;
        final Instant upperBound = serviceDate.getUpperBoundAsInstant() != null ? serviceDate.getUpperBoundAsInstant().toInstant() : null;
        final java.util.function.Predicate<LocalDate> lowerBoundCheck = lowerBound == null ? (date) -> true : (date) -> compareLocalDate(date, lowerBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getLowerBound().getPrefix());
        final java.util.function.Predicate<LocalDate> upperBoundCheck = upperBound == null ? (date) -> true : (date) -> compareLocalDate(date, upperBound.atZone(ZoneId.systemDefault()).toLocalDate(), serviceDate.getUpperBound().getPrefix());
        return claimEntities.stream().filter(entity -> lowerBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity)) && upperBoundCheck.test(claimType.getServiceEndAttributeFunction().apply(entity))).collect(Collectors.toList());
    }
    return claimEntities;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdParam(ca.uhn.fhir.rest.annotation.IdParam) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) ListIterator(java.util.ListIterator) Description(ca.uhn.fhir.model.api.annotation.Description) IdType(org.hl7.fhir.dstu3.model.IdType) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) Matcher(java.util.regex.Matcher) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Predicate(javax.persistence.criteria.Predicate) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LoadedFilterManager(gov.cms.bfd.server.war.commons.LoadedFilterManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) ParamPrefixEnum(ca.uhn.fhir.rest.param.ParamPrefixEnum) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) LocalDate(java.time.LocalDate) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Pattern(java.util.regex.Pattern) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) QueryUtils(gov.cms.bfd.server.war.commons.QueryUtils) Trace(com.newrelic.api.agent.Trace) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Nullable(javax.annotation.Nullable) Root(javax.persistence.criteria.Root) Read(ca.uhn.fhir.rest.annotation.Read) OffsetLinkBuilder(gov.cms.bfd.server.war.commons.OffsetLinkBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Operation(gov.cms.bfd.server.war.Operation) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Component(org.springframework.stereotype.Component) Comparator(java.util.Comparator) Root(javax.persistence.criteria.Root) Instant(java.time.Instant) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) LocalDate(java.time.LocalDate) Predicate(javax.persistence.criteria.Predicate) Timer(com.codahale.metrics.Timer) Trace(com.newrelic.api.agent.Trace)

Example 3 with FINAL

use of org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class InpatientClaimTransformerV2 method transformClaim.

/**
 * @param claimGroup the CCW {@link InpatientClaim} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     InpatientClaim}
 */
private static ExplanationOfBenefit transformClaim(InpatientClaim claimGroup) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    // Required values not directly mapped
    eob.getMeta().addProfile(ProfileConstants.C4BB_EOB_INPATIENT_PROFILE_URL);
    // 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.INPATIENT, claimGroup.getClaimGroupId().toPlainString(), MedicareSegment.PART_A, Optional.of(claimGroup.getDateFrom()), Optional.of(claimGroup.getDateThrough()), Optional.of(claimGroup.getPaymentAmount()), claimGroup.getFinalAction());
    // map eob type codes into FHIR
    // NCH_CLM_TYPE_CD              => ExplanationOfBenefit.type.coding
    // EOB Type                     => ExplanationOfBenefit.type.coding
    // Claim Type  (institutional)  => ExplanationOfBenefit.type.coding
    // NCH_NEAR_LINE_REC_IDENT_CD   => ExplanationOfBenefit.extension
    TransformerUtilsV2.mapEobType(eob, ClaimTypeV2.INPATIENT, Optional.of(claimGroup.getNearLineRecordIdCode()), Optional.of(claimGroup.getClaimTypeCode()));
    // set the provider number which is common among several claim types
    // PRVDR_NUM => ExplanationOfBenefit.provider.identifier
    TransformerUtilsV2.addProviderSlice(eob, C4BBOrganizationIdentifierType.PRN, claimGroup.getProviderNumber(), claimGroup.getLastUpdated());
    // NCH_PTNT_STUS_IND_CD => ExplanationOfBenefit.supportingInfo.code
    claimGroup.getPatientStatusCd().ifPresent(c -> TransformerUtilsV2.addInformationWithCode(eob, CcwCodebookVariable.NCH_PTNT_STUS_IND_CD, CcwCodebookVariable.NCH_PTNT_STUS_IND_CD, c));
    // CLM_ADMSN_DT       => ExplanationOfBenefit.supportingInfo:admissionperiod
    // NCH_BENE_DSCHRG_DT => ExplanationOfBenefit.supportingInfo:admissionperiod
    TransformerUtilsV2.addInformation(eob, TransformerUtilsV2.createInformationAdmPeriodSlice(eob, claimGroup.getClaimAdmissionDate(), claimGroup.getBeneficiaryDischargeDate()));
    // add EOB information to fields that are common between the Inpatient and SNF claim types
    // CLM_IP_ADMSN_TYPE_CD             => ExplanationOfBenefit.supportingInfo.code
    // CLM_SRC_IP_ADMSN_CD              => ExplanationOfBenefit.supportingInfo.code
    // NCH_VRFD_NCVRD_STAY_FROM_DT      => ExplanationOfBenefit.supportingInfo.timingPeriod
    // NCH_VRFD_NCVRD_STAY_THRU_DT      => ExplanationOfBenefit.supportingInfo.timingPeriod
    // NCH_ACTV_OR_CVRD_LVL_CARE_THRU   => ExplanationOfBenefit.supportingInfo.timingDate
    // NCH_BENE_MDCR_BNFTS_EXHTD_DT_I   => ExplanationOfBenefit.supportingInfo.timingDate
    // CLM_DRG_CD                       => ExplanationOfBenefit.supportingInfo.code
    TransformerUtilsV2.addCommonEobInformationInpatientSNF(eob, claimGroup.getAdmissionTypeCd(), claimGroup.getSourceAdmissionCd(), claimGroup.getNoncoveredStayFromDate(), claimGroup.getNoncoveredStayThroughDate(), claimGroup.getCoveredCareThoughDate(), claimGroup.getMedicareBenefitsExhaustedDate(), claimGroup.getDiagnosisRelatedGroupCd());
    // IME_OP_CLM_VAL_AMT => ExplanationOfBenefit.extension
    TransformerUtilsV2.addAdjudicationTotal(eob, CcwCodebookVariable.IME_OP_CLM_VAL_AMT, claimGroup.getIndirectMedicalEducationAmount());
    // DSH_OP_CLM_VAL_AMT => ExplanationOfBenefit.extension
    TransformerUtilsV2.addAdjudicationTotal(eob, CcwCodebookVariable.DSH_OP_CLM_VAL_AMT, claimGroup.getDisproportionateShareAmount());
    // CLM_PASS_THRU_PER_DIEM_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.CLM_PASS_THRU_PER_DIEM_AMT, Optional.ofNullable(claimGroup.getPassThruPerDiemAmount()));
    // NCH_PROFNL_CMPNT_CHRG_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.NCH_PROFNL_CMPNT_CHRG_AMT, Optional.ofNullable(claimGroup.getProfessionalComponentCharge()));
    // CLM_TOT_PPS_CPTL_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.CLM_TOT_PPS_CPTL_AMT, claimGroup.getClaimTotalPPSCapitalAmount());
    /*
     * add field values to the benefit balances that are common between the
     * Inpatient and SNF claim types
     */
    // BENE_TOT_COINSRNC_DAYS_CNT       => ExplanationOfBenefit.benefitBalance.financial
    // CLM_NON_UTLZTN_DAYS_CNT          => ExplanationOfBenefit.benefitBalance.financial
    // NCH_BENE_IP_DDCTBL_AMT           => ExplanationOfBenefit.benefitBalance.financial
    // NCH_BENE_PTA_COINSRNC_LBLTY_AMT  => ExplanationOfBenefit.benefitBalance.financial
    // NCH_BLOOD_PNTS_FRNSHD_QTY        => ExplanationOfBenefit.supportingInfo.valueQuantity
    // NCH_IP_NCVRD_CHRG_AMT            => ExplanationOfBenefit.benefitBalance.financial
    // NCH_IP_TOT_DDCTN_AMT             => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_CPTL_DSPRPRTNT_SHR_AMT   => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_CPTL_EXCPTN_AMT          => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_CPTL_FSP_AMT             => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_CPTL_IME_AMT             => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_CPTL_OUTLIER_AMT         => ExplanationOfBenefit.benefitBalance.financial
    // CLM_PPS_OLD_CPTL_HLD_HRMLS_AMT   => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addCommonGroupInpatientSNF(eob, claimGroup.getCoinsuranceDayCount(), claimGroup.getNonUtilizationDayCount(), claimGroup.getDeductibleAmount(), claimGroup.getPartACoinsuranceLiabilityAmount(), claimGroup.getBloodPintsFurnishedQty(), claimGroup.getNoncoveredCharge(), claimGroup.getTotalDeductionAmount(), claimGroup.getClaimPPSCapitalDisproportionateShareAmt(), claimGroup.getClaimPPSCapitalExceptionAmount(), claimGroup.getClaimPPSCapitalFSPAmount(), claimGroup.getClaimPPSCapitalIMEAmount(), claimGroup.getClaimPPSCapitalOutlierAmount(), claimGroup.getClaimPPSOldCapitalHoldHarmlessAmount());
    // NCH_DRG_OUTLIER_APRVD_PMT_AMT => ExplanationOfBenefit.extension
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.NCH_DRG_OUTLIER_APRVD_PMT_AMT, claimGroup.getDrgOutlierApprovedPaymentAmount());
    // Map care team
    // AT_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Primary)
    // AT_PHYSN_UPIN    => ExplanationOfBenefit.careTeam.provider
    // OP_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Assisting)
    // OP_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider
    // OT_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Other)
    // OT_PHYSN_UPIN    => ExplanationOfBenefit.careTeam.provider
    TransformerUtilsV2.mapCareTeam(eob, claimGroup.getAttendingPhysicianNpi(), claimGroup.getOperatingPhysicianNpi(), claimGroup.getOtherPhysicianNpi(), claimGroup.getAttendingPhysicianUpin(), claimGroup.getOperatingPhysicianUpin(), claimGroup.getOtherPhysicianUpin());
    // Common group level fields between Inpatient, Outpatient and SNF
    // NCH_BENE_BLOOD_DDCTBL_LBLTY_AM   => ExplanationOfBenefit.benefitBalance.financial
    // CLAIM_QUERY_CODE                 => ExplanationOfBenefit.billablePeriod.extension
    // CLM_MCO_PD_SW                    => ExplanationOfBenefit.supportingInfo.code
    TransformerUtilsV2.mapEobCommonGroupInpOutSNF(eob, claimGroup.getBloodDeductibleLiabilityAmount(), claimGroup.getClaimQueryCode(), claimGroup.getMcoPaidSw());
    // Common group level fields between Inpatient, Outpatient Hospice, HHA and SNF
    // ORG_NPI_NUM              => ExplanationOfBenefit.provider
    // CLM_FAC_TYPE_CD          => ExplanationOfBenefit.facility.extension
    // CLM_FREQ_CD              => ExplanationOfBenefit.supportingInfo
    // CLM_MDCR_NON_PMT_RSN_CD  => ExplanationOfBenefit.extension
    // PTNT_DSCHRG_STUS_CD      => ExplanationOfBenefit.supportingInfo
    // CLM_SRVC_CLSFCTN_TYPE_CD => ExplanationOfBenefit.extension
    // NCH_PRMRY_PYR_CD         => ExplanationOfBenefit.supportingInfo
    // CLM_TOT_CHRG_AMT         => ExplanationOfBenefit.total.amount
    // NCH_PRMRY_PYR_CLM_PD_AMT => ExplanationOfBenefit.benefitBalance.financial (PRPAYAMT)
    TransformerUtilsV2.mapEobCommonGroupInpOutHHAHospiceSNF(eob, claimGroup.getOrganizationNpi(), claimGroup.getClaimFacilityTypeCode(), claimGroup.getClaimFrequencyCode(), claimGroup.getClaimNonPaymentReasonCode(), claimGroup.getPatientDischargeStatusCode(), claimGroup.getClaimServiceClassificationTypeCode(), claimGroup.getClaimPrimaryPayerCode(), claimGroup.getTotalChargeAmount(), claimGroup.getPrimaryPayerPaidAmount(), claimGroup.getFiscalIntermediaryNumber(), claimGroup.getLastUpdated());
    // CLM_UTLZTN_DAY_CNT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalInt(eob, CcwCodebookVariable.CLM_UTLZTN_DAY_CNT, Optional.of(claimGroup.getUtilizationDayCount()));
    // CLM_E_POA_IND_SW(1-12)   => diagnosis.type
    for (Diagnosis diagnosis : DiagnosisUtilV2.extractDiagnoses(claimGroup)) {
        DiagnosisUtilV2.addDiagnosisCode(eob, diagnosis, ClaimTypeV2.INPATIENT);
    }
    // Handle Procedures
    // ICD_PRCDR_CD(1-25)        => ExplanationOfBenefit.procedure.procedureCodableConcept
    // ICD_PRCDR_VRSN_CD(1-25)   => ExplanationOfBenefit.procedure.procedureCodableConcept
    // PRCDR_DT(1-25)            => ExplanationOfBenefit.procedure.date
    final int FIRST_PROCEDURE = 1;
    final int LAST_PROCEDURE = 25;
    IntStream.range(FIRST_PROCEDURE, LAST_PROCEDURE + 1).mapToObj(i -> TransformerUtilsV2.extractCCWProcedure(i, claimGroup)).filter(p -> p.isPresent()).forEach(p -> TransformerUtilsV2.addProcedureCode(eob, p.get()));
    // NCH_WKLY_PROC_DT => ExplanationOfBenefit.supportinginfo.timingDate
    TransformerUtilsV2.addInformation(eob, TransformerUtilsV2.createInformationRecievedDateSlice(eob, CcwCodebookVariable.NCH_WKLY_PROC_DT, Optional.of(claimGroup.getWeeklyProcessDate())));
    // CLM_PPS_CPTL_DRG_WT_NUM => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalInt(eob, CcwCodebookVariable.CLM_PPS_CPTL_DRG_WT_NUM, claimGroup.getClaimPPSCapitalDrgWeightNumber());
    // BENE_LRD_USED_CNT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalInt(eob, CcwCodebookVariable.BENE_LRD_USED_CNT, claimGroup.getLifetimeReservedDaysUsedCount());
    // ClaimLine => ExplanationOfBenefit.item
    for (InpatientClaimLine line : claimGroup.getLines()) {
        ItemComponent item = TransformerUtilsV2.addItem(eob);
        // Override the default sequence
        // CLM_LINE_NUM => item.sequence
        item.setSequence(line.getLineNumber().intValue());
        // PRVDR_STATE_CD => item.location
        TransformerUtilsV2.addLocationState(item, claimGroup.getProviderStateCode());
        // REV_CNTR                   => ExplanationOfBenefit.item.revenue
        // REV_CNTR_RATE_AMT          => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_TOT_CHRG_AMT      => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_NCVRD_CHRG_AMT    => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_NDC_QTY           => ExplanationOfBenefit.item.quantity
        // REV_CNTR_NDC_QTY_QLFR_CD   => ExplanationOfBenefit.modifier
        TransformerUtilsV2.mapEobCommonItemRevenue(item, eob, line.getRevenueCenter(), line.getRateAmount(), line.getTotalChargeAmount(), Optional.of(line.getNonCoveredChargeAmount()), line.getNationalDrugCodeQuantity(), line.getNationalDrugCodeQualifierCode());
        // REV_CNTR_DDCTBL_COINSRNC_CD => item.revenue
        TransformerUtilsV2.addItemRevenue(item, eob, CcwCodebookVariable.REV_CNTR_DDCTBL_COINSRNC_CD, line.getDeductibleCoinsuranceCd());
        // HCPCS_CD => item.productOrService
        line.getHcpcsCode().ifPresent(c -> item.setProductOrService(new CodeableConcept().setCoding(Arrays.asList(new Coding().setSystem(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.HCPCS_CD)).setCode(c), new Coding().setSystem(TransformerConstants.CODING_SYSTEM_HCPCS).setCode(c)))));
        // RNDRNG_PHYSN_UPIN => ExplanationOfBenefit.careTeam.provider
        TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.UPIN, C4BBClaimInstitutionalCareTeamRole.PERFORMING, line.getRevenueCenterRenderingPhysicianUPIN());
        // RNDRNG_PHYSN_NPI => ExplanationOfBenefit.careTeam.provider
        TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.NPI, C4BBClaimInstitutionalCareTeamRole.PERFORMING, line.getRevenueCenterRenderingPhysicianNPI());
    }
    // Last Updated => ExplanationOfBenefit.meta.lastUpdated
    TransformerUtilsV2.setLastUpdated(eob, claimGroup.getLastUpdated());
    return eob;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) MetricRegistry(com.codahale.metrics.MetricRegistry) C4BBPractitionerIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBPractitionerIdentifierType) Trace(com.newrelic.api.agent.Trace) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) ProfileConstants(gov.cms.bfd.server.war.commons.ProfileConstants) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) C4BBClaimInstitutionalCareTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimInstitutionalCareTeamRole) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) C4BBOrganizationIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBOrganizationIdentifierType) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) Coding(org.hl7.fhir.r4.model.Coding) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) Coding(org.hl7.fhir.r4.model.Coding) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 4 with FINAL

use of org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class OutpatientClaimTransformerV2 method transformClaim.

/**
 * @param claimGroup the CCW {@link InpatientClaim} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     InpatientClaim}
 */
private static ExplanationOfBenefit transformClaim(OutpatientClaim claimGroup) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    // Required values not directly mapped
    eob.getMeta().addProfile(ProfileConstants.C4BB_EOB_OUTPATIENT_PROFILE_URL);
    // Common group level fields between all claim types
    // Claim Type + Claim ID    => ExplanationOfBenefit.id
    // CLM_ID                   => ExplanationOfBenefit.identifier
    // CLM_GRP_ID               => ExplanationOfBenefit.identifier
    // 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.OUTPATIENT, 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 care team
    // AT_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Primary)
    // AT_PHYSN_UPIN    => ExplanationOfBenefit.careTeam.provider
    // OP_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Assisting)
    // OP_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider
    // OT_PHYSN_NPI     => ExplanationOfBenefit.careTeam.provider (Other)
    // OT_PHYSN_UPIN    => ExplanationOfBenefit.careTeam.provider
    TransformerUtilsV2.mapCareTeam(eob, claimGroup.getAttendingPhysicianNpi(), claimGroup.getOperatingPhysicianNpi(), claimGroup.getOtherPhysicianNpi(), claimGroup.getAttendingPhysicianUpin(), claimGroup.getOperatingPhysicianUpin(), claimGroup.getOtherPhysicianUpin());
    // map eob type codes into FHIR
    // NCH_CLM_TYPE_CD => ExplanationOfBenefit.type.coding
    // EOB Type => ExplanationOfBenefit.type.coding
    // Claim Type (institutional) => ExplanationOfBenefit.type.coding
    // NCH_NEAR_LINE_REC_IDENT_CD => ExplanationOfBenefit.extension
    TransformerUtilsV2.mapEobType(eob, ClaimTypeV2.OUTPATIENT, Optional.of(claimGroup.getNearLineRecordIdCode()), Optional.of(claimGroup.getClaimTypeCode()));
    // set the provider number which is common among several claim types
    // PRVDR_NUM => ExplanationOfBenefit.provider.identifier
    TransformerUtilsV2.addProviderSlice(eob, C4BBOrganizationIdentifierType.PRN, claimGroup.getProviderNumber(), claimGroup.getLastUpdated());
    // NCH_PROFNL_CMPNT_CHRG_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.NCH_PROFNL_CMPNT_CHRG_AMT, Optional.ofNullable(claimGroup.getProfessionalComponentCharge()));
    // NCH_BENE_PTB_DDCTBL_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.NCH_BENE_PTB_DDCTBL_AMT, Optional.ofNullable(claimGroup.getDeductibleAmount()));
    // NCH_BENE_PTB_COINSRNC_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.NCH_BENE_PTB_COINSRNC_AMT, Optional.ofNullable(claimGroup.getCoinsuranceAmount()));
    // CLM_OP_PRVDR_PMT_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.CLM_OP_PRVDR_PMT_AMT, Optional.ofNullable(claimGroup.getProviderPaymentAmount()));
    // CLM_OP_PRVDR_PMT_AMT => ExplanationOfBenefit.benefitBalance.financial
    TransformerUtilsV2.addBenefitBalanceFinancialMedicalAmt(eob, CcwCodebookVariable.CLM_OP_BENE_PMT_AMT, Optional.ofNullable(claimGroup.getBeneficiaryPaymentAmount()));
    // Common group level fields between Inpatient, Outpatient and SNF
    // NCH_BENE_BLOOD_DDCTBL_LBLTY_AM =>
    // ExplanationOfBenefit.benefitBalance.financial
    // CLAIM_QUERY_CODE => ExplanationOfBenefit.billablePeriod.extension
    // CLM_MCO_PD_SW => ExplanationOfBenefit.supportingInfo.code
    TransformerUtilsV2.mapEobCommonGroupInpOutSNF(eob, claimGroup.getBloodDeductibleLiabilityAmount(), claimGroup.getClaimQueryCode(), claimGroup.getMcoPaidSw());
    // Common group level fields between Inpatient, Outpatient Hospice, HHA and SNF
    // ORG_NPI_NUM              => ExplanationOfBenefit.provider
    // CLM_FAC_TYPE_CD          => ExplanationOfBenefit.facility.extension
    // CLM_FREQ_CD              => ExplanationOfBenefit.supportingInfo
    // CLM_MDCR_NON_PMT_RSN_CD  => ExplanationOfBenefit.extension
    // PTNT_DSCHRG_STUS_CD      => ExplanationOfBenefit.supportingInfo
    // CLM_SRVC_CLSFCTN_TYPE_CD => ExplanationOfBenefit.extension
    // NCH_PRMRY_PYR_CD         => ExplanationOfBenefit.supportingInfo
    // CLM_TOT_CHRG_AMT         => ExplanationOfBenefit.total.amount
    // NCH_PRMRY_PYR_CLM_PD_AMT => ExplanationOfBenefit.benefitBalance.financial (PRPAYAMT)
    TransformerUtilsV2.mapEobCommonGroupInpOutHHAHospiceSNF(eob, claimGroup.getOrganizationNpi(), claimGroup.getClaimFacilityTypeCode(), claimGroup.getClaimFrequencyCode(), claimGroup.getClaimNonPaymentReasonCode(), claimGroup.getPatientDischargeStatusCode().get(), claimGroup.getClaimServiceClassificationTypeCode(), claimGroup.getClaimPrimaryPayerCode(), claimGroup.getTotalChargeAmount(), claimGroup.getPrimaryPayerPaidAmount(), claimGroup.getFiscalIntermediaryNumber(), claimGroup.getLastUpdated());
    // ICD_DGNS_E_VRSN_CD(1-12) => diagnosis.diagnosisCodeableConcept
    for (Diagnosis diagnosis : DiagnosisUtilV2.extractDiagnoses(claimGroup)) {
        DiagnosisUtilV2.addDiagnosisCode(eob, diagnosis, ClaimTypeV2.OUTPATIENT);
    }
    // Handle Inpatient Diagnosis.  Only three, so just brute force it
    // RSN_VISIT_CD1        => diagnosis.diagnosisCodeableConcept
    // RSN_VISIT_VRSN_CD1   => diagnosis.diagnosisCodeableConcept
    DiagnosisUtilV2.addDiagnosisCode(eob, DiagnosisUtilV2.extractDiagnosis("Admission1", claimGroup, Optional.empty(), DiagnosisLabel.REASONFORVISIT), ClaimTypeV2.OUTPATIENT);
    // RSN_VISIT_CD2        => diagnosis.diagnosisCodeableConcept
    // RSN_VISIT_VRSN_CD2   => diagnosis.diagnosisCodeableConcept
    DiagnosisUtilV2.addDiagnosisCode(eob, DiagnosisUtilV2.extractDiagnosis("Admission2", claimGroup, Optional.empty(), DiagnosisLabel.REASONFORVISIT), ClaimTypeV2.OUTPATIENT);
    // RSN_VISIT_CD3        => diagnosis.diagnosisCodeableConcept
    // RSN_VISIT_VRSN_CD3   => diagnosis.diagnosisCodeableConcept
    DiagnosisUtilV2.addDiagnosisCode(eob, DiagnosisUtilV2.extractDiagnosis("Admission3", claimGroup, Optional.empty(), DiagnosisLabel.REASONFORVISIT), ClaimTypeV2.OUTPATIENT);
    // Handle Procedures
    // ICD_PRCDR_CD(1-25)        => ExplanationOfBenefit.procedure.procedureCodableConcept
    // ICD_PRCDR_VRSN_CD(1-25)   => ExplanationOfBenefit.procedure.procedureCodableConcept
    // PRCDR_DT(1-25)            => ExplanationOfBenefit.procedure.date
    final int FIRST_PROCEDURE = 1;
    final int LAST_PROCEDURE = 25;
    IntStream.range(FIRST_PROCEDURE, LAST_PROCEDURE + 1).mapToObj(i -> TransformerUtilsV2.extractCCWProcedure(i, claimGroup)).filter(p -> p.isPresent()).forEach(p -> TransformerUtilsV2.addProcedureCode(eob, p.get()));
    // ClaimLine => ExplanationOfBenefit.item
    for (OutpatientClaimLine line : claimGroup.getLines()) {
        ItemComponent item = TransformerUtilsV2.addItem(eob);
        // CLM_LINE_NUM => item.sequence
        item.setSequence(line.getLineNumber().intValue());
        // PRVDR_STATE_CD => item.location
        TransformerUtilsV2.addLocationState(item, claimGroup.getProviderStateCode());
        // REV_CNTR => item.revenue
        item.setRevenue(TransformerUtilsV2.createCodeableConcept(eob, CcwCodebookVariable.REV_CNTR, line.getRevenueCenterCode()));
        // REV_CNTR_1ST_ANSI_CD => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationDenialReasonSlice(eob, CcwCodebookVariable.REV_CNTR_1ST_ANSI_CD, line.getRevCntr1stAnsiCd()));
        // REV_CNTR_2ND_ANSI_CD => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationDenialReasonSlice(eob, CcwCodebookVariable.REV_CNTR_2ND_ANSI_CD, line.getRevCntr2ndAnsiCd()));
        // REV_CNTR_3RD_ANSI_CD => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationDenialReasonSlice(eob, CcwCodebookVariable.REV_CNTR_3RD_ANSI_CD, line.getRevCntr3rdAnsiCd()));
        // REV_CNTR_4RD_ANSI_CD => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationDenialReasonSlice(eob, CcwCodebookVariable.REV_CNTR_4TH_ANSI_CD, line.getRevCntr4thAnsiCd()));
        // HCPCS_CD               => ExplanationOfBenefit.item.productOrService
        // HCPCS_1ST_MDFR_CD      => ExplanationOfBenefit.item.modifier
        // HCPCS_2ND_MDFR_CD      => ExplanationOfBenefit.item.modifier
        TransformerUtilsV2.mapHcpcs(eob, item, line.getHcpcsCode(), Optional.empty(), Arrays.asList(line.getHcpcsInitialModifierCode(), line.getHcpcsSecondModifierCode()));
        // REV_CNTR                   => ExplanationOfBenefit.item.revenue
        // REV_CNTR_RATE_AMT          => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_TOT_CHRG_AMT      => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_NCVRD_CHRG_AMT    => ExplanationOfBenefit.item.adjudication
        // REV_CNTR_NDC_QTY           => ExplanationOfBenefit.item.quantity
        // REV_CNTR_NDC_QTY_QLFR_CD   => ExplanationOfBenefit.modifier
        TransformerUtilsV2.mapEobCommonItemRevenue(item, eob, line.getRevenueCenterCode(), line.getRateAmount(), line.getTotalChargeAmount(), Optional.of(line.getNonCoveredChargeAmount()), line.getNationalDrugCodeQuantity(), line.getNationalDrugCodeQualifierCode());
        // REV_CNTR_BLOOD_DDCTBL_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_BLOOD_DDCTBL_AMT, C4BBAdjudication.DEDUCTIBLE, line.getBloodDeductibleAmount()));
        // REV_CNTR_CASH_DDCTBL_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_CASH_DDCTBL_AMT, C4BBAdjudication.DEDUCTIBLE, line.getCashDeductibleAmount()));
        // REV_CNTR_COINSRNC_WGE_ADJSTD_C => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_COINSRNC_WGE_ADJSTD_C, C4BBAdjudication.COINSURANCE, line.getWageAdjustedCoinsuranceAmount()));
        // REV_CNTR_RDCD_COINSRNC_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_RDCD_COINSRNC_AMT, C4BBAdjudication.COINSURANCE, line.getReducedCoinsuranceAmount()));
        // REV_CNTR_1ST_MSP_PD_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_1ST_MSP_PD_AMT, C4BBAdjudication.PRIOR_PAYER_PAID, line.getFirstMspPaidAmount()));
        // REV_CNTR_2ND_MSP_PD_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_2ND_MSP_PD_AMT, C4BBAdjudication.PRIOR_PAYER_PAID, line.getSecondMspPaidAmount()));
        // REV_CNTR_PRVDR_PMT_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_PRVDR_PMT_AMT, C4BBAdjudication.PAID_TO_PROVIDER, line.getProviderPaymentAmount()));
        // REV_CNTR_BENE_PMT_AMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_BENE_PMT_AMT, C4BBAdjudication.PAID_TO_PATIENT, line.getBenficiaryPaymentAmount()));
        // REV_CNTR_PTNT_RSPNSBLTY_PMT => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.addAdjudication(item, TransformerUtilsV2.createAdjudicationAmtSlice(CcwCodebookVariable.REV_CNTR_PTNT_RSPNSBLTY_PMT, C4BBAdjudication.PAID_BY_PATIENT, line.getPatientResponsibilityAmount()));
        // Common item level fields between Outpatient, HHA and Hospice
        // REV_CNTR_DT              => ExplanationOfBenefit.item.servicedDate
        // REV_CNTR_PMT_AMT_AMT     => ExplanationOfBenefit.item.adjudication
        TransformerUtilsV2.mapEobCommonItemRevenueOutHHAHospice(item, line.getRevenueCenterDate(), line.getPaymentAmount());
        // REV_CNTR_IDE_NDC_UPC_NUM => ExplanationOfBenefit.item.productOrService.extension
        TransformerUtilsV2.addNationalDrugCode(item, line.getNationalDrugCode());
        // RNDRNG_PHYSN_UPIN => ExplanationOfBenefit.careTeam.provider
        TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.UPIN, C4BBClaimInstitutionalCareTeamRole.PERFORMING, line.getRevenueCenterRenderingPhysicianUPIN());
        // RNDRNG_PHYSN_NPI => ExplanationOfBenefit.careTeam.provider
        TransformerUtilsV2.addCareTeamMember(eob, item, C4BBPractitionerIdentifierType.NPI, C4BBClaimInstitutionalCareTeamRole.PERFORMING, line.getRevenueCenterRenderingPhysicianNPI());
        // REV_CNTR_STUS_IND_CD => ExplanationOfBenefit.item.revenue.extension
        TransformerUtilsV2.mapEobCommonItemRevenueStatusCode(item, eob, line.getStatusCode());
    }
    TransformerUtilsV2.setLastUpdated(eob, claimGroup.getLastUpdated());
    return eob;
}
Also used : OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) MetricRegistry(com.codahale.metrics.MetricRegistry) C4BBPractitionerIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBPractitionerIdentifierType) Trace(com.newrelic.api.agent.Trace) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) ProfileConstants(gov.cms.bfd.server.war.commons.ProfileConstants) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) DiagnosisLabel(gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel) C4BBClaimInstitutionalCareTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimInstitutionalCareTeamRole) C4BBOrganizationIdentifierType(gov.cms.bfd.server.war.commons.carin.C4BBOrganizationIdentifierType) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) C4BBAdjudication(gov.cms.bfd.server.war.commons.carin.C4BBAdjudication) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit)

Example 5 with FINAL

use of org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.FINAL in project beneficiary-fhir-data by CMSgov.

the class TransformerTestUtilsV2 method findAdjudicationByCategoryAndAmount.

/**
 * Finds an {@link AdjudicationComponent} using a code in the category and value in amount
 *
 * @param code
 * @param amount
 * @param components
 * @return
 */
static AdjudicationComponent findAdjudicationByCategoryAndAmount(String code, BigDecimal amount, List<AdjudicationComponent> components) {
    final BigDecimal amt = amount.setScale(2, RoundingMode.HALF_DOWN);
    Optional<AdjudicationComponent> adjudication = components.stream().filter(cmp -> (amt.equals(cmp.getAmount().getValue()))).filter(cmp -> cmp.getCategory().getCoding().stream().filter(c -> code.equals(c.getCode())).count() > 0).findFirst();
    assertTrue(adjudication.isPresent());
    return adjudication.get();
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Arrays(java.util.Arrays) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.r4.model.Identifier) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) BenefitComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) Reference(org.hl7.fhir.r4.model.Reference) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) ProcedureComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ProcedureComponent) Money(org.hl7.fhir.r4.model.Money) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) BigDecimal(java.math.BigDecimal) FhirContext(ca.uhn.fhir.context.FhirContext) BaseDateTimeType(org.hl7.fhir.r4.model.BaseDateTimeType) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Duration(java.time.Duration) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Quantity(org.hl7.fhir.r4.model.Quantity) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) CareTeamComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.CareTeamComponent) Method(java.lang.reflect.Method) RoundingMode(java.math.RoundingMode) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) Instant(java.time.Instant) C4BBClaimProfessionalAndNonClinicianCareTeamRole(gov.cms.bfd.server.war.commons.carin.C4BBClaimProfessionalAndNonClinicianCareTeamRole) InvocationTargetException(java.lang.reflect.InvocationTargetException) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Coding(org.hl7.fhir.r4.model.Coding) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) FHIRException(org.hl7.fhir.exceptions.FHIRException) Extension(org.hl7.fhir.r4.model.Extension) DiagnosisComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.DiagnosisComponent) AdjudicationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent) BigDecimal(java.math.BigDecimal)

Aggregations

Test (org.junit.jupiter.api.Test)229 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)85 HashMap (java.util.HashMap)83 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)59 List (java.util.List)53 Bundle (org.hl7.fhir.dstu3.model.Bundle)50 Nonnull (javax.annotation.Nonnull)48 Patient (org.hl7.fhir.dstu3.model.Patient)46 Organization (org.hl7.fhir.dstu3.model.Organization)45 ArrayList (java.util.ArrayList)44 Bundle (org.hl7.fhir.r4.model.Bundle)41 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 UUID (java.util.UUID)38 Collectors (java.util.stream.Collectors)38 Coding (org.hl7.fhir.r4.model.Coding)34 FhirContext (ca.uhn.fhir.context.FhirContext)33 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)32 IParser (ca.uhn.fhir.parser.IParser)31 IOException (java.io.IOException)29 IdType (org.hl7.fhir.dstu3.model.IdType)28