5 * For DataTables documentation see: http://legacy.datatables.net/
8 * @link http://www.open-emr.org
9 * @author Thomas Pantelis <tompantelis@gmail.com>
10 * @copyright Copyright (c) 2020 Thomas Pantelis <tompantelis@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once('../../globals.php');
15 require_once($GLOBALS['srcdir'] . '/patient.inc.php');
16 require_once($GLOBALS['srcdir'] . '/csv_like_join.php');
17 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
19 use OpenEMR\Common\Csrf\CsrfUtils
;
20 use OpenEMR\Core\Header
;
22 $codetype = empty($_GET['codetype']) ?
'' : $_GET['codetype'];
23 if (!empty($codetype)) {
24 $allowed_codes = split_csv_line($codetype);
31 <title
><?php
echo xlt('Select Codes'); ?
></title
>
33 <?php Header
::setupHeader(['opener', 'datatables', 'datatables-bs', 'datatables-colreorder']); ?
>
39 // Keeps track of which items have been selected during this session.
40 var oSelectedIDs
= {};
43 // Initializing the DataTable.
44 oTable
= $
('#my_data_table').dataTable({
47 // Next 2 lines invoke server side processing
49 "sAjaxSource": "find_code_dynamic_ajax.php?csrf_token_form=" +
<?php
echo js_url(CsrfUtils
::collectCsrfToken()); ?
>,
51 // Vertical length options and their default
52 "aLengthMenu": [15, 25, 50, 100],
55 // Specify a width for the first column.
56 "aoColumns": [{"sWidth": "10%"}, null],
58 // This callback function passes some form data on each call to the ajax handler.
59 "fnServerParams": function (aoData
) {
60 aoData
.push({"name": "what", "value": <?php
echo js_escape('codes'); ?
>});
61 aoData
.push({"name": "codetype", "value": document
.forms
[0].form_code_type
.value
});
62 aoData
.push({"name": "inactive", "value": (document
.forms
[0].form_include_inactive
.checked ?
1 : 0)});
65 // Drawing a row, apply styling if it is previously selected.
66 "fnCreatedRow": function (nRow
, aData
, iDataIndex
) {
67 showRowSelection(nRow
)
70 // Language strings are included so we can translate them
72 "sSearch": <?php
echo xlj('Search for'); ?
> +
":",
73 "sLengthMenu": <?php
echo xlj('Show'); ?
> +
" _MENU_ " +
<?php
echo xlj('entries'); ?
>,
74 "sZeroRecords": <?php
echo xlj('No matching records found'); ?
>,
75 "sInfo": <?php
echo xlj('Showing'); ?
> +
" _START_ " +
<?php
echo xlj('to{{range}}'); ?
> +
" _END_ " +
<?php
echo xlj('of'); ?
> +
" _TOTAL_ " +
<?php
echo xlj('entries'); ?
>,
76 "sInfoEmpty": <?php
echo xlj('Nothing to show'); ?
>,
77 "sInfoFiltered": "(" +
<?php
echo xlj('filtered from'); ?
> +
" _MAX_ " +
<?php
echo xlj('total entries'); ?
> +
")",
79 "sFirst": <?php
echo xlj('First'); ?
>,
80 "sPrevious": <?php
echo xlj('Previous'); ?
>,
81 "sNext": <?php
echo xlj('Next'); ?
>,
82 "sLast": <?php
echo xlj('Last'); ?
>
85 initComplete
: function () {
86 const input
= $
('.dataTables_filter input').unbind(),
88 $searchButton = $
('<button class="btn btn-sm btn-outline-primary fa fa-search p-2">').click(function () {
89 event
.preventDefault();
90 event
.stopPropagation();
91 self
.search(input
.val()).draw();
93 $clearButton = $
('<button type="button" class="btn btn-sm btn-outline-warning fa-solid fa-eraser p-2">')
97 $
('.dataTables_filter').append($searchButton, $clearButton);
101 // OnClick handler for the rows
102 oTable
.on('click', 'tbody tr', function () {
103 oSelectedIDs
[this
.id
] = oSelectedIDs
[this
.id
] ?
0 : 1;
104 showRowSelection(this
)
107 // onmouseover handler for rows
108 oTable
.on('mouseover', 'tr', function () {
113 function showRowSelection(row
) {
114 row
.style
.fontWeight
= oSelectedIDs
[row
.id
] ?
'bold' : 'normal';
117 function showCursor(row
) {
118 row
.style
.cursor
= "pointer";
122 if (opener
.closed ||
!opener
.OnCodeSelected
) {
123 alert(<?php
echo xlj('The destination form was closed.'); ?
>);
125 var ids
= Object.keys(oSelectedIDs
)
126 for (i
= 0; i
< ids
.length
; i++
) {
127 if (!oSelectedIDs
[ids
[i
]]) {
131 // Row ids are of the form "CID|jsonstring".
132 var jobj
= JSON
.parse(ids
[i
].substring(4));
133 var code
= jobj
['code'].toString().split('|');
134 var msg
= opener
.OnCodeSelected(jobj
['codetype'], code
[0], code
[1], jobj
['description']);
149 <body id
="codes_search">
150 <div
class="container-fluid">
151 <form method
='post' name
='theform'>
153 echo "<div class='form-group row mb-3'>\n";
154 if (isset($allowed_codes)) {
155 if (count($allowed_codes) == 1) {
156 echo "<div class='col'><input type='text' name='form_code_type' value='" . attr($codetype) . "' size='5' readonly /></div>\n";
158 echo "<div class='col'><select name='form_code_type' onchange='oTable.fnDraw()'>\n";
159 foreach ($allowed_codes as $code) {
160 echo " <option value='" . attr($code) . "'>" . xlt($code_types[$code]['label']) . "</option>\n";
162 echo "</select></div>\n";
165 echo "<div class='col'><select class='form-control' name='form_code_type' onchange='oTable.fnDraw()'>\n";
166 foreach ($code_types as $key => $value) {
167 echo " <option value='" . attr($key) . "'";
168 echo ">" . xlt($value['label']) . "</option>\n";
170 echo " <option value='PROD'";
171 echo ">" . xlt("Product") . "</option>\n";
172 echo " </select></div>\n";
175 echo "<div class='col'>";
176 echo "<input type='checkbox' name='form_include_inactive' value='1' onclick='oTable.fnDraw()' />" . xlt('Include Inactive') . "\n";
178 echo "<button class='btn btn-secondary btn-sm btn-save' value='" . xla('OK') . "' onclick='onOK()'>" . xla('Ok') . "</button>\n";
180 echo "<button class='btn btn-secondary btn-sm btn-cancel' value='" . xla('Cancel') . "' onclick='dlgclose()'>" . xla('Cancel') . "</button>\n";
186 <!-- Exception here
: Do not
use table
-responsive
as it breaks datatables
!-->
187 <table id
="my_data_table" class="table table-sm">
190 <th
><?php
echo xlt('Code'); ?
></th
>
191 <th
><?php
echo xlt('Description'); ?
></th
>
196 <!-- Class "dataTables_empty" is defined in jquery
.dataTables
.css
-->
197 <td colspan
="2" class="dataTables_empty">...</td
>