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-2020 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 $getdir = isset($_POST['sel_pt']) ?
$_POST['sel_pt'] : 0;
21 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/' . convert_safe_file_dir_name($getdir) . '/';
23 if (!mkdir($tdir, 0755, true) && !is_dir($tdir)) {
24 die(xl('Failed to create folder'));
28 $tdir = $GLOBALS['OE_SITE_DIR'] . '/documents/onsite_portal_documents/templates/';
31 function getAuthUsers()
33 $response = sqlStatement("SELECT patient_data.pid, Concat_Ws(' ', patient_data.fname, patient_data.lname) as ptname FROM patient_data WHERE allow_patient_portal = 'YES'");
35 while ($row = sqlFetchArray($response)) {
42 function getTemplateList($dir)
45 if (substr($dir, -1) !== "/") {
49 $d = @dir
($dir) or die("File List: Failed opening directory " . text($dir) . " for reading");
50 while (false !== ($entry = $d->read())) {
51 if ($entry[0] === "." ||
substr($entry, -3) !== 'tpl') {
55 if (is_dir("$dir$entry")) {
57 'pathname' => "$dir$entry",
60 'lastmod' => filemtime("$dir$entry")
62 } elseif (is_readable("$dir$entry")) {
64 'pathname' => "$dir$entry",
66 'size' => filesize("$dir$entry"),
67 'lastmod' => filemtime("$dir$entry")
80 <meta charset
="UTF-8">
81 <title
><?php
echo xlt('Portal'); ?
> |
<?php
echo xlt('Templates'); ?
></title
>
82 <meta name
="description" content
="Developed By sjpadgett@gmail.com">
83 <?php Header
::setupHeader(['no_main-theme', 'datetime-picker', 'summernote', 'summernote-ext-nugget', 'patientportal-style']); ?
>
88 let tedit
= function (docname
) {
89 currentEdit
= docname
;
90 getDocument(docname
, 'get', '');
94 let tsave
= function () {
95 let makrup
= $
('#templatecontent').summernote('code');
96 getDocument(currentEdit
, 'save', makrup
)
98 let tdelete
= function (docname
) {
99 let delok
= confirm(<?php
echo xlj('You are about to delete template'); ?
> +
": " + docname +
"\n" +
<?php
echo xlj('Is this Okay?'); ?
>);
100 if (delok
=== true) {
101 getDocument(docname
, 'delete', '')
106 function getDocument(docname
, mode
, content
) {
107 let liburl
= 'import_template.php';
111 data
: {docid
: docname
, mode
: mode
, content
: content
},
112 beforeSend
: function (xhr
) {
113 console
.log("Please wait..." + content
);
115 error
: function (qXHR
, textStatus
, errorThrow
) {
116 console
.log("There was an error");
117 alert(<?php
echo xlj("File Error") ?
> +
"\n" + docname
)
119 success
: function (templateHtml
, textStatus
, jqXHR
) {
121 let editHtml
= '<div class="edittpl" id="templatecontent"></div>';
122 dlgopen('','popeditor','modal-full', 850,'', '', {
124 {text
: <?php
echo xlj('Save'); ?
>, close
: false, style
: 'success btn-sm', click
: tsave
},
125 {text
: <?php
echo xlj('Dismiss'); ?
>, style
: 'danger btn-sm', close
: true}
134 $
('#templatecontent').summernote('destroy');
135 $
('#templatecontent').empty().append(templateHtml
);
136 $
('#templatecontent').summernote({
140 ['style', ['bold', 'italic', 'underline', 'clear']],
141 ['fontsize', ['fontsize']],
142 ['color', ['color']],
143 ['para', ['ul', 'ol', 'paragraph']],
144 ['insert', ['link', 'picture', 'video', 'hr']],
145 ['view', ['fullscreen', 'codeview']],
146 ['insert', ['nugget']],
147 ['edit', ['undo', 'redo']]
151 '{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}'
154 tooltip
: 'Select Directive to insert at current cursor position.'
158 } else if (mode
=== 'save') {
159 $
('#templatecontent').summernote('destroy');
161 } else if (mode
=== 'delete') {
169 .modal
.modal
-wide
.modal
-dialog
{
173 .modal
-wide
.modal
-body
{
177 <body
class="body-top">
178 <div
class='container'>
179 <h3
><?php
echo xlt('Patient Document Template Maintenance'); ?
></h3
>
181 <div
class="jumbotron jumbotron-fluid p-1 text-center">
183 <?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
/>
184 <em
><?php
echo xlt('For example: Privacy_Agreement.txt becomes Privacy Agreement button in Patient Documents.'); ?
></em
>
187 <form id
="form_upload" class="form" action
="import_template.php" method
="post" enctype
="multipart/form-data">
188 <div
class="btn-group my-2">
189 <input
class="btn btn-outline-info" type
="file" name
="tplFile">
190 <button
class="btn btn-outline-primary" type
="submit" name
="upload_submit" id
="upload_submit"><?php
echo xlt('Upload For'); ?
> <span
class="badge badge-warning" id
='ptstatus'></span
></button
>
191 <button
class="btn btn-success" type
="button" onclick
="location.href='./patient/provider'"><?php
echo xlt('Dashboard'); ?
></button
>
193 <input type
='hidden' name
="up_dir" value
='<?php global $getdir;
198 <h4
><?php
echo xlt('Active Templates'); ?
></h4
>
199 <div
class='col col-md col-lg'>
200 <form id
="edit_form" name
="edit_form" class="form-inline" action
="" method
="post">
201 <div
class="form-group">
202 <label
for="sel_pt"><?php
echo xlt('Patient'); ?
></label
>
203 <select
class="form-control" id
="sel_pt" name
="sel_pt">
204 <option value
='0'><?php
echo xlt("Global All Patients") ?
></option
>
206 $ppt = getAuthUsers();
208 foreach ($ppt as $pt) {
209 if ($getdir != $pt['pid']) {
210 echo "<option value=" . attr($pt['pid']) . ">" . text($pt['ptname']) . "</option>";
212 echo "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname']) . "</option>";
217 <button type
="submit" class="btn btn-secondary"><?php
echo xlt('Refresh'); ?
></button
>
221 $dirlist = getTemplateList($tdir);
222 echo "<table class='table table-responsive-sm table-striped table-bordered'>";
224 echo "<tr><th>" . xlt("Template") . " - <i>" . xlt("Click to edit") . "</i></th><th>" . xlt("Size") . "</th><th>" . xlt("Last Modified") . "</th></tr>";
227 foreach ($dirlist as $file) {
228 $t = $file['pathname'];
230 echo '<button id="tedit' . attr($t) .
231 '" class="btn btn-sm btn-outline-primary" onclick="tedit(' . attr_js($t) . ')" type="button">' . text($file['name']) . '</button>' .
232 '<button id="tdelete' . attr($t) .
233 '" class="btn btn-sm btn-outline-danger" onclick="tdelete(' . attr_js($t) . ')" type="button">' . xlt("Delete") . '</button>';
234 echo "</td><td>" . text($file['size']) . "</td>";
235 echo "<td>" . text(date('r', $file['lastmod'])) . "</td>";
244 $
("#sel_pt").change(function () {
245 $
("#edit_form").submit();
247 $
("#ptstatus").text($
("#sel_pt").find(":selected").text())