use of org.hl7.fhir.r4b.model.Reference in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method mapEobCommonGroupCarrierDME.
/**
* Transforms the common group level data elements between the {@link CarrierClaim} and {@link
* DMEClaim} claim types to FHIR. The method parameter fields from {@link CarrierClaim} and {@link
* DMEClaim} are listed below and their corresponding RIF CCW fields (denoted in all CAPS below
* from {@link CarrierClaimColumn} and {@link DMEClaimColumn}).
*
* @param eob the {@link ExplanationOfBenefit} to modify
* @param benficiaryId BEME_ID, *
* @param carrierNumber CARR_NUM,
* @param clinicalTrialNumber CLM_CLNCL_TRIL_NUM,
* @param beneficiaryPartBDeductAmount CARR_CLM_CASH_DDCTBL_APLD_AMT,
* @param paymentDenialCode CARR_CLM_PMT_DNL_CD,
* @param referringPhysicianNpi RFR_PHYSN_NPI
* @param providerAssignmentIndicator CARR_CLM_PRVDR_ASGNMT_IND_SW,
* @param providerPaymentAmount NCH_CLM_PRVDR_PMT_AMT,
* @param beneficiaryPaymentAmount NCH_CLM_BENE_PMT_AMT,
* @param submittedChargeAmount NCH_CARR_CLM_SBMTD_CHRG_AMT,
* @param allowedChargeAmount NCH_CARR_CLM_ALOWD_AMT,
*/
static void mapEobCommonGroupCarrierDME(ExplanationOfBenefit eob, String beneficiaryId, String carrierNumber, Optional<String> clinicalTrialNumber, BigDecimal beneficiaryPartBDeductAmount, String paymentDenialCode, Optional<String> referringPhysicianNpi, Optional<Character> providerAssignmentIndicator, BigDecimal providerPaymentAmount, BigDecimal beneficiaryPaymentAmount, BigDecimal submittedChargeAmount, BigDecimal allowedChargeAmount, String claimDispositionCode, Optional<String> claimCarrierControlNumber) {
eob.addExtension(createExtensionIdentifier(CcwCodebookVariable.CARR_NUM, carrierNumber));
// Carrier Claim Control Number
if (claimCarrierControlNumber.isPresent()) {
eob.addExtension(createExtensionIdentifier(CcwCodebookMissingVariable.CARR_CLM_CNTL_NUM, claimCarrierControlNumber.get()));
}
eob.addExtension(createExtensionCoding(eob, CcwCodebookVariable.CARR_CLM_PMT_DNL_CD, paymentDenialCode));
// Claim Disposition Code
eob.setDisposition(claimDispositionCode);
/*
* Referrals are represented as contained resources, since they share the lifecycle and identity
* of their containing EOB.
*/
if (referringPhysicianNpi.isPresent()) {
ReferralRequest referral = new ReferralRequest();
referral.setStatus(ReferralRequestStatus.COMPLETED);
referral.setSubject(referencePatient(beneficiaryId));
referral.setRequester(new ReferralRequestRequesterComponent(referencePractitioner(referringPhysicianNpi.get())));
referral.addRecipient(referencePractitioner(referringPhysicianNpi.get()));
// Set the ReferralRequest as a contained resource in the EOB:
eob.setReferral(new Reference(referral));
}
if (providerAssignmentIndicator.isPresent()) {
eob.addExtension(createExtensionCoding(eob, CcwCodebookVariable.ASGMNTCD, providerAssignmentIndicator));
}
if (clinicalTrialNumber.isPresent()) {
eob.addExtension(createExtensionIdentifier(CcwCodebookVariable.CLM_CLNCL_TRIL_NUM, clinicalTrialNumber));
}
addAdjudicationTotal(eob, CcwCodebookVariable.CARR_CLM_CASH_DDCTBL_APLD_AMT, beneficiaryPartBDeductAmount);
addAdjudicationTotal(eob, CcwCodebookVariable.NCH_CLM_PRVDR_PMT_AMT, providerPaymentAmount);
addAdjudicationTotal(eob, CcwCodebookVariable.NCH_CLM_BENE_PMT_AMT, beneficiaryPaymentAmount);
addAdjudicationTotal(eob, CcwCodebookVariable.NCH_CARR_CLM_SBMTD_CHRG_AMT, submittedChargeAmount);
addAdjudicationTotal(eob, CcwCodebookVariable.NCH_CARR_CLM_ALOWD_AMT, allowedChargeAmount);
}
use of org.hl7.fhir.r4b.model.Reference 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;
}
use of org.hl7.fhir.r4b.model.Reference in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method createExtensionDate.
/**
* @param ccwVariable the {@link CcwCodebookInterface} being mapped
* @param dateYear the value to use for {@link Coding#getCode()} for the resulting {@link Coding}
* @return the output {@link Extension}, with {@link Extension#getValue()} set to represent the
* specified input values
*/
static Extension createExtensionDate(CcwCodebookInterface ccwVariable, Optional<BigDecimal> dateYear) {
Extension extension = null;
if (!dateYear.isPresent()) {
throw new NoSuchElementException();
}
try {
String stringDate = String.format("%04d", dateYear.get().intValue());
DateType dateYearValue = new DateType(stringDate);
String extensionUrl = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
extension = new Extension(extensionUrl, dateYearValue);
} catch (DataFormatException e) {
throw new InvalidRifValueException(String.format("Unable to create DateType with reference year: '%s'.", dateYear.get()), e);
}
return extension;
}
use of org.hl7.fhir.r4b.model.Reference in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method createAdjudicationCategory.
/**
* @param ccwVariable the {@link CcwCodebookInterface} being mapped
* @return the {@link AdjudicationComponent#getCategory()} {@link CodeableConcept} to use for the
* specified {@link CcwCodebookInterface}
*/
static CodeableConcept createAdjudicationCategory(CcwCodebookInterface ccwVariable) {
/*
* Adjudication.category is mapped a bit differently than other Codings/CodeableConcepts: they
* all share the same Coding.system and use the CcwCodebookVariable reference URL as their
* Coding.code. This looks weird, but makes it easy for API developers to find more information
* about what the specific adjudication they're looking at means.
*/
String conceptCode = CCWUtils.calculateVariableReferenceUrl(ccwVariable);
CodeableConcept categoryConcept = createCodeableConcept(TransformerConstants.CODING_CCW_ADJUDICATION_CATEGORY, conceptCode);
categoryConcept.getCodingFirstRep().setDisplay(ccwVariable.getVariable().getLabel());
return categoryConcept;
}
use of org.hl7.fhir.r4b.model.Reference in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addResourcesToBundle.
/**
* @param bundle a {@link Bundle} to add the list of {@link ExplanationOfBenefit} resources to.
* @param resources a list of either {@link ExplanationOfBenefit}s, {@link Coverage}s, or {@link
* Patient}s, of which a portion will be added to the bundle based on the paging values
* @return Returns a {@link Bundle} of {@link ExplanationOfBenefit}s, {@link Coverage}s, or {@link
* Patient}s, which may contain multiple matching resources, or may also be empty.
*/
public static Bundle addResourcesToBundle(Bundle bundle, List<IBaseResource> resources) {
Set<String> beneIds = new HashSet<String>();
for (IBaseResource res : resources) {
BundleEntryComponent entry = bundle.addEntry();
entry.setResource((Resource) res);
if (entry.getResource().getResourceType() == ResourceType.ExplanationOfBenefit) {
ExplanationOfBenefit eob = ((ExplanationOfBenefit) entry.getResource());
if (eob != null && eob.getPatient() != null && !Strings.isNullOrEmpty(eob.getPatient().getReference())) {
String reference = eob.getPatient().getReference().replace("Patient/", "");
if (!Strings.isNullOrEmpty(reference)) {
beneIds.add(reference);
}
}
} else if (entry.getResource().getResourceType() == ResourceType.Patient) {
Patient patient = ((Patient) entry.getResource());
if (patient != null && !Strings.isNullOrEmpty(patient.getId())) {
beneIds.add(patient.getId());
}
} else if (entry.getResource().getResourceType() == ResourceType.Coverage) {
Coverage coverage = ((Coverage) entry.getResource());
if (coverage != null && coverage.getBeneficiary() != null && !Strings.isNullOrEmpty(coverage.getBeneficiary().getReference())) {
String reference = coverage.getBeneficiary().getReference().replace("Patient/", "");
if (!Strings.isNullOrEmpty(reference)) {
beneIds.add(reference);
}
}
}
}
logBeneIdToMdc(beneIds);
return bundle;
}
Aggregations