php8.1 fixes (#5676)
[openemr.git] / portal / import_template_ui.php
blobc07f5a9bf97354d795ba95e35e560c136a14d1ee
1 <?php
3 /**
4 * import_template_ui.php
6 * @package OpenEMR
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-2022 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\Common\Acl\AclMain;
18 use OpenEMR\Common\Csrf\CsrfUtils;
19 use OpenEMR\Core\Header;
20 use OpenEMR\Services\DocumentTemplates\DocumentTemplateService;
22 if (!(isset($GLOBALS['portal_onsite_two_enable'])) || !($GLOBALS['portal_onsite_two_enable'])) {
23 echo xlt('Patient Portal is turned off');
24 exit;
27 $authUploadTemplates = AclMain::aclCheckCore('admin', 'forms');
29 $templateService = new DocumentTemplateService();
30 $from_demo_pid = $_GET['from_demo_pid'] ?? '0';
31 $patient = $_REQUEST['selected_patients'] ?? null;
32 $patient = $patient ?: ($_REQUEST['upload_pid'] ?? 0);
34 $category = $_REQUEST['template_category'] ?? '';
35 $category_list = $templateService->fetchDefaultCategories();
36 $profile_list = $templateService->fetchDefaultProfiles();
37 $group_list = $templateService->fetchDefaultGroups();
39 $none_message = xlt("Nothing to show for current actions.");
42 <!DOCTYPE html>
43 <head>
44 <meta charset="UTF-8">
45 <title><?php echo xlt('Portal'); ?> | <?php echo xlt('Templates'); ?></title>
46 <meta name="description" content="Developed By sjpadgett@gmail.com">
47 <?php Header::setupHeader(['datetime-picker', 'select2', 'ckeditor']); ?>
48 <script>
49 const profiles = <?php echo js_escape($profile_list); ?>;
50 let currentEdit = "";
51 let editor;
52 let templateEdit = function (id, flag = '') {
53 currentEdit = id;
54 handleTemplate(id, 'get', '', flag);
55 return false;
58 let templateSave = function () {
59 let markup = CKEDITOR.instances.templateContent.getData();
60 handleTemplate(currentEdit, 'save', markup);
63 let templateDelete = function (id, template = '') {
64 let delok = confirm(<?php echo xlj('You are about to delete a template'); ?> +
65 ": " + "\n" + <?php echo xlj('Is this Okay?'); ?>);
66 if (delok === true) {
67 handleTemplate(id, 'delete', '', false, template, <?php echo js_escape(CsrfUtils::collectCsrfToken('import-template-delete')); ?>)
69 return false;
72 function getSendChecks() {
73 let checked = [];
74 $('input:checked[name=send]:checked').each(function () {
75 let isProfile = this.dataset.send_profile;
76 if (isProfile == 'yes') {
77 checked.push([$(this).val(), true]);
78 } else {
79 checked.push($(this).val());
81 });
82 console.log(checked)
83 return checked;
86 function getSendCheckProfiles() {
87 let checked = [];
88 $('input:checked[name=send_profile]:checked').each(
89 function () {
90 let isProfile = this.dataset.send_profile;
91 if (isProfile == 'yes') {
92 checked.push($(this).val());
94 });
95 console.log(checked)
96 return checked;
99 function updateCategory(id) {
100 top.restoreSession();
101 let url = 'import_template.php';
102 let category = event.currentTarget.value;
103 const data = new FormData();
104 data.append('docid', id);
105 data.append('category', category);
106 data.append('mode', 'update_category');
107 fetch(url, {
108 method: 'POST',
109 body: data,
110 }).then(rtn => rtn.text()).then((rtn) => {
111 (async (time) => {
112 await asyncAlertMsg(rtn, time, 'success', 'lg');
113 })(2000).then(rtn => {
114 //document.edit_form.submit();
116 }).catch((error) => {
117 console.error('Error:', error);
121 function sendTemplate(mode = 'send', content = '') {
122 top.restoreSession();
123 let url = 'import_template.php';
124 let ids = $('#selected_patients').select2('val');
125 let category = $('#template_category').val();
126 let checked = getSendChecks();
127 const data = new FormData();
128 data.append('docid', JSON.stringify(ids));
129 data.append('category', category);
130 data.append('checked', JSON.stringify(checked));
131 data.append('mode', mode);
132 data.append('content', content);
133 fetch(url, {
134 method: 'POST',
135 body: data,
136 }).then(rtn => rtn.text()).then((rtn) => {
137 (async (time) => {
138 await asyncAlertMsg(rtn, time, 'success', 'lg');
139 })(1500).then(rtn => {
140 document.edit_form.submit();
142 }).catch((error) => {
143 console.error('Error:', error);
147 function sendProfiles() {
148 top.restoreSession();
149 let mode = 'send_profiles'
150 let url = 'import_template.php';
151 let checked = getSendCheckProfiles();
152 const data = new FormData();
153 data.append('checked', JSON.stringify(checked));
154 data.append('mode', mode);
155 fetch(url, {
156 method: 'POST',
157 body: data,
158 }).then(rtn => rtn.text()).then((rtn) => {
159 (async (time) => {
160 await asyncAlertMsg(rtn, time, 'success', 'lg');
161 })(1500).then(rtn => {
162 document.edit_form.submit();
164 }).catch((error) => {
165 console.error('Error:', error);
169 function handleTemplate(id, mode, content = '', isDocument = '', template = '', csrf = '') {
170 top.restoreSession();
171 let libUrl = 'import_template.php';
172 let renderUrl = 'import_template.php?mode=editor_render_html&docid=' + id;
174 if (document.getElementById('is_modal').checked && mode === 'get') {
175 dialog.popUp(renderUrl, null, 'edit' + id);
176 return false;
178 if (isDocument == true) {
179 dialog.popUp(renderUrl, null, ('edit' + id));
180 return false;
182 if (mode == 'get') {
183 renderUrl += '&dialog=true';
184 dlgopen(renderUrl, 'pop-editor', 'modal-lg', 850, '', '', {
185 /*buttons: [
186 {text: <?php echo xlj('Save'); ?>, close: false, style: 'success btn-sm', click: templateSave},
187 {text: <?php echo xlj('Dismiss'); ?>, style: 'danger btn-sm', close: true}
188 ],*/
189 resolvePromiseOn: 'show',
190 allowDrag: true,
191 allowResize: true,
192 sizeHeight: 'full',
193 //onClosed: 'reload'
196 $.ajax({
197 type: "POST",
198 url: libUrl,
199 data: {docid: id, mode: mode, content: content, template: template, csrf_token_form: csrf},
200 error: function (qXHR, textStatus, errorThrow) {
201 console.log("There was an error");
202 alert(<?php echo xlj("File Error") ?> +"\n" + id)
204 success: function (templateHtml, textStatus, jqXHR) {
205 document.edit_form.submit();
210 function popProfileDialog() {
211 top.restoreSession();
212 let url = './import_template.php?mode=render_profile';
213 dlgopen(url, 'pop-profile', 'modal-lg', 850, '', '', {
214 allowDrag: true,
215 allowResize: true,
216 sizeHeight: 'full',
220 function popPatientDialog() {
221 top.restoreSession();
222 let url = './lib/patient_groups.php';
223 dlgopen(url, 'pop-profile', 'modal-lg', 850, '', '', {
224 allowDrag: true,
225 allowResize: true,
226 sizeHeight: 'full'
230 function popGroupsDialog() {
231 let url = './lib/patient_groups.php?render_group_assignments=true';
232 dlgopen(url, 'pop-groups', 'modal-lg', 850, '', '', {
233 allowDrag: true,
234 allowResize: true,
235 sizeHeight: 'full',
239 $(function () {
240 $('.select-dropdown').removeClass('d-none');
241 $('.select-dropdown').select2({
242 multiple: true,
243 placeholder: xl('Type to search.'),
244 theme: 'bootstrap4',
245 dropdownAutoWidth: true,
246 width: 'resolve',
247 closeOnSelect: false,
248 <?php require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?>
251 $('#fetch_files').on('click touchstart', function () {
252 $(this).val('');
254 $('#fetch_files').change(function (e) {
255 $('#upload_submit').removeClass('d-none');
256 $('#upload_submit_questionnaire').removeClass('d-none');
259 $('input:checkbox[name=send]').change(function () {
260 let checked = getSendChecks();
261 if (checked.length > 0) {
262 $('#send-button').removeClass('d-none');
263 $('#category_group').addClass('d-none');
264 $('#send-profile-hide').addClass('d-none');
265 } else {
266 $('#send-button').addClass('d-none');
267 $('#category_group').removeClass('d-none');
271 $('input:checkbox[name=send_profile]').change(function () {
272 $('#send-profile-hide').removeClass('d-none');
273 $('#category_group').addClass('d-none');
274 $('input:checkbox[name=send]').addClass('d-none');
277 $('#selected_patients').on('select2:close', function () {
278 let checked = getSendChecks();
279 if (checked.length > 0) {
280 return false;
282 $('#edit_form').submit();
285 $('#upload-nav').on('hidden.bs.collapse', function () {
286 $('#upload-nav-value').val('collapse');
288 $('#upload-nav').on('show.bs.collapse', function () {
289 $('#upload-nav-value').val('show');
290 //$('#edit_form').submit();
293 $("#template_category").change(function () {
294 $('#edit_form').submit();
297 $('#template-collapse').on('show.bs.collapse', function () {
298 $('#edit_form #all_state').val('show');
300 $('#template-collapse').on('hidden.bs.collapse', function () {
301 $('#edit_form #all_state').val('collapse');
304 $('#assigned_collapse').on('show.bs.collapse', function () {
305 $('#repository-collapse').collapse('hide');
306 $('#template-collapse').collapse('hide');
307 $('#edit_form #assigned_state').val('show');
309 $('#assigned_collapse').on('hidden.bs.collapse', function () {
310 $('#edit_form #assigned_state').val('collapse');
313 $('#repository-collapse').on('show.bs.collapse', function () {
314 $('#edit_form #repository_send_state').val('show');
316 $('#repository-collapse').on('hidden.bs.collapse', function () {
317 $('#edit_form #repository_send_state').val('collapse');
320 let selText = '';
321 let selCat = $('#template_category').find(':selected').text();
322 let ids = $('#selected_patients').find(':selected').each(function () {
323 selText += $(this).text() + '; ';
325 $('#upload_scope_category').empty().append(' ' + xl('For Category') + ': ' + selCat);
326 $("#upload_scope").empty().append(xl('To Repository Location') + ': ' + xl("Repository always."));
328 $(document).on('select2:open', () => {
329 document.querySelector('.select2-search__field').focus();
332 </script>
333 <style>
334 caption {
335 caption-side: top !important;
337 </style>
338 </head>
339 <body class="body-top">
340 <div class='container-xl'>
341 <nav class='nav navbar bg-light text-dark sticky-top'>
342 <span class='title'><?php echo xlt('Template Maintenance'); ?></span>
343 <div class="ml-auto">
344 <label class="form-check"><?php echo xlt('Full Editor'); ?>
345 <input type='checkbox' class='form-check-inline mx-1' id='is_modal' name='is_modal' checked='checked' />
346 </label>
347 </div>
348 <div class='btn-group ml-1'>
349 <button type='button' class='btn btn-secondary' data-toggle='collapse' data-target='#help-panel'>
350 <?php echo xlt('Help') ?>
351 </button>
352 <button class='btn btn-success' type='button' onclick="location.href='./patient/provider'">
353 <?php echo xlt('Dashboard'); ?>
354 </button>
355 </div>
356 </nav>
357 <div class='col col-12'>
358 <hr />
359 <?php include_once('./../Documentation/help_files/template_maintenance_help.php'); ?>
360 <!-- Actions Scope to act on -->
361 <nav class='navbar navbar-dark bg-dark text-light sticky-top'>
362 <form id="edit_form" name="edit_form" class="row form-inline w-100" action="" method="get">
363 <a class='navbar-brand ml-1'><?php echo xlt('Scope'); ?></a>
364 <div class="form-group">
365 <label class='font-weight-bold mx-1' for='selected_patients'><?php echo xlt('Location'); ?></label>
366 <?PHP
367 $ppt = $templateService->fetchPortalAuthUsers();
368 $auth = '';
369 foreach ($ppt as $pt) {
370 if (!empty($from_demo_pid)) {
371 $patient = [$from_demo_pid];
373 if ((is_array($patient) && !in_array($pt['pid'], $patient)) || empty($patient)) {
374 $auth .= '<option value=' . attr($pt['pid']) . '>' . text($pt['ptname']) . '</option>';
375 } else {
376 $auth .= "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname'] . ' ') . '</option>';
380 <select class="form-control select-dropdown d-none" id="selected_patients" name="selected_patients[]" multiple="multiple">
381 <?php echo $auth ?>
382 </select>
383 <a class='btn-refresh ml-1' onclick="$('#selected_patients').val(null).trigger('change');" role="button"></a>
384 </div>
385 <?php
386 $select_cat_options = '<option value="">' . xlt('General') . "</option>\n";
387 foreach ($category_list as $option_category) {
388 if (stripos($option_category['option_id'], 'repository') !== false) {
389 continue;
391 if ($category === $option_category['option_id']) {
392 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "' selected>" . text($option_category['title']) . "</option>\n";
393 } else {
394 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
398 <div class="input-group" id="category_group">
399 <label class="font-weight-bold mx-1" for="template_category"><?php echo xlt('Category'); ?></label>
400 <select class="form-control" id="template_category" name="template_category">
401 <?php echo $select_cat_options ?>
402 </select>
403 </div>
404 <div class="form-group">
405 <div class='btn-group ml-1'>
406 <button type='submit' class='btn btn-search btn-light'><i class="btn-refresh"></i></button>
407 <button type='button' id="send-button" class='btn btn-transmit btn-success d-none' onclick="return sendTemplate()">
408 <?php echo xlt('Send'); ?>
409 </button>
410 <button class='btn btn-sm btn-primary' onclick='return popProfileDialog()'><?php echo xlt('Profiles') ?></button>
411 <button type='button' class='btn btn-primary' onclick='return popPatientDialog()'><?php echo xlt('Groups') ?></button>
412 <button type='button' class='btn btn-primary' onclick='return popGroupsDialog()'><?php echo xlt('Assign') ?></button>
413 </div>
414 </div>
415 <input type='hidden' id='upload-nav-value' name='upload-nav-value' value='<?php echo attr($_REQUEST['upload-nav-value'] ?? 'collapse') ?>' />
416 <input type='hidden' id='persist_checks' name='persist_checks' value='' />
417 <input type='hidden' id='all_state' name='all_state' value='<?php echo attr($_REQUEST['all_state'] ?? 'collapse') ?>' />
418 <input type='hidden' id='assigned_state' name='assigned_state' value='<?php echo attr($_REQUEST['assigned_state'] ?? 'collapse') ?>' />
419 <input type='hidden' id='repository_send_state' name='repository_send_state' value='<?php echo attr($_REQUEST['repository_send_state'] ?? 'collapse') ?>' />
420 </form>
421 </nav>
422 <!-- Upload -->
423 <nav class="collapse my-2 <?php echo attr($_REQUEST['upload-nav-value'] ?? '') ?>" id="upload-nav">
424 <div class='col col-12'>
425 <?php if ($authUploadTemplates) { ?>
426 <form id='form_upload' class='form-inline row' action='import_template.php' method='post' enctype='multipart/form-data'>
427 <hr />
428 <div class='col'>
429 <div id='upload_scope_category'></div>
430 <div class='mb-2' id='upload_scope'></div>
431 </div>
432 <div class='form-group col'>
433 <div class='form-group'>
434 <input type="hidden" name="csrf_token_form" id="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken('import-template-upload')); ?>" />
435 <input type='file' class='btn btn-outline-info' id="fetch_files" name='template_files[]' multiple />
436 <button class='btn btn-outline-success d-none' type='submit' name='upload_submit' id='upload_submit'><i class='fa fa-upload' aria-hidden='true' mr-1></i><?php echo xlt("Templates"); ?></button>
437 <button class='btn btn-outline-success d-none' type='submit' name='upload_submit_questionnaire' id='upload_submit_questionnaire'><i class='fa fa-upload aria-hidden='true' mr-1'></i><?php echo xlt("Questionnaires Only"); ?></button>
438 </div>
439 </div>
440 <input type='hidden' name='upload_pid' value='<?php echo attr(json_encode([-1])); ?>' />
441 <input type='hidden' name="template_category" value='<?php echo attr($category); ?>' />
442 </form>
443 <?php } else { ?>
444 <div class="alert alert-danger"><?php echo xlt("Not Authorized to Upload Templates") ?></div>
445 <?php } ?>
446 </div>
447 </nav>
448 <hr />
449 <!-- Repository -->
450 <div class='row'>
451 <div class='col col-12'>
452 <div class="h5"><i class='fa fa-eye mr-1' data-toggle='collapse' data-target='#repository-collapse' role='button' title="<?php echo xlt('Click to expand or collapse Repository templates panel.'); ?>"></i><?php echo xlt('Template Repository') ?>
453 <span>
454 <button type='button' id='upload-nav-button' name='upload-nav-button' class='btn btn-sm btn-primary' data-toggle='collapse' data-target='#upload-nav'>
455 <i class='fa fa-upload mr-1' aria-hidden='true'></i><?php echo xlt('Upload') ?>
456 </button></span></div>
457 </div>
458 <!-- Repository table -->
459 <div class='col col-12 table-responsive <?php echo attr($_REQUEST['repository_send_state'] ?? 'collapse') ?>' id="repository-collapse">
460 <?php
461 $templates = [];
462 $show_cat_flag = false;
463 if (!empty($category)) {
464 $templates = $templateService->getTemplateListByCategory($category, -1);
465 } else {
466 $templates = $templateService->getTemplateListAllCategories(-1);
468 echo "<table class='table table-sm table-striped table-bordered'>\n";
469 echo "<thead>\n";
470 echo "<tr>\n" .
471 "<th style='width:5%'>" . xlt('Send') . "</th>" .
472 '<th>' . xlt('Category') . '</th>' .
473 "<th>" . xlt("Template Actions") . "</th>" .
474 "<th>" . xlt("Size") . "</th>" .
475 "<th>" . xlt("Last Modified") . "</th>" .
476 "</tr>\n";
477 echo "</thead>\n";
478 echo "<tbody>\n";
479 foreach ($templates as $cat => $files) {
480 if (empty($cat)) {
481 $cat = xlt('General');
483 foreach ($files as $file) {
484 $template_id = $file['id'];
485 $this_cat = $file['category'];
486 $notify_flag = false;
487 $select_cat_options = '<option value="">' . xlt('General') . "</option>\n";
488 foreach ($category_list as $option_category) {
489 if (stripos($option_category['option_id'], 'repository') !== false) {
490 continue;
492 if ($this_cat === $option_category['option_id']) {
493 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "' selected>" . text($option_category['title']) . "</option>\n";
494 } else {
495 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
498 echo "<tr>";
499 if ($file['mime'] == 'application/pdf') {
500 $this_cat = xlt('PDF Document');
501 $notify_flag = true;
502 echo '<td>' . '*' . '</td>';
503 echo "<td>" . $this_cat . " Id: " . attr($template_id) . "</td>";
504 } else {
505 echo "<td><input type='checkbox' class='form-check-inline' name='send' value='" . attr($template_id) . "' /></td>";
506 echo '<td><select class="form-control form-control-sm" id="category_table' . attr($template_id) .
507 '" onchange="updateCategory(' . attr_js($template_id) . ')" value="' . attr($this_cat) . '">' .
508 $select_cat_options . '</select></td>';
510 echo '<td>' .
511 '<button id="templateEdit' . attr($template_id) .
512 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ',' . attr_js($notify_flag) . ')" type="button">' . text($file['template_name']) .
513 '</button>';
514 if ($authUploadTemplates) {
515 echo '<button id="templateDelete' . attr($template_id) .
516 '" class="btn btn-sm btn-outline-danger float-right" onclick="templateDelete(' . attr_js($template_id) . ',' . attr_js($file['template_name']) . ')" type="button">' . xlt("Delete") .
517 '</button>';
519 echo "</td>";
520 echo "<td>" . text($file['size']) . "</td>";
521 echo "<td>" . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . "</td>";
522 echo "</tr>";
524 <?php
527 if (empty($template_id)) {
528 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
530 echo "</tbody>\n";
531 echo "</table>\n";
533 <div>
534 <?php
535 echo "<table class='table table-sm table-striped table-bordered'>\n";
536 echo '<caption>' . xlt('Profiles in Portal') . "</caption>";
537 echo "<thead>\n";
538 echo "<tr>\n" .
539 "<th>" . xlt('Active') . "<button type='button' id='send-profile-hide' class='btn btn-sm ml-1 py-0 btn-transmit btn-success d-none' onclick='return sendProfiles()'>" . xlt('Update') . "</button></th>" .
540 '<th style="min-width: 25%">' . xlt('Profile') . '</th>' .
541 '<th>' . xlt('Assigned Templates') . '</th>' .
542 '<th>' . xlt('Assigned Groups') . '</th>' .
543 "</tr>\n";
544 echo "</thead>\n";
545 foreach ($profile_list as $profile => $profiles) {
546 $template_list = '';
547 $group_list_text = '';
548 $group_items_list = $templateService->getPatientGroupsByProfile($profile);
549 $profile_items_list = $templateService->getTemplateListByProfile($profile);
550 if (empty($profile_items_list)) {
551 continue;
553 $total = 0;
554 foreach ($profile_items_list as $key => $files) {
555 $total += count($files ?? []);
556 foreach ($files as $file) {
557 if (is_array($file)) {
558 $template_list .= $file['template_name'] . ', ';
562 $template_list = substr($template_list, 0, -2);
563 $profile_esc = attr($profile);
564 foreach ($group_items_list as $key => $groups) {
565 foreach ($groups as $group) {
566 if (is_array($group)) {
567 $group_list_text .= $group_list[$group['member_of']]['title'] . ', ';
571 $group_list_text = substr($group_list_text, 0, -2);
572 $send = 'send';
573 if (!empty($group_list_text)) {
574 $send = 'send_profile';
576 echo '<tr>';
577 $is_checked = '';
578 if ((int)$templateService->fetchProfileStatus($profiles['option_id']) === 1) {
579 $is_checked = 'checked';
581 echo "<td><input type='checkbox' class='form-check-inline' $is_checked name='" . attr($send) . "' data-send_profile='yes' value='" . $profile_esc . "' /></td>";
582 echo '<td>' . text($profiles['title']) . '</td>';
583 echo '<td><em>' . text($template_list) . '</em></td>';
584 echo '<td><em>' . text($group_list_text) . '</em></td>';
585 echo '</tr>';
587 if (empty($profile_list)) {
588 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
590 echo "</tbody>\n";
591 echo "</table>\n";
593 </div>
594 </div>
595 </div>
596 <!-- All Patients -->
597 <hr />
598 <div class='row'>
599 <div class='col col-12' data-toggle='collapse' data-target='#template-collapse'>
600 <h5><i class='fa fa-eye mr-1' role='button' title="<?php echo xlt('Click to expand or collapse All active patient templates panel.'); ?>"></i><?php echo '' . xlt('Default Patient Templates') . '' ?></h5>
601 </div>
602 <div class='col col-12 table-responsive <?php echo attr(($_REQUEST['all_state'] ?? '') ?: 'collapse') ?>' id='template-collapse'>
603 <?php
604 $templates = [];
605 $show_cat_flag = false;
606 if (!empty($category)) {
607 $templates = $templateService->getTemplateListByCategory($category);
608 } else {
609 $templates = $templateService->getTemplateListAllCategories();
611 echo "<table class='table table-sm table-striped table-bordered'>\n";
612 echo "<thead>\n";
613 echo "<tr>\n" .
614 '<th>' . xlt('Category') . '</th>' .
615 '<th>' . xlt('Template Actions') . '</th>' .
616 '<th>' . xlt('Size') . '</th>' .
617 '<th>' . xlt('Last Modified') . '</th>' .
618 "</tr>\n";
619 echo "</thead>\n";
620 echo "<tbody>\n";
621 foreach ($templates as $cat => $files) {
622 if (empty($cat)) {
623 $cat = xlt('General');
625 foreach ($files as $file) {
626 $template_id = $file['id'];
627 echo '<tr>';
628 /*echo "<td><input type='checkbox' class='form-check-inline' id='send' name='send' value='" . attr($template_id) . "' /></td>";*/
629 echo '<td>' . text(ucwords($cat)) . '</td><td>';
630 echo '<button id="templateEdit' . attr($template_id) .
631 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ')" type="button">' . text($file['template_name']) . '</button>';
632 if ($authUploadTemplates) {
633 echo '<button id="templateDelete' . attr($template_id) .
634 '" class="btn btn-sm btn-outline-danger" onclick="templateDelete(' . attr_js($template_id) . ')" type="button">' . xlt('Delete') . '</button>';
636 echo '<td>' . text($file['size']) . '</td>';
637 echo '<td>' . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . '</td>';
638 echo '</tr>';
640 <?php
643 if (empty($files)) {
644 echo '<tr><td>' . $none_message . "</td></tr>\n";
646 echo "</tbody>\n";
647 echo "</table>\n";
649 </div>
650 </div>
651 <hr />
652 <div class='row'>
653 <div class='col col-12'>
654 <div class='h5'>
655 <i class='fa fa-eye mr-1' data-toggle='collapse' data-target='#assigned_collapse' role='button' title="<?php echo xla('Click to expand or collapse Assigned Patients panel.'); ?>"></i><?php echo xlt('Patient Assigned Templates') ?>
656 </div>
657 </div>
658 <!-- Assigned table -->
659 <div class='col col-12 table-responsive <?php echo attr(($_REQUEST['assigned_state'] ?? '') ?: 'collapse') ?>' id="assigned_collapse">
660 <?php
661 // by categories and patient pid.
662 $templates = [];
663 $show_cat_flag = false;
664 if (is_array($patient) && $patient[0] === '0') {// All templates for all patients
665 $patient_templates = $templateService->getPortalAssignedTemplates(0, $category, false);
666 } else {// Category selected so get all of them for pid's
667 $patient_templates = $templateService->getTemplateCategoriesByPids($patient, $category);
669 echo "<table class='table table-sm table-bordered'>\n";
670 echo "<tbody>";
671 $idcnt = 0;
672 foreach ($patient_templates as $name => $templates) {
673 $count = 0;
674 $fetched_groups = $fetch_pid = null;
675 foreach ($templates as $c => $t) {
676 if (is_array($t)) {
677 $fetch_pid = $t[0]['pid'];
678 if (empty($fetched_groups)) {
679 $fetched_groups = str_replace('|', ', ', $t[0]['patient_groups'] ?? '');
681 $count += count($t);
685 echo "<tr><td class='h6 font-weight-bolder bg-light text-dark' data-toggle='collapse' data-target='" .
686 attr('#id' . ++$idcnt) . "' role='button'>" . text($name) .
687 " (" . text($count . ' ' . xl('Templates')) . ") in " . text($fetched_groups) . "</td></tr>";
688 echo "<td class='collapse' id='" . attr('id' . $idcnt) . "'><table class='table table-sm table-striped table-bordered'>\n";
689 //echo '<caption><h5>' . text($name) . '</h5></caption>';
690 echo "<thead>\n";
691 echo "<tr>\n" .
692 '</th><th>' . xlt('Category') . '</th>' .
693 '<th>' . xlt('Profile') .
694 '<th>' . xlt('Template Actions') .
695 '</th><th>' . xlt('Status') .
696 '</th><th>' . xlt('Last Action') . '</th>' .
697 '</th><th>' . xlt('Next Due') .
698 "</tr>\n";
699 echo "</thead>\n";
700 echo "<tbody>\n";
701 foreach ($templates as $cat => $files) {
702 if (empty($cat)) {
703 $cat = xlt('General');
705 foreach ($files as $file) {
706 $template_id = $file['id'];
707 $audit_status = array (
708 'pid' => '',
709 'create_date' => ($file['profile_date'] ?: $file['modified_date']) ?? '',
710 'doc_type' => '',
711 'patient_signed_time' => '',
712 'authorize_signed_time' => '',
713 'patient_signed_status' => '',
714 'review_date' => '',
715 'denial_reason' => $file['status'] ?? '',
716 'file_name' => '',
717 'file_path' => '',
719 $audit_status_fetch = $templateService->fetchTemplateStatus($file['pid'], $file['id']);
720 if (is_array($audit_status_fetch)) {
721 $audit_status = $audit_status_fetch;
723 $next_due = $templateService->showTemplateFromEvent($file, true);
724 if ($next_due > 1) {
725 if ($audit_status['denial_reason'] === 'In Review') {
726 $audit_status['denial_reason'] = xl('Scheduled') . ' ' . xl('but Needs Review');
727 } else {
728 $audit_status['denial_reason'] = xl('Scheduled');
730 $next_due = date('m/d/Y', $next_due);
731 } elseif ($next_due === 1 || ($next_due === true && $file['recurring'] ?? 0)) {
732 $audit_status['denial_reason'] = xl('Recurring');
733 $next_due = xl('Active');
734 } elseif ($next_due === 0) {
735 $audit_status['denial_reason'] = xl('Completed');
736 $next_due = xl('Inactive');
737 } elseif ($next_due === true && empty($file['recurring'] ?? 0)) {
738 $next_due = xl('Active');
741 echo '<tr><td>' . text(ucwords($cat)) . '</td>';
742 echo '<td>' . text($profile_list[$file['profile']]['title'] ?? '') . '</td>';
743 echo '<td>' .
744 '<button type="button" id="patientEdit' . attr($template_id) .
745 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ')">' .
746 text($file['template_name']) . "</button>\n";
747 if ($authUploadTemplates && empty($file['member_of']) && !empty($file['status'])) {
748 echo '<button type="button" id="patientDelete' . attr($template_id) .
749 '" class="btn btn-sm btn-outline-danger" onclick="templateDelete(' . attr_js($template_id) . ')">' . xlt('Delete') . "</button></td>\n";
751 echo '<td>' . text($audit_status['denial_reason']) . '</td>';
752 echo '<td>' . text(date('m/d/Y H:i:s', strtotime($audit_status['create_date']))) . '</td>';
753 echo '<td>' . text($next_due) . '</td>';
754 echo "</tr>\n";
757 echo "</tbody>\n";
758 echo "</table></td>\n";
760 if (empty($templates)) {
761 echo '<tr><td>' . xlt('Multi Select Patients or All Patients using toolbar Location') . "</td></tr>\n";
763 echo "</tbody>\n";
764 echo "</table>\n";
766 </div>
767 </div>
768 <hr />
769 </div>
770 </div>
771 </body>
772 </html>