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 static gov.va.med.ewv.util.EwvSetToNullsLastList.*; // non-generic implementation
// generic implementation
import static gov.va.med.ewv.util.EwvNullsLastSortedList.getEwvAmbulanceInfo5010List;
import static gov.va.med.ewv.util.EwvNullsLastSortedList.getEwvServiceLineOhisList;
import static gov.va.med.ewv.util.EwvNullsLastSortedList.getEwvServiceLinesList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import gov.va.med.domain.ewv.EwvAmbulanceInfo5010;
import gov.va.med.domain.ewv.EwvClaims;
import gov.va.med.domain.ewv.EwvServiceLineOhis;
import gov.va.med.domain.ewv.EwvServiceLines;
import gov.va.med.domain.ewv.EwvSlProvider;
import gov.va.med.domain.ewv.EwvSvcLineDme;
import gov.va.med.ewv.exceptions.NonUniqueRecordsException;
import gov.va.med.ewv.model.response.AmbulanceCert;
import gov.va.med.ewv.model.response.AmbulanceInfo;
import gov.va.med.ewv.model.response.DrugLine;
import gov.va.med.ewv.model.response.MedicalEquipmentLine;
import gov.va.med.ewv.model.response.Provider;
import gov.va.med.ewv.model.response.ServiceLineOhiAdjustment;
import gov.va.med.ewv.model.response.ToothLine;
import gov.va.med.ewv.service.IEwvAmbulanceAndServiceLinesInfoService;
import gov.va.med.ewv.util.ClaimType;
import gov.va.med.ewv.util.DTOBase;
import gov.va.med.ewv.util.EwvUtils;
import gov.va.med.ewv.util.OhiType;
import gov.va.med.ewv.util.ServiceLine;
@Service
public class EwvAmbulanceAndServiceLinesInfoServiceImpl extends DTOBase
implements IEwvAmbulanceAndServiceLinesInfoService {
private static final Logger logger = LogManager.getLogger(EwvAmbulanceAndServiceLinesInfoServiceImpl.class);
@Override
public List<ServiceLine> populateServiceLines(EwvClaims claim) throws NonUniqueRecordsException {
logger.info("Invoked populateServiceLines() for guid : " + claim.getGuid());
List<EwvServiceLines> ewvServiceLinesList = getEwvServiceLinesList(claim); // in order
// Implementation with stream
// List<ServiceLine> listOfServiceLines = ewvServiceLinesList.stream()
// .map((line) -> {
// ServiceLine bean = null;
// try { bean = populateServiceLine(line, claim);}
// catch(NonUniqueRecordsException ex) {
// ex.printStackTrace();}; return bean;
// })
// .filter((bean) -> bean != null) // filter out nulls (from exceptions)
// .collect(Collectors.toList())
// ;
// Implementation with for loop
// Collect populateServiceLine(line, claim);
List<ServiceLine> listOfServiceLines = new ArrayList<>();
// Awkwardly, EwvServiceLines refers to a single service line
for (EwvServiceLines ewvServiceLine : ewvServiceLinesList) {
// but what happens if there is an exception here:
ServiceLine bean = populateServiceLine(ewvServiceLine, claim);
listOfServiceLines.add(bean);
}
// I think that having serviceLineList in order is sufficient produce listOfServiceLines in the desired order.
// If it is not, we could sort listOfServiceLines after it is made.
// Collections.sort(listOfServiceLines, EwvVs::vs); // Don't use natural order, use the one we define
logger.info("Exiting populateServiceLines() for guid : "+claim.getGuid());
return listOfServiceLines;
}
public String getQuantityOrType(EwvServiceLines line) {
return EwvUtils.defaultToSpace(line.getQuantity()) + " " + EwvUtils.defaultToSpace(line.getType());
}
@Override
public ServiceLine populateServiceLine(EwvServiceLines line, EwvClaims claim) throws NonUniqueRecordsException {
logger.info("Invoked populateServiceLine() for guid : " + claim.getGuid());
String dateOfService = null;
String beginDateOfService = null;
String endDateOfService = null;
String operatorPhysicianNpi = null;
String operatorPhysicianName = null;
String revCode = line.getRevenueCode();
String procedureCode = line.getProcedureCode();
String ndcCode = line.getNdc();
String modifiers = EwvUtils.combineModifiers(", ", line.getModifier1(), line.getModifier2(),
line.getModifier3(), line.getModifier4());
String quantityOrType = getQuantityOrType(line);
// Added quantity and type for phase II
String quantity = line.getQuantity();
String type = line.getType();
String serviceTax = line.getServiceTax();
String facilityTax = line.getFacilityTax();
String charge = line.getCharge();
String lineNumber = String.valueOf(line.getLineNumber());
List<DrugLine> listOfDrugs = null;
List<ToothLine> listOfTeeth = null;
List<MedicalEquipmentLine> listOfEquipment = null;
List<Provider> listOfProviderInfo = null;
String dxDtPointers = EwvUtils.combineModifiers(", ", line.getDx1(), line.getDx2(), line.getDx3(),
line.getDx4());
String salesTax = line.getSalesTax();
String pos = line.getPos();
for(EwvSlProvider ewvSlProvider : line.getEwvSlProviders()) {
if("OPERATING PHYSICIAN".equalsIgnoreCase(ewvSlProvider.getProviderType())) {
operatorPhysicianNpi = ewvSlProvider.getProviderNpi5010();
operatorPhysicianName = ewvSlProvider.getProviderFname()+" "+(StringUtils.isNotBlank(ewvSlProvider.getProviderMname()) ? ewvSlProvider.getProviderMname()+" ":"")+ewvSlProvider.getProviderLname();
break;
}
}
// Begin and End, new for Phase II, do not depend on claim type
beginDateOfService = line.getBeginDateOfService();
endDateOfService = line.getEndDateOfService();
// 5010 Stuff
AmbulanceInfo serviceLineLevelAmbulanceInfo = populateServiceLineLevelAmbulanceInfo(line);
ClaimType claimType = ClaimType.typeOf(claim.getClaimType());
if (claimType.equals(ClaimType.INSTITUTIONAL)) {
dateOfService = EwvUtils.formatDateRangeEWV2(line.getBeginDateOfService(), line.getEndDateOfService(),
" - ", true);
// drugs occur in prof lines or inst
listOfDrugs = createDrugLines(line.getEwvServiceLinesDrugses());//ewvServiceLinesDrugsRepository.getEwvServiceLinesDrugs(line.getGuid()));
listOfProviderInfo = createProviders(line.getEwvSlProviders());//ewvSlProviderRepository.getEwvSlProviders(line.getGuid()));
} else if (claimType.equals(ClaimType.PROFESSIONAL)) {
dateOfService = EwvUtils.formatDateRangeEWV2(line.getBeginDateOfService(), line.getEndDateOfService(),
" - ", true);
// drugs occur in prof lines or inst
listOfDrugs = createDrugLines(line.getEwvServiceLinesDrugses());//ewvServiceLinesDrugsRepository.getEwvServiceLinesDrugs(line.getGuid()));
// medical equipment occurs only on professional svc lines
listOfEquipment = createMedicalEquipmentLines(line.getEwvSvcLineDmes());//ewvSvcLineDmeRepository.getEwvSvcLineDme(line.getGuid()));
listOfProviderInfo = createProviders(line.getEwvSlProviders());//ewvSlProviderRepository.getEwvSlProviders(line.getGuid()));
} else if (claimType.equals(ClaimType.DENTAL)) {
// dental is it's own
dateOfService = line.getBeginDateOfService();
listOfTeeth = createToothLines(line.getEwvSvcLineTeeths());//ewvSvcLineTeethRepository.getEwvSvcLineTeeth(line.getGuid()));
listOfProviderInfo = createProviders(line.getEwvSlProviders());//ewvSlProviderRepository.getEwvSlProviders(line.getGuid()));
}
// Put together service line Ohi stuff
String primaryPayerPaidAmount = null;
List<ServiceLineOhiAdjustment> primaryOhiServiceLineAdjustments = null;
String secondaryPayerPaidAmount = null;
List<ServiceLineOhiAdjustment> secondaryOhiServiceLineAdjustments = null;
// Go through the ohis for this service line
List<EwvServiceLineOhis> serviceLineOhiList = getEwvServiceLineOhisList(line);
for (EwvServiceLineOhis lineOhi : serviceLineOhiList) {
// Is this a primary, secondary, or tertiary OHI?
OhiType ohiType = determineOhiType(lineOhi, claim);
// Check for primary
if (ohiType.equals(OhiType.PRIMARY)) {
primaryPayerPaidAmount = lineOhi.getOhiPaid();
primaryOhiServiceLineAdjustments = populateServiceLineAdjustments(lineOhi.getEwvServiceLineOhiAdjtmtses());
//ewvServiceLineOhiAdjtmtRepository.getEwvServiceLineOhiAdjtmts(lineOhi.getGuid()));
}
// Check for secondary
else if (ohiType.equals(OhiType.SECONDARY)) {
secondaryPayerPaidAmount = lineOhi.getOhiPaid();
secondaryOhiServiceLineAdjustments = populateServiceLineAdjustments(lineOhi.getEwvServiceLineOhiAdjtmtses());
//ewvServiceLineOhiAdjtmtRepository.getEwvServiceLineOhiAdjtmts(lineOhi.getGuid()));
}
// TBD ?? What about tertiary?
}
ServiceLine newServiceLine = new ServiceLine(dateOfService, beginDateOfService, endDateOfService, revCode,
procedureCode, ndcCode, modifiers, quantityOrType, quantity, type, primaryPayerPaidAmount,
primaryOhiServiceLineAdjustments, secondaryPayerPaidAmount, secondaryOhiServiceLineAdjustments,
serviceTax, facilityTax, charge, lineNumber, listOfDrugs, listOfTeeth, listOfEquipment, dxDtPointers,
salesTax, operatorPhysicianNpi, operatorPhysicianName, listOfProviderInfo, pos, serviceLineLevelAmbulanceInfo);
logger.info("Exiting populateServiceLine() for guid : "+ claim.getGuid());
return newServiceLine;
}
@Override
public AmbulanceInfo populateServiceLineLevelAmbulanceInfo(EwvServiceLines serviceLineBean)
throws NonUniqueRecordsException {
logger.info("Invoked populateServiceLineLevelAmbulanceInfo() for service line guid : "+ serviceLineBean.getGuid());
AmbulanceInfo returnInfo = null;
// Get the ambulance info from the service line
List<EwvAmbulanceInfo5010> ambulanceInfoList = getEwvAmbulanceInfo5010List(serviceLineBean);
//ewvAmbulanceInfo5010Repository.getEwvAmbulanceInfo5010s(serviceLineBean.getGuid());
// There will be no more than one entry in the set
int ambulanceLineCounter = 0;
for (EwvAmbulanceInfo5010 ambulanceInfo : ambulanceInfoList) {
ambulanceLineCounter++;
if (ambulanceLineCounter > 1) {
throw new NonUniqueRecordsException("Too many service-line-level ambulance lines");
}
returnInfo = new AmbulanceInfo();
// Pickup Address
returnInfo.setPickupAddressLine1(ambulanceInfo.getPickupAddressLine1());
returnInfo.setPickupAddressLine2(ambulanceInfo.getPickupAddressLine2());
returnInfo.setPickupCity(ambulanceInfo.getPickupCity());
returnInfo.setPickupState(ambulanceInfo.getPickupState());
returnInfo.setPickupZip(ambulanceInfo.getPickupZip());
// Dropoff Address
returnInfo.setDropoffAddressLine1(ambulanceInfo.getDropoffAddressLine1());
returnInfo.setDropoffAddressLine2(ambulanceInfo.getDropoffAddressLine2());
returnInfo.setDropoffCity(ambulanceInfo.getDropoffCity());
returnInfo.setDropoffState(ambulanceInfo.getDropoffState());
returnInfo.setDropoffZip(ambulanceInfo.getDropoffZip());
// Transport Fields
returnInfo.setTransportReasonCode(ambulanceInfo.getTransportReasonCode());
returnInfo.setTransportDistance(EwvUtils.formatAsInteger(ambulanceInfo.getTransportDistance()));
returnInfo.setRoundTripPurpose(ambulanceInfo.getRoundTripPurpose());
returnInfo.setRoundTripPurposeShort(EwvUtils.shorten(returnInfo.getRoundTripPurpose(), 50));
returnInfo.setUseRoundTripPurposeModalPanel(returnInfo.getRoundTripPurposeShort().endsWith("..."));
returnInfo.setStretcherPurpose(ambulanceInfo.getStretcherPurpose());
returnInfo.setStretcherPurposeShort(EwvUtils.shorten(returnInfo.getStretcherPurpose(), 50));
returnInfo.setUseStretcherPurposeModalPanel(returnInfo.getStretcherPurposeShort().endsWith("..."));
// // Transport Fields
// returnInfo.setTransportReasonCode(ambulanceInfo.getTransportReasonCode());
// returnInfo.setRoundTripPurpose(ambulanceInfo.getRoundTripPurpose());
// returnInfo.setTransportDistance(ambulanceInfo.getTransportDistance());
// returnInfo.setStretcherPurpose(ambulanceInfo.getStretcherPurpose());
//
// Three possible Certs are slammed together into a single database
// row
List<AmbulanceCert> certs = new ArrayList<AmbulanceCert>();
// Cert #1
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator1(), ambulanceInfo.getCertIndicator1(),
ambulanceInfo.getConditionCode12(), ambulanceInfo.getConditionCode13(),
ambulanceInfo.getConditionCode14(), ambulanceInfo.getConditionCode15());
// Cert #2
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator2(), ambulanceInfo.getConditionCode21(),
ambulanceInfo.getConditionCode22(), ambulanceInfo.getConditionCode23(),
ambulanceInfo.getConditionCode24(), ambulanceInfo.getConditionCode25());
// Cert #2
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator3(), ambulanceInfo.getConditionCode31(),
ambulanceInfo.getConditionCode32(), ambulanceInfo.getConditionCode33(),
ambulanceInfo.getConditionCode34(), ambulanceInfo.getConditionCode35());
// Attach the certs to the ambulance info, if there are any certs
if (certs.size() > 0) {
returnInfo.setCerts(certs);
}
}
logger.info("Exiting populateServiceLineLevelAmbulanceInfo() for service line guid : "+ serviceLineBean.getGuid());
return returnInfo;
}
@Override
public List<MedicalEquipmentLine> createMedicalEquipmentLines(Set<EwvSvcLineDme> list) {
logger.info("Invoked createMedicalEquipmentLines() for EwvSvcLineDme list");
List<MedicalEquipmentLine> equips = new ArrayList<MedicalEquipmentLine>();
for (EwvSvcLineDme dme : list) {
String lengthOfMedicalNecessity = dme.getDmeLengthMedicalNecessity();
String frequency = dme.getDmeFrequency();
String rentalAmt = dme.getDmeRentalAmt();
String purchaseAmt = dme.getDmePurchaseAmt();
equips.add(new MedicalEquipmentLine(lengthOfMedicalNecessity, frequency, rentalAmt, purchaseAmt));
}
logger.info("Exiting createMedicalEquipmentLines() for EwvSvcLineDme list");
return equips;
}
@Override
public AmbulanceInfo populateClaimLevelAmbulanceInfo(EwvClaims claimBean) throws NonUniqueRecordsException {
logger.info("Invoked populateClaimLevelAmbulanceInfo() for claim guid "+ claimBean.getGuid());
AmbulanceInfo returnInfo = null;
// Get the ambulance info from the claim
Set<EwvAmbulanceInfo5010> ambulanceInfoSet = claimBean.getEwvAmbulanceInfo5010s();
//ewvAmbulanceInfo5010Repository.getEwvAmbulanceInfo5010s(claimBean.getGuid());
// There will be no more than one entry in the set
int ambulanceLineCounter = 0;
for (EwvAmbulanceInfo5010 ambulanceInfo : ambulanceInfoSet) {
ambulanceLineCounter++;
if (ambulanceLineCounter > 1) {
throw new NonUniqueRecordsException("Too many claim-level ambulance lines");
}
returnInfo = new AmbulanceInfo();
// Pickup Address
returnInfo.setPickupAddressLine1(ambulanceInfo.getPickupAddressLine1());
returnInfo.setPickupAddressLine2(ambulanceInfo.getPickupAddressLine2());
returnInfo.setPickupCity(ambulanceInfo.getPickupCity());
returnInfo.setPickupState(ambulanceInfo.getPickupState());
returnInfo.setPickupZip(ambulanceInfo.getPickupZip());
// Dropoff Address
returnInfo.setDropoffAddressLine1(ambulanceInfo.getDropoffAddressLine1());
returnInfo.setDropoffAddressLine2(ambulanceInfo.getDropoffAddressLine2());
returnInfo.setDropoffCity(ambulanceInfo.getDropoffCity());
returnInfo.setDropoffState(ambulanceInfo.getDropoffState());
returnInfo.setDropoffZip(ambulanceInfo.getDropoffZip());
// Transport Fields
returnInfo.setTransportReasonCode(ambulanceInfo.getTransportReasonCode());
returnInfo.setTransportDistance(EwvUtils.formatAsInteger(ambulanceInfo.getTransportDistance()));
returnInfo.setRoundTripPurpose(ambulanceInfo.getRoundTripPurpose());
returnInfo.setRoundTripPurposeShort(EwvUtils.shorten(returnInfo.getRoundTripPurpose(), 50));
returnInfo.setUseRoundTripPurposeModalPanel(returnInfo.getRoundTripPurposeShort().endsWith("..."));
returnInfo.setStretcherPurpose(ambulanceInfo.getStretcherPurpose());
returnInfo.setStretcherPurposeShort(EwvUtils.shorten(returnInfo.getStretcherPurpose(), 50));
returnInfo.setUseStretcherPurposeModalPanel(returnInfo.getStretcherPurposeShort().endsWith("..."));
// Three possible Certs are slammed together into a single database
// row
List<AmbulanceCert> certs = new ArrayList<AmbulanceCert>();
// Cert #1
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator1(), ambulanceInfo.getConditionCode11(),
ambulanceInfo.getConditionCode12(), ambulanceInfo.getConditionCode13(),
ambulanceInfo.getConditionCode14(), ambulanceInfo.getConditionCode15());
// Cert #2
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator2(), ambulanceInfo.getConditionCode21(),
ambulanceInfo.getConditionCode22(), ambulanceInfo.getConditionCode23(),
ambulanceInfo.getConditionCode24(), ambulanceInfo.getConditionCode25());
// Cert #2
populateAmbulanceCert(certs, ambulanceInfo.getCertIndicator3(), ambulanceInfo.getConditionCode31(),
ambulanceInfo.getConditionCode32(), ambulanceInfo.getConditionCode33(),
ambulanceInfo.getConditionCode34(), ambulanceInfo.getConditionCode35());
// Attach the certs to the ambulance info, if there are any certs
if (certs.size() > 0) {
returnInfo.setCerts(certs);
}
}
logger.info("Exiting populateClaimLevelAmbulanceInfo() for claim guid "+ claimBean.getGuid());
return returnInfo;
}
}