Fix #4950 (#4951)
[openemr.git] / portal / import_template_ui.php
blob0bfa83f0021d4f43bc82aeb62132988ce8f82bf1
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\Core\Header;
18 use OpenEMR\Services\DocumentTemplates\DocumentTemplateService;
20 $templateService = new DocumentTemplateService();
21 $from_demo_pid = $_GET['from_demo_pid'] ?? '0';
22 $patient = $_REQUEST['selected_patients'] ?? null;
23 $patient = $patient ?: ($_REQUEST['upload_pid'] ?? 0);
25 $category = $_REQUEST['template_category'] ?? '';
26 $category_list = $templateService->fetchDefaultCategories();
27 $profile_list = $templateService->fetchDefaultProfiles();
28 $group_list = $templateService->fetchDefaultGroups();
30 $none_message = xlt("Nothing to show for current actions.");
33 <!DOCTYPE html>
34 <head>
35 <meta charset="UTF-8">
36 <title><?php echo xlt('Portal'); ?> | <?php echo xlt('Templates'); ?></title>
37 <meta name="description" content="Developed By sjpadgett@gmail.com">
38 <?php Header::setupHeader(['datetime-picker', 'select2', 'ckeditor']); ?>
39 <script>
40 const profiles = <?php echo js_escape($profile_list); ?>;
41 let currentEdit = "";
42 let editor;
43 let templateEdit = function (id, flag = '') {
44 currentEdit = id;
45 handleTemplate(id, 'get', '', flag);
46 return false;
49 let templateSave = function () {
50 let markup = CKEDITOR.instances.templateContent.getData();
51 handleTemplate(currentEdit, 'save', markup);
54 let templateDelete = function (id, template = '') {
55 let delok = confirm(<?php echo xlj('You are about to delete a template'); ?> +
56 ": " + "\n" + <?php echo xlj('Is this Okay?'); ?>);
57 if (delok === true) {
58 handleTemplate(id, 'delete', '', false, template)
60 return false;
63 function getSendChecks() {
64 let checked = [];
65 $('input:checked[name=send]:checked').each(function () {
66 let isProfile = this.dataset.send_profile;
67 if (isProfile == 'yes') {
68 checked.push([$(this).val(), true]);
69 } else {
70 checked.push($(this).val());
72 });
73 console.log(checked)
74 return checked;
77 function getSendCheckProfiles() {
78 let checked = [];
79 $('input:checked[name=send_profile]:checked').each(
80 function () {
81 let isProfile = this.dataset.send_profile;
82 if (isProfile == 'yes') {
83 checked.push($(this).val());
85 });
86 console.log(checked)
87 return checked;
90 function updateCategory(id) {
91 top.restoreSession();
92 let url = 'import_template.php';
93 let category = event.currentTarget.value;
94 const data = new FormData();
95 data.append('docid', id);
96 data.append('category', category);
97 data.append('mode', 'update_category');
98 fetch(url, {
99 method: 'POST',
100 body: data,
101 }).then(rtn => rtn.text()).then((rtn) => {
102 (async (time) => {
103 await asyncAlertMsg(rtn, time, 'success', 'lg');
104 })(2000).then(rtn => {
105 //document.edit_form.submit();
107 }).catch((error) => {
108 console.error('Error:', error);
112 function sendTemplate(mode = 'send', content = '') {
113 top.restoreSession();
114 let url = 'import_template.php';
115 let ids = $('#selected_patients').select2('val');
116 let category = $('#template_category').val();
117 let checked = getSendChecks();
118 const data = new FormData();
119 data.append('docid', JSON.stringify(ids));
120 data.append('category', category);
121 data.append('checked', JSON.stringify(checked));
122 data.append('mode', mode);
123 data.append('content', content);
124 fetch(url, {
125 method: 'POST',
126 body: data,
127 }).then(rtn => rtn.text()).then((rtn) => {
128 (async (time) => {
129 await asyncAlertMsg(rtn, time, 'success', 'lg');
130 })(1500).then(rtn => {
131 document.edit_form.submit();
133 }).catch((error) => {
134 console.error('Error:', error);
138 function sendProfiles() {
139 top.restoreSession();
140 let mode = 'send_profiles'
141 let url = 'import_template.php';
142 let checked = getSendCheckProfiles();
143 const data = new FormData();
144 data.append('checked', JSON.stringify(checked));
145 data.append('mode', mode);
146 fetch(url, {
147 method: 'POST',
148 body: data,
149 }).then(rtn => rtn.text()).then((rtn) => {
150 (async (time) => {
151 await asyncAlertMsg(rtn, time, 'success', 'lg');
152 })(1500).then(rtn => {
153 document.edit_form.submit();
155 }).catch((error) => {
156 console.error('Error:', error);
160 function handleTemplate(id, mode, content = '', isDocument = '', template = '') {
161 top.restoreSession();
162 let libUrl = 'import_template.php';
163 let renderUrl = 'import_template.php?mode=editor_render_html&docid=' + id;
165 if (document.getElementById('is_modal').checked && mode === 'get') {
166 dialog.popUp(renderUrl, null, 'edit' + id);
167 return false;
169 if (isDocument == true) {
170 dialog.popUp(renderUrl, null, ('edit' + id));
171 return false;
173 if (mode == 'get') {
174 renderUrl += '&dialog=true';
175 dlgopen(renderUrl, 'pop-editor', 'modal-lg', 850, '', '', {
176 /*buttons: [
177 {text: <?php echo xlj('Save'); ?>, close: false, style: 'success btn-sm', click: templateSave},
178 {text: <?php echo xlj('Dismiss'); ?>, style: 'danger btn-sm', close: true}
179 ],*/
180 resolvePromiseOn: 'show',
181 allowDrag: true,
182 allowResize: true,
183 sizeHeight: 'full',
184 //onClosed: 'reload'
187 $.ajax({
188 type: "POST",
189 url: libUrl,
190 data: {docid: id, mode: mode, content: content, template: template},
191 error: function (qXHR, textStatus, errorThrow) {
192 console.log("There was an error");
193 alert(<?php echo xlj("File Error") ?> +"\n" + id)
195 success: function (templateHtml, textStatus, jqXHR) {
196 document.edit_form.submit();
201 function popProfileDialog() {
202 top.restoreSession();
203 let url = './import_template.php?mode=render_profile';
204 dlgopen(url, 'pop-profile', 'modal-lg', 850, '', '', {
205 allowDrag: true,
206 allowResize: true,
207 sizeHeight: 'full',
211 function popPatientDialog() {
212 top.restoreSession();
213 let url = './lib/patient_groups.php';
214 dlgopen(url, 'pop-profile', 'modal-lg', 850, '', '', {
215 allowDrag: true,
216 allowResize: true,
217 sizeHeight: 'full'
221 function popGroupsDialog() {
222 let url = './lib/patient_groups.php?render_group_assignments=true';
223 dlgopen(url, 'pop-groups', 'modal-lg', 850, '', '', {
224 allowDrag: true,
225 allowResize: true,
226 sizeHeight: 'full',
230 $(function () {
231 $('.select-dropdown').removeClass('d-none');
232 $('.select-dropdown').select2({
233 multiple: true,
234 placeholder: xl('Type to search.'),
235 theme: 'bootstrap4',
236 dropdownAutoWidth: true,
237 width: 'resolve',
238 closeOnSelect: false,
239 <?php require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?>
242 $('#fetch_files').on('click touchstart', function () {
243 $(this).val('');
245 $('#fetch_files').change(function (e) {
246 $('#upload_submit').removeClass('d-none');
249 $('input:checkbox[name=send]').change(function () {
250 let checked = getSendChecks();
251 if (checked.length > 0) {
252 $('#send-button').removeClass('d-none');
253 $('#category_group').addClass('d-none');
254 $('#send-profile-hide').addClass('d-none');
255 } else {
256 $('#send-button').addClass('d-none');
257 $('#category_group').removeClass('d-none');
261 $('input:checkbox[name=send_profile]').change(function () {
262 $('#send-profile-hide').removeClass('d-none');
263 $('#category_group').addClass('d-none');
264 $('input:checkbox[name=send]').addClass('d-none');
267 $('#selected_patients').on('select2:close', function () {
268 let checked = getSendChecks();
269 if (checked.length > 0) {
270 return false;
272 $('#edit_form').submit();
275 $('#upload-nav').on('hidden.bs.collapse', function () {
276 $('#upload-nav-value').val('collapse');
278 $('#upload-nav').on('show.bs.collapse', function () {
279 $('#upload-nav-value').val('show');
280 //$('#edit_form').submit();
283 $("#template_category").change(function () {
284 $('#edit_form').submit();
287 $('#template-collapse').on('show.bs.collapse', function () {
288 $('#edit_form #all_state').val('show');
290 $('#template-collapse').on('hidden.bs.collapse', function () {
291 $('#edit_form #all_state').val('collapse');
294 $('#assigned_collapse').on('show.bs.collapse', function () {
295 $('#repository-collapse').collapse('hide');
296 $('#template-collapse').collapse('hide');
297 $('#edit_form #assigned_state').val('show');
299 $('#assigned_collapse').on('hidden.bs.collapse', function () {
300 $('#edit_form #assigned_state').val('collapse');
303 $('#repository-collapse').on('show.bs.collapse', function () {
304 $('#edit_form #repository_send_state').val('show');
306 $('#repository-collapse').on('hidden.bs.collapse', function () {
307 $('#edit_form #repository_send_state').val('collapse');
310 let selText = '';
311 let selCat = $('#template_category').find(':selected').text();
312 let ids = $('#selected_patients').find(':selected').each(function () {
313 selText += $(this).text() + '; ';
315 $('#upload_scope_category').empty().append(' ' + xl('For Category') + ': ' + selCat);
316 $("#upload_scope").empty().append(xl('To Repository Location') + ': ' + xl("Repository always."));
318 $(document).on('select2:open', () => {
319 document.querySelector('.select2-search__field').focus();
322 </script>
323 <style>
324 caption {
325 caption-side: top !important;
327 </style>
328 </head>
329 <body class="body-top">
330 <div class='container-xl'>
331 <nav class='nav navbar bg-light text-dark sticky-top'>
332 <span class='title'><?php echo xlt('Template Maintenance'); ?></span>
333 <div class="ml-auto">
334 <label class="form-check"><?php echo xlt('Full Editor'); ?>
335 <input type='checkbox' class='form-check-inline mx-1' id='is_modal' name='is_modal' checked='checked' />
336 </label>
337 </div>
338 <div class='btn-group ml-1'>
339 <button type='button' class='btn btn-secondary' data-toggle='collapse' data-target='#help-panel'>
340 <?php echo xlt('Help') ?>
341 </button>
342 <button class='btn btn-success' type='button' onclick="location.href='./patient/provider'">
343 <?php echo xlt('Dashboard'); ?>
344 </button>
345 </div>
346 </nav>
347 <div class='col col-12'>
348 <hr />
349 <?php include_once('./../Documentation/help_files/template_maintenance_help.php'); ?>
350 <!-- Actions Scope to act on -->
351 <nav class='navbar navbar-dark bg-dark text-light sticky-top'>
352 <form id="edit_form" name="edit_form" class="row form-inline w-100" action="" method="get">
353 <a class='navbar-brand ml-1'><?php echo xlt('Scope'); ?></a>
354 <div class="form-group">
355 <label class='font-weight-bold mx-1' for='selected_patients'><?php echo xlt('Location'); ?></label>
356 <?PHP
357 $ppt = $templateService->fetchPortalAuthUsers();
358 $auth = '';
359 foreach ($ppt as $pt) {
360 if (!empty($from_demo_pid)) {
361 $patient = [$from_demo_pid];
363 if ((is_array($patient) && !in_array($pt['pid'], $patient)) || empty($patient)) {
364 $auth .= '<option value=' . attr($pt['pid']) . '>' . text($pt['ptname']) . '</option>';
365 } else {
366 $auth .= "<option value='" . attr($pt['pid']) . "' selected='selected'>" . text($pt['ptname'] . ' ') . '</option>';
370 <select class="form-control select-dropdown d-none" id="selected_patients" name="selected_patients[]" multiple="multiple">
371 <?php echo $auth ?>
372 </select>
373 <a class='btn-refresh ml-1' onclick="$('#selected_patients').val(null).trigger('change');" role="button"></a>
374 </div>
375 <?php
376 $select_cat_options = '<option value="">' . xlt('General') . "</option>\n";
377 foreach ($category_list as $option_category) {
378 if (stripos($option_category['option_id'], 'repository') !== false) {
379 continue;
381 if ($category === $option_category['option_id']) {
382 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "' selected>" . text($option_category['title']) . "</option>\n";
383 } else {
384 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
388 <div class="input-group" id="category_group">
389 <label class="font-weight-bold mx-1" for="template_category"><?php echo xlt('Category'); ?></label>
390 <select class="form-control" id="template_category" name="template_category">
391 <?php echo $select_cat_options ?>
392 </select>
393 </div>
394 <div class="form-group">
395 <div class='btn-group ml-1'>
396 <button type='submit' class='btn btn-search btn-light'><i class="btn-refresh"></i></button>
397 <button type='button' id="send-button" class='btn btn-transmit btn-success d-none' onclick="return sendTemplate()">
398 <?php echo xlt('Send'); ?>
399 </button>
400 <button class='btn btn-sm btn-primary' onclick='return popProfileDialog()'><?php echo xlt('Profiles') ?></button>
401 <button type='button' class='btn btn-primary' onclick='return popPatientDialog()'><?php echo xlt('Groups') ?></button>
402 <button type='button' class='btn btn-primary' onclick='return popGroupsDialog()'><?php echo xlt('Assign') ?></button>
403 </div>
404 </div>
405 <input type='hidden' id='upload-nav-value' name='upload-nav-value' value='<?php echo attr($_REQUEST['upload-nav-value'] ?? 'collapse') ?>' />
406 <input type='hidden' id='persist_checks' name='persist_checks' value='' />
407 <input type='hidden' id='all_state' name='all_state' value='<?php echo attr($_REQUEST['all_state'] ?? 'collapse') ?>' />
408 <input type='hidden' id='assigned_state' name='assigned_state' value='<?php echo attr($_REQUEST['assigned_state'] ?? 'collapse') ?>' />
409 <input type='hidden' id='repository_send_state' name='repository_send_state' value='<?php echo attr($_REQUEST['repository_send_state'] ?? 'collapse') ?>' />
410 </form>
411 </nav>
412 <!-- Upload -->
413 <nav class="collapse my-2 <?php echo attr($_REQUEST['upload-nav-value'] ?? '') ?>" id="upload-nav">
414 <div class='col col-12'>
415 <form id='form_upload' class='form-inline row' action='import_template.php' method='post' enctype='multipart/form-data'>
416 <hr />
417 <div class='col'>
418 <div id='upload_scope_category'></div>
419 <div class='mb-2' id='upload_scope'></div>
420 </div>
421 <div class='form-group col'>
422 <div class='form-group'>
423 <input type='file' class='btn btn-outline-info' id="fetch_files" name='template_files[]' multiple />
424 <button class='btn btn-outline-success d-none' type='submit' name='upload_submit' id='upload_submit'><i class='fa fa-upload' aria-hidden='true'></i></button>
425 </div>
426 </div>
427 <input type='hidden' name='upload_pid' value='<?php echo attr(json_encode([-1])); ?>' />
428 <input type='hidden' name="template_category" value='<?php echo attr($category); ?>' />
429 </form>
430 </div>
431 </nav>
432 <hr />
433 <!-- Repository -->
434 <div class='row'>
435 <div class='col col-12'>
436 <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') ?>
437 <span>
438 <button type='button' id='upload-nav-button' name='upload-nav-button' class='btn btn-sm btn-primary' data-toggle='collapse' data-target='#upload-nav'>
439 <i class='fa fa-upload mr-1' aria-hidden='true'></i><?php echo xlt('Upload') ?>
440 </button></span></div>
441 </div>
442 <!-- Repository table -->
443 <div class='col col-12 table-responsive <?php echo attr($_REQUEST['repository_send_state'] ?? 'collapse') ?>' id="repository-collapse">
444 <?php
445 $templates = [];
446 $show_cat_flag = false;
447 if (!empty($category)) {
448 $templates = $templateService->getTemplateListByCategory($category, -1);
449 } else {
450 $templates = $templateService->getTemplateListAllCategories(-1);
452 echo "<table class='table table-sm table-striped table-bordered'>\n";
453 echo "<thead>\n";
454 echo "<tr>\n" .
455 "<th style='width:5%'>" . xlt('Send') . "</th>" .
456 '<th>' . xlt('Category') . '</th>' .
457 "<th>" . xlt("Template Actions") . "</th>" .
458 "<th>" . xlt("Size") . "</th>" .
459 "<th>" . xlt("Last Modified") . "</th>" .
460 "</tr>\n";
461 echo "</thead>\n";
462 echo "<tbody>\n";
463 foreach ($templates as $cat => $files) {
464 if (empty($cat)) {
465 $cat = xlt('General');
467 foreach ($files as $file) {
468 $template_id = $file['id'];
469 $this_cat = $file['category'];
470 $notify_flag = false;
471 $select_cat_options = '<option value="">' . xlt('General') . "</option>\n";
472 foreach ($category_list as $option_category) {
473 if (stripos($option_category['option_id'], 'repository') !== false) {
474 continue;
476 if ($this_cat === $option_category['option_id']) {
477 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "' selected>" . text($option_category['title']) . "</option>\n";
478 } else {
479 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
482 echo "<tr>";
483 if ($file['mime'] == 'application/pdf') {
484 $this_cat = xlt('PDF Document');
485 $notify_flag = true;
486 echo '<td>' . '*' . '</td>';
487 echo "<td>" . $this_cat . " Id: " . attr($template_id) . "</td>";
488 } else {
489 echo "<td><input type='checkbox' class='form-check-inline' name='send' value='" . attr($template_id) . "' /></td>";
490 echo '<td><select class="form-control form-control-sm" id="category_table' . attr($template_id) .
491 '" onchange="updateCategory(' . attr_js($template_id) . ')" value="' . attr($this_cat) . '">' .
492 $select_cat_options . '</select></td>';
494 echo '<td>' .
495 '<button id="templateEdit' . attr($template_id) .
496 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ',' . attr_js($notify_flag) . ')" type="button">' . text($file['template_name']) .
497 '</button>' .
498 '<button id="templateDelete' . attr($template_id) .
499 '" class="btn btn-sm btn-outline-danger float-right" onclick="templateDelete(' . attr_js($template_id) . ',' . attr_js($file['template_name']) . ')" type="button">' . xlt("Delete") .
500 '</button></td>';
501 echo "<td>" . text($file['size']) . "</td>";
502 echo "<td>" . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . "</td>";
503 echo "</tr>";
505 <?php
508 if (empty($template_id)) {
509 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
511 echo "</tbody>\n";
512 echo "</table>\n";
514 <div>
515 <?php
516 echo "<table class='table table-sm table-striped table-bordered'>\n";
517 echo '<caption>' . xlt('Profiles in Portal') . "</caption>";
518 echo "<thead>\n";
519 echo "<tr>\n" .
520 "<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>" .
521 '<th style="min-width: 25%">' . xlt('Profile') . '</th>' .
522 '<th>' . xlt('Assigned Templates') . '</th>' .
523 '<th>' . xlt('Assigned Groups') . '</th>' .
524 "</tr>\n";
525 echo "</thead>\n";
526 foreach ($profile_list as $profile => $profiles) {
527 $template_list = '';
528 $group_list_text = '';
529 $group_items_list = $templateService->getPatientGroupsByProfile($profile);
530 $profile_items_list = $templateService->getTemplateListByProfile($profile);
531 if (empty($profile_items_list)) {
532 continue;
534 $total = 0;
535 foreach ($profile_items_list as $key => $files) {
536 $total += count($files ?? []);
537 foreach ($files as $file) {
538 if (is_array($file)) {
539 $template_list .= $file['template_name'] . ', ';
543 $template_list = substr($template_list, 0, -2);
544 $profile_esc = attr($profile);
545 foreach ($group_items_list as $key => $groups) {
546 foreach ($groups as $group) {
547 if (is_array($group)) {
548 $group_list_text .= $group_list[$group['member_of']]['title'] . ', ';
552 $group_list_text = substr($group_list_text, 0, -2);
553 $send = 'send';
554 if (!empty($group_list_text)) {
555 $send = 'send_profile';
557 echo '<tr>';
558 $is_checked = '';
559 if ((int)$templateService->fetchProfileStatus($profiles['option_id']) === 1) {
560 $is_checked = 'checked';
562 echo "<td><input type='checkbox' class='form-check-inline' $is_checked name='" . attr($send) . "' data-send_profile='yes' value='" . $profile_esc . "' /></td>";
563 echo '<td>' . text($profiles['title']) . '</td>';
564 echo '<td><em>' . text($template_list) . '</em></td>';
565 echo '<td><em>' . text($group_list_text) . '</em></td>';
566 echo '</tr>';
568 if (empty($profile_list)) {
569 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
571 echo "</tbody>\n";
572 echo "</table>\n";
574 </div>
575 </div>
576 </div>
577 <!-- All Patients -->
578 <hr />
579 <div class='row'>
580 <div class='col col-12' data-toggle='collapse' data-target='#template-collapse'>
581 <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>
582 </div>
583 <div class='col col-12 table-responsive <?php echo attr(($_REQUEST['all_state'] ?? '') ?: 'collapse') ?>' id='template-collapse'>
584 <?php
585 $templates = [];
586 $show_cat_flag = false;
587 if (!empty($category)) {
588 $templates = $templateService->getTemplateListByCategory($category);
589 } else {
590 $templates = $templateService->getTemplateListAllCategories();
592 echo "<table class='table table-sm table-striped table-bordered'>\n";
593 echo "<thead>\n";
594 echo "<tr>\n" .
595 '<th>' . xlt('Category') . '</th>' .
596 '<th>' . xlt('Template Actions') . '</th>' .
597 '<th>' . xlt('Size') . '</th>' .
598 '<th>' . xlt('Last Modified') . '</th>' .
599 "</tr>\n";
600 echo "</thead>\n";
601 echo "<tbody>\n";
602 foreach ($templates as $cat => $files) {
603 if (empty($cat)) {
604 $cat = xlt('General');
606 foreach ($files as $file) {
607 $template_id = $file['id'];
608 echo '<tr>';
609 /*echo "<td><input type='checkbox' class='form-check-inline' id='send' name='send' value='" . attr($template_id) . "' /></td>";*/
610 echo '<td>' . text(ucwords($cat)) . '</td><td>';
611 echo '<button id="templateEdit' . attr($template_id) .
612 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ')" type="button">' . text($file['template_name']) . '</button>' .
613 '<button id="templateDelete' . attr($template_id) .
614 '" class="btn btn-sm btn-outline-danger" onclick="templateDelete(' . attr_js($template_id) . ')" type="button">' . xlt('Delete') . '</button>';
615 echo '<td>' . text($file['size']) . '</td>';
616 echo '<td>' . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . '</td>';
617 echo '</tr>';
619 <?php
622 if (empty($files)) {
623 echo '<tr><td>' . $none_message . "</td></tr>\n";
625 echo "</tbody>\n";
626 echo "</table>\n";
628 </div>
629 </div>
630 <hr />
631 <div class='row'>
632 <div class='col col-12'>
633 <div class='h5'>
634 <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') ?>
635 </div>
636 </div>
637 <!-- Assigned table -->
638 <div class='col col-12 table-responsive <?php echo attr(($_REQUEST['assigned_state'] ?? '') ?: 'collapse') ?>' id="assigned_collapse">
639 <?php
640 // by categories and patient pid.
641 $templates = [];
642 $show_cat_flag = false;
643 if (is_array($patient) && $patient[0] === '0') {// All templates for all patients
644 $patient_templates = $templateService->getPortalAssignedTemplates(0, $category, false);
645 } else {// Category selected so get all of them for pid's
646 $patient_templates = $templateService->getTemplateCategoriesByPids($patient, $category);
648 echo "<table class='table table-sm table-bordered'>\n";
649 echo "<tbody>";
650 $idcnt = 0;
651 foreach ($patient_templates as $name => $templates) {
652 $count = 0;
653 $fetched_groups = $fetch_pid = null;
654 foreach ($templates as $c => $t) {
655 if (is_array($t)) {
656 $fetch_pid = $t[0]['pid'];
657 if (empty($fetched_groups)) {
658 $fetched_groups = str_replace('|', ', ', $t[0]['patient_groups'] ?? '');
660 $count += count($t);
664 echo "<tr><td class='h6 font-weight-bolder bg-light text-dark' data-toggle='collapse' data-target='" .
665 attr('#id' . ++$idcnt) . "' role='button'>" . text($name) .
666 " (" . text($count . ' ' . xl('Templates')) . ") in " . text($fetched_groups) . "</td></tr>";
667 echo "<td class='collapse' id='" . attr('id' . $idcnt) . "'><table class='table table-sm table-striped table-bordered'>\n";
668 //echo '<caption><h5>' . text($name) . '</h5></caption>';
669 echo "<thead>\n";
670 echo "<tr>\n" .
671 '</th><th>' . xlt('Category') . '</th>' .
672 '<th>' . xlt('Profile') .
673 '<th>' . xlt('Template Actions') .
674 '</th><th>' . xlt('Status') .
675 '</th><th>' . xlt('Last Action') . '</th>' .
676 '</th><th>' . xlt('Next Due') .
677 "</tr>\n";
678 echo "</thead>\n";
679 echo "<tbody>\n";
680 foreach ($templates as $cat => $files) {
681 if (empty($cat)) {
682 $cat = xlt('General');
684 foreach ($files as $file) {
685 $template_id = $file['id'];
686 $audit_status = array (
687 'pid' => '',
688 'create_date' => ($file['profile_date'] ?: $file['modified_date']) ?? '',
689 'doc_type' => '',
690 'patient_signed_time' => '',
691 'authorize_signed_time' => '',
692 'patient_signed_status' => '',
693 'review_date' => '',
694 'denial_reason' => $file['status'] ?? '',
695 'file_name' => '',
696 'file_path' => '',
698 $audit_status_fetch = $templateService->fetchTemplateStatus($file['pid'], $file['id']);
699 if (is_array($audit_status_fetch)) {
700 $audit_status = $audit_status_fetch;
702 $next_due = $templateService->showTemplateFromEvent($file, true);
703 if ($next_due > 1) {
704 if ($audit_status['denial_reason'] === 'In Review') {
705 $audit_status['denial_reason'] = xl('Scheduled') . ' ' . xl('but Needs Review');
706 } else {
707 $audit_status['denial_reason'] = xl('Scheduled');
709 $next_due = date('m/d/Y', $next_due);
710 } elseif ($next_due === 1 || ($next_due === true && $file['recurring'] ?? 0)) {
711 $audit_status['denial_reason'] = xl('Recurring');
712 $next_due = xl('Active');
713 } elseif ($next_due === 0) {
714 $audit_status['denial_reason'] = xl('Completed');
715 $next_due = xl('Inactive');
716 } elseif ($next_due === true && empty($file['recurring'] ?? 0)) {
717 $next_due = xl('Active');
720 echo '<tr><td>' . text(ucwords($cat)) . '</td>';
721 echo '<td>' . text($profile_list[$file['profile']]['title'] ?? '') . '</td>';
722 echo '<td>' .
723 '<button type="button" id="patientEdit' . attr($template_id) .
724 '" class="btn btn-sm btn-outline-primary" onclick="templateEdit(' . attr_js($template_id) . ')">' .
725 text($file['template_name']) . "</button>\n";
726 if (empty($file['member_of']) && !empty($file['status'])) {
727 echo '<button type="button" id="patientDelete' . attr($template_id) .
728 '" class="btn btn-sm btn-outline-danger" onclick="templateDelete(' . attr_js($template_id) . ')">' . xlt('Delete') . "</button></td>\n";
730 echo '<td>' . text($audit_status['denial_reason']) . '</td>';
731 echo '<td>' . text(date('m/d/Y H:i:s', strtotime($audit_status['create_date']))) . '</td>';
732 echo '<td>' . text($next_due) . '</td>';
733 echo "</tr>\n";
736 echo "</tbody>\n";
737 echo "</table></td>\n";
739 if (empty($templates)) {
740 echo '<tr><td>' . xlt('Multi Select Patients or All Patients using toolbar Location') . "</td></tr>\n";
742 echo "</tbody>\n";
743 echo "</table>\n";
745 </div>
746 </div>
747 <hr />
748 </div>
749 </div>
750 </body>
751 </html>