4 * This section handles ajax for insurance,patient and for encounters.
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"])) {
29 //=================================
30 function AjaxDropDownCode()
32 if ($_POST["ajax_mode"] == "set") {//insurance
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>
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,' ','')==>Used while -->KEY PRESS<-- over list.List vanishes and the clicked one gets listed in the parent page's text box.
42 //PutTheValuesClick(' ','')==>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,' ','')\" onclick=\"PutTheValuesClick(' ','')\">
45 <td colspan='3' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
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) {
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>
73 $StringForAjax .= "</table></div>";
74 echo text(strlen($_POST['insurance_text_ajax'])) . '~`~`' . $StringForAjax;
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";
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
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>
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,' ','')\" onclick=\"$StringToAppend(' ','')\">
115 <td colspan='5' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
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",
131 while ($row = sqlFetchArray($res)) {
132 if ($CountIndex %
2 == 1) {
133 $bgcolor = '#ddddff';
135 $bgcolor = '#ffdddd';
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>
155 $StringForAjax .= "</table></div>";
156 echo text(strlen($patient_code_complete)) . '~`~`' . $StringForAjax;
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";
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>
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,' ','')\" onclick=\"$StringToAppend(' ','')\">
179 <td colspan='2' align='center'><a id='anchor_insurance_code_" . attr($CountIndex) . "' href='#'></a></td>
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';
189 $bgcolor = '#ffdddd';
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>
204 $StringForAjax .= "</table></div>";