From a1ca1d4df37ffc3ddf6d45dcb8b73f27aeab4e57 Mon Sep 17 00:00:00 2001 From: bradymiller Date: Thu, 11 Nov 2010 10:36:16 -0800 Subject: [PATCH] Added functionality to check insurance eligibility. Contributed by MMF Systems. --- images/deleteBtn.png | Bin 0 -> 495 bytes interface/globals.php | 3 + interface/main/left_nav.php | 4 + interface/patient_file/summary/demographics.php | 11 +- interface/reports/edi_270.php | 408 +++++++++++++ interface/reports/edi_271.php | 298 +++++++++ library/calendar.inc | 4 +- library/edi.inc | 776 ++++++++++++++++++++++++ sql/3_2_0-to-4_0_0_upgrade.sql | 28 +- sql/database.sql | 37 ++ version.php | 2 +- 11 files changed, 1566 insertions(+), 5 deletions(-) create mode 100755 images/deleteBtn.png create mode 100644 interface/reports/edi_270.php create mode 100644 interface/reports/edi_271.php create mode 100644 library/edi.inc diff --git a/images/deleteBtn.png b/images/deleteBtn.png new file mode 100755 index 0000000000000000000000000000000000000000..c455293c7caa0e74f0ce9af2b5ebaf76d714f487 GIT binary patch literal 495 zcwPbT0TBL)P)B8nT%MjuAV8G7^l~KCFRF&=wWOuqkDK@5Z4k3X=Z1L0Hkm2+dC=lJMaas#extq2(v6M78da2J%F>g7<)F`cLP!23m!u|js<#A zt%jqq3ES3w{MOmO`xfY1=~R|O*)Ol8Ox{ybPp{bUJN@i*!OL-2HklDtC~%&Yji{+x zG(i;bDU{ggXipi!LxTtka!3F_GMxE_OQQknW#yu70lgl)REk)24H6E=&z0V$r?Icq z;@IuR-y`syT}bM5NLb8x@drSOtu1V-YvG%l%P^;LGCBfZTN~VcePAAACy2+QRH1AB l_Yb9u-*pQ6e9)%=0{|B?J_+vMPm2Hm002ovPDHLkV1jTU*%bf) literal 0 HcwPel00001 diff --git a/interface/globals.php b/interface/globals.php index f43ceb06d..09b2c6939 100644 --- a/interface/globals.php +++ b/interface/globals.php @@ -168,6 +168,9 @@ $GLOBALS['incdir'] = $include_root; // Location of the login screen file $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php"; +// Variable set for Eligibility Verification [EDI-271] path +$GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/"; + // Include the translation engine. This will also call sql.inc to // open the openemr mysql connection. include_once (dirname(__FILE__) . "/../library/translation.inc.php"); diff --git a/interface/main/left_nav.php b/interface/main/left_nav.php index 95e1ae032..b14223cbe 100644 --- a/interface/main/left_nav.php +++ b/interface/main/left_nav.php @@ -1020,6 +1020,10 @@ if (!empty($reg)) { + + + + diff --git a/interface/patient_file/summary/demographics.php b/interface/patient_file/summary/demographics.php index 1dbb16e69..0080deef4 100644 --- a/interface/patient_file/summary/demographics.php +++ b/interface/patient_file/summary/demographics.php @@ -22,6 +22,7 @@ $fake_register_globals=false; require_once("$srcdir/options.inc.php"); require_once("../history/history.inc.php"); require_once("$srcdir/formatting.inc.php"); + require_once("$srcdir/edi.inc"); if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) { include_once("$srcdir/pid.inc"); @@ -362,7 +363,7 @@ if ($GLOBALS['patient_id_category_name']) { expand_collapse_widget($widgetTitle, $widgetLabel, $widgetButtonLabel , $widgetButtonLink, $widgetButtonClass, $linkMethod, $bodyClass, $widgetAuth, $fixedWidth); ?> 1 ) { + if ( $insurance_count > 0 ) { ?>"; + show_eligibility_information($pid,true); + echo ""; + ///////////////////////////////// END INSURANCE SECTION ?> diff --git a/interface/reports/edi_270.php b/interface/reports/edi_270.php new file mode 100644 index 000000000..6674b40e7 --- /dev/null +++ b/interface/reports/edi_270.php @@ -0,0 +1,408 @@ + +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + + /** This report is the batch report required for batch eligibility verification. **/ + + //SANITIZE ALL ESCAPES + $sanitize_all_escapes=true; + // + + //STOP FAKE REGISTER GLOBALS + $fake_register_globals=false; + // + + require_once("../globals.php"); + require_once("$srcdir/forms.inc"); + require_once("$srcdir/billing.inc"); + require_once("$srcdir/patient.inc"); + require_once("$srcdir/formatting.inc.php"); + require_once "$srcdir/options.inc.php"; + require_once "$srcdir/formdata.inc.php"; + include_once("$srcdir/calendar.inc"); + include_once("$srcdir/edi.inc"); + + // Element data seperator + $eleDataSep = "*"; + + // Segment Terminator + $segTer = "~"; + + // Component Element seperator + $compEleSep = "^"; + + // filter conditions for the report and batch creation + + $from_date = fixDate($_POST['form_from_date'], date('Y-m-d')); + $to_date = fixDate($_POST['form_to_date'], date('Y-m-d')); + $form_facility = $_POST['form_facility'] ? $_POST['form_facility'] : ''; + $form_provider = $_POST['form_users'] ? $_POST['form_users'] : ''; + $exclude_policy = $_POST['removedrows'] ? $_POST['removedrows'] : ''; + $X12info = $_POST['form_x12'] ? explode("|",$_POST['form_x12']) : ''; + + //Set up the sql variable binding array (this prevents sql-injection attacks) + $sqlBindArray = array(); + + $where = "e.pc_pid IS NOT NULL AND e.pc_eventDate >= ?"; + array_push($sqlBindArray, $from_date); + + //$where .="and e.pc_eventDate = (select max(pc_eventDate) from openemr_postcalendar_events where pc_aid = d.id)"; + + if ($to_date) { + $where .= " AND e.pc_eventDate <= ?"; + array_push($sqlBindArray, $to_date); + } + + if($form_facility != "") { + $where .= " AND f.id = ? "; + array_push($sqlBindArray, $form_facility); + } + + if($form_provider != "") { + $where .= " AND d.id = ? "; + array_push($sqlBindArray, $form_provider); + } + + if($exclude_policy != ""){ $arrayExplode = explode(",", $exclude_policy); + array_walk($arrayExplode, 'arrFormated'); + $exclude_policy = implode(",",$arrayExplode); + $where .= " AND i.policy_number not in (".stripslashes($exclude_policy).")"; + } + + $where .= " AND (i.policy_number is not null and i.policy_number != '')"; + + $query = sprintf(" SELECT DATE_FORMAT(e.pc_eventDate, '%%Y%%m%%d') as pc_eventDate, + e.pc_facility, + p.lname, + p.fname, + p.mname, + DATE_FORMAT(p.dob, '%%Y%%m%%d') as dob, + p.ss, + p.sex, + p.pid, + p.pubpid, + i.policy_number, + i.provider as payer_id, + i.subscriber_relationship, + i.subscriber_lname, + i.subscriber_fname, + i.subscriber_mname, + DATE_FORMAT(i.subscriber_dob, '%%m/%%d/%%Y') as subscriber_dob, + i.subscriber_ss, + i.subscriber_sex, + DATE_FORMAT(i.date,'%%Y%%m%%d') as date, + d.lname as provider_lname, + d.fname as provider_fname, + d.npi as provider_npi, + d.upin as provider_pin, + f.federal_ein, + f.facility_npi, + f.name as facility_name, + c.name as payer_name + FROM openemr_postcalendar_events AS e + LEFT JOIN users AS d on (e.pc_aid is not null and e.pc_aid = d.id) + LEFT JOIN facility AS f on (f.id = e.pc_facility) + LEFT JOIN patient_data AS p ON p.pid = e.pc_pid + LEFT JOIN insurance_data AS i ON (i.id =( + SELECT id + FROM insurance_data AS i + WHERE pid = p.pid AND type = 'primary' + ORDER BY date DESC + LIMIT 1 + ) + ) + LEFT JOIN insurance_companies as c ON (c.id = i.provider) + WHERE %s ", $where ); + + // Run the query + $res = sqlStatement($query, $sqlBindArray); + + // Get the facilities information + $facilities = getUserFacilities($_SESSION['authId']); + + // Get the Providers information + $providers = getUsernames(); + + //Get the x12 partners information + $clearinghouses = getX12Partner(); + + + if (isset($_POST['form_savefile']) && !empty($_POST['form_savefile']) && $res) { + header('Content-Type: text/plain'); + header(sprintf('Content-Disposition: attachment; filename="elig-270..%s.%s.txt"', + $from_date, + $to_date + )); + print_elig($res,$X12info,$segTer,$compEleSep); + exit; + } +?> + + + + + + + + <?php echo htmlspecialchars( xl('Eligibility 270 Inquiry Batch'), ENT_NOQUOTES); ?> + + + + + + + + + + + + + + + + + + + + + + + - + +
+ +
+ +
+ +
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ : + + + [?]'> + + : + + + [?]'> +  
+ : + + + + : + + +   +
+ : + + + * +
+
+
+ + + + +
+ +
+
+
+ +
+ +
+ +
+ + + + + + + diff --git a/interface/reports/edi_271.php b/interface/reports/edi_271.php new file mode 100644 index 000000000..6fc126ca2 --- /dev/null +++ b/interface/reports/edi_271.php @@ -0,0 +1,298 @@ + +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + + //SANITIZE ALL ESCAPES + $sanitize_all_escapes=true; + // + + //STOP FAKE REGISTER GLOBALS + $fake_register_globals=false; + // + + // START - INCLUDE STATEMENTS + include_once(dirname(__file__)."/../globals.php"); + include_once("$srcdir/forms.inc"); + include_once("$srcdir/billing.inc"); + include_once("$srcdir/pnotes.inc"); + include_once("$srcdir/patient.inc"); + include_once("$srcdir/report.inc"); + include_once("$srcdir/calendar.inc"); + include_once("$srcdir/classes/Document.class.php"); + include_once("$srcdir/classes/Note.class.php"); + include_once("$srcdir/sqlconf.php"); + include_once("$srcdir/edi.inc"); + + // END - INCLUDE STATEMENTS + + + // File location (URL or server path) + + $target = $GLOBALS['edi_271_file_path']; + + if(isset($_FILES) && !empty($_FILES)) + { + + $target = $target .time().basename( $_FILES['uploaded']['name']); + + $FilePath = $target; + + if ($_FILES['uploaded']['size'] > 350000) + { + $message .= htmlspecialchars( xl('Your file is too large'), ENT_NOQUOTES)."
"; + + } + + if ($_FILES['uploaded']['type']!="text/plain") + { + $message .= htmlspecialchars( xl('You may only upload .txt files'), ENT_NOQUOTES)."
"; + } + if(!isset($message)) + { + if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) + { + $message = htmlspecialchars( xl('The following EDI file has been uploaded:').' "'. basename( $_FILES['uploaded']['name']).'"', ENT_NOQUOTES); + + // Stores the content of the file + $Response271= file($FilePath); + + // Counts the number of lines + $LineCount = count($Lines); + + //This will be a two dimensional array + //that holds the content nicely organized + + $DataSegment271 = array(); + $Segments271 = array(); + + // We will use this as an index + $i = 0; + $j = 0; + $patientId = ""; + + // Loop through each line + foreach($Response271 as $Value) + { + // In the array store this line + // with values delimited by ^ (tilt) + // as separate array values + + $DataSegment271[$i] = explode("^", $Value); + + + if(count($DataSegment271[$i])<6) + { + $messageEDI = true; + $message = ""; + if(file_exists($target)) + { + unlink($target); + } + } + else + { + foreach ($DataSegment271[$i] as $datastrings) + { + + $Segments271[$j] = explode("*", $datastrings); + + $segment = $Segments271[$j][0]; + + + // Switch Case for Segment + + switch ($segment) + { + case 'ISA': + + $j = 0; + + foreach($Segments271[$j] as $segmentVal){ + + if($j == 6) + { + $x12PartnerId = $segmentVal; + } + + $j = $j + 1; + } + + break; + + case 'REF': + + foreach($Segments271[$j] as $segmentVal){ + + if($segmentVal == "EJ") + { + $patientId = $Segments271[$j][2]; + } + } + + break; + + case 'EB': + + foreach($Segments271[$j] as $segmentVal){ + + + } + break; + + case 'MSG': + + foreach($Segments271[$j] as $segmentVal){ + + if($segment != $segmentVal) + { + eligibility_response_save($segmentVal,$x12PartnerId); + + eligibility_verification_save($segmentVal,$x12PartnerId,$patientId); + } + } + + break; + + + + } + + + + // Increase the line index + $j++; + } + } + //Increase the line index + $i++; + } + } + } + else + { + $message .= htmlspecialchars( xl('Sorry, there was a problem uploading your file'), ENT_NOQUOTES). "

"; + } + } + +?> + + + +<?php echo htmlspecialchars( xl('EDI-271 Response File Upload'), ENT_NOQUOTES); ?> + + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+ +
+ + + + + +
+
+ + + + + +
:
+
+
+ + + + +
+
+ + +
+
+
+
+ + + + + +
+ + diff --git a/library/calendar.inc b/library/calendar.inc index fbd03645d..af6f18ecd 100644 --- a/library/calendar.inc +++ b/library/calendar.inc @@ -90,8 +90,8 @@ function getUserFacilities($uID) { from users_facility uf left join facility f on (uf.facility_id = f.id) where uf.tablename='users' - and uf.table_id = '$uID' - "); + and uf.table_id = ? + ", array($uID) ); } $returnVal = array(); while ($row = sqlFetchArray($rez)) diff --git a/library/edi.inc b/library/edi.inc new file mode 100644 index 000000000..1a4c9f1a6 --- /dev/null +++ b/library/edi.inc @@ -0,0 +1,776 @@ + +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// SEGMENT FUNCTION START + +// ISA Segment - EDI-270 format + +function create_ISA($row,$X12info,$segTer,$compEleSep) { + + $ISA = array(); + + $ISA[0] = "ISA"; // Interchange Control Header Segment ID + + $ISA[1] = "00"; // Author Info Qualifier + + $ISA[2] = str_pad("0000000",10," "); // Author Information + + $ISA[3] = "00"; // Security Information Qualifier + // MEDI-CAL NOTE: For Leased-Line & Dial-Up use '01', + // for BATCH use '00'. + // '00' No Security Information Present + // (No Meaningful Information in I04) + + $ISA[4] = str_pad("0000000000",10," "); // Security Information + + $ISA[5] = str_pad("ZZ",2," "); // Interchange ID Qualifier + + $ISA[6] = str_pad($X12info[2],15," "); // INTERCHANGE SENDER ID + + $ISA[7] = str_pad("ZZ",2," "); // Interchange ID Qualifier + + $ISA[8] = str_pad($X12info[3],15," "); // INTERCHANGE RECEIVER ID + + $ISA[9] = str_pad(date('ymd'),6," "); // Interchange Date (YYMMDD) + + $ISA[10] = str_pad(date('Hi'),4," "); // Interchange Time (HHMM) + + $ISA[11] = "U"; // Interchange Control Standards Identifier + + $ISA[12] = str_pad("00401",5," "); // Interchange Control Version Number + + $ISA[13] = str_pad("000000001",9," "); // INTERCHANGE CONTROL NUMBER + + $ISA[14] = str_pad("1",1," "); // Acknowledgment Request [0= not requested, 1= requested] + + $ISA[15] = str_pad("P",1," "); // Usage Indicator [ P = Production Data, T = Test Data ] + + $ISA['Created'] = implode('*', $ISA); // Data Element Separator + + $ISA['Created'] = $ISA['Created'] ."*"; + + $ISA['Created'] = $ISA ['Created'] . $segTer . $compEleSep; + + return trim($ISA['Created']); + +} + +// GS Segment - EDI-270 format + +function create_GS($row,$X12info,$segTer,$compEleSep) { + + $GS = array(); + + $GS[0] = "GS"; // Functional Group Header Segment ID + + $GS[1] = "HS"; // Functional ID Code [ HS = Eligibility, Coverage or Benefit Inquiry (270) ] + + $GS[2] = $X12info[2]; // Application Sender’s ID + + $GS[3] = $X12info[3]; // Application Receiver’s ID + + $GS[4] = date('Ymd'); // Date [CCYYMMDD] + + $GS[5] = date('His'); // Time [HHMM] – Group Creation Time + + $GS[6] = "000000002"; // Group Control Number + + $GS[7] = "X"; // Responsible Agency Code Accredited Standards Committee X12 ] + + $GS[8] = "004010X092A1"; // Version –Release / Industry[ Identifier Code Query + + $GS['Created'] = implode('*', $GS); // Data Element Separator + + $GS['Created'] = $GS ['Created'] . $compEleSep; + + return trim($GS['Created']); + +} + +// ST Segment - EDI-270 format + +function create_ST($row,$X12info,$segTer,$compEleSep) { + + $ST = array(); + + $ST[0] = "ST"; // Transaction Set Header Segment ID + + $ST[1] = "270"; // Transaction Set Identifier Code (Inquiry Request) + + $ST[2] = "000000003"; // Transaction Set Control Number - Must match SE's + + $ST['Created'] = implode('*', $ST); // Data Element Separator + + $ST['Created'] = $ST ['Created'] . $compEleSep; + + return trim($ST['Created']); + +} + +// BHT Segment - EDI-270 format + +function create_BHT($row,$X12info,$segTer,$compEleSep) { + + $BHT = array(); + + $BHT[0] = "BHT"; // Beginning of Hierarchical Transaction Segment ID + + $BHT[1] = "0022"; // Subscriber Structure Code + + $BHT[2] = "13"; // Purpose Code - This is a Request + + $BHT[3] = "PROVTest600"; // Submitter Transaction Identifier + //This information is required by the information Receiver + //when using Real Time transactions. + //For BATCH this can be used for optional information. + + $BHT[4] = str_pad(date('Ymd'),8," "); // Date Transaction Set Created + + $BHT[5] = str_pad(date('His'),8," "); // Time Transaction Set Created + + $BHT['Created'] = implode('*', $BHT); // Data Element Separator + + $BHT['Created'] = $BHT ['Created'] . $compEleSep; + + return trim($BHT['Created']); + +} + +// HL Segment - EDI-270 format + +function create_HL($row, $nHlCounter,$X12info,$segTer,$compEleSep) { + + $HL = array(); + + $HL[0] = "HL"; // Hierarchical Level Segment ID + $HL_LEN[0] = 2; + + $HL[1] = $nHlCounter; // Hierarchical ID No. + + if($nHlCounter == 1) + { + $HL[2] = ""; + $HL[3] = 20; // Description: Identifies the payor, maintainer, or source of the information. + $HL[4] = 1; // 1 Additional Subordinate HL Data Segment in This Hierarchical Structure. + } + else if($nHlCounter == 2) + { + $HL[2] = 1; // Hierarchical Parent ID Number + $HL[3] = 21; // Hierarchical Level Code. '21' Information Receiver + $HL[4] = 1; // 1 Additional Subordinate HL Data Segment in This Hierarchical Structure. + } + else + { + $HL[2] = 2; + $HL[3] = 22; // Hierarchical Level Code.'22' Subscriber + $HL[4] = 0; // 0 no Additional Subordinate in the Hierarchical Structure. + } + + $HL['Created'] = implode('*', $HL); // Data Element Separator + + $HL['Created'] = $HL ['Created'] . $compEleSep; + + return trim($HL['Created']); + +} + +// NM1 Segment - EDI-270 format + +function create_NM1($row,$nm1Cast,$X12info,$segTer,$compEleSep) { + + $NM1 = array(); + + $NM1[0] = "NM1"; // Subscriber Name Segment ID + + if($nm1Cast == 'PR') + { + $NM1[1] = "PR"; // Entity ID Code - Payer [PR Payer] + $NM1[2] = "2"; // Entity Type - Non-Person + $NM1[3] = $row["payer_name"]; // Organizational Name + $NM1[4] = ""; // Data Element not required. + $NM1[5] = ""; // Data Element not required. + $NM1[6] = ""; // Data Element not required. + $NM1[7] = ""; // Data Element not required. + $NM1[8] = "46"; // 46 - Electronic Transmitter Identification Number (ETIN) + $NM1[9] = $X12info[3]; // Application Sender’s ID + } + else if($nm1Cast == '1P') + { + $NM1[1] = "IP"; // Entity ID Code - Provider [1P Provider] + $NM1[2] = "1"; // Entity Type - Person + $NM1[3] = $row['facility_name']; // Organizational Name + $NM1[4] = $row['provider_lname']; // Data Element not required. + $NM1[5] = $row['provider_fname']; // Data Element not required. + $NM1[6] = ""; // Data Element not required. + $NM1[7] = ""; // Data Element not required. + $NM1[8] = "XX"; + $NM1[9] = $row['provider_npi']; + } + else if($nm1Cast == 'IL') + { + $NM1[1] = "IL"; // Insured or Subscriber + $NM1[2] = "1"; // Entity Type - Person + $NM1[3] = $row['lname']; // last Name + $NM1[4] = $row['fname']; // first Name + $NM1[5] = $row['mname']; // middle Name + $NM1[6] = ""; // data element + $NM1[7] = ""; // data element + $NM1[8] = "MI"; // Identification Code Qualifier + $NM1[9] = $row['subscriber_ss']; // Identification Code + } + + $NM1['Created'] = implode('*', $NM1); // Data Element Separator + + $NM1['Created'] = $NM1['Created'] . $compEleSep; + + return trim($NM1['Created']); + +} + +// REF Segment - EDI-270 format + +function create_REF($row,$ref,$X12info,$segTer,$compEleSep) { + + $REF = array(); + + $REF[0] = "REF"; // Subscriber Additional Identification + + if($ref == '1P') + { + $REF[1] = "4A"; // Reference Identification Qualifier + $REF[2] = $row['provider_pin']; // Provider Pin. + } + else + { + $REF[1] = "EJ"; // 'EJ' for Patient Account Number + $REF[2] = $row['pid']; // Patient Account No. + } + $REF['Created'] = implode('*', $REF); // Data Element Separator + + $REF['Created'] = $REF['Created'] . $compEleSep; + + return trim($REF['Created']); + +} + +// TRN Segment - EDI-270 format + +function create_TRN($row,$tracno,$refiden,$X12info,$segTer,$compEleSep) { + + $TRN = array(); + + $TRN[0] = "TRN"; // Subscriber Trace Number Segment ID + + $TRN[1] = "1"; // Trace Type Code – Current Transaction Trace Numbers + + $TRN[2] = $tracno; // Trace Number + + $TRN[3] = "9000000000"; // Originating Company ID – must be 10 positions in length + + $TRN[4] = $refiden; // Additional Entity Identifier (i.e. Subdivision) + + $TRN['Created'] = implode('*', $TRN); // Data Element Separator + + $TRN['Created'] = $TRN['Created'] . $compEleSep; + + return trim($TRN['Created']); + +} + +// DMG Segment - EDI-270 format + +function create_DMG($row,$X12info,$segTer,$compEleSep) { + + $DMG = array(); + + $DMG[0] = "DMG"; // Date or Time or Period Segment ID + + $DMG[1] = "D8"; // Date Format Qualifier - (D8 means CCYYMMDD) + + $DMG[2] = $row['dob']; // Subscriber's Birth date + + $DMG['Created'] = implode('*', $DMG); // Data Element Separator + + $DMG['Created'] = $DMG['Created'] . $compEleSep; + + return trim($DMG['Created']); +} + +// DTP Segment - EDI-270 format + +function create_DTP($row,$qual,$X12info,$segTer,$compEleSep) { + + $DTP = array(); + + $DTP[0] = "DTP"; // Date or Time or Period Segment ID + + $DTP[1] = $qual; // Qualifier - Date of Service + + $DTP[2] = "D8"; // Date Format Qualifier - (D8 means CCYYMMDD) + + if($qual == '102'){ + $DTP[3] = $row['date']; // Date + }else{ + $DTP[3] = $row['pc_eventDate']; // Date of Service + } + $DTP['Created'] = implode('*', $DTP); // Data Element Separator + + $DTP['Created'] = $DTP['Created'] . $compEleSep; + + return trim($DTP['Created']); +} + +// EQ Segment - EDI-270 format + +function create_EQ($row,$X12info,$segTer,$compEleSep) { + + $EQ = array(); + + $EQ[0] = "EQ"; // Subscriber Eligibility or Benefit Inquiry Information + + $EQ[1] = "30"; // Service Type Code + + $EQ['Created'] = implode('*', $EQ); // Data Element Separator + + $EQ['Created'] = $EQ['Created'] . $compEleSep; + + return trim($EQ['Created']); +} + +// SE Segment - EDI-270 format + +function create_SE($row,$segmentcount,$X12info,$segTer,$compEleSep) { + + $SE = array(); + + $SE[0] = "SE"; // Transaction Set Trailer Segment ID + + $SE[1] = $segmentcount; // Segment Count + + $SE[2] = "000000003"; // Transaction Set Control Number - Must match ST's + + $SE['Created'] = implode('*', $SE); // Data Element Separator + + $SE['Created'] = $SE['Created'] . $compEleSep; + + return trim($SE['Created']); +} + +// GE Segment - EDI-270 format + +function create_GE($row,$X12info,$segTer,$compEleSep) { + + $GE = array(); + + $GE[0] = "GE"; // Functional Group Trailer Segment ID + + $GE[1] = "1"; // Number of included Transaction Sets + + $GE[2] = "000000002"; // Group Control Number + + $GE['Created'] = implode('*', $GE); // Data Element Separator + + $GE['Created'] = $GE['Created'] . $compEleSep; + + return trim($GE['Created']); +} + +// IEA Segment - EDI-270 format + +function create_IEA($row,$X12info,$segTer,$compEleSep) { + + $IEA = array(); + + $IEA[0] = "IEA"; // Interchange Control Trailer Segment ID + + $IEA[1] = "1"; // Number of included Functional Groups + + $IEA[2] = "000000001"; // Interchange Control Number + + $IEA['Created'] = implode('*', $IEA); + + $IEA['Created'] = $IEA['Created'] . $compEleSep; + + return trim($IEA['Created']); +} + +function translate_relationship($relationship) { + switch ($relationship) { + case "spouse": + return "01"; + break; + case "child": + return "19"; + break; + case "self": + default: + return "S"; + } +} + +// EDI-270 Batch file Generation + +function print_elig($res,$X12info,$segTer,$compEleSep){ + + $i=1; + + $PATEDI = ""; + + // For Header Segment + + $nHlCounter = 1; + $rowCount = 0; + $trcNo = 1234501; + $refiden = 5432101; + + while ($row = sqlFetchArray($res)) + { + + if($nHlCounter == 1) + { + // create ISA + $PATEDI = create_ISA($row,$X12info,$segTer,$compEleSep); + + // create GS + $PATEDI .= create_GS($row,$X12info,$segTer,$compEleSep); + + // create ST + $PATEDI .= create_ST($row,$X12info,$segTer,$compEleSep); + + // create BHT + $PATEDI .= create_BHT($row,$X12info,$segTer,$compEleSep); + + // For Payer Segment + + $PATEDI .= create_HL($row,1,$X12info,$segTer,$compEleSep); + $PATEDI .= create_NM1($row,'PR',$X12info,$segTer,$compEleSep); + + // For Provider Segment + + $PATEDI .= create_HL($row,2,$X12info,$segTer,$compEleSep); + $PATEDI .= create_NM1($row,'1P',$X12info,$segTer,$compEleSep); + $PATEDI .= create_REF($row,'1P',$X12info,$segTer,$compEleSep); + + $nHlCounter = $nHlCounter + 2; + $segmentcount = 7; // segement counts - start from ST + } + + // For Subscriber Segment + + $PATEDI .= create_HL($row,$nHlCounter,$X12info,$segTer,$compEleSep); + $PATEDI .= create_TRN($row,$trcNo,$refiden,$X12info,$segTer,$compEleSep); + $PATEDI .= create_NM1($row,'IL',$X12info,$segTer,$compEleSep); + $PATEDI .= create_REF($row,'IL',$X12info,$segTer,$compEleSep); + $PATEDI .= create_DMG($row,$X12info,$segTer,$compEleSep); + + // $PATEDI .= create_DTP($row,'102',$X12info,$segTer,$compEleSep); + + $PATEDI .= create_DTP($row,'472',$X12info,$segTer,$compEleSep); + $PATEDI .= create_EQ($row,$X12info,$segTer,$compEleSep); + + $segmentcount = $segmentcount + 7; + $nHlCounter = $nHlCounter + 1; + $rowCount = $rowCount + 1; + $trcNo = $trcNo + 1; + $refiden = $refiden + 1; + + + if($rowCount == sqlNumRows($res)) + { + $segmentcount = $segmentcount + 1; + $PATEDI .= create_SE($row,$segmentcount,$X12info,$segTer,$compEleSep); + $PATEDI .= create_GE($row,$X12info,$segTer,$compEleSep); + $PATEDI .= create_IEA($row,$X12info,$segTer,$compEleSep); + } + } + + echo $PATEDI; +} + +// Report Generation + +function show_elig($res,$X12info,$segTer,$compEleSep){ + + $i=0; + echo "
+ + + + + + + + + + + + + + + + + "; + + while ($row = sqlFetchArray($res)) { + + + $i= $i+1; + + if($i%2 == 0){ + $background = '#FFF'; + }else{ + $background = '#FFF'; + } + + $elig = array(); + $elig[0] = $row['facility_name']; // Inquiring Provider Name calendadr + $elig[1] = $row['facility_npi']; // Inquiring Provider NPI + $elig[2] = $row['payer_name']; // Payer Name our insurance co name + $elig[3] = $row['policy_number']; // Subscriber ID + $elig[4] = $row['subscriber_lname']; // Subscriber Last Name + $elig[5] = $row['subscriber_fname']; // Subscriber First Name + $elig[6] = $row['subscriber_mname']; // Subscriber Middle Initial + $elig[7] = $row['subscriber_dob']; // Subscriber Date of Birth + $elig[8] = substr($row['subscriber_sex'], 0, 1); // Subscriber Sex + $elig[9] = $row['subscriber_ss']; // Subscriber SSN + $elig[10] = translate_relationship($row['subscriber_relationship']); // Pt Relationship to insured + $elig[11] = $row['lname']; // Dependent Last Name + $elig[12] = $row['fname']; // Dependent First Name + $elig[13] = $row['mname']; // Dependent Middle Initial + $elig[14] = $row['dob']; // Dependent Date of Birth + $elig[15] = substr($row['sex'], 0, 1); // Dependent Sex + $elig[16] = $row['pc_eventDate']; // Date of service + $elig[17] = "30"; // Service Type + $elig[18] = $row['pubpid']; // Patient Account Number pubpid + + echo " + + + + + + + + + + + "; + + + unset($elig); + } + + if($i==0){ + + echo " + + "; + } + echo " +
". htmlspecialchars( xl('Facility Name'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('Facility NPI'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('Insurance Comp'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('Policy No'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('Patient Name'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('DOB'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('Gender'), ENT_NOQUOTES) ." ". htmlspecialchars( xl('SSN'), ENT_NOQUOTES) ."  
". htmlspecialchars( $row['facility_name'], ENT_NOQUOTES) ."". htmlspecialchars( $row['facility_npi'], ENT_NOQUOTES) ."". htmlspecialchars( $row['payer_name'], ENT_NOQUOTES) ."". htmlspecialchars( $row['policy_number'], ENT_NOQUOTES) ."". htmlspecialchars( $row['subscriber_lname']." ".$row['subscriber_fname'], ENT_NOQUOTES) ."". htmlspecialchars( $row['subscriber_dob'], ENT_NOQUOTES) ."". htmlspecialchars( $row['subscriber_sex'], ENT_NOQUOTES) ."". htmlspecialchars( $row['subscriber_ss'], ENT_NOQUOTES) ." + +
+
". htmlspecialchars( xl('No records found'), ENT_NOQUOTES) . "
+
"; +} + +// To Show Eligibility Verification data + +function show_eligibility_information($pid) +{ + + $query = " SELECT eligr.response_description as ResponseMessage, + DATE_FORMAT(eligv.eligibility_check_date, '%d %M %Y') as VerificationDate, + eligv.copay, eligv.deductible, eligv.deductiblemet, + if(eligr.response_status = 'A','Active','Inactive') as Status, + insd.pid, insc.name + FROM eligibility_verification eligv + INNER JOIN eligibility_response eligr on eligr.response_id = eligv.response_id + INNER JOIN insurance_data insd on insd.id = eligv.insurance_id + INNER JOIN insurance_companies insc on insc.id = insd.provider + WHERE insd.pid = ? + AND eligr.response_status = 'A' + AND eligv.eligibility_check_date = (SELECT max(eligibility_check_date) + FROM eligibility_verification + WHERE insurance_id = eligv.insurance_id)"; + $result = sqlStatement($query, array($pid) ); + + $row = sqlFetchArray($result); + + $showString .= "
" . + "" . + htmlspecialchars( xl('Insurance Provider'), ENT_NOQUOTES) . ": " . + (!empty($row['name']) ? htmlspecialchars( $row['name'], ENT_NOQUOTES) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
\n" . + "" . + htmlspecialchars( xl('Status'), ENT_NOQUOTES) . ": " . + (!empty($row['ResponseMessage']) ? htmlspecialchars( $row['ResponseMessage'], ENT_NOQUOTES) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
\n" . + "" . + htmlspecialchars( xl('Last Verified On'), ENT_NOQUOTES) . ": " . + (!empty($row['VerificationDate']) ? htmlspecialchars( $row['VerificationDate'], ENT_NOQUOTES) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
" . + "" . htmlspecialchars( xl('Copay'), ENT_NOQUOTES) . ": " . + (!empty($row['copay']) ? htmlspecialchars( $row['copay'], ENT_NOQUOTES) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
" . htmlspecialchars( xl('Deductible'), ENT_NOQUOTES) . ": " . + (!empty($row['deductible']) ? htmlspecialchars( $row['deductible'], ENT_NOQUOTES) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
" . htmlspecialchars( xl('Deductible Met'), ENT_NOQUOTES) . ": " . + (!empty($row['deductiblemet']) ? ($row['deductiblemet'] == 'Y' ? htmlspecialchars( xl('Yes'), ENT_NOQUOTES) : htmlspecialchars( xl('No'), ENT_NOQUOTES)) : htmlspecialchars( xl('n/a'), ENT_NOQUOTES)) . + "
"; + + echo $showString; +} + +// For EDI 271 + + +// Function to save the values in eligibility_response table + +function eligibility_response_save($segmentVal,$vendorID) +{ + + $resCount = 0; + + $query = " SELECT count(*) as RecordsCount + FROM eligibility_response + WHERE response_description = ? and + response_vendor_id = ?"; + + $resCount = sqlStatement($query, array($segmentVal, $vendorID) ); + + + if(isset($resCount)) + { + + $row = sqlFetchArray($resCount); + + $resCount = $row['RecordsCount']; + + } + + if($resCount == 0) + { + + $query = "INSERT into eligibility_response SET response_description =?, + response_vendor_id = ?, + response_create_date = now(), + response_modify_date = now()"; + $res = sqlStatement($query, array($segmentVal, $vendorID) ); + } + +} + +// Function to save the values in eligibility_verification table + +function eligibility_verification_save($segmentVal,$x12PartnerId,$patientId) +{ + + $resCount = 0; + + // For fetching the response Id + + $query = " SELECT response_id + FROM eligibility_response + WHERE response_description = ? and + response_vendor_id = ?"; + + $resId = sqlStatement($query, array($segmentVal, $x12PartnerId) ); + + // For fetching the insuarace data Id + + $query = " SELECT id,copay + FROM insurance_data + WHERE type = 'primary' and + pid = ?"; + + $insId = sqlStatement($query, array($patientId) ); + + if(isset($resId)) + { + + $row = sqlFetchArray($resId); + + $responseId = $row['response_id']; + + } + if(isset($insId)) + { + + $row = sqlFetchArray($insId); + + $insuranceId = $row['id']; + $copay = $row['copay']; + + } + + if($resCount == 0) + { + + if(isset($insuranceId) && !empty($insuranceId)){ + + //Set up the sql variable binding array (this prevents sql-injection attacks) + $sqlBindArray = array(); + $query = "INSERT into eligibility_verification SET response_id = ? , + insurance_id = ?,"; + array_push($sqlBindArray, $responseId, $insuranceId); + + if(!empty($copay)) + { + $query .= "copay = ?,"; + array_push($sqlBindArray, $copay); + } + $query .= "eligibility_check_date = now(), + create_date = now()"; + $res = sqlStatement($query, $sqlBindArray); + } + } +} + +// Function to fetch the Patient information - eligibility + +function eligibility_information($insuranceId) +{ + $insuranceId = 1; + + $query = " SELECT * + FROM eligibility_verification + WHERE insuranceid = ?"; + + $result = sqlStatement($query, array($insuranceId) ); + $row = sqlFetchArray($result); + return $row; + +} +// return array of X12 partners + +function getX12Partner() { + $rez = sqlStatement("select * from x12_partners"); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +// return array of provider usernames +function getUsernames() { + $rez = sqlStatement("select distinct username, lname, fname,id from users " . + "where authorized = 1 and username != ''"); + for($iter=0; $row=sqlFetchArray($rez); $iter++) + $returnval[$iter]=$row; + + return $returnval; +} + +// return formated array + +function arrFormated(&$item, $key){ + $item = strstr($item, '_'); + $item = substr($item,1,strlen($item)-1); + $item = "'".$item; +} +?> diff --git a/sql/3_2_0-to-4_0_0_upgrade.sql b/sql/3_2_0-to-4_0_0_upgrade.sql index aba44ee90..8ea69e69e 100644 --- a/sql/3_2_0-to-4_0_0_upgrade.sql +++ b/sql/3_2_0-to-4_0_0_upgrade.sql @@ -865,6 +865,33 @@ INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ( INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ('payment_type', 'patient', 'Patient', 20, 0); #EndIf +#IfNotTable eligibility_response +CREATE TABLE `eligibility_response` ( + `response_id` bigint(20) NOT NULL auto_increment, + `response_description` varchar(255) default NULL, + `response_status` enum('A','D') NOT NULL default 'A', + `response_vendor_id` bigint(20) default NULL, + `response_create_date` date default NULL, + `response_modify_date` date default NULL, + PRIMARY KEY (`response_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1; +#EndIf + +#IfNotTable eligibility_verification +CREATE TABLE `eligibility_verification` ( + `verification_id` bigint(20) NOT NULL auto_increment, + `response_id` bigint(20) default NULL, + `insurance_id` bigint(20) default NULL, + `eligibility_check_date` datetime default NULL, + `copay` int(11) default NULL, + `deductible` int(11) default NULL, + `deductiblemet` enum('Y','N') default 'Y', + `create_date` date default NULL, + PRIMARY KEY (`verification_id`), + KEY `insurance_id` (`insurance_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1; +#EndIf + #IfNotRow2D list_options list_id lists option_id smoking_status INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ('lists' ,'smoking_status','Smoking Status', 1,0); INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ('smoking_status', '1', 'Current every day smoker', 10, 0); @@ -885,4 +912,3 @@ ALTER TABLE drug_sales ADD distributor_id bigint(20) NOT NULL DEFAULT 0; #IfNotRow2D list_options list_id abook_type option_id dist INSERT INTO list_options (list_id,option_id,title,seq,is_default) VALUES ('abook_type','dist','Distributor',30,0); #EndIf - diff --git a/sql/database.sql b/sql/database.sql index 6bb7608c7..75d92d515 100644 --- a/sql/database.sql +++ b/sql/database.sql @@ -378,6 +378,43 @@ CREATE TABLE `drugs` ( -- -------------------------------------------------------- +-- +-- Table structure for table `eligibility_response` +-- + +DROP TABLE IF EXISTS `eligibility_response`; +CREATE TABLE `eligibility_response` ( + `response_id` bigint(20) NOT NULL auto_increment, + `response_description` varchar(255) default NULL, + `response_status` enum('A','D') NOT NULL default 'A', + `response_vendor_id` bigint(20) default NULL, + `response_create_date` date default NULL, + `response_modify_date` date default NULL, + PRIMARY KEY (`response_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `eligibility_verification` +-- + +DROP TABLE IF EXISTS `eligibility_verification`; +CREATE TABLE `eligibility_verification` ( + `verification_id` bigint(20) NOT NULL auto_increment, + `response_id` bigint(20) default NULL, + `insurance_id` bigint(20) default NULL, + `eligibility_check_date` datetime default NULL, + `copay` int(11) default NULL, + `deductible` int(11) default NULL, + `deductiblemet` enum('Y','N') default 'Y', + `create_date` date default NULL, + PRIMARY KEY (`verification_id`), + KEY `insurance_id` (`insurance_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1; + +-- -------------------------------------------------------- + -- -- Table structure for table `employer_data` -- diff --git a/version.php b/version.php index 9de130155..351a71069 100644 --- a/version.php +++ b/version.php @@ -15,7 +15,7 @@ $v_tag = '-dev'; // minor revision number, should be empty for production rele // Please add a comment that includes the database.sql version that relates to // change below -$v_database = 6; +$v_database = 7; // 4) 3_2_0-to-4_0_0_upgrade.sql new revision: 1.31 // database.sql,v new revision: 1.180 // 6) 2010-10-29 by sunsetsystems - 1.182 I guess - what are these entries for? -- 2.11.4.GIT