4 * import_template_ui.php
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2016-2021 Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../interface/globals.php");
17 use OpenEMR\Core\Header
;
19 $patient = (int)($_POST['sel_pt'] ??
0);
20 $patient_dir = $patient > 0 ?
convert_safe_file_dir_name($patient . "_tpls") : "";
21 $cat_dir = convert_safe_file_dir_name($_POST['doc_category']) ??
"";
23 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
24 if (!empty($patient_dir)) {
25 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $patient_dir . '/';
26 } elseif (!empty($cat_dir)) {
27 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . $cat_dir . '/';
30 $rtn = sqlStatement("SELECT `option_id`, `title`, `seq` FROM `list_options` WHERE `list_id` = ? ORDER BY `seq`", array('Document_Template_Categories'));
31 $category_list = array();
32 while ($row = sqlFetchArray($rtn)) {
33 $category_list[] = $row;
36 function getAuthUsers()
38 $response = sqlStatement("SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'");
40 while ($row = sqlFetchArray($response)) {
47 function getTemplateList($dir, $location = "")
50 if (substr($dir, -1) !== "/") {
54 if (false === $d = @dir
($dir)) {
57 while (false !== ($entry = $d->read())) {
58 if ($entry[0] === "." ||
substr($entry, -3) !== 'tpl') {
61 if (is_dir("$dir$entry")) {
65 if (is_readable("$dir$entry")) {
67 'pathname' => "$dir$entry",
69 'size' => filesize("$dir$entry"),
70 'lastmod' => filemtime("$dir$entry"),
71 'location' => text("./documents/onsite_portal_documents/templates/" . $location)
84 <meta charset
="UTF-8">
85 <title
><?php
echo xlt('Portal'); ?
> |
<?php
echo xlt('Templates'); ?
></title
>
86 <meta name
="description" content
="Developed By sjpadgett@gmail.com">
87 <?php Header
::setupHeader(['datetime-picker', 'summernote', 'summernote-ext-nugget']); ?
>
92 let tedit
= function (docname
) {
93 currentEdit
= docname
;
94 getDocument(docname
, 'get', '');
98 let tsave
= function () {
99 let makrup
= $
('#templatecontent').summernote('code');
100 getDocument(currentEdit
, 'save', makrup
)
102 let tdelete
= function (docname
) {
103 let delok
= confirm(<?php
echo xlj('You are about to delete template'); ?
> +
": " + docname +
"\n" +
<?php
echo xlj('Is this Okay?'); ?
>);
104 if (delok
=== true) {
105 getDocument(docname
, 'delete', '')
110 function getDocument(docname
, mode
, content
) {
111 let liburl
= 'import_template.php';
115 data
: {docid
: docname
, mode
: mode
, content
: content
},
116 beforeSend
: function (xhr
) {
117 console
.log("Please wait..." + content
);
119 error
: function (qXHR
, textStatus
, errorThrow
) {
120 console
.log("There was an error");
121 alert(<?php
echo xlj("File Error") ?
> +
"\n" + docname
)
123 success
: function (templateHtml
, textStatus
, jqXHR
) {
125 let editHtml
= '<div class="edittpl" id="templatecontent"></div>';
126 dlgopen('', 'popeditor', 'modal-full', 850, '', '', {
128 {text
: <?php
echo xlj('Save'); ?
>, close
: false, style
: 'success btn-sm', click
: tsave
},
129 {text
: <?php
echo xlj('Dismiss'); ?
>, style
: 'danger btn-sm', close
: true}
138 $
('#templatecontent').summernote('destroy');
139 $
('#templatecontent').empty().append(templateHtml
);
140 $
('#templatecontent').summernote({
144 ['style', ['bold', 'italic', 'underline', 'clear']],
145 ['fontsize', ['fontsize']],
146 ['color', ['color']],
147 ['para', ['ul', 'ol', 'paragraph']],
148 ['insert', ['link', 'picture', 'video', 'hr']],
149 ['view', ['fullscreen', 'codeview']],
150 ['insert', ['nugget']],
151 ['edit', ['undo', 'redo']]
155 '{ParseAsHTML}', '{TextInput}', '{sizedTextInput:120px}', '{smTextInput}', '{TextBox:03x080}', '{DatePicker}', '{CheckMark}', '{ynRadioGroup}', '{TrueFalseRadioGroup}', '{DateTimePicker}', '{StandardDatePicker}', '{DOS}', '{ReferringDOC}', '{PatientID}', '{PatientName}', '{PatientSex}', '{PatientDOB}', '{PatientPhone}', '{Address}', '{City}', '{State}', '{Zip}', '{PatientSignature}', '{AdminSignature}', '{Medications}', '{ProblemList}', '{Allergies}', '{ChiefComplaint}', '{EncounterForm:LBF}', '{DEM: }', '{HIS: }', '{LBF: }', '{GRP}{/GRP}'
158 tooltip
: 'Select Directive to insert at current cursor position.'
162 } else if (mode
=== 'save') {
163 $
('#templatecontent').summernote('destroy');
165 } else if (mode
=== 'delete') {
173 .modal
.modal
-wide
.modal
-dialog
{
177 .modal
-wide
.modal
-body
{
181 <body
class="body-top">
182 <div
class='container'>
183 <h3
><?php
echo xlt('Patient Document Template Maintenance'); ?
></h3
>
185 <div
class="jumbotron jumbotron-fluid p-1 text-center">
187 <?php
echo xlt('Select a text or html template and upload for selected patient or all portal patients.'); ?
><br
/><?php
echo xlt('Files base name becomes a pending document selection in Portal Documents.'); ?
><br
/>
188 <em
><?php
echo xlt('For example: Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents.'); ?
></em
>
191 <form id
="form_upload" class="form-inline" action
="import_template.php" method
="post" enctype
="multipart/form-data">
192 <div
class="form-group">
193 <div
class="btn-group">
194 <input
class="btn btn-outline-info" type
="file" name
="tplFile">
195 <button
class="btn btn-outline-primary" type
="submit" name
="upload_submit" id
="upload_submit"><?php
echo xlt('Uploading For'); ?
> <label id
='ptstatus'></label
></button
>
197 <button
class="btn btn-success ml-2" type
="button" onclick
="location.href='./patient/provider'"><?php
echo xlt('Dashboard'); ?
></button
>
199 <input type
='hidden' name
="up_dir" value
='<?php global $patient_dir;
200 echo $patient_dir; ?>' />
201 <input type
='hidden' name
="doc_category" value
='<?php global $cat_dir;
202 echo $cat_dir; ?>' />
206 <h4
><?php
echo xlt('Active Templates'); ?
></h4
>
207 <div
class='col col-md col-lg'>
208 <form id
="edit_form" name
="edit_form" class="form-inline mb-2" action
="" method
="post">
209 <div
class="form-group">
210 <label
class="label mx-1" for="doc_category"><?php
echo xlt('Category'); ?
></label
>
211 <select
class="form-control" id
="doc_category" name
="doc_category">
212 <option value
=""><?php
echo xlt('General'); ?
></option
>
214 foreach ($category_list as $dir) {
215 if ($cat_dir == $dir['option_id']) {
216 echo "<option value='" . text($dir['option_id']) . "' selected>" . text($dir['title']) . "</option>\n";
218 echo "<option value='" . text($dir['option_id']) . "'>" . text($dir['title']) . "</option>\n";
223 <label
class="label mx-1" for="sel_pt"><?php
echo xlt('Patient'); ?
></label
>
224 <select
class="form-control" id
="sel_pt" name
="sel_pt">
225 <option value
='0'><?php
echo xlt("All Patients") ?
></option
>
227 $ppt = getAuthUsers();
229 foreach ($ppt as $pt) {
230 if ($patient_dir != $pt['pid'] . "_tpls") {
231 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
233 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
239 <button type
="submit" class="btn btn-secondary"><?php
echo xlt('Refresh'); ?
></button
>
244 $show_cat_flag = false;
245 if (!empty($cat_dir)) {
246 $dir_list['general'] = getTemplateList($tdir);
248 $dir_list['general'] = getTemplateList($tdir);
249 foreach ($category_list as $cat) {
250 if (!empty($cat_dir) && $cat_dir != $cat['option_id']) {
253 if ($cat_dir_iter = getTemplateList(($tdir . $cat['option_id']), $cat['option_id'])) {
254 $dir_list[$cat['title']] = $cat_dir_iter;
258 echo "<table class='table table-sm table-striped table-bordered'>\n";
261 "<th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th>" .
262 "<th>" . xlt("Category") . "</th><th>" . xlt("Location") . "</th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th>" .
266 foreach ($dir_list as $cat => $files) {
267 foreach ($files as $file) {
268 $t = $file['pathname'];
270 echo '<button id="tedit' . attr($t) .
271 '" class="btn btn-sm btn-outline-primary" onclick="tedit(' . attr_js($t) . ')" type="button">' . text($file['name']) . '</button>' .
272 '<button id="tdelete' . attr($t) .
273 '" class="btn btn-sm btn-outline-danger" onclick="tdelete(' . attr_js($t) . ')" type="button">' . xlt("Delete") . '</button>';
274 echo "</td><td>" . text(ucwords($cat)) . "</td>";
275 echo "<td>" . text($file['location']) . "</td>";
276 echo "<td>" . text($file['size']) . "</td>";
277 echo "<td>" . text(date('r', $file['lastmod'])) . "</td>";
288 $
("#sel_pt").change(function () {
289 if (checkCategory()) {
290 $
("#edit_form").submit();
294 $
("#doc_category").change(function () {
295 if (checkCategory()) {
296 $
("#edit_form").submit();
300 $
("#ptstatus").text($
("#sel_pt").find(":selected").text());
301 $
("#ptstatus").append(' ' +
xl("to Category") +
' ');
302 $
("#ptstatus").append($
("#doc_category").find(":selected").text());
304 function checkCategory() {
305 let cat
= $
("#doc_category").val();
306 let patient
= $
("#sel_pt").val();
307 if (patient
!== "0" && cat
!== "") {
308 alert(xl("Alert! Can only use the General category with patients."));
309 $
("#doc_category").val("");