fix: set default x12 partner for item in billing manager (#7502)
[openemr.git] / library / ajax / payment_ajax.php
blobcf609fd389715a2214146d024b7216ad7ca9da74
1 <?php
3 /**
4 * This section handles ajax for insurance,patient and for encounters.
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Eldho Chacko <eldho@zhservices.com>
9 * @author Paul Simon K <paul@zhservices.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../../interface/globals.php");
18 use OpenEMR\Common\Csrf\CsrfUtils;
20 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
21 CsrfUtils::csrfNotVerified();
24 //=================================
25 if (isset($_POST["ajax_mode"])) {
26 AjaxDropDownCode();
29 //=================================
30 function AjaxDropDownCode()
32 if ($_POST["ajax_mode"] == "set") {//insurance
33 $CountIndex = 1;
34 $StringForAjax = "<div id='AjaxContainerInsurance'><table class='table table-sm table-striped w-100 bg-light text-dark'>
35 <tr class='text bg-dark text-light'>
36 <td width='50'>" . xlt('Code') . "</td>
37 <td width='300'>" . xlt('Name') . "</td>
38 <td width='200'>" . xlt('Address') . "</td>
39 </tr>" .
40 //ProcessKeyForColoring(event,$CountIndex)==>Shows the navigation in the listing by change of colors and focus.Happens when down or up arrow is pressed.
41 //PlaceValues(event,'&nbsp;','')==>Used while -->KEY PRESS<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
42 //PutTheValuesClick('&nbsp;','')==>Used while -->CLICK<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
43 "<tr class='text' height='20' bgcolor='" . attr($bgcolor ?? '') . "' id=\"tr_insurance_" . attr($CountIndex) . "\"
44 onkeydown=\"ProcessKeyForColoring(event," . attr_js($CountIndex) . ");PlaceValues(event,'&nbsp;','')\" onclick=\"PutTheValuesClick('&nbsp;','')\">
45 <td colspan='3' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
46 </tr>";
47 $insurance_text_ajax = trim((isset($_POST['insurance_text_ajax']) ? $_POST['insurance_text_ajax'] : ''));
48 $res = sqlStatement("SELECT insurance_companies.id,name,city,state,country FROM insurance_companies
49 left join addresses on insurance_companies.id=addresses.foreign_id where name like ? or insurance_companies.id like ? ORDER BY name", array($insurance_text_ajax . '%', $insurance_text_ajax . '%'));
50 while ($row = sqlFetchArray($res)) {
51 if ($CountIndex % 2 == 1) {
52 $bgcolor = '#ddddff';
53 } else {
54 $bgcolor = '#ffdddd';
57 $CountIndex++;
58 $Id = $row['id'];
59 $Name = $row['name'];
60 $City = $row['city'];
61 $State = $row['state'];
62 $Country = $row['country'];
63 $Address = $City . ', ' . $State . ', ' . $Country;
64 $StringForAjax .= "<tr class='text' id=\"tr_insurance_" . attr($CountIndex) . "\"
65 onkeydown='ProcessKeyForColoring(event,$CountIndex);PlaceValues(event," . attr_js($Id) . "," . attr_js($Name) . ")'
66 onclick='PutTheValuesClick(" . attr_js($Id) . "," . attr_js($Name) . ")'>
67 <td><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'>" . text($Id) . "</a></td>
68 <td><a href='#'>" . text($Name) . "</a></td>
69 <td><a href='#'>" . text($Address) . "</a></td>
70 </tr>";
73 $StringForAjax .= "</table></div>";
74 echo text(strlen($_POST['insurance_text_ajax'])) . '~`~`' . $StringForAjax;
75 die;
78 //===============================================================================
79 if ($_POST["ajax_mode"] == "set_patient") {//patient.
80 //From 2 areas this ajax is called.So 2 pairs of functions are used.
81 //PlaceValues==>Used while -->KEY PRESS<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
82 //PutTheValuesClick==>Used while -->CLICK<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
83 //PlaceValuesDistribute==>Used while -->KEY PRESS<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
84 //PutTheValuesClickDistribute==>Used while -->CLICK<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
85 if (isset($_POST['patient_code']) && $_POST['patient_code'] != '') {
86 $patient_code = trim((isset($_POST['patient_code']) ? $_POST['patient_code'] : ''));
87 if (isset($_POST['submit_or_simple_type']) && $_POST['submit_or_simple_type'] == 'Simple') {
88 $StringToAppend = "PutTheValuesClickPatient";
89 $StringToAppend2 = "PlaceValuesPatient";
90 } else {
91 $StringToAppend = "PutTheValuesClickDistribute";
92 $StringToAppend2 = "PlaceValuesDistribute";
95 $patient_code_complete = $_POST['patient_code'];//we need the spaces here
96 } elseif (isset($_POST['insurance_text_ajax']) && $_POST['insurance_text_ajax'] != '') {
97 $patient_code = trim((isset($_POST['insurance_text_ajax']) ? $_POST['insurance_text_ajax'] : ''));
98 $StringToAppend = "PutTheValuesClick";
99 $StringToAppend2 = "PlaceValues";
100 $patient_code_complete = $_POST['insurance_text_ajax'];//we need the spaces here
103 $CountIndex = 1;
104 $StringForAjax = "<div id='AjaxContainerPatient'><table class='table table-sm table-striped w-50 bg-light text-dark'>
105 <tr class='text bg-dark text-light'>
106 <td width='50'>" . xlt('Code') . "</td>
107 <td width='100'>" . xlt('Last Name') . "</td>
108 <td width='100'>" . xlt('First Name') . "</td>
109 <td width='100'>" . xlt('Middle Name') . "</td>
110 <td width='100'>" . xlt('Date of Birth') . "</td>
111 </tr>" .
112 //ProcessKeyForColoring(event,$CountIndex)==>Shows the navigation in the listing by change of colors and focus.Happens when down or up arrow is pressed.
113 "<tr class='text' id=\"tr_insurance_" . attr($CountIndex) . "\"
114 onkeydown=\"ProcessKeyForColoring(event," . attr_js($CountIndex) . ");$StringToAppend2(event,'&nbsp;','')\" onclick=\"$StringToAppend('&nbsp;','')\">
115 <td colspan='5' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
116 </tr>
119 $res = sqlStatement(
120 "SELECT pid as id,fname,lname,mname,DOB FROM patient_data
121 where fname like ? or lname like ? or mname like ? or
122 CONCAT(lname,' ',fname,' ',mname) like ? or pid like ? ORDER BY lname",
123 array(
124 $patient_code . '%',
125 $patient_code . '%',
126 $patient_code . '%',
127 $patient_code . '%',
128 $patient_code . '%'
131 while ($row = sqlFetchArray($res)) {
132 if ($CountIndex % 2 == 1) {
133 $bgcolor = '#ddddff';
134 } else {
135 $bgcolor = '#ffdddd';
138 $CountIndex++;
139 $Id = $row['id'];
140 $fname = $row['fname'];
141 $lname = $row['lname'];
142 $mname = $row['mname'];
143 $Name = $lname . ' ' . $fname . ' ' . $mname;
144 $DOB = oeFormatShortDate($row['DOB']);
145 $StringForAjax .= "<tr class='text' id=\"tr_insurance_" . attr($CountIndex) . "\"
146 onkeydown='ProcessKeyForColoring(event,$CountIndex);$StringToAppend2(event," . attr_js($Id) . "," . attr_js($Name) . ")' onclick=\"$StringToAppend(" . attr_js($Id) . ", " . attr_js($Name) . ")\">
147 <td><a id='anchor_insurance_code_$CountIndex' href='#' >" . text($Id) . "</a></td>
148 <td><a href='#'>" . text($lname) . "</a></td>
149 <td><a href='#'>" . text($fname) . "</a></td>
150 <td><a href='#'>" . text($mname) . "</a></td>
151 <td><a href='#'>" . text($DOB) . "</a></td>
152 </tr>";
155 $StringForAjax .= "</table></div>";
156 echo text(strlen($patient_code_complete)) . '~`~`' . $StringForAjax;
157 die;
160 //===============================================================================
161 if ($_POST["ajax_mode"] == "encounter") {//encounter
162 //PlaceValuesEncounter==>Used while -->KEY PRESS<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
163 //PutTheValuesClickEncounter==>Used while -->CLICK<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
164 if (isset($_POST['encounter_patient_code'])) {
165 $patient_code = trim((isset($_POST['encounter_patient_code']) ? $_POST['encounter_patient_code'] : ''));
166 $StringToAppend = "PutTheValuesClickEncounter";
167 $StringToAppend2 = "PlaceValuesEncounter";
170 $CountIndex = 1;
171 $StringForAjax = "<div id='AjaxContainerEncounter'><table width='202' border='1' cellspacing='0' cellpadding='0'>
172 <tr class='text' bgcolor='#dddddd'>
173 <td width='100'>" . xlt('Encounter') . "</td>
174 <td width='100'>" . xlt('Date') . "</td>
175 </tr>" .
176 //ProcessKeyForColoring(event,$CountIndex)==>Shows the navigation in the listing by change of colors and focus.Happens when down or up arrow is pressed.
177 "<tr class='text' height='20' bgcolor='" . attr($bgcolor) . "' id=\"tr_insurance_" . attr($CountIndex) . "\"
178 onkeydown=\"ProcessKeyForColoring(event," . attr_js($CountIndex) . ");$StringToAppend2(event,'&nbsp;','')\" onclick=\"$StringToAppend('&nbsp;','')\">
179 <td colspan='2' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
180 </tr>
183 $res = sqlStatement("SELECT date,encounter FROM form_encounter
184 where pid =? ORDER BY encounter", array($patient_code));
185 while ($row = sqlFetchArray($res)) {
186 if ($CountIndex % 2 == 1) {
187 $bgcolor = '#ddddff';
188 } else {
189 $bgcolor = '#ffdddd';
192 $CountIndex++;
193 $Date = $row['date'];
194 $Date = explode(' ', $Date);
195 $Date = oeFormatShortDate($Date[0]);
196 $Encounter = $row['encounter'];
197 $StringForAjax .= "<tr class='text' bgcolor='" . attr($bgcolor) . "' id=\"tr_insurance_" . attr($CountIndex) . "\"
198 onkeydown=\"ProcessKeyForColoring(event," . attr_js($CountIndex) . ");$StringToAppend2(event," . attr_js($Encounter) . "," . attr_js($Date) . ")\" onclick=\"$StringToAppend(" . attr_js($Encounter) . "," . attr_js($Date) . ")\">
199 <td><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#' >" . text($Encounter) . "</a></td>
200 <td><a href='#'>" . text($Date) . "</a></td>
201 </tr>";
204 $StringForAjax .= "</table></div>";
205 echo $StringForAjax;
206 die;