use of org.hl7.fhir.r4.model.ExplanationOfBenefit 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.r4.model.ExplanationOfBenefit 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.r4.model.ExplanationOfBenefit in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addDiagnosisCode.
/**
* @param eob the {@link ExplanationOfBenefit} to (possibly) modify
* @param diagnosis the {@link Diagnosis} to add, if it's not already present
* @return the {@link DiagnosisComponent#getSequence()} of the existing or newly-added entry
*/
static int addDiagnosisCode(ExplanationOfBenefit eob, Diagnosis diagnosis) {
Optional<DiagnosisComponent> existingDiagnosis = eob.getDiagnosis().stream().filter(d -> d.getDiagnosis() instanceof CodeableConcept).filter(d -> diagnosis.isContainedIn((CodeableConcept) d.getDiagnosis())).findAny();
if (existingDiagnosis.isPresent())
return existingDiagnosis.get().getSequenceElement().getValue();
DiagnosisComponent diagnosisComponent = new DiagnosisComponent().setSequence(eob.getDiagnosis().size() + 1);
diagnosisComponent.setDiagnosis(diagnosis.toCodeableConcept());
for (DiagnosisLabel diagnosisLabel : diagnosis.getLabels()) {
CodeableConcept diagnosisTypeConcept = createCodeableConcept(diagnosisLabel.getSystem(), diagnosisLabel.toCode());
diagnosisTypeConcept.getCodingFirstRep().setDisplay(diagnosisLabel.getDisplay());
diagnosisComponent.addType(diagnosisTypeConcept);
}
if (diagnosis.getPresentOnAdmission().isPresent()) {
diagnosisComponent.addExtension(createExtensionCoding(eob, CcwCodebookVariable.CLM_POA_IND_SW1, diagnosis.getPresentOnAdmission()));
}
eob.getDiagnosis().add(diagnosisComponent);
return diagnosisComponent.getSequenceElement().getValue();
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit 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;
}
use of org.hl7.fhir.r4.model.ExplanationOfBenefit in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addProcedureCode.
/**
* @param eob the {@link ExplanationOfBenefit} to (possibly) modify
* @param diagnosis the {@link Diagnosis} to add, if it's not already present
* @return the {@link ProcedureComponent#getSequence()} of the existing or newly-added entry
*/
static int addProcedureCode(ExplanationOfBenefit eob, CCWProcedure procedure) {
Optional<ProcedureComponent> existingProcedure = eob.getProcedure().stream().filter(pc -> pc.getProcedure() instanceof CodeableConcept).filter(pc -> isCodeInConcept((CodeableConcept) pc.getProcedure(), procedure.getFhirSystem(), procedure.getCode())).findAny();
if (existingProcedure.isPresent())
return existingProcedure.get().getSequenceElement().getValue();
ProcedureComponent procedureComponent = new ProcedureComponent().setSequence(eob.getProcedure().size() + 1);
procedureComponent.setProcedure(createCodeableConcept(procedure.getFhirSystem(), null, retrieveProcedureCodeDisplay(procedure.getCode()), procedure.getCode()));
if (procedure.getProcedureDate().isPresent()) {
procedureComponent.setDate(convertToDate(procedure.getProcedureDate().get()));
}
eob.getProcedure().add(procedureComponent);
return procedureComponent.getSequenceElement().getValue();
}
Aggregations