Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.ewv.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import gov.va.med.ars.dao.ewv.IEwvClaimRepository;
import gov.va.med.ars.dao.ewv.ILuClaimAdjustReasonCodeRepository;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.domain.ewv.EwvClaimLevelAdjustments;
import gov.va.med.domain.ewv.EwvClaimOhis;
import gov.va.med.domain.ewv.EwvClaims;
import gov.va.med.domain.ewv.EwvServiceLineOhiAdjtmts;
import gov.va.med.domain.ewv.EwvServiceLineOhis;
import gov.va.med.domain.ewv.EwvServiceLines;
import gov.va.med.ewv.codes.RemittanceCode;
import gov.va.med.ewv.model.response.Adjustment;
import gov.va.med.ewv.model.response.ClaimOhi;
import gov.va.med.ewv.model.response.ClaimOhiAdjustment;
import gov.va.med.ewv.model.response.ClaimOhiAdjustmentsBean;
import gov.va.med.ewv.model.response.ClaimOhiContainer;
import gov.va.med.ewv.model.response.ClaimOhiHeader;
import gov.va.med.ewv.model.response.CobAmountsBean;
import gov.va.med.ewv.model.response.DetailServiceLineOhiOutputRow;
import gov.va.med.ewv.model.response.MedicareInPatientAdjudicationBean;
import gov.va.med.ewv.model.response.MedicareOutPatientAdjudicationBean;
import gov.va.med.ewv.model.response.OhiInfoContainer;
import gov.va.med.ewv.model.response.QuickViewServiceLineOhiOutputRow;
import gov.va.med.ewv.model.response.ServiceLineOhiAdjustment;
import gov.va.med.ewv.service.IEwvOhiService;
import gov.va.med.ewv.util.AdjustmentType;
import gov.va.med.ewv.util.ClaimType;
import gov.va.med.ewv.util.DTOBase;
import gov.va.med.ewv.util.EwvNullsLastComparator;
//import static gov.va.med.ewv.util.EwvSetToNullsLastList.*; // non-generic implementation
import static gov.va.med.ewv.util.EwvNullsLastSortedList.*; // generic implementation
import gov.va.med.ewv.util.EwvUtils;
@Service
public class EwvOhiServiceImpl extends DTOBase implements IEwvOhiService {
private static final Logger logger = LogManager.getLogger(EwvClaimServiceImpl.class);
@Autowired
IEwvClaimRepository ewvClaimRepository;
@Autowired
ILuClaimAdjustReasonCodeRepository luClaimAdjustReasonCodeRepository;
@Override
public OhiInfoContainer getOhiData(EwvClaims claimBean) throws GenericException {
logger.debug("getOhiData() retrieving EwvClaims for pdi :" + claimBean.getPdi());
// Get the necessary pieces from the database
logger.debug("getOhiData() retrieving EwvServiceLines for guid :" + claimBean.getGuid());
List<EwvServiceLines> ewvServiceLinesList = getEwvServiceLinesList(claimBean);
logger.debug("getOhiData() retrieving EwvClaimOhis for guid :" + claimBean.getGuid());
Set<EwvClaimOhis> claimOhiSet = claimBean.getEwvClaimOhises();
// Loop through the claim ohis, adding a data structure for each one
List<ClaimOhiContainer> claimOhiList = new ArrayList<ClaimOhiContainer>(0);
for (EwvClaimOhis ewvClaimOhis : claimOhiSet) {
logger.debug("getOhiData() retrieving EwvClaimLevelAdjustments for guid :" + ewvClaimOhis.getGuid());
Set<EwvClaimLevelAdjustments> claimOhiAdjustments = ewvClaimOhis.getEwvClaimLevelAdjustmentses();
logger.debug("getOhiData() retrieving ClaimOhi ");
ClaimOhiContainer newClaimOhiContainer = getClaimOhi(ewvClaimOhis, claimOhiAdjustments,claimBean.getClaimType());
claimOhiList.add(newClaimOhiContainer);
}
// sortedList(claimOhiList, EwvClaims::getEwvClaimOhises, EwvNullsLastComparator::compare)
Collections.sort(claimOhiList, EwvNullsLastComparator::compare); // for highlighting purposes This only sorts on "PST": Primary, ...
// Determine whether there are any problems with payer identification
// Three different problems might exist that cause a change in our
// Quickview layout
logger.debug("getOhiData() retrieving ClaimOhi getHasMultipleSeqP_Payers");
boolean hasMultipleSeqP_Payers = getHasMultipleSeqP_Payers(claimOhiSet);
logger.debug("getOhiData() retrieving ClaimOhi getHasMultipleSeqS_Payers ");
boolean hasMultipleSeqS_Payers = getHasMultipleSeqS_Payers(claimOhiSet);
logger.debug("getOhiData() retrieving ClaimOhi getHasMultipleSeqT_Payers ");
boolean hasMultipleSeqT_Payers = getHasMultipleSeqT_Payers(claimOhiSet);
logger.debug("getOhiData() retrieving ClaimOhi hasMultipleSeqT_Payers");
boolean hasMultiplePayersWithSamePayerId = getHasMultiplePayersWithSamePayerId(claimOhiSet);
boolean hasPayerIdProblem =
hasMultipleSeqP_Payers ||
hasMultipleSeqS_Payers ||
hasMultipleSeqT_Payers ||
hasMultiplePayersWithSamePayerId;
// A fourth type of payer id problem is not as serious.
// Is this flag even necessary?
logger.debug("getOhiData() retrieving ClaimOhi getHasMultipleAdjudicationsFromSamePayer");
Set<EwvServiceLines> ewvServiceLinesSet = claimBean.getEwvServiceLineses(); // order doesn't matter
boolean hasMultipleAdjudicationsFromSamePayer = getHasMultipleAdjudicationsFromSamePayer(ewvServiceLinesSet);
String seqP_ClaimOhiPayerId = null;
String seqS_ClaimOhiPayerId = null;
String seqT_ClaimOhiPayerId = null;
ClaimOhi seqP_ClaimOhi = null;
ClaimOhi seqS_ClaimOhi = null;
ClaimOhi seqT_ClaimOhi = null;
Boolean seqT_OhiExists = false;
List<QuickViewServiceLineOhiOutputRow> quickviewServiceLineOhiOutputRows = null;
// Only do some of this stuff if there is no payer id problem
if (!hasPayerIdProblem) {
// Put together the primary and secondary Claim Ohi records, for use in sub-tables
logger.debug("getOhiData() retrieving ClaimOhi populateClaimOhi for primary");
seqP_ClaimOhi = populateClaimOhi(claimOhiSet, ewvServiceLinesSet, "P");
logger.debug("getOhiData() retrieving ClaimOhi populateClaimOhi for secondary");
seqS_ClaimOhi = populateClaimOhi(claimOhiSet, ewvServiceLinesSet, "S");
logger.debug("getOhiData() retrieving ClaimOhi populateClaimOhi for tertiary");
seqT_ClaimOhi = populateClaimOhi(claimOhiSet, ewvServiceLinesSet, "T");
logger.debug("getOhiData() retrieving ClaimOhi getTertiaryOhiExists");
seqT_OhiExists = getTertiaryOhiExists(claimOhiSet);
// Phase Two Stuff
// Put together a data structure to hold service lines plus ohis
// plus adjustment info
// This is used for the table near the bottom of the QuickView tab,
// which would be
// difficult to do as three separate tables because of the line
// breaks due to
// multiple primary or secondary adjustments.
if (seqP_ClaimOhi != null) {
seqP_ClaimOhiPayerId = seqP_ClaimOhi.getOhiPayerId();
}
if (seqS_ClaimOhi != null) {
seqS_ClaimOhiPayerId = seqS_ClaimOhi.getOhiPayerId();
}
if (seqT_ClaimOhi != null) {
seqT_ClaimOhiPayerId = seqT_ClaimOhi.getOhiPayerId();
}
logger.debug("getOhiData() retrieving ClaimOhi populateQuickviewServiceLineOhiOutputRows");
quickviewServiceLineOhiOutputRows = populateQuickviewServiceLineOhiOutputRows(ewvServiceLinesList,
seqP_ClaimOhiPayerId, seqS_ClaimOhiPayerId, seqT_ClaimOhiPayerId);
}
logger.debug("getOhiData() retrieving ClaimOhi populateDetailServiceLineOutputRows");
List<DetailServiceLineOhiOutputRow> detailServiceLineOhiOutputRows = populateDetailServiceLineOutputRows(
ewvServiceLinesList, hasMultiplePayersWithSamePayerId, claimOhiSet);
// End of Phase Two Stuff
OhiInfoContainer ohiInfoContainer = new OhiInfoContainer(claimOhiList, seqP_ClaimOhi, seqS_ClaimOhi,
seqT_ClaimOhi, seqT_OhiExists, quickviewServiceLineOhiOutputRows, detailServiceLineOhiOutputRows,
hasPayerIdProblem, hasMultipleSeqP_Payers, hasMultipleSeqS_Payers,
hasMultiplePayersWithSamePayerId, hasMultipleAdjudicationsFromSamePayer);
logger.debug("getOhiData() returning ohiInfoContainer :" + ohiInfoContainer);
return ohiInfoContainer;
}
private ClaimOhiContainer getClaimOhi(EwvClaimOhis claimOhi, Set<EwvClaimLevelAdjustments> adjustmentSet,String strClaimType) {
logger.debug("Invoked getClaimOhi() ");
MedicareInPatientAdjudicationBean medicareInPatientAdjudicationBean = createMedicareInPatientAdjudicationBean(
claimOhi);
MedicareOutPatientAdjudicationBean medicareOutPatientAdjudicationBean = createMedicareOutPatientAdjudicationBean(
claimOhi);
/* Defect 883594. X12 only have MOA or MIA segment. So, show only medicareInPatientAdjudication info
* or medicareOutPatientAdjudication info. Not real scenario, if got both segments,
* show MOA for Professional and Dental; MIA for Institutional */
ClaimType claimType = ClaimType.typeOf(strClaimType);
if ( medicareInPatientAdjudicationBean!= null && medicareOutPatientAdjudicationBean != null ) {
if (claimType.equals(ClaimType.INSTITUTIONAL)) {
medicareOutPatientAdjudicationBean = null;
}else if (claimType.equals(ClaimType.PROFESSIONAL)) {
medicareInPatientAdjudicationBean = null;
} else if (claimType.equals(ClaimType.DENTAL)) {
medicareInPatientAdjudicationBean = null;
}
}
CobAmountsBean claimOhiAmountsBean = createCOBAmountsBean(claimOhi);
ClaimOhiHeader claimOhiHeader = createClaimOhiHeaderBean(claimOhi);
// Adjustments
ClaimOhiAdjustmentsBean claimOhiAdjustmentsBean = createClaimOhiAdjustmentsBean(claimOhi.getOhiPayerId(),
adjustmentSet);
ClaimOhiContainer claimOhiContainer = new ClaimOhiContainer(claimOhiHeader, claimOhiAdjustmentsBean,
claimOhiAmountsBean, medicareInPatientAdjudicationBean, medicareOutPatientAdjudicationBean);
logger.debug("getClaimOhi() : Returning ClaimOhiContainer");
return claimOhiContainer;
}
private MedicareOutPatientAdjudicationBean createMedicareOutPatientAdjudicationBean(EwvClaimOhis claim) {
logger.debug("Invoked createMedicareOutPatientAdjudicationBean() ");
String ohiPayerId = claim.getOhiPayerId();
List<RemittanceCode> remittanceRemarkCodes = createOutpatientRemittanceRemarkCodes(claim);
String reimbursementRate = claim.getOptReimbursementRate();
String claimHcpcsPayableAmount = claim.getOptClaimHcpcsPayableAmt();
String esrdPaidAmount = claim.getOptEsrdPaidAmt();
String nonPayableProfessionalComponentAmount = claim.getOptNonpayableProfComponent();
boolean nonEmpty = EwvUtils.okToRender(reimbursementRate,claimHcpcsPayableAmount,
esrdPaidAmount,nonPayableProfessionalComponentAmount);
if (!nonEmpty){
nonEmpty = EwvUtils.okToRender(remittanceRemarkCodes);
}
MedicareOutPatientAdjudicationBean ret = null;
if (nonEmpty) {
ret = new MedicareOutPatientAdjudicationBean(ohiPayerId,remittanceRemarkCodes, reimbursementRate,
claimHcpcsPayableAmount, esrdPaidAmount,nonPayableProfessionalComponentAmount);
}
logger.debug("createMedicareOutPatientAdjudicationBean() : returning ");
return ret;
}
private List<RemittanceCode> createOutpatientRemittanceRemarkCodes(EwvClaimOhis claim) {
logger.debug("Invoked createOutpatientRemittanceRemarkCodes() ");
List<RemittanceCode> listOf = new ArrayList<RemittanceCode>(0);
if (claim.getOptRemittanceRemarkCode1() != null) {
listOf.add(new RemittanceCode(claim.getOptRemittanceRemarkCode1(), claim.getOptRemittanceRemarkDesc1(),
EwvUtils.shorten(claim.getOptRemittanceRemarkDesc1(), 60)));
}
if (claim.getOptRemittanceRemarkCode2() != null) {
listOf.add(new RemittanceCode(claim.getOptRemittanceRemarkCode2(), claim.getOptRemittanceRemarkDesc2(),
EwvUtils.shorten(claim.getOptRemittanceRemarkDesc2(), 60)));
}
if (claim.getOptRemittanceRemarkCode3() != null) {
listOf.add(new RemittanceCode(claim.getOptRemittanceRemarkCode3(), claim.getOptRemittanceRemarkDesc3(),
EwvUtils.shorten(claim.getOptRemittanceRemarkDesc3(), 60)));
}
if (claim.getOptRemittanceRemarkCode4() != null) {
listOf.add(new RemittanceCode(claim.getOptRemittanceRemarkCode4(), claim.getOptRemittanceRemarkDesc4(),
EwvUtils.shorten(claim.getOptRemittanceRemarkDesc4(), 60)));
}
if (claim.getOptRemittanceRemarkCode5() != null) {
listOf.add(new RemittanceCode(claim.getOptRemittanceRemarkCode5(), claim.getOptRemittanceRemarkDesc5(),
EwvUtils.shorten(claim.getOptRemittanceRemarkDesc5(), 60)));
}
logger.debug("createOutpatientRemittanceRemarkCodes() : returning ");
return listOf;
}
private MedicareInPatientAdjudicationBean createMedicareInPatientAdjudicationBean(EwvClaimOhis claim) {
logger.debug("Invoked createMedicareInPatientAdjudicationBean() ");
String ohiPayerId = claim.getOhiPayerId();
String coveredDays = claim.getInpCoveredDays();
// Defect #UAT-20 fix
String ppsOperatingFederalSpecDrugAmount = claim.getInpPpsOperFedSpecDrgAmt();
String lifetimeReserveDays = claim.getInpLifetimeReserveDays();
String ppsCapitalOutlierAmount = claim.getInpPpsCapitalOutlrAmt();
String lifetimePsychiatricDays = claim.getInpLifetimePsychiatricDays();
String claimIndirectTeachingAmount = claim.getInpClaimIndirectTeachAmt();
String claimDrugAmount = claim.getInpClaimDrgAmt();
String nonPayableProfessionalComponent = claim.getInpNonpayableProfComponent();
String claimDisproportionateShare = claim.getInpClaimDisproporShare();
String ppsCapitalExceptionAmount = claim.getInpPpsCapitalExceptionAmt();
String mspPassThruAmount = claim.getInpMspPassThroughAmt();
String costReportDayCount = claim.getInpCostReportDayCount();
String claimPpsCapitalAmount = claim.getInpClaimPpsCapitalAmt();
String ppsCapitalFspDrugAmount = claim.getInpPpsCapitalFspDrgAmt();
String ppsCapitalHspDrugAmount = claim.getInpPpsCapitalHspDrgAmt();
String ppsCapitalDshDrugAmount = claim.getInpPpsCapitalDshDrgAmt();
String oldCapitalAmount = claim.getInpOldCapitalAmt();
List<RemittanceCode> remittanceRemarkCodes = createInPatientRemittanceRemarkCodes(claim);
String ppsCapitalImeAmount = claim.getInpPpsCapitalImeAmt();
String ppsOperHospitalSpecicalDrugAmount = claim.getInpPpsOperHospSpecDrgAmt();
boolean nonEmpty = EwvUtils.okToRender(coveredDays,
ppsOperatingFederalSpecDrugAmount, lifetimeReserveDays, ppsCapitalOutlierAmount,
lifetimePsychiatricDays, claimIndirectTeachingAmount, claimDrugAmount, nonPayableProfessionalComponent,
claimDisproportionateShare, ppsCapitalExceptionAmount, mspPassThruAmount, costReportDayCount,
claimPpsCapitalAmount, ppsCapitalFspDrugAmount, ppsCapitalHspDrugAmount, ppsCapitalDshDrugAmount,
oldCapitalAmount, ppsCapitalImeAmount, ppsOperHospitalSpecicalDrugAmount);
if (!nonEmpty){
nonEmpty = EwvUtils.okToRender(remittanceRemarkCodes);
}
MedicareInPatientAdjudicationBean ret = null;
if (nonEmpty) {
ret = new MedicareInPatientAdjudicationBean(ohiPayerId, coveredDays,
ppsOperatingFederalSpecDrugAmount, lifetimeReserveDays, ppsCapitalOutlierAmount,
lifetimePsychiatricDays, claimIndirectTeachingAmount, claimDrugAmount, nonPayableProfessionalComponent,
claimDisproportionateShare, ppsCapitalExceptionAmount, mspPassThruAmount, costReportDayCount,
claimPpsCapitalAmount, ppsCapitalFspDrugAmount, ppsCapitalHspDrugAmount, ppsCapitalDshDrugAmount,
oldCapitalAmount, remittanceRemarkCodes, ppsCapitalImeAmount, ppsOperHospitalSpecicalDrugAmount);
}
logger.debug("createMedicareInPatientAdjudicationBean() : returning ");
return ret;
}
private List<RemittanceCode> createInPatientRemittanceRemarkCodes(EwvClaimOhis claim) {
logger.debug("Invoked createInPatientRemittanceRemarkCodes() ");
List<RemittanceCode> listOf = new ArrayList<RemittanceCode>(0);
if (claim.getInpRemittanceRemarkCode1() != null) {
listOf.add(new RemittanceCode(claim.getInpRemittanceRemarkCode1(), claim.getInpRemittanceRemarkDesc1(),
EwvUtils.shorten(claim.getInpRemittanceRemarkDesc1(), 60)));
}
if (claim.getInpRemittanceRemarkCode2() != null) {
listOf.add(new RemittanceCode(claim.getInpRemittanceRemarkCode2(), claim.getInpRemittanceRemarkDesc2(),
EwvUtils.shorten(claim.getInpRemittanceRemarkDesc2(), 60)));
}
if (claim.getInpRemittanceRemarkCode3() != null) {
listOf.add(new RemittanceCode(claim.getInpRemittanceRemarkCode3(), claim.getInpRemittanceRemarkDesc3(),
EwvUtils.shorten(claim.getInpRemittanceRemarkDesc3(), 60)));
}
if (claim.getInpRemittanceRemarkCode4() != null) {
listOf.add(new RemittanceCode(claim.getInpRemittanceRemarkCode4(), claim.getInpRemittanceRemarkDesc4(),
EwvUtils.shorten(claim.getInpRemittanceRemarkDesc4(), 60)));
}
if (claim.getInpRemittanceRemarkCode5() != null) {
listOf.add(new RemittanceCode(claim.getInpRemittanceRemarkCode5(), claim.getInpRemittanceRemarkDesc5(),
EwvUtils.shorten(claim.getInpRemittanceRemarkDesc5(), 60)));
}
logger.debug("createInPatientRemittanceRemarkCodes() : returning ");
return listOf;
}
private CobAmountsBean createCOBAmountsBean(EwvClaimOhis claim) {
logger.debug("Invoked : createCOBAmountsBean()");
String ohiPayerId = claim.getOhiPayerId();
String cobSubmittedCharges = claim.getCobSubmittedCharges();
String cobTotalAllowedAmount = claim.getCobTotalAllowedAmt();
String cobApprovedAmount = claim.getCobApprovedAmt();
String cobTotalNonCoveredAmount = claim.getCobTotalNoncoveredAmt();
String cobPayerPaidAmount = claim.getCobPayerPaidAmt();
String cobTotalDeniedAmount = claim.getCobTotalDeniedAmt();
String cobPatientPaidAmount = claim.getCobPatientPaidAmt();
String cobTotalMedicarePaidAmount = claim.getCobTotalMedicarePaidAmt();
String cobPatientResponsibility = claim.getCobPatientResponsibility();
String medicarePaidAmt = claim.getCobTotalMedicarePaidAmt();
String cobMedicareATrustFund = claim.getCobMedicareATrustFund();
String cobMedicareBTrustFund = claim.getCobMedicareBTrustFund();
String medicarePaidEightyPercentAmount = claim.getCobMedicarePaidAmt80();
String medicarePaidOneHundredPercentAmount = claim.getCobMedicarePaidAmt100();
CobAmountsBean ret = new CobAmountsBean(ohiPayerId, cobSubmittedCharges, cobTotalAllowedAmount,
cobApprovedAmount, cobTotalNonCoveredAmount, cobPayerPaidAmount, cobTotalDeniedAmount,
cobPatientPaidAmount, cobTotalMedicarePaidAmount, medicarePaidOneHundredPercentAmount,
medicarePaidEightyPercentAmount, cobPatientResponsibility, medicarePaidAmt, cobMedicareATrustFund,
cobMedicareBTrustFund);
logger.debug("Returned : createCOBAmountsBean()");
return ret;
}
private ClaimOhiAdjustmentsBean createClaimOhiAdjustmentsBean(String theOhiPayerId,
Set<EwvClaimLevelAdjustments> adjustmentSet) {
String ohiPayerId = theOhiPayerId;
List<Adjustment> adjustmentList = new ArrayList<Adjustment>();
for (EwvClaimLevelAdjustments adjust : adjustmentSet) {
adjustmentList.add(createClaimOhiAdjustment(ohiPayerId, adjust));
}
// sort by amounts, OA, PI, PR etc...
Collections.sort(adjustmentList);
return new ClaimOhiAdjustmentsBean(ohiPayerId, adjustmentList);
}
private ClaimOhiAdjustment createClaimOhiAdjustment(String ohiPayerId, EwvClaimLevelAdjustments adjust) {
String claimAdjustmentReasonCode = adjust.getClaimAdjustmentReasonCode();
String quantity = adjust.getQuantity();
String descriptionLong = adjust.getDescription();
String descriptionShort = EwvUtils.shorten(descriptionLong, 15);
String coAmount = adjust.getCoAmt();
String crAmount = adjust.getCrAmt();
String oaAmount = adjust.getOaAmt();
String piAmount = adjust.getPiAmt();
String prAmount = adjust.getPrAmt();
String note = "";
if ( claimAdjustmentReasonCode != null && !(claimAdjustmentReasonCode.trim().isEmpty())) {
note = luClaimAdjustReasonCodeRepository.getNoteByReasonCode(claimAdjustmentReasonCode) ;
descriptionLong = descriptionLong + " " + note;
}
ClaimOhiAdjustment ret = new ClaimOhiAdjustment(ohiPayerId, claimAdjustmentReasonCode, descriptionLong,
descriptionShort, quantity, coAmount, crAmount, oaAmount, piAmount, prAmount);
if (coAmount != null) {
ret.setAdjustmentType(AdjustmentType.CO);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_CO);
} else if (crAmount != null) {
ret.setAdjustmentType(AdjustmentType.CR);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_CR);
} else if (oaAmount != null) {
ret.setAdjustmentType(AdjustmentType.OA);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_OA);
} else if (piAmount != null) {
ret.setAdjustmentType(AdjustmentType.PI);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_PI);
} else if (prAmount != null) {
ret.setAdjustmentType(AdjustmentType.PR);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_PR);
}
return ret;
}
private ClaimOhiHeader createClaimOhiHeaderBean(EwvClaimOhis claim) {
String paymentSequenceIndicator = claim.getPaymentSequenceIndicator();
String ohiGroupName = claim.getOhiGroupName();
String filingIndicator = claim.getFilingIndicator();
String benefitsAssignmentIndicator = claim.getBenefitsAssignmentIndicator();
String insuranceType = claim.getInsuranceType();
String claimAdjustmentDate = claim.getClaimAdjustmentDate();
String ohiPayerID = claim.getOhiPayerId();
String subscriberPayerId = claim.getSubscriberPayerId();
String otherPayerName = claim.getOtherPayerName();
// TODO where is this coming from?
String ohiOne = "XXX";
ClaimOhiHeader ret = new ClaimOhiHeader(paymentSequenceIndicator, ohiGroupName, filingIndicator,
benefitsAssignmentIndicator, insuranceType, claimAdjustmentDate, ohiPayerID, subscriberPayerId, otherPayerName, ohiOne);
return ret;
}
private ClaimOhi populateClaimOhi(Set<EwvClaimOhis> claimOhis, Set<EwvServiceLines> serviceLines, String ohiType) {
ClaimOhi returnBean = null;
// Find the pertinent ohi
EwvClaimOhis sourceOhi = null;
for (EwvClaimOhis claimOhi : claimOhis) {
if (ohiType.equals(claimOhi.getPaymentSequenceIndicator())) {
sourceOhi = claimOhi;
break;
}
}
// If after looking for the pertinent ohi, we did not find one, give up
if (sourceOhi == null) {
return null;
}
// Start up an object to return
returnBean = new ClaimOhi();
// Get the string fields
returnBean.setOtherPayerName(sourceOhi.getOtherPayerName());
returnBean.setOhiGroupName(sourceOhi.getOhiGroupName());
returnBean.setOhiPayerId(sourceOhi.getOhiPayerId());
returnBean.setPayerPaidAmount(EwvUtils.formatAsCurrency(sourceOhi.getCobPayerPaidAmt()));
// Get the Claim OHI adjustments
Set<EwvClaimLevelAdjustments> sourceClaimOhiAdjustments = sourceOhi.getEwvClaimLevelAdjustmentses();
List<ClaimOhiAdjustment> returnClaimOhiAdjustments = new ArrayList<ClaimOhiAdjustment>();
for (EwvClaimLevelAdjustments sourceClaimOhiAdjustment : sourceClaimOhiAdjustments) {
ClaimOhiAdjustment claimOhiAdjustment = createClaimOhiAdjustment(sourceOhi.getOhiPayerId(),
sourceClaimOhiAdjustment);
returnClaimOhiAdjustments.add(claimOhiAdjustment);
}
// recheck
returnBean.setClaimOhiAdjustments(returnClaimOhiAdjustments);
// Get the remittance remark code stuff
List<RemittanceCode> remittanceCodes = getRemittanceCodesForOhi(sourceOhi);
returnBean.setRemittanceRemarkCodes(remittanceCodes);
// Get the service line stuff
return returnBean;
}
private boolean getTertiaryOhiExists(Set<EwvClaimOhis> claimOhis) {
boolean returnVal = false;
// Find the pertinent ohi
for (EwvClaimOhis claimOhi : claimOhis) {
if ("T".equals(claimOhi.getPaymentSequenceIndicator())) {
returnVal = true;
break;
}
}
return returnVal;
}
private List<RemittanceCode> getRemittanceCodesForOhi(EwvClaimOhis ohi) {
logger.info("Invoked getRemittanceCodesForOhi() for EwvClaimOhis guid : "+ohi.getGuid());
List<RemittanceCode> remittanceCodes = new ArrayList<RemittanceCode>();
RemittanceCode nextRemittanceCode = null;
// Look through both inpatient and outpatient, for now
// For this purpose, we do not need short names
if (ohi.getInpRemittanceRemarkCode1() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getInpRemittanceRemarkCode1(),
ohi.getInpRemittanceRemarkDesc1(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getInpRemittanceRemarkCode2() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getInpRemittanceRemarkCode2(),
ohi.getInpRemittanceRemarkDesc2(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getInpRemittanceRemarkCode3() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getInpRemittanceRemarkCode3(),
ohi.getInpRemittanceRemarkDesc3(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getInpRemittanceRemarkCode4() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getInpRemittanceRemarkCode4(),
ohi.getInpRemittanceRemarkDesc4(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getInpRemittanceRemarkCode5() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getInpRemittanceRemarkCode5(),
ohi.getInpRemittanceRemarkDesc5(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getOptRemittanceRemarkCode1() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getOptRemittanceRemarkCode1(),
ohi.getOptRemittanceRemarkDesc1(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getOptRemittanceRemarkCode2() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getOptRemittanceRemarkCode2(),
ohi.getOptRemittanceRemarkDesc2(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getOptRemittanceRemarkCode3() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getOptRemittanceRemarkCode3(),
ohi.getOptRemittanceRemarkDesc3(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getOptRemittanceRemarkCode4() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getOptRemittanceRemarkCode4(),
ohi.getOptRemittanceRemarkDesc4(), null);
remittanceCodes.add(nextRemittanceCode);
}
if (ohi.getOptRemittanceRemarkCode5() != null) {
nextRemittanceCode = new RemittanceCode(ohi.getOptRemittanceRemarkCode5(),
ohi.getOptRemittanceRemarkDesc5(), null);
remittanceCodes.add(nextRemittanceCode);
}
logger.info("Exiting getRemittanceCodesForOhi() for EwvClaimOhis guid : "+ohi.getGuid());
return remittanceCodes;
}
private List<DetailServiceLineOhiOutputRow> populateDetailServiceLineOutputRows(
List<EwvServiceLines> serviceLinesList,
boolean hasMultiplePayersWithSamePayerId, Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoked populateDetailServiceLineOutputRows() ");
List<DetailServiceLineOhiOutputRow> returnList = new ArrayList<DetailServiceLineOhiOutputRow>();
// Go through the service lines.
for (EwvServiceLines nextServiceLine : serviceLinesList) {
// Go through the ohi records for this service line
List<EwvServiceLineOhis> serviceLineOhiList = getEwvServiceLineOhisList(nextServiceLine);
for (EwvServiceLineOhis serviceLineOhi : serviceLineOhiList) {
// Create an output row. (Each service line ohi will get at least one output row.)
DetailServiceLineOhiOutputRow newOutputRow = new DetailServiceLineOhiOutputRow();
// Put the service-line-level info into the output row
newOutputRow.setLineNumber(EwvUtils.formatAsInteger(nextServiceLine.getLineNumber()));
newOutputRow.setProcedureCode(nextServiceLine.getProcedureCode());
newOutputRow.setLineCharge(EwvUtils.formatAsCurrency(nextServiceLine.getCharge()));
newOutputRow.setBeginDateOfService(EwvUtils.formatAsDate(nextServiceLine.getBeginDateOfService()));
// Put the ohi-level info into the output row
newOutputRow.setAdjudicationDate(EwvUtils.formatAsDate(serviceLineOhi.getOhiAdjudicatedDate()));
newOutputRow.setBundledUnbundledLineNumber(
EwvUtils.formatAsInteger(serviceLineOhi.getBundledUnbundledLineNumber()));
newOutputRow.setRevenueCode(serviceLineOhi.getRevenueCode());
newOutputRow.setModifiers(EwvUtils.combineModifiers(", ", serviceLineOhi.getModifier1(),
serviceLineOhi.getModifier2(), serviceLineOhi.getModifier3(), serviceLineOhi.getModifier4()));
newOutputRow.setPayerPaidAmount(EwvUtils.formatAsCurrency(serviceLineOhi.getOhiPaid()));
// The payerId used to need special attention
String payerId = determinePayerId(serviceLineOhi);
newOutputRow.setPayerId(payerId);
// The payment sequence indicator still needs special attention
String paymentSequenceIndicator = "?";
if (payerId != null && !hasMultiplePayersWithSamePayerId) {
paymentSequenceIndicator = determinePaymentSequenceIndicator(payerId, claimOhiSet);
}
newOutputRow.setPaymentSequenceIndicator(paymentSequenceIndicator);
newOutputRow.setQuantity(serviceLineOhi.getQuantity());
// Get the adjustments for this ohi
List<EwvServiceLineOhiAdjtmts> adjustmentsList = getEwvServiceLineOhiAdjtmtsList(serviceLineOhi);
// Put the info from the first adjustment into the output row
if (adjustmentsList.size() > 0) {
EwvServiceLineOhiAdjtmts firstAdjustmentDb = adjustmentsList.get(0);
ServiceLineOhiAdjustment firstAdjustment = createServiceLineOhiAdjustment(firstAdjustmentDb);
newOutputRow.setAdjustment(firstAdjustment);
}
// Finish with this output row
returnList.add(newOutputRow);
// Loop through any remaining adjustments, putting together more
// output rows
// Keep adding output rows until there are no more adjustments
// of either type
int adjustmentListSize = adjustmentsList.size();
for (int rowCounter = 1; rowCounter < adjustmentListSize; rowCounter++) {
// Create an output row.
DetailServiceLineOhiOutputRow nextOutputRow = new DetailServiceLineOhiOutputRow();
// Put the adjustment info into the output row
if (adjustmentListSize >= rowCounter + 1) {
EwvServiceLineOhiAdjtmts nextAdjustmentDb = adjustmentsList.get(rowCounter);
ServiceLineOhiAdjustment nextAdjustment = createServiceLineOhiAdjustment(nextAdjustmentDb);
nextOutputRow.setAdjustment(nextAdjustment);
}
// Finish with this output row
returnList.add(nextOutputRow);
}
}
}
logger.info("Exiting populateDetailServiceLineOutputRows() ");
return returnList;
}
private List<QuickViewServiceLineOhiOutputRow> populateQuickviewServiceLineOhiOutputRows(
List<EwvServiceLines> ewvServiceLinesList, String seqP_PayerId, String seqS_PayerId,
String seqT_PayerId) {
logger.info("Invoked populateQuickviewServiceLineOhiOutputRows() ");
// Return value
List<QuickViewServiceLineOhiOutputRow> returnList = new ArrayList<QuickViewServiceLineOhiOutputRow>();
// Local variables - service line level
QuickViewServiceLineOhiOutputRow newOutputRow = null;
// Local variables - service line adjudication level
List<EwvServiceLineOhis> seqP_ServiceLineOhiList = null;
List<EwvServiceLineOhis> seqS_ServiceLineOhiList = null;
List<EwvServiceLineOhis> seqT_ServiceLineOhiList = null;
EwvServiceLineOhis seqP_thisRowAdjudication = null;
EwvServiceLineOhis seqS_thisRowAdjudication = null;
EwvServiceLineOhis seqT_thisRowAdjudication = null;
// Local variables - service line adjudication adjustment level
List<EwvServiceLineOhiAdjtmts> seqP_adjustments = null;
List<EwvServiceLineOhiAdjtmts> seqS_adjustments = null;
List<EwvServiceLineOhiAdjtmts> seqT_adjustments = null;
EwvServiceLineOhiAdjtmts seqP_thisRowAdjustment = null;
EwvServiceLineOhiAdjtmts seqS_thisRowAdjustment = null;
EwvServiceLineOhiAdjtmts seqT_thisRowAdjustment = null;
// Go through the service lines, putting together output rows
for (EwvServiceLines ewvServiceLines : ewvServiceLinesList) {
// Get the ohi records (actually adjudications) for this service
// line
List<EwvServiceLineOhis> ewvServiceLineOhisList = getEwvServiceLineOhisList(ewvServiceLines);
// At this point, the serviceLineOhiList is being split into three lists
// Split the adjudications into three lists, one from the primary,
// one from the secondary, and one from tertiary
// Check the payer id to determine which list to put each
// adjudication in
// In a case of payers with the same id, this method would not
// have been called
seqP_ServiceLineOhiList = new ArrayList<EwvServiceLineOhis>();
seqS_ServiceLineOhiList = new ArrayList<EwvServiceLineOhis>();
seqT_ServiceLineOhiList = new ArrayList<EwvServiceLineOhis>();
// Fix the order for highlighting purposes
// BigDecimal guid
for (EwvServiceLineOhis nextOhi : ewvServiceLineOhisList) {
// If the payer ID has not been set (during dev or testing),
// use the old
// location, in the adjustment
String nextOhiPayerId = determinePayerId(nextOhi);
if (seqP_PayerId != null && seqP_PayerId.equals(nextOhiPayerId)) {
seqP_ServiceLineOhiList.add(nextOhi);
} else if (seqS_PayerId != null && seqS_PayerId.equals(nextOhiPayerId)) {
seqS_ServiceLineOhiList.add(nextOhi);
} else if (seqT_PayerId != null && seqT_PayerId.equals(nextOhiPayerId)) {
seqT_ServiceLineOhiList.add(nextOhi);
} else {
// Looks like this is ignored. Is it right?
}
}
// Find out how many adjudication rows will be made for this service line
// One adjudication row shows a primary and/or secondary adjudication,
// as well as the first primary adjustment and/or first secondary adjustment
int seqP_OhiAdjudicationCount = seqP_ServiceLineOhiList.size();
int seqS_OhiAdjudicationCount = seqS_ServiceLineOhiList.size();
int seqT_OhiAdjudicationCount = seqT_ServiceLineOhiList.size();
int adjudicationRowCount = Math.max(seqP_OhiAdjudicationCount, seqS_OhiAdjudicationCount);
adjudicationRowCount = Math.max(adjudicationRowCount, seqT_OhiAdjudicationCount);
// logger.info("Adjudication rows: " + adjudicationRowCount);
// If there are adjudication rows, loop through them
if (adjudicationRowCount > 0) {
for (int i = 0; i < adjudicationRowCount; i++) {
// Get the current primary and secondary adjudications
if (i < seqP_ServiceLineOhiList.size()) {
seqP_thisRowAdjudication = seqP_ServiceLineOhiList.get(i);
} else {
seqP_thisRowAdjudication = null;
}
if (i < seqS_ServiceLineOhiList.size()) {
seqS_thisRowAdjudication = seqS_ServiceLineOhiList.get(i);
} else {
seqS_thisRowAdjudication = null;
}
if (i < seqT_ServiceLineOhiList.size()) {
seqT_thisRowAdjudication = seqT_ServiceLineOhiList.get(i);
} else {
seqT_thisRowAdjudication = null;
}
// Get the adjustments
seqP_adjustments = getEwvServiceLineOhiAdjtmtsList(seqP_thisRowAdjudication);
seqS_adjustments = getEwvServiceLineOhiAdjtmtsList(seqS_thisRowAdjudication);
seqT_adjustments = getEwvServiceLineOhiAdjtmtsList(seqT_thisRowAdjudication);
// Determine the maximum number of adjustments for this
// adjudication
int seqP_AdjustmentCount = seqP_adjustments.size();
int seqS_AdjustmentCount = seqS_adjustments.size();
int seqT_AdjustmentCount = seqT_adjustments.size();
int adjustmentRowCount = Math.max(Math.max(seqP_AdjustmentCount, seqS_AdjustmentCount), seqT_AdjustmentCount);
// If there are adjustment rows, loop through them
if (adjustmentRowCount > 0) {
// Loop up to the number of adjustment rows
for (int j = 0; j < adjustmentRowCount; j++) {
// Get the current primary and secondary
// adjustments
if (j < seqP_adjustments.size()) {
seqP_thisRowAdjustment = seqP_adjustments.get(j);
} else {
seqP_thisRowAdjustment = null;
}
if (j < seqS_adjustments.size()) {
seqS_thisRowAdjustment = seqS_adjustments.get(j);
} else {
seqS_thisRowAdjustment = null;
}
if (j < seqT_adjustments.size()) {
seqT_thisRowAdjustment = seqT_adjustments.get(j);
} else {
seqT_thisRowAdjustment = null;
}
// For the first adjudication and adjustment,
// include the service line stuff
EwvServiceLines serviceLineToPass = null;
if (i == 0 && j == 0) {
serviceLineToPass = ewvServiceLines;
}
// For the first adjustment, include the
// adjudication stuff
EwvServiceLineOhis seqP_AdjudicationToPass = null;
EwvServiceLineOhis seqS_AdjudicationToPass = null;
EwvServiceLineOhis seqT_AdjudicationToPass = null;
if (j == 0) {
seqP_AdjudicationToPass = seqP_thisRowAdjudication;
seqS_AdjudicationToPass = seqS_thisRowAdjudication;
seqT_AdjudicationToPass = seqT_thisRowAdjudication;
}
newOutputRow = popQuickviewServiceLineOhiOutputRow(serviceLineToPass,
seqP_AdjudicationToPass, seqS_AdjudicationToPass, seqT_AdjudicationToPass,
seqP_thisRowAdjustment, seqS_thisRowAdjustment, seqT_thisRowAdjustment);
returnList.add(newOutputRow);
// logger.info("Added an output row, size now: " +
} // end of looping through the adjustment rows
} else {
// If there are no adjustments, make a single row
// anyway
// with just the service-line and adjudication stuff
// For the first adjudication and adjustment,
// include the service line stuff
EwvServiceLines serviceLineToPass = null;
if (i == 0) {
serviceLineToPass = ewvServiceLines;
}
newOutputRow = popQuickviewServiceLineOhiOutputRow(serviceLineToPass,
seqP_thisRowAdjudication, seqS_thisRowAdjudication, seqS_thisRowAdjudication, null, null, null);
returnList.add(newOutputRow);
}
} // end of looping through the adjudication rows
}
} // End of service lines
logger.info("Exiting populateQuickviewServiceLineOhiOutputRows");
return returnList;
}
private QuickViewServiceLineOhiOutputRow popQuickviewServiceLineOhiOutputRow(EwvServiceLines inServiceLine,
EwvServiceLineOhis inSeqP_Ohi, EwvServiceLineOhis inSeqS_Ohi, EwvServiceLineOhis inSeqT_Ohi,
EwvServiceLineOhiAdjtmts inSeqP_Adjustment, EwvServiceLineOhiAdjtmts inSeqS_Adjustment,
EwvServiceLineOhiAdjtmts inSeqT_Adjustment) {
logger.info("Invoking popQuickviewServiceLineOhiOutputRow()");
QuickViewServiceLineOhiOutputRow outputRow = new QuickViewServiceLineOhiOutputRow();
// Service-line-level fields
if (inServiceLine != null) {
outputRow.setLineNumber(EwvUtils.formatAsInteger(inServiceLine.getLineNumber()));
outputRow.setBeginDateOfService(EwvUtils.formatAsDate(inServiceLine.getBeginDateOfService()));
outputRow.setCharge(EwvUtils.formatAsCurrency(inServiceLine.getCharge()));
}
// Primary Service-line-ohi-level fields
if (inSeqP_Ohi != null) {
outputRow.setPrimaryPayerPaidAmount(EwvUtils.formatAsCurrency(inSeqP_Ohi.getOhiPaid()));
outputRow.setPrimaryPayerProcedureCode(inSeqP_Ohi.getProcedureCode());
outputRow.setOhiModifiers(EwvUtils.combineModifiers(", ", inSeqP_Ohi.getModifier1(),
inSeqP_Ohi.getModifier2(), inSeqP_Ohi.getModifier3(), inSeqP_Ohi.getModifier4()));
}
// Secondary Service-line-ohi-level fields
if (inSeqS_Ohi != null) {
outputRow.setSecondaryPayerPaidAmount(EwvUtils.formatAsCurrency(inSeqS_Ohi.getOhiPaid()));
outputRow.setSecondaryPayerProcedureCode(inSeqS_Ohi.getProcedureCode());
}
// Tertiary Service-line-ohi-level fields
if (inSeqT_Ohi != null) {
outputRow.setTertiaryPayerPaidAmount(EwvUtils.formatAsCurrency(inSeqT_Ohi.getOhiPaid()));
outputRow.setTertiaryPayerProcedureCode(inSeqT_Ohi.getProcedureCode());
}
// Primary Service-line-ohi-adjustment-level fields
if (inSeqP_Adjustment != null) {
ServiceLineOhiAdjustment seqP_Adjustment = createServiceLineOhiAdjustment(inSeqP_Adjustment);
outputRow.setPrimaryServiceLineAdjustment(seqP_Adjustment);
}
// Secondary Service-line-ohi-adjustment-level fields
if (inSeqS_Adjustment != null) {
ServiceLineOhiAdjustment seqS_Adjustment = createServiceLineOhiAdjustment(inSeqS_Adjustment);
outputRow.setSecondaryServiceLineAdjustment(seqS_Adjustment);
}
// Tertiary Service-line-ohi-adjustment-level fields
if (inSeqT_Adjustment != null) {
ServiceLineOhiAdjustment seqT_Adjustment = createServiceLineOhiAdjustment(inSeqT_Adjustment);
outputRow.setTertiaryServiceLineAdjustment(seqT_Adjustment);
}
logger.info("Exiting popQuickviewServiceLineOhiOutputRow()");
return outputRow;
}
private ServiceLineOhiAdjustment createServiceLineOhiAdjustment(EwvServiceLineOhiAdjtmts adjustment) {
logger.info("Invoking createServiceLineOhiAdjustment()");
String quantity = adjustment.getQuantity();
String descriptionLong = adjustment.getDescription();
String descriptionShort = EwvUtils.shorten(descriptionLong, 15);
String reasonCode = adjustment.getSvcLineAdjustmtReasonCode();
String coAmount = adjustment.getCoAmt();
String crAmount = adjustment.getCrAmt();
String oaAmount = adjustment.getOaAmt();
String piAmount = adjustment.getPiAmt();
String prAmount = adjustment.getPrAmt();
String note = "";
if ( reasonCode != null && !(reasonCode.trim().isEmpty())) {
note = luClaimAdjustReasonCodeRepository.getNoteByReasonCode(reasonCode) ;
descriptionLong = descriptionLong + " " + note;
}
ServiceLineOhiAdjustment ret = new ServiceLineOhiAdjustment(
// payerId,
descriptionLong, descriptionShort, reasonCode, quantity, coAmount, crAmount, oaAmount, piAmount,
prAmount);
if (coAmount != null) {
ret.setAdjustmentType(AdjustmentType.CO);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_CO);
} else if (crAmount != null) {
ret.setAdjustmentType(AdjustmentType.CR);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_CR);
} else if (oaAmount != null) {
ret.setAdjustmentType(AdjustmentType.OA);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_OA);
} else if (piAmount != null) {
ret.setAdjustmentType(AdjustmentType.PI);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_PI);
} else if (prAmount != null) {
ret.setAdjustmentType(AdjustmentType.PR);
ret.setAdjCodeGroupDescription(DTOBase.ADJ_CODE_GROUP_PR);
}
logger.info("Exiting createServiceLineOhiAdjustment()");
return ret;
}
private EwvServiceLineOhis determineServiceLineOhiForPayer(Set<EwvServiceLineOhis> serviceLineOhiSet,
String payerId) {
logger.info("Invoking determineServiceLineOhiForPayer()");
EwvServiceLineOhis returnOhi = null;
// Loop through the service line ohis, looking for one that "matches"
// the payer id
for (EwvServiceLineOhis nextOhi : serviceLineOhiSet) {
// First, look in the payer_id column of service line ohis
if (payerId != null && payerId.equals(nextOhi.getPayerId())) {
returnOhi = nextOhi;
}
// If nothing is there, check the adjustments' seqP_payer_id
// field. This is
// deprecated for new data, but older data might still have it
// there.
else {
// Set<EwvServiceLineOhiAdjtmts> adjustments =
// ewvServiceLineOhiAdjtmtRepository.getEwvServiceLineOhiAdjtmts(nextOhi.getGuid());
Set<EwvServiceLineOhiAdjtmts> adjustments = nextOhi.getEwvServiceLineOhiAdjtmtses();
if (adjustments != null && adjustments.size() > 0) {
String payerIdFromAdjustments = null;
for (EwvServiceLineOhiAdjtmts nextAdjustment : adjustments) {
String nextPayerId = nextAdjustment.getPrimaryPayerId();
if (nextPayerId != null && !nextPayerId.isEmpty()) {
payerIdFromAdjustments = nextPayerId;
}
}
if (payerIdFromAdjustments != null && !payerIdFromAdjustments.isEmpty()) {
if (payerIdFromAdjustments.equals(payerId)) {
returnOhi = nextOhi;
}
}
}
}
}
logger.info("Exiting determineServiceLineOhiForPayer()");
return returnOhi;
}
public boolean getHasMultiplePayersWithSamePayerId(Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoking getHasMultiplePayersWithSamePayerId()");
boolean returnValue = false;
// Loop through them, getting out their payer id values
List<String> payerIdList = new ArrayList<String>();
for (EwvClaimOhis claimOhi : claimOhiSet) {
payerIdList.add(claimOhi.getOhiPayerId());
}
// Find out whether there are duplicates ?? Can you get duplicates from a Set<>?
returnValue = EwvUtils.hasNonNullDuplicates(payerIdList);
logger.info("Exiting getHasMultiplePayersWithSamePayerId()");
return returnValue;
}
public boolean getHasMultipleSeqP_Payers(Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoking getHasMultipleSeqP_Payers()");
// Get the EWV_Claim_Ohi records
// Count how many of them are marked as Primary
int seqP_OhiCounter = 0;
for (EwvClaimOhis claimOhi : claimOhiSet) {
if (claimOhi.getPaymentSequenceIndicator().equals("P")) {
seqP_OhiCounter += 1; // ?? you could stop now
}
}
logger.info("Exiting getHasMultipleSeqP_Payers()");
return (seqP_OhiCounter > 1);
}
public boolean getHasMultipleSeqS_Payers(Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoking getHasMultipleSeqS_Payers()");
// Get the EWV_Claim_Ohi records
// Count how many of them are marked as Secondary
int seqS_OhiCounter = 0;
for (EwvClaimOhis claimOhi : claimOhiSet) {
if (claimOhi.getPaymentSequenceIndicator().equals("S")) {
seqS_OhiCounter += 1; // ?? you could stop now
}
}
logger.info("Exiting getHasMultipleSeqS_Payers()");
return (seqS_OhiCounter > 1);
}
public boolean getHasMultipleSeqT_Payers(Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoking getHasMultipleSeqT_Payers()");
// Get the EWV_Claim_Ohi records
// Count how many of them are marked as Tertiary
int seqT_OhiCounter = 0;
for (EwvClaimOhis claimOhi : claimOhiSet) {
if (claimOhi.getPaymentSequenceIndicator().equals("T")) {
seqT_OhiCounter += 1; // ?? you could stop now
}
}
logger.info("Exiting getHasMultipleSeqT_Payers()");
return (seqT_OhiCounter > 1);
}
public boolean getHasMultipleAdjudicationsFromSamePayer(Set<EwvServiceLines> serviceLineSet) {
logger.info("Invoking getHasMultipleAdjudicationsFromSamePayer()");
boolean returnValue = false;
List<String> adjudicationList;
// Loop through the service lines
for (EwvServiceLines serviceLine : serviceLineSet) {
// For each service line, put together a list of its adjudications
Set<EwvServiceLineOhis> serviceLineOhiSet = serviceLine.getEwvServiceLineOhises();
adjudicationList = new ArrayList<String>();
for (EwvServiceLineOhis serviceLineOhi : serviceLineOhiSet) {
adjudicationList.add(serviceLineOhi.getPayerId());
}
// Find out whether there are duplicates
boolean dupsExist = EwvUtils.hasNonNullDuplicates(adjudicationList);
if (dupsExist) {
returnValue = true;
}
}
logger.info("Exiting getHasMultipleAdjudicationsFromSamePayer()");
return returnValue;
}
private String determinePaymentSequenceIndicator(String payerId, Set<EwvClaimOhis> claimOhiSet) {
logger.info("Invoking determinePaymentSequenceIndicator()");
// If no matches are found, display hyphens
// This should never happen, though.
String returnVal = "---";
// Go through the claimOhiSet, looking for a match
// We can assume no more than one match, because that scenario is
// checked earlier,
// and this procedure is not called if there are multiple payers with
// the same payer id
// (Instead, a ? appears)
for (EwvClaimOhis nextClaimOhi : claimOhiSet) {
if (payerId.equals(nextClaimOhi.getOhiPayerId())) {
returnVal = nextClaimOhi.getPaymentSequenceIndicator();
break;
}
}
logger.info("Exiting determinePaymentSequenceIndicator()");
return returnVal;
}
private String determinePayerId(EwvServiceLineOhis inOhi) {
logger.info("Invoking determinePayerId() for EwvServiceLineOhis guid :"+inOhi.getGuid());
String returnValue = null;
// First, use the new location, on the service line ohi, where it should
// be
returnValue = inOhi.getPayerId();
if (returnValue != null) {
return returnValue;
}
// If that does not work, look through its adjustments.
// The Phase I code actually took the last adjustment's value, so we
// finish the loop here
Set<EwvServiceLineOhiAdjtmts> serviceLineOhiAdjustments = inOhi.getEwvServiceLineOhiAdjtmtses();
for (EwvServiceLineOhiAdjtmts nextAdjustment : serviceLineOhiAdjustments) {
if (nextAdjustment.getPrimaryPayerId() != null) {
returnValue = nextAdjustment.getPrimaryPayerId();
}
}
if (returnValue != null) {
return returnValue;
}
EwvServiceLines serviceLine = inOhi.getEwvServiceLines();
Set<EwvServiceLineOhis> allOhis = serviceLine.getEwvServiceLineOhises();
for (EwvServiceLineOhis nextOhi : allOhis) {
Set<EwvServiceLineOhiAdjtmts> allAdjustmentsThisOhi = nextOhi.getEwvServiceLineOhiAdjtmtses();
for (EwvServiceLineOhiAdjtmts nextAdjustment : allAdjustmentsThisOhi) {
if (nextAdjustment.getPrimaryPayerId() != null) {
returnValue = nextAdjustment.getPrimaryPayerId();
}
}
}
if (returnValue != null) {
return returnValue;
}
// If that still does not work, try the other service lines
EwvClaims claim = serviceLine.getEwvClaims();
Set<EwvServiceLines> allServiceLines = claim.getEwvServiceLineses();
for (EwvServiceLines nextServiceLine : allServiceLines) {
Set<EwvServiceLineOhis> thisServiceLineOhis = nextServiceLine.getEwvServiceLineOhises();
for (EwvServiceLineOhis nextOhi : thisServiceLineOhis) {
Set<EwvServiceLineOhiAdjtmts> allAdjustmentsThisOhi = nextOhi.getEwvServiceLineOhiAdjtmtses();
for (EwvServiceLineOhiAdjtmts nextAdjustment : allAdjustmentsThisOhi) {
if (nextAdjustment.getPrimaryPayerId() != null) {
returnValue = nextAdjustment.getPrimaryPayerId();
}
}
}
}
logger.info("Exiting determinePayerId() for EwvServiceLineOhis guid :"+inOhi.getGuid());
return returnValue;
}
}