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.ars.service.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import gov.va.med.ars.constants.ErrorMessages;
import gov.va.med.ars.dao.ars.EntityNameRepository;
import gov.va.med.ars.dao.ars.EreposdataRepository;
import gov.va.med.ars.dao.ars.IArsReportTypeRepository;
import gov.va.med.ars.dao.ars.IClaimSubmissionRepository;
import gov.va.med.ars.dao.ars.IReferenceIdentificationRepository;
import gov.va.med.ars.dao.ars.ITraceNumberRepository;
import gov.va.med.ars.dao.ars.ITransactionsRepository;
import gov.va.med.ars.dao.erepos.IRfaiEreposRepository;
import gov.va.med.ars.dao.ewv.IEwvClaimAttachmentRepository;
import gov.va.med.ars.dao.ewv.IRfaiEwvRepository;
import gov.va.med.ars.dao.fpps.IFppsClaimAttachmentsRepository;
import gov.va.med.ars.dao.fpps.IRfaiFppsClaimRepository;
import gov.va.med.ars.exceptions.EntityNotFoundException;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.exceptions.ValidationException;
import gov.va.med.ars.model.ClaimAttachmentsInformation;
import gov.va.med.ars.model.Trn02AndMedRecNum;
import gov.va.med.ars.model.request.Unmatched837Request;
import gov.va.med.ars.service.IUnmatched837AttachmentService;
import gov.va.med.domain.ars.ClaimSubmission;
import gov.va.med.domain.ars.TraceNumber;
import gov.va.med.domain.ars.Transactions;
import gov.va.med.domain.ereposModel.ClaimSuplInfo;
import gov.va.med.domain.ewv.EwvClaims;
import gov.va.med.domain.ewv.EwvClaimsAttachment;
import gov.va.med.domain.ewv.EwvClaimsAttachmentId;
import gov.va.med.domain.fee.Claim;
import gov.va.med.domain.fee.ClaimAttachments;
import gov.va.med.domain.fee.ClaimAttachmentsId;

@Service
public class Unmatched837AttachmentServiceImpl implements IUnmatched837AttachmentService {

private static final Logger logger = LogManager.getLogger(Unmatched837AttachmentServiceImpl.class);
private DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

@Autowired
IRfaiEwvRepository ewvClaimRepository;

@Autowired
IEwvClaimAttachmentRepository ewvClaimAttachmentRepository;

@Autowired
IRfaiFppsClaimRepository fppsClaimRepository;

@Autowired
IFppsClaimAttachmentsRepository fppsClaimAttachmentsRepository;

@Autowired
IRfaiEreposRepository ereposClaimRepository;

@Autowired
ITraceNumberRepository arsTraceNumberRepository;

@Autowired
IArsReportTypeRepository arsReportTypeRepository;

@Autowired
ITransactionsRepository arsTransactionsRepository;

@Autowired
EreposdataRepository arsEreposDataRepository;

@Autowired
IReferenceIdentificationRepository arsRefIdRepository;

@Autowired
IClaimSubmissionRepository arsClaimSubmissionRepository;

@Autowired
EntityNameRepository arsEntityNameRepository;

private ClaimAttachmentsInformation result = null;

private static final String DATA_ACCESS_ERROR = "data_access_error";

@Override
public Boolean matchClaimAttachment(Unmatched837Request request)
throws ValidationException, GenericException, EntityNotFoundException {
Boolean matchedAttachmentWithClaimId = false;

String claimIdToMatch = request.getUnmatched837Id();
String attachmentIdToMatch = request.getAttachIdLx().split("\\.", 2)[0];
String attachIdLxToMatch = request.getAttachIdLx();
EwvClaims ewvClaim = null;
Claim fppsClaim = null;
ClaimAttachmentsInformation claimAttachInfo = null;
Date patientDob = null;
String vaFacilityCd = "";
try {
if (claimIdToMatch.length() <= 15) {

if (claimIdToMatch.length() == 15 && isPdiValid(claimIdToMatch)) {

logger.debug("User entered EWV PDI " + claimIdToMatch + " and it meets validation");

logger.debug("===== ewvRepository.findByPdi(claimIdToMatch); START =====");
ewvClaim = ewvClaimRepository.findByPdi(claimIdToMatch);
logger.debug("===== ewvRepository.findByPdi(claimIdToMatch); END =====");

if (ewvClaim != null && !ewvClaim.getEdiClaimKey().isEmpty()) {

String claimKeyFromEwv = ewvClaim.getEdiClaimKey().trim();
logger.debug("Claim Key from EWV is: " + claimKeyFromEwv);

claimAttachInfo = getClaimAttachInfoFromEreposAndArs(attachmentIdToMatch, claimKeyFromEwv,
request.getAttachIdLx(), request.getUnmatched837Id());
String receiverId = claimAttachInfo.getReceiverId();
logger.debug("receiverId is: " + receiverId);

if ((receiverId.contains("84146") || receiverId.contains("84147"))) {
logger.debug("Inserting to EWV.EWV_CLAIMS_ATTACHMENT");
saveToEwvClaimAttachments(attachIdLxToMatch, claimKeyFromEwv, claimAttachInfo);

logger.debug("Updating ARS.TRANSACTIONS with PatientDOB and VA Facility Code");
patientDob = parsePatientDobToDate(ewvClaim.getPatientDob());
vaFacilityCd = "XXX";
updateArsTransactionsTable(request, claimKeyFromEwv, claimAttachInfo, patientDob,
vaFacilityCd);
matchedAttachmentWithClaimId = true;
return matchedAttachmentWithClaimId;
} else {
logger.info("claimAttachment or receiverId was null, or receiverId did contain 84146/7");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Entered PDI does not have information required for matching",
HttpStatus.NOT_FOUND);
}
} else {
logger.info("ewvClaim was null");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Entered PDI does not have information required for matching", HttpStatus.NOT_FOUND);
}
} else if (claimIdToMatch.length() == 15 && !isPdiValid(claimIdToMatch)) {
logger.info("User entered EWV PDI " + claimIdToMatch + " and it does NOT meet validation");
throw new GenericException(ErrorMessages.NOT_FOUND, "PDI entered does not meet validation",
HttpStatus.NOT_FOUND);
} else {

// FPPS
logger.debug("ClaimId is less than 15 digits, FPPS Claim Index is " + claimIdToMatch);

logger.debug("===== fppsRepository.findOne START =====");
fppsClaim = fppsClaimRepository
.getClaimWithVaFacilityAndPersonInfo(BigInteger.valueOf(Long.parseLong(claimIdToMatch)));
logger.debug("===== fppsRepository.findOne END =====");

if (fppsClaim != null && !fppsClaim.getEdiClaimKey().isEmpty()) {

String claimKeyFromFpps = fppsClaim.getEdiClaimKey().trim();
logger.debug("Claim Key from FPPS is: " + claimKeyFromFpps);

claimAttachInfo = getClaimAttachInfoFromEreposAndArs(attachmentIdToMatch, claimKeyFromFpps,
request.getAttachIdLx(), request.getUnmatched837Id());
String receiverId = claimAttachInfo.getReceiverId();
logger.debug("receiverId is: " + receiverId);

if ((receiverId.contains("12115") || receiverId.contains("12116"))) {
logger.debug("Saving to FPPS.CLAIM_ATTACHMENT and updating ARS.TRANSACTIONS");
saveToFppsClaimAttachments(attachIdLxToMatch, claimKeyFromFpps, claimAttachInfo);

if (!fppsClaim.getPersonInfos().isEmpty()) {
patientDob = fppsClaim.getPersonInfos().iterator().next().getBirthDate();
}
vaFacilityCd = fppsClaim.getVaFacility().getVaFacilityCd();
updateArsTransactionsTable(request, claimKeyFromFpps, claimAttachInfo, patientDob,
vaFacilityCd);
matchedAttachmentWithClaimId = true;
return matchedAttachmentWithClaimId;
} else {
logger.info("claimAttachment or receiverId was null, or receiverId did contain 12115/6");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Entered Claim Index does not have information required for matching",
HttpStatus.NOT_FOUND);
}

} else {
logger.info("fppsClaim was null");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Entered Claim Index does not have information required for matching",
HttpStatus.NOT_FOUND);
}
}
} else {
logger.info("claimId in request exceeds 15 digits");
throw new GenericException(ErrorMessages.NOT_FOUND, "Entered PDI/Claim Index exceeds 15 digits",
HttpStatus.NOT_FOUND);
}
} catch (DataAccessException ex) {
logger.info("Cannot connect to the database!");
throw new GenericException(ErrorMessages.DATA_ACCESS_ERROR,
"Cannot connect to the database. Please contact the administrator for details.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
logger.info("Exception occurred at Unmatched837AttachmentServiceImpl.matchAttachment()" + e.getMessage());
logger.info("exception class " + e.getClass() + "and cause " + e.getCause());
throw e;
}

}

void updateArsTransactionsTable(Unmatched837Request request, String claimKey,
ClaimAttachmentsInformation claimAttachmentInfo, Date patientDob, String vaFacilityCd)
throws GenericException {
logger.debug("updateArsTransactionsTable()");

try {

logger.debug("===== transactionsRepository.findByattachmentIdLx START =====");
Transactions transaction = arsTransactionsRepository.findByattachmentIdLx(request.getAttachIdLx());
logger.debug("===== transactionsRepository.findByattachmentIdLx END =====");

if (transaction != null) {
transaction.setExternalClaimId(request.getUnmatched837Id());
transaction.setClaimKey(claimKey);
transaction.setPatientDob(patientDob);
transaction.setVaFacilityCd(vaFacilityCd);
transaction.setReportCode(claimAttachmentInfo.getReportCode());

logger.debug("===== transactionsRepository.save START =====");
arsTransactionsRepository.save(transaction);
logger.debug("===== transactionsRepository.save END =====");

} else {
logger.info("Transaction not found!");
throw new GenericException(DATA_ACCESS_ERROR, "Could not find Claim in ARS",
HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
logger.info("Exception occurred at Unmatched837AttachmentServiceImpl.updateArsTransactionsTable()"
+ e.getMessage());
throw new GenericException(DATA_ACCESS_ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

}

/**
*
* @param attachmentId
* @param claimKey
* @param attachmentIdLx
* @param claimIdToMatch
* @return
* @throws GenericException
*/
private ClaimAttachmentsInformation getClaimAttachInfoFromEreposAndArs(String attachmentId, String claimKey,
String attachmentIdLx, String claimIdToMatch) throws GenericException {

try {

List<gov.va.med.domain.ereposModel.Claim> ereposInfo = ereposClaimRepository.getEreposClaimRows((claimKey));
List<ClaimSuplInfo> ereposClaimSup = ereposClaimRepository.getEreposClaimSup(ereposInfo.get(0));

if (!ereposInfo.isEmpty()) {
logger.debug("Patient Control Number from EREPOS: " + ereposInfo.get(0).getClm01ptAcctNbr());
logger.debug("Billing Provider NPI from EREPOS: " + ereposInfo.get(0).getNm109billPrvdId());
}

if (!ereposInfo.isEmpty() && StringUtils.isNotBlank(ereposInfo.get(0).getClm01ptAcctNbr())
&& StringUtils.isNotBlank(ereposInfo.get(0).getNm109billPrvdId())) {

String reportCode = ereposClaimSup.get(0).getPwk01rptTypeCd();
String pwk06 = ereposClaimSup.get(0).getPwk06atmntCtlNbr();
// String providerNpi = ereposInfo.get(0).getNm109billPrvdId();

logger.debug("PWK06 from erepos claimSup: " + pwk06);

logger.debug("===== arsReportTypeRepository.findByCodeIgnoreCase START =====");
String reportDescription = arsReportTypeRepository.findByCodeIgnoreCase(reportCode).getDefinition();
logger.debug("===== arsReportTypeRepository.findByCodeIgnoreCase END =====");

// this only returns 1 even for multipart
/*
* List<PatientIdProvNpi> arsPatientIdAndProviderNPI = arsEntityNameRepository
* .getPatientIdProviderNpi(attachmentId);
*/

TraceNumber traceNumber = arsTraceNumberRepository.findByAttachmentIdLx(attachmentIdLx);

logger.debug("TraceNumber TRN01: " + traceNumber.getTrn01() + "TraceNumber TRN02: "
+ traceNumber.getTrn02());

Integer paCtrNum = new Integer(String.valueOf(attachmentId));
String patientControlNumber = arsRefIdRepository.getPatientCtrlNoByAttachId(paCtrNum);
String patientId = arsEntityNameRepository.getPatientId(attachmentId);
List<String> patientIdsFromErepos = ereposClaimRepository.getPatientIdsFromErepos(claimKey);

// unsolicited
if (StringUtils.isNotBlank(traceNumber.getTrn01()) && traceNumber.getTrn01().trim().equals("1")) {
// match provider attachment control number
if (StringUtils.isNotBlank(pwk06) && pwk06.equalsIgnoreCase(traceNumber.getTrn02()) &&
// match member ID
StringUtils.isNotBlank(patientId) && !patientIdsFromErepos.isEmpty()
&& patientId.equals(patientIdsFromErepos.get(0)) &&
// match patient control number
StringUtils.isNotBlank(patientControlNumber)
&& StringUtils.isNotBlank(ereposInfo.get(0).getClm01ptAcctNbr())
&& patientControlNumber.equals(ereposInfo.get(0).getClm01ptAcctNbr())) {
result = saveAndAssignInfo(attachmentId, ereposInfo, reportCode, reportDescription);
} else {
/*
* result = compareArsToErepos(attachmentId, ereposInfo, reportCode,
* providerNpi, reportDescription, arsPatientIdAndProviderNPI);
*/
logger.info(
"patient contrl number and provider NPI from claim did not match with that of the attachment.");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Claim's Provider NPI and Patient Control Number does not match those of 275 attachment.",
HttpStatus.NOT_FOUND);

}
// Solicited
} else if (StringUtils.isNotEmpty(traceNumber.getTrn01())
&& (traceNumber.getTrn01().trim().equals("2"))) {

List<String> trn02From275SplittedValues = Arrays.asList(traceNumber.getTrn02().split("-"));
String submissionId = trn02From275SplittedValues.get(1);

logger.debug("TRN02 Values: " + trn02From275SplittedValues.toString()
+ "TRN secondValue (submissionid): " + submissionId);

// should only return 1 bc it's by submission id.
ClaimSubmission claimSubmission = arsClaimSubmissionRepository
.findClaimSubmissionBysubmissionid(new BigInteger(submissionId));

if (claimSubmission != null) {

String trn02From277PayerClaimControlNumber = claimSubmission.getTrn02pyrclmctrlnmbr();
// match Provider Attachment Control Number / Payer claim number
if (trn02From277PayerClaimControlNumber != null
&& !trn02From277PayerClaimControlNumber.isEmpty()
&& trn02From277PayerClaimControlNumber.equals(claimIdToMatch) &&
// match Member ID
StringUtils.isNotBlank(patientId) && !patientIdsFromErepos.isEmpty()
&& patientId.equals(patientIdsFromErepos.get(0)) &&
// match Patient Control Number
StringUtils.isNotBlank(patientControlNumber)
&& StringUtils.isNotBlank(ereposInfo.get(0).getClm01ptAcctNbr())
&& patientControlNumber.equals(ereposInfo.get(0).getClm01ptAcctNbr())) {

logger.debug("found a 277 submission that matches claim");
result = saveAndAssignInfo(attachmentId, ereposInfo, reportCode, reportDescription);

// TODO: check STC of 277 with STC of 275

// update status of 277 claim submission to COMPLETE and save.
arsClaimSubmissionRepository.updateSubmissionStatusAndSetModifiedDate("COMPLETE",
new BigInteger(submissionId), new Date());
} else {
/*
* logger.debug(
* "found a 277 submission, but does not match claim. attempting to match by patient ctrl num and provider npi instead."
* ); result = compareArsToErepos(attachmentId, ereposInfo, reportCode,
* providerNpi, reportDescription, arsPatientIdAndProviderNPI);
*/
logger.info(
"patient contrl number and provider NPI from claim did not match with that of the attachment.");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Claim's Provider NPI and Patient Control Number does not match those of 275 attachment.",
HttpStatus.NOT_FOUND);
}
} else {
logger.info("277 submission for claim is not found");
throw new GenericException(ErrorMessages.NOT_FOUND, "277 submission for claim was not found.",
HttpStatus.NOT_FOUND);
}

/*
* if (claimSubmission == null) {
* logger.info("277 submission for claim is not found"); throw new
* GenericException(ErrorMessages.NOT_FOUND,
* "277 submission for claim was not found.", HttpStatus.NOT_FOUND); }
*/

} else {
logger.info("TRN01 value " + traceNumber.getTrn01().trim() + " was not a 1 or 2 for: "
+ attachmentIdLx);
throw new GenericException(ErrorMessages.NOT_FOUND,
"TRN01 value was not a one or two for: " + attachmentIdLx, HttpStatus.NOT_FOUND);
}

} else {
logger.info("ereposInfo was empty or patient control number or provider npi was null");
throw new GenericException(ErrorMessages.NOT_FOUND,
"Could not find matching information associated with provided Claim ID.", HttpStatus.NOT_FOUND);
}

} catch (Exception e) {
logger.info("Exception occurred at Unmatched837AttachmentServiceImpl.callEreposAndArs()" + e.getMessage());
throw e;

}

return result;
}

/**
* @param attachmentId
* @param result
* @param ereposInfo
* @param reportCode
* @param providerNpi
* @param reportDescription
* @param arsPatientIdAndProviderNPI
* @return
* @throws NumberFormatException
* @throws GenericException
*/
/*
* private ClaimAttachmentsInformation compareArsToErepos(String attachmentId,
* List<gov.va.med.domain.ereposModel.Claim> ereposInfo, String reportCode,
* String providerNpi, String reportDescription, List<PatientIdProvNpi>
* arsPatientIdAndProviderNPI) throws GenericException { String
* patientCtrlNoByAttachId;
*
* patientCtrlNoByAttachId =
* arsRefIdRepository.getPatientCtrlNoByAttachId(Integer.parseInt(attachmentId))
* ;
*
* //solicited/unsolicited if (!arsPatientIdAndProviderNPI.isEmpty() &&
* !ereposInfo.isEmpty() &&
* patientCtrlNoByAttachId.equals(ereposInfo.get(0).getClm01ptAcctNbr()) &&
* providerNpi.equals(arsPatientIdAndProviderNPI.get(0).getProvidernpi())) {
*
* logger.debug("compareArsToErepos()-PatientCtrlNoByAttachId: " +
* patientCtrlNoByAttachId + " EREPOS-CLM01PTACCTNbr: " +
* ereposInfo.get(0).getClm01ptAcctNbr()); logger.debug("ProviderNPI: " +
* providerNpi + " arsPatientIdAndProviderNPI: " +
* arsPatientIdAndProviderNPI.get(0).getProvidernpi());
*
* result = saveAndAssignInfo(attachmentId, ereposInfo, reportCode,
* reportDescription); } else { logger.
* info("patient contrl number and provider NPI from claim did not match with that of the attachment."
* ); throw new GenericException(ErrorMessages.NOT_FOUND,
* "Claim's Provider NPI and Patient Control Number does not match those of 275 attachment."
* , HttpStatus.NOT_FOUND); } return result; }
*/

/**
*
* @param attachmentId
* @param result
* @param ereposInfo
* @param reportCode
* @param reportDescription
* @return
* @throws GenericException
*/

private ClaimAttachmentsInformation saveAndAssignInfo(String attachmentId,
List<gov.va.med.domain.ereposModel.Claim> ereposInfo, String reportCode, String reportDescription) {

logger.debug("saveAndAssignInfo()");

logger.debug("===== ereposClaimRepository.findArsDataByAttachmentId START =====");
List<Trn02AndMedRecNum> arsInfo = arsEreposDataRepository
.findArsRefInfoByAttachmentId(Integer.parseInt(attachmentId));
logger.debug("===== ereposClaimRepository.findArsDataByAttachmentId END =====");

String medicalRecordNumber = "";
if (arsInfo != null && !arsInfo.isEmpty() && StringUtils.isNotBlank(arsInfo.get(0).getMedicalrecordnumber())) {
medicalRecordNumber = arsInfo.get(0).getMedicalrecordnumber();
}

result = new ClaimAttachmentsInformation(reportCode, reportDescription, null, medicalRecordNumber,
ereposInfo.get(0).getReceiverId());
if (result.getMedicalRecordNumber() != null && result.getTrn02FromTraceNumber() != null
&& ereposInfo.get(0).getReceiverId() != null) {
logger.debug("saveAndAssignInfo().claimAttachmentsInformation: " + result.getMedicalRecordNumber() + ":"
+ result.getTrn02FromTraceNumber() + " receiver id: " + ereposInfo.get(0).getReceiverId());
}

return result;
}

private void saveToEwvClaimAttachments(String attachmentIdLx, String claimKeyFromEwv,
ClaimAttachmentsInformation claimAttachmentInfo) throws GenericException {
logger.debug("Inside saveToEwvClaimAttachments()");

try {
// now saving attachIdLx instead of attachmentId
EwvClaimsAttachmentId id = new EwvClaimsAttachmentId();
id.setAttachmentId(new BigDecimal(attachmentIdLx));
id.setEdiClaimKey(claimKeyFromEwv);
id.setMedicalRecordNumber(claimAttachmentInfo.getMedicalRecordNumber());
id.setReportTypeCd(claimAttachmentInfo.getReportCode());
id.setReportTypeDesc(claimAttachmentInfo.getReportDescription());
id.setTraceNumber(claimAttachmentInfo.getTrn02FromTraceNumber());

EwvClaimsAttachment claimAttachment = new EwvClaimsAttachment(id);
logger.debug("===== ewvClaimAttachmentRepository.save START =====");
ewvClaimAttachmentRepository.save(claimAttachment);
logger.debug("===== ewvClaimAttachmentRepository.save END =====");

} catch (Exception e) {
logger.info("Exception occurred at Unmatched837AttachmentServiceImpl.saveToEwvClaimAttachments()"
+ e.getMessage());
throw new GenericException(DATA_ACCESS_ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

void saveToFppsClaimAttachments(String attachmentIdLx, String claimKey,
ClaimAttachmentsInformation claimAttachmentsInfo) throws GenericException {
logger.debug("Inside saveToFppsClaimAttachments()");

try {
// now saving attachIdLx instead of attachmentId
ClaimAttachmentsId id = new ClaimAttachmentsId();
id.setAttachmentId(new BigDecimal(attachmentIdLx));
id.setEdiClaimKey(claimKey);
id.setReportTypeCd(claimAttachmentsInfo.getReportCode());
id.setReportTypeDesc(claimAttachmentsInfo.getReportDescription());

ClaimAttachments fppsClaimAttachment = new ClaimAttachments(id);
logger.debug("===== fppsClaimAttachmentsRepository.save START =====");
fppsClaimAttachmentsRepository.save(fppsClaimAttachment);
logger.debug("===== fppsClaimAttachmentsRepository.save END =====");

} catch (Exception e) {
logger.info("Exception occurred at Unmatched837AttachmentServiceImpl.saveToFppsClaimAttachments()"
+ e.getMessage());
throw new GenericException(DATA_ACCESS_ERROR, e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);

}
}

private Date parsePatientDobToDate(String patientDob) throws GenericException {
try {
logger.debug("PATIENT DOB FOR EWV is: " + patientDob);
return dateFormat.parse(patientDob);
} catch (ParseException e) {
logger.info("Error parsing EWV Patient DOB");
throw new GenericException("parsing_error", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

private boolean isPdiValid(String claimIdToMatch) {
boolean isValid = Integer.valueOf(claimIdToMatch.substring(4, 7)) <= 366;
List<String> claimTypeCodes = Arrays.asList("03", "04", "05", "06", "07", "08", "09", "10", "50", "60", "70",
"91", "92", "93", "94", "95", "96", "98", "99");
return (claimTypeCodes.contains(claimIdToMatch.substring(7, 9)) && isValid) ? true : false;
}

@Override
public Boolean checkForDuplicateAssociateClaimKey(Unmatched837Request request) {
Transactions transaction = arsTransactionsRepository.findByattachmentIdLx(request.getAttachIdLx());

return (transaction != null && transaction.getExternalClaimId() != null
&& transaction.getExternalClaimId().equalsIgnoreCase(request.getUnmatched837Id())) ? true : false;
}
}