#!/usr/bin/perl -w use strict; use warnings; use XML::XPath; use MIME::Lite::TT; use File::Copy; #use Time::localTime; my $file = 'test.xml'; my $xp = XML::XPath->new(filename => $file); my $title='835 REPORT'; my $to='jarel@medirecpr.COM, jafet.medirec@gmail.com'; my $from='mediclear@MEDIRECPR.COM'; my $subject='MediClear - 835 REPORT EMAIL MESSAGE'; my $icncount = 1; my $transactioncount = 1; my $claimpaymentcount = 1; #my $servicepaymentcount = 1; my $tm = (localtime); my $FileName = "$file\_835_Report.LOG"; my $LogFiles='/home/jramirez/PayerDownload/LogFiles/'; open(FILEHANDLE, ">$FileName") or die "cannot open file for reading: $!"; foreach my $InterchangeControlHeader ($xp->find('//InterchangeControlHeader')->get_nodelist){ print FILEHANDLE '=================================================================' . "\n"; print FILEHANDLE 'Batch X12 File: ' . $file . "\n"; print FILEHANDLE 'Reading Date: ' . $tm . "\n"; print FILEHANDLE 'User Id: Generated by MediClear' . "\n"; print FILEHANDLE 'Last Modified: N/A ' . "\n"; print FILEHANDLE '=================================================================' . "\n"; # print 'Functional Group Count: ' . $icncount . "\n"; # print 'ICN: ' . $InterchangeControlHeader->find('//@InterchangeControlNumber13')->string_value . "\n"; foreach my $Transaction835 ($xp->find('//Transaction835')->get_nodelist){ # print $transactioncount . ') ' . 'Transaction Set Control Number : ' . $Transaction835->find('TransactionSetHeader/@TransactionSetControlNumber2')->string_value . "\n"; print FILEHANDLE 'Check/EFT Amount: ' . $Transaction835->find('FinancialInformation/@TotalActualProviderPaymentAmount2')->string_value . "\n"; print FILEHANDLE 'Check/EFT Credit/Debit Type: ' . $Transaction835->find('FinancialInformation/@CreditorDebitFlagCode3')->string_value . "\n"; print FILEHANDLE 'Check/EFT Type: ' . $Transaction835->find('FinancialInformation/@PaymentMethodCode4')->string_value . "\n"; print FILEHANDLE 'Check/EFT Payment Date: ' . $Transaction835->find('FinancialInformation/@CheckIssueorEFTEffectiveDate16')->string_value . "\n"; print FILEHANDLE 'Check/EFT Number: ' . $Transaction835->find('ReassociationTraceNumber/@CheckorEFTTraceNumber2')->string_value . "\n"; print FILEHANDLE 'Production Date: ' . $Transaction835->find('ProductionDate/@ProductionDate2')->string_value . "\n"; print FILEHANDLE 'Payer Name: ' . $Transaction835->find('//PayerIdentificationLoop/PayerIdentification/@PayerName2')->string_value . "\n"; print FILEHANDLE 'Payer Address: ' . $Transaction835->find('//PayerIdentificationLoop/PayerAddress/@PayerAddressLine1')->string_value . " "; print FILEHANDLE $Transaction835->find('//PayerIdentificationLoop/PayerCity_State_ZIPCode/@PayerCityName1')->string_value . " "; print FILEHANDLE $Transaction835->find('//PayerIdentificationLoop/PayerCity_State_ZIPCode/@PayerStateCode2')->string_value . " "; print FILEHANDLE $Transaction835->find('//PayerIdentificationLoop/PayerCity_State_ZIPCode/@PayerPostalZoneorZIPCode3')->string_value . "\n"; print FILEHANDLE 'Payee Name: ' . $Transaction835->find('//PayeeIdentificationLoop/PayeeIdentification/@PayeeName2')->string_value . "\n"; print FILEHANDLE 'Payee ICN: ' . $Transaction835->find('//PayeeIdentificationLoop/PayeeIdentification/@PayeeIdentificationCode4')->string_value . "\n"; print FILEHANDLE 'Provider Adjustment: ' . $Transaction835->find('//ProviderAdjustment/@ProviderAdjustmentAmount4')->string_value . "\n"; print FILEHANDLE 'Provider Adjustment Reason Code: ' . $Transaction835->find('//ProviderAdjustment/AdjustmentIdentifier3/@AdjustmentReasonCode1')->string _value . "\n"; foreach my $ClaimPaymentInformationLoop ($xp->find('.//ClaimPaymentInformationLoop', $Transaction835)->get_nodelist){ print FILEHANDLE "\n"; print FILEHANDLE 'Invoice: ' . $ClaimPaymentInformationLoop->find('ClaimPaymentInformation/@PatientControlNumber1')->string_value . "\n"; print FILEHANDLE '------------------------------------' . "\n"; print FILEHANDLE 'Claim Status: ' . $ClaimPaymentInformationLoop->find('ClaimPaymentInformation/@ClaimStatusCode2')->string_value . "\n"; print FILEHANDLE 'Billed Amount: ' . $ClaimPaymentInformationLoop->find('ClaimPaymentInformation/@TotalClaimChargeAmount3')->string_value . "\n"; print FILEHANDLE 'Insurance Payment Amount: ' . $ClaimPaymentInformationLoop->find('ClaimPaymentInformation/@ClaimPaymentAmount4')->string_value . "\n"; print FILEHANDLE 'Deductible Amount: ? ' . "\n"; print FILEHANDLE 'Payer ICN: ' . $ClaimPaymentInformationLoop->find('ClaimPaymentInformation/@PayerClaimControlNumber7')->string_value . "\n"; print FILEHANDLE 'Name Patient: ' . $ClaimPaymentInformationLoop->find('PatientName/@PatientFirstName4')->string_value . " "; print FILEHANDLE $ClaimPaymentInformationLoop->find('PatientName/@PatientLastName3')->string_value . "\n"; #$claimpaymentcount++; my $MOARemarkCode1 = $ClaimPaymentInformationLoop->find('OutpatientAdjudicationInformation/@RemarkCode1')->string_value; my $MOARemarkCode2 = $ClaimPaymentInformationLoop->find('OutpatientAdjudicationInformation/@RemarkCode2')->string_value; my $MOARemarkCode3 = $ClaimPaymentInformationLoop->find('OutpatientAdjudicationInformation/@RemarkCode3')->string_value; my $MOARemarkCode4 = $ClaimPaymentInformationLoop->find('OutpatientAdjudicationInformation/@RemarkCode4')->string_value; my $MOARemarkCode5 = $ClaimPaymentInformationLoop->find('OutpatientAdjudicationInformation/@RemarkCode5')->string_value; if ($MOARemarkCode1 ne '') { print FILEHANDLE 'MOA01: ' . $MOARemarkCode1 . "\n"; } if ($MOARemarkCode2 ne '') { print FILEHANDLE 'MOA02: ' . $MOARemarkCode2 . "\n"; } if ($MOARemarkCode3 ne '') { print FILEHANDLE 'MOA03: ' . $MOARemarkCode3 . "\n"; } if ($MOARemarkCode4 ne '') { print FILEHANDLE 'MOA04: ' . $MOARemarkCode4 . "\n"; } if ($MOARemarkCode5 ne '') { print FILEHANDLE 'MOA05: ' . $MOARemarkCode5 . "\n"; } my $CoveredDaysorVisitsCount1 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@CoveredDaysorVisitsCount1')->string_value; my $PPSOperatingOutlierAmount2 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPSOperatingOutlierAmount2')->string_value; my $LifetimePsychiatricDaysCount3 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@LifetimePsychiatricDaysCount3')->string_value; my $ClaimDRGAmount4 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimDRGAmount4')->string_value; my $RemarkCode5 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@RemarkCode5')->string_value; my $ClaimDisproportionateShareAmount6 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimDisproportionateShareAmount6') ->string_value; my $ClaimMSPPass_throughAmount7 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimMSPPass_throughAmount7')->string_val ue; my $ClaimPPSCapitalAmount8 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimPPSCapitalAmount8')->string_value; my $PPS_CapitalFSPDRGAmount9 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_CapitalFSPDRGAmount')->string_value; my $PPS_CapitalHSPDRGAmount10 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_CapitalHSPDRGAmount10')->string_value; my $PPS_CapitalDSHDRGAmount11 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_CapitalDSHDRGAmount11')->string_value; my $OldCapitalAmount12 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@OldCapitalAmount12')->string_value; my $PPS_CapitalIMEamount13 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_CapitalIMEamount13')->string_value; my $PPS_OperatingHospitalSpecificDRGAmount14 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_OperatingHospitalSpecifi cDRGAmount14')->string_value; my $CostReportDayCount15 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@CostReportDayCount15')->string_value; my $PPS_OperatingFederalSpecificDRGAmount16 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_OperatingFederalSpecificD RGAmount16')->string_value; my $ClaimPPSCapitalOutlierAmount17 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimPPSCapitalOutlierAmount17')->stri ng_value; my $ClaimIndirectTeachingAmount18 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@ClaimIndirectTeachingAmount18')->string _value; my $NonpayableProfessionalComponentAmount19 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@NonpayableProfessionalCompone ntAmount19')->string_value; my $RemarkCode20 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@RemarkCode20')->string_value; my $RemarkCode21 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@RemarkCode21')->string_value; my $RemarkCode22 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@RemarkCode22')->string_value; my $RemarkCode23 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@RemarkCode23')->string_value; my $PPS_CapitalExceptionAmount24 = $ClaimPaymentInformationLoop->find('InpatientAdjudicationInformation/@PPS_CapitalExceptionAmount24')->string_v alue; if ($CoveredDaysorVisitsCount1 ne '') { print FILEHANDLE 'MOA01: ' . $CoveredDaysorVisitsCount1 . "\n"; } if ($PPSOperatingOutlierAmount2 ne '') { print FILEHANDLE 'MOA02: ' . $PPSOperatingOutlierAmount2 . "\n"; } if ($LifetimePsychiatricDaysCount3 ne '') { print FILEHANDLE 'MIA03: ' . $LifetimePsychiatricDaysCount3 . "\n"; } if ($ClaimDRGAmount4 ne '') { print FILEHANDLE 'MIA04: ' . $ClaimDRGAmount4 . "\n"; } if ($RemarkCode5 ne '') { print FILEHANDLE 'MIA05: ' . $RemarkCode5 . "\n"; } if ($ClaimDisproportionateShareAmount6 ne '') { print FILEHANDLE 'MIA06: ' . $ClaimDisproportionateShareAmount6 . "\n"; } if ($ClaimMSPPass_throughAmount7 ne '') { print FILEHANDLE 'MIA07: ' . $ClaimMSPPass_throughAmount7 . "\n"; } if ($ClaimPPSCapitalAmount8 ne '') { print FILEHANDLE 'MIA08: ' . $ClaimPPSCapitalAmount8 . "\n"; } if ($PPS_CapitalFSPDRGAmount9 ne '') { print FILEHANDLE 'MIA09: ' . $PPS_CapitalFSPDRGAmount9 . "\n"; } if ($PPS_CapitalHSPDRGAmount10 ne '') { print FILEHANDLE 'MIA10: ' . $PPS_CapitalHSPDRGAmount10 . "\n"; } if ($PPS_CapitalDSHDRGAmount11 ne '') { print FILEHANDLE 'MIA11: ' . $PPS_CapitalDSHDRGAmount11 . "\n"; } if ($OldCapitalAmount12 ne '') { print FILEHANDLE 'MIA12: ' . $OldCapitalAmount12 . "\n"; } if ($PPS_CapitalIMEamount13 ne '') { print FILEHANDLE 'MIA:13 ' . $PPS_CapitalIMEamount13 . "\n"; } if ($PPS_OperatingHospitalSpecificDRGAmount14 ne '') { print FILEHANDLE 'MIA14: ' . $PPS_OperatingHospitalSpecificDRGAmount14 . "\n"; } if ($CostReportDayCount15 ne '') { print FILEHANDLE 'MIA15: ' . $CostReportDayCount15 . "\n"; } if ($PPS_OperatingFederalSpecificDRGAmount16 ne '') { print FILEHANDLE 'MIA16: ' . $PPS_OperatingFederalSpecificDRGAmount16 . "\n"; } if ($ClaimPPSCapitalOutlierAmount17 ne '') { print FILEHANDLE 'MIA17: ' . $ClaimPPSCapitalOutlierAmount17 . "\n"; } if ($ClaimIndirectTeachingAmount18 ne '') { print FILEHANDLE 'MIA18: ' . $ClaimIndirectTeachingAmount18 . "\n"; } if ($NonpayableProfessionalComponentAmount19 ne '') { print FILEHANDLE 'MIA19: ' . $NonpayableProfessionalComponentAmount19 . "\n"; } if ($RemarkCode20 ne '') { print FILEHANDLE 'MIA20: ' . $RemarkCode20 . "\n"; } if ($RemarkCode21 ne '') { print FILEHANDLE 'MIA21: ' . $RemarkCode21 . "\n"; } if ($RemarkCode22 ne '') { print FILEHANDLE 'MIA22: ' . $RemarkCode22 . "\n"; } if ($RemarkCode23 ne '') { print FILEHANDLE 'MIA23: ' . $RemarkCode23 . "\n"; } if ($PPS_CapitalExceptionAmount24 ne '') { print FILEHANDLE 'MIA24: ' . $PPS_CapitalExceptionAmount24 . "\n"; } print FILEHANDLE "\n"; print FILEHANDLE 'CPT Details' . "\n"; print FILEHANDLE '-----------' . "\n"; my $servicepaymentcount = "1"; foreach my $ServicePaymentInformationLoop ($xp->find('.//ServicePaymentInformationLoop', $ClaimPaymentInformationLoop)->get_nodelist){ print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Code: ' . $ServicePaymentInformationLoop->find('ServicePaymentInformation/Compos iteMedicalProcedureIdentifier1/@Product_ServiceID2')->string_value . "\n"; print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Modifier: ' . $ServicePaymentInformationLoop->find('ServicePaymentInformation/Co mpositeMedicalProcedureIdentifier1/@ProcedureModifier3')->string_value . "\n"; print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Billed Amount: ' . $ServicePaymentInformationLoop->find('ServicePaymentInformation/@LineItemChargeAmount2')->string_value . "\n"; print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Allow Amount: ' . $ServicePaymentInformationLoop->find('ServicePaymentInformation/@LineItemProviderP aymentAmount3')->string_value . "\n"; print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Service Date: ' . $ServicePaymentInformationLoop->find('ServiceDate/@ServiceDate 2')->string_value . "\n"; my $RemarkCode2 = $ServicePaymentInformationLoop->find('HealthCareRemarkCodes/@RemarkCode2')->string_value; if ($RemarkCode2 ne '') { print FILEHANDLE '(' . $servicepaymentcount . ')' . 'CPT Healtch Care Remark Code: ' . $RemarkCode2 . "\n"; } my $adjustmentgroupcount = "1"; foreach my $ServiceAdjustment ($xp->find('.//ServiceAdjustment', $ServicePaymentInformationLoop)->get_nodelist){ print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . ')' . 'Adjustment Group Code: ' . $ServiceAdjus tment->find('@ClaimAdjustmentGroupCode1')->string_value . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . ')' . 'Adjustment Group Message: ?' . "\n"; my $AdjustmentReasonCode2 = $ServiceAdjustment->find('@AdjustmentReasonCode2')->string_value; my $AdjustmentAmount3 = $ServiceAdjustment->find('@AdjustmentAmount3')->string_value; my $AdjustmentReasonCode5 = $ServiceAdjustment->find('@AdjustmentReasonCode5')->string_value; my $AdjustmentAmount6 = $ServiceAdjustment->find('@AdjustmentAmount6')->string_value; my $AdjustmentReasonCode8 = $ServiceAdjustment->find('@AdjustmentReasonCode8')->string_value; my $AdjustmentAmount9 = $ServiceAdjustment->find('@AdjustmentAmount9')->string_value; my $adjustmentreasoncodecount = "1"; if ($AdjustmentReasonCode2 ne '') { print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecoun t . ')' . 'Adjustment Reason Code: ' . $AdjustmentReasonCode2 . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecount . ')' . 'Adjustment Re ason Message: ?' . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecount . ')' . 'Adjustment Group Code Amount: ' . $AdjustmentAmount3 . "\n"; $adjustmentreasoncodecount++; } if ($AdjustmentReasonCode5 ne '') { print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecount . ')' . 'Adjustment Re ason Code: ' . $AdjustmentReasonCode5 . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecount . ')' . 'Adjustment Reason Mes sage: ?' . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecount . ')' . 'Adjustment Gr oup Code Amount: ' . $AdjustmentAmount6 . "\n"; $adjustmentreasoncodecount++; } if ($AdjustmentReasonCode8 ne '') { print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecoun t . ')' . 'Adjustment Reason Code: ' . $AdjustmentReasonCode8 . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecoun t . ')' . 'Adjustment Reason Message: ?' . "\n"; print FILEHANDLE ' (' . $servicepaymentcount . '.' . $adjustmentgroupcount . '.' . $adjustmentreasoncodecoun t . ')' . 'Adjustment Group Code Amount: ' . $AdjustmentAmount9 . "\n"; $adjustmentreasoncodecount++; } print FILEHANDLE "\n"; $adjustmentgroupcount++; } $servicepaymentcount++; } $transactioncount++; } $icncount++; } } close (FILEHANDLE); open (MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; open (MESSAGE, "<", "$FileName") or die "$!"; print MAIL ; close (MESSAGE); close (MAIL); print $FileName . "\n"; move($FileName, $LogFiles); #unlink glob('/home/jramirez/PayerDownload/SES/XMLTEMP/*.xml');