Feat openemr fix 7480 7494 email prescription (#7495)
[openemr.git] / library / custom_template / custom_template.php
blob7a90e35f05b09f27083f9d0da917935935abe129
1 <?php
3 // +-----------------------------------------------------------------------------+
4 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
5 //
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
19 // A copy of the GNU General Public License is included along with this program:
20 // openemr/interface/login/GnuGPL.html
21 // For more information write to the Free Software
22 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 // Author: Eldho Chacko <eldho@zhservices.com>
25 // Jacob T Paul <jacob@zhservices.com>
26 // Jerry Padgett <sjpadgett@gmail.com> 2019-2021
28 // +------------------------------------------------------------------------------+
30 require_once("../../interface/globals.php");
31 require_once("$srcdir/lists.inc.php");
32 require_once("$srcdir/user.inc.php");
34 use OpenEMR\Core\Header;
35 use OpenEMR\Common\Csrf\CsrfUtils;
37 // mdsupport : li code
38 function listitemCode($strDisp, $strInsert, $ref = '')
40 if ($strInsert) {
41 if (!empty($ref)) {
42 $id = text($ref);
43 $ref = " {|$id|}";
45 echo '<li><a href="#" onclick="top.restoreSession();CKEDITOR.instances.textarea1.insertText(' .
46 "'" . text($strInsert) . $ref . "'" . ');">' . text($strDisp) . '</a></li>';
50 $allowTemplateWarning = checkUserSetting('disable_template_warning', '1') === true ? 0 : 1;
51 $contextName = !empty($_GET['contextName']) ? $_GET['contextName'] : '';
52 $type = $_GET['type'] ?? '';
53 $cc_flag = $_GET['ccFlag'] ?? '';
55 $isNN = empty($cc_flag) ? 1 : 0;
56 if (empty($isNN)) {
57 $contextName = empty($contextName) ? "Encounters" : $contextName;
59 // either NN context from layout or text template default.
60 $rowContext = sqlQuery("SELECT * FROM customlists WHERE cl_list_type = 2 AND cl_list_item_long = ?", array($contextName));
61 if (empty($isNN) && empty($rowContext)) {
62 $contextName .= " <small><em>(" . xlt("Add Missing Context Template.") . ")</em></small>";
65 <html>
66 <head>
67 <style>
68 .draggable {
69 cursor: pointer !important;
71 .is-dragging {
72 cursor: move !important;
74 </style>
75 <?php Header::setupHeader(['common', 'opener', 'select2', 'ckeditor']); ?>
76 <script src="<?php echo $GLOBALS['webroot'] ?>/library/js/ajax_functions_writer.js"></script>
78 <script>
79 let allowTemplateWarning = <?php echo $allowTemplateWarning; ?>;
80 <?php if (!$isNN) { ?>
81 $(function () {
82 $('#contextSearch').select2({
83 placeholder: <?php echo xlj('Select Template Context'); ?>,
84 width: 'resolve',
85 theme: 'bootstrap4',
86 ajax: {
87 url: top.webroot_url + '/library/ajax/template_context_search.php',
88 data: function (params) {
89 let query = {
90 search: params.term,
91 csrf_token_form: <?php echo js_escape(CsrfUtils::collectCsrfToken()); ?>
93 return query;
95 dataType: 'json',
97 <?php require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?>
98 });
100 $('#contextSearch').on('select2:select', function (e) {
101 let data = e.params.data;
102 top.restoreSession();
103 $("#contextName").val(data.text);
104 $("#mainForm").submit();
107 <?php } ?>
109 function refreshme() {
110 top.restoreSession();
111 document.location.reload();
114 CKEDITOR.config.customConfig = top.webroot_url + '/library/js/nncustom_config.js';
116 $(function () {
117 tabbify();
119 $(".iframe_small").on('click', function (e) {
120 e.preventDefault();
121 e.stopPropagation();
122 dlgopen('', '', 330, 120, '', '', {
123 buttons: [
124 {text: '<?php echo xla('Close'); ?>', close: true, style: 'secondary btn-sm'}
126 onClosed: 'refreshme',
127 type: 'iframe',
128 url: $(this).attr('href')
132 $(".iframe_medium").on('click', function (e) {
133 e.preventDefault();
134 e.stopPropagation();
135 dlgopen('', '', 725, 575, '', '', {
136 buttons: [
137 {text: '<?php echo xla('Close'); ?>', close: true, style: 'secondary btn-sm'}
139 onClosed: 'refreshme',
140 type: 'iframe',
141 url: $(this).attr('href')
145 $(".iframe_abvmedium").on('click', function (e) {
146 e.preventDefault();
147 e.stopPropagation();
148 dlgopen('', '', 700, 500, '', '', {
149 buttons: [
150 {text: '<?php echo xla('Close'); ?>', close: true, style: 'secondary btn-sm'}
152 onClosed: 'refreshme',
153 type: 'iframe',
154 url: $(this).attr('href')
158 $("#menu5 > li > a.expanded + ul").slideToggle("medium");
159 $("#menu5 > li > a").click(function () {
160 $("#menu5 > li > a.expanded").not(this).toggleClass("expanded").toggleClass("collapsed").parent().find('> ul').slideToggle("medium");
161 $(this).toggleClass("expanded").toggleClass("collapsed").parent().find('> ul').slideToggle("medium");
164 </script>
165 <script>
166 $(function () {
167 function sortableCallback(elem){
168 let clorder = [];
169 for (let i=0; i< elem.length; i++) {
170 let ele = elem[i];
171 if(ele.tagName == "DIV"){
172 clorder.push("clorder[]="+ele.firstElementChild.id.split("_")[1]);
175 $.post("updateDB.php", clorder.join('&')+"&action=updateRecordsListings");
177 oeSortable(sortableCallback);
179 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
180 </script>
181 </head>
182 <body class="body_top">
183 <div class="container-fluid">
184 <input type="hidden" name="list_id" id="list_id" value="<?php echo $rowContext['cl_list_id'] ?? ''; ?>" />
185 <?php if (($rowContext['cl_list_item_long'] ?? null) || !$isNN) { ?>
186 <!-- don't escape $contextName it's html -->
187 <h3 class="text-center"><?php echo (text($rowContext['cl_list_item_long'] ?? '')) ?: $contextName; ?></h3>
188 <div id="tab1" class="tabset_content tabset_content_active">
189 <form id="mainForm">
190 <input type="hidden" name="type" id="type" value="<?php echo attr($type); ?>" />
191 <input type="hidden" name="ccFlag" id="type" value="<?php echo attr($cc_flag); ?>" />
192 <input type="hidden" name="contextName" id="contextName" value="<?php echo attr($contextName); ?>" />
193 <div class="row">
194 <div class="col-md-12">
195 <?php if (!$isNN) { ?>
196 <div id="searchCriteria">
197 <div class="select-box form-inline mb-1">
198 <label for="contextId"><?php echo xlt('Context') . ':'; ?></label>
199 <select id="contextSearch" name="contextId" class="form-control form-control-sm w-50">
200 <option value=""></option>
201 </select>
202 </div>
203 </div>
204 <?php } ?>
205 </div>
206 <div class="col-md-4 text mb-2" id="templateDD">
207 <select class="form-control form-control-sm" name="template" id="template" onchange="TemplateSentence(this.value)">
208 <option value=""><?php echo htmlspecialchars(xl('Select category'), ENT_QUOTES); ?></option>
209 <?php
210 $resTemplates = sqlStatement("SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE tu.tu_user_id=? AND c.cl_list_type=3 AND cl_list_id=? AND cl_deleted=0 ORDER BY c.cl_list_item_long", array($_SESSION['authUserID'], ($rowContext['cl_list_id'] ?? null)));
211 while ($rowTemplates = sqlFetchArray($resTemplates)) {
212 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'], ENT_QUOTES) . "'>" . htmlspecialchars(xl($rowTemplates['cl_list_item_long']), ENT_QUOTES) . "</option>";
215 </select>
216 </div>
217 <div class="col-md-8 text mb-1">
218 <div id="share" style="display:none"></div>
219 <!-- Enter Key !-->
220 <a href="#" id="enter" onclick="top.restoreSession();ascii_write('13','textarea1');" title="<?php echo htmlspecialchars(xl('Enter Key'), ENT_QUOTES); ?>"><i class="fas fa-sign-in-alt"></i></a>&nbsp;
221 <!-- Question Mark !-->
222 <a href="#" id="quest" onclick="top.restoreSession();CKEDITOR.instances.textarea1.insertText('? ');" title="<?php echo htmlspecialchars(xl('Question Mark'), ENT_QUOTES); ?>"><i class="fas fa-question-circle"></i></a>&nbsp;
223 <!-- Paragraph !-->
224 <a href="#" id="para" onclick="top.restoreSession();ascii_write('para','textarea1');" title="<?php echo htmlspecialchars(xl('New Paragraph'), ENT_QUOTES); ?>"><i class="fas fa-paragraph"></i></a>&nbsp;
225 <!-- Space !-->
226 <a href="#" id="space" onclick="top.restoreSession();ascii_write('32','textarea1');" class="btn btn-primary btn-sm" title="<?php echo htmlspecialchars(xl('Space'), ENT_QUOTES); ?>"><?php echo htmlspecialchars(xl('Space'), ENT_QUOTES); ?></a>
227 <?php
228 $res = sqlStatement("SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS cl ON cl.cl_list_slno = tu.tu_template_id WHERE tu.tu_user_id = ? AND cl.cl_list_type = 6 AND cl.cl_deleted = 0 ORDER BY cl.cl_order", array($_SESSION['authUserID']));
229 while ($row = sqlFetchArray($res)) { ?>
230 <a href="#" onclick="top.restoreSession();CKEDITOR.instances.textarea1.insertText('<?php echo $row['cl_list_item_short']; ?>');" class="btn btn-primary" title="<?php echo htmlspecialchars(xl($row['cl_list_item_long']), ENT_QUOTES); ?>"><?php echo ucfirst(htmlspecialchars(xl($row['cl_list_item_long']), ENT_QUOTES)); ?></a>
231 <?php } ?>
232 <a class="btn btn-primary btn-sm btn-transmit float-right" href="#" onclick="return SelectToSave(<?php echo attr_js($type); ?>, <?php echo attr_js($cc_flag); ?>)"><?php echo xlt('Insert in Form'); ?></a>
233 </div>
234 <div class="col-md-4">
235 <div class="bg-light">
236 <div style="overflow-y: scroll; overflow-x: hidden; height: 400px">
237 <ul id="menu5" class="example_menu w-100">
238 <li>
239 <a class="expanded"><?php echo htmlspecialchars(xl('Components'), ENT_QUOTES); ?></a>
240 <ul>
241 <div id="template_sentence"></div>
242 </ul>
243 </li>
244 <?php
245 if ($pid != '') {
246 $row = sqlQuery("SELECT p.*, IF(ISNULL(p.providerID), NULL, CONCAT(u.lname,',',u.fname)) pcp " .
247 "FROM patient_data p LEFT OUTER JOIN users u " .
248 "ON u.id=p.providerID WHERE pid=?", array($pid));
250 <li>
251 <a class="collapsed"><?php echo htmlspecialchars(xl('Patient Details'), ENT_QUOTES); ?></a>
252 <ul>
253 <?php
254 listitemCode(xl('First name'), $row['fname']);
255 listitemCode(xl('Last name'), $row['lname']);
256 listitemCode(xl('Phone'), $row['phone_home']);
257 listitemCode(xl('SSN'), $row['ss']);
258 listitemCode(xl('Date Of Birth'), $row['DOB']);
259 listitemCode(xl('PCP'), $row['pcp']);
261 </ul>
262 </li>
263 <?php
264 foreach ($ISSUE_TYPES as $issType => $issTypeDesc) {
265 $res = sqlStatement('SELECT title, id, IF(diagnosis="","",CONCAT(" [",diagnosis,"]")) codes FROM lists WHERE pid=? AND type=? AND enddate IS NULL ORDER BY title', array($pid, $issType));
266 if (sqlNumRows($res)) { ?>
267 <li>
268 <a class="collapsed"><?php echo htmlspecialchars(xl($issTypeDesc[0]), ENT_QUOTES); ?></a>
269 <ul>
270 <?php
271 while ($row = sqlFetchArray($res)) {
272 if (!empty($isNN)) {
273 $row['id'] = "";
275 listitemCode((strlen($row['title']) > 20) ? (substr($row['title'], 0, 18) . '..') : $row['title'], ($row['title'] . $row['codes']), $row['id']);
278 </ul>
279 </li>
280 <?php }
282 } ?>
283 </ul>
284 </div>
285 </div>
286 <a href="personalize.php?list_id=<?php echo $rowContext['cl_list_id'] ?? ''; ?>" id="personalize_link" class="iframe_medium btn btn-primary btn-sm"><?php echo htmlspecialchars(xl('Personalize'), ENT_QUOTES); ?></a>
287 <a href="add_custombutton.php" id="custombutton" class="iframe_medium btn btn-primary btn-sm" title="<?php echo htmlspecialchars(xl('Add Buttons for Special Chars,Texts to be Displayed on Top of the Editor for inclusion to the text on a Click'), ENT_QUOTES); ?>"><?php echo htmlspecialchars(xl('Add Buttons'), ENT_QUOTES); ?></a>
288 </div>
289 <div class="col-md-8">
290 <textarea class="ckeditor" cols="100" rows="180" id="textarea1" name="textarea1"></textarea>
291 <span class="float-right my-1"><a href="#" onclick="return SelectToSave(<?php echo attr_js($type); ?>, <?php echo attr_js($cc_flag); ?>)" class="btn btn-primary btn-sm btn-save float-right"><?php echo xlt('Insert in Form'); ?></a></span>
292 </div>
293 </div>
294 </form>
295 </div>
296 <?php
297 } else {
298 echo htmlspecialchars(xl('NO SUCH CONTEXT NAME') . $contextName, ENT_QUOTES);
299 exit();
302 <table>
303 <script>
304 <?php if (!$isNN) { ?>
305 CKEDITOR.on('instanceReady', function(){$("#cke_1_toolbar_collapser").click();});
306 <?php } ?>
307 $(function () {
308 edit(<?php echo js_escape($type); ?>, <?php echo js_escape($cc_flag); ?>);
310 <?php if ($allowTemplateWarning && !$isNN) { ?>
311 // teeheehee
312 let msg = xl("These templates are text only and will not render any other formatting other than pure text.") + " ";
313 msg += xl("You may still use formatting if template is also used in Nation Notes however, pure text will still render here.") +
314 "<br /><br />";
315 msg += xl("Click Got it icon to dismiss this alert forever.");
316 alertMsg(msg, 10000, 'danger', 'lg', 'disable_template_warning');
317 <?php } ?>
318 </script>
319 </table>
320 </div>
321 </body>
322 </html>