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-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.");
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']); ?
>
40 const profiles
= <?php
echo js_escape($profile_list); ?
>;
43 let templateEdit
= function (id
, flag
= '') {
45 handleTemplate(id
, 'get', '', flag
);
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?'); ?
>);
58 handleTemplate(id
, 'delete', '', false, template
)
63 function getSendChecks() {
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]);
70 checked
.push($
(this
).val());
77 function getSendCheckProfiles() {
79 $
('input:checked[name=send_profile]:checked').each(
81 let isProfile
= this
.dataset
.send_profile
;
82 if (isProfile
== 'yes') {
83 checked
.push($
(this
).val());
90 function updateCategory(id
) {
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');
101 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
127 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
149 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
169 if (isDocument
== true) {
170 dialog
.popUp(renderUrl
, null, ('edit' + id
));
174 renderUrl +
= '&dialog=true';
175 dlgopen(renderUrl
, 'pop-editor', 'modal-lg', 850, '', '', {
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}
180 resolvePromiseOn
: 'show',
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, '', '', {
211 function popPatientDialog() {
212 top
.restoreSession();
213 let url
= './lib/patient_groups.php';
214 dlgopen(url
, 'pop-profile', 'modal-lg', 850, '', '', {
221 function popGroupsDialog() {
222 let url
= './lib/patient_groups.php?render_group_assignments=true';
223 dlgopen(url
, 'pop-groups', 'modal-lg', 850, '', '', {
231 $
('.select-dropdown').removeClass('d-none');
232 $
('.select-dropdown').select2({
234 placeholder
: xl('Type to search.'),
236 dropdownAutoWidth
: true,
238 closeOnSelect
: false,
239 <?php
require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?
>
242 $
('#fetch_files').on('click touchstart', function () {
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');
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) {
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');
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();
325 caption
-side
: top
!important
;
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' />
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') ?
>
342 <button
class='btn btn-success' type
='button' onclick
="location.href='./patient/provider'">
343 <?php
echo xlt('Dashboard'); ?
>
347 <div
class='col col-12'>
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
>
357 $ppt = $templateService->fetchPortalAuthUsers();
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>';
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">
373 <a
class='btn-refresh ml-1' onclick
="$('#selected_patients').val(null).trigger('change');" role
="button"></a
>
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) {
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";
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 ?
>
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'); ?
>
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
>
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
') ?>' />
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'>
418 <div id
='upload_scope_category'></div
>
419 <div
class='mb-2' id
='upload_scope'></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
>
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); ?>' />
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') ?
>
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
>
442 <!-- Repository table
-->
443 <div
class='col col-12 table-responsive <?php echo attr($_REQUEST['repository_send_state
'] ?? 'collapse
') ?>' id
="repository-collapse">
446 $show_cat_flag = false;
447 if (!empty($category)) {
448 $templates = $templateService->getTemplateListByCategory($category, -1);
450 $templates = $templateService->getTemplateListAllCategories(-1);
452 echo "<table class='table table-sm table-striped table-bordered'>\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>" .
463 foreach ($templates as $cat => $files) {
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) {
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";
479 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
483 if ($file['mime'] == 'application/pdf') {
484 $this_cat = xlt('PDF Document');
486 echo '<td>' . '*' . '</td>';
487 echo "<td>" . $this_cat . " Id: " . attr($template_id) . "</td>";
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>';
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']) .
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") .
501 echo "<td>" . text($file['size']) . "</td>";
502 echo "<td>" . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . "</td>";
508 if (empty($template_id)) {
509 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
516 echo "<table class='table table-sm table-striped table-bordered'>\n";
517 echo '<caption>' . xlt('Profiles in Portal') . "</caption>";
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>' .
526 foreach ($profile_list as $profile => $profiles) {
528 $group_list_text = '';
529 $group_items_list = $templateService->getPatientGroupsByProfile($profile);
530 $profile_items_list = $templateService->getTemplateListByProfile($profile);
531 if (empty($profile_items_list)) {
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);
554 if (!empty($group_list_text)) {
555 $send = 'send_profile';
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>';
568 if (empty($profile_list)) {
569 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
577 <!-- All Patients
-->
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
>
583 <div
class='col col-12 table-responsive <?php echo attr(($_REQUEST['all_state
'] ?? '') ?: 'collapse
') ?>' id
='template-collapse'>
586 $show_cat_flag = false;
587 if (!empty($category)) {
588 $templates = $templateService->getTemplateListByCategory($category);
590 $templates = $templateService->getTemplateListAllCategories();
592 echo "<table class='table table-sm table-striped table-bordered'>\n";
595 '<th>' . xlt('Category') . '</th>' .
596 '<th>' . xlt('Template Actions') . '</th>' .
597 '<th>' . xlt('Size') . '</th>' .
598 '<th>' . xlt('Last Modified') . '</th>' .
602 foreach ($templates as $cat => $files) {
604 $cat = xlt('General');
606 foreach ($files as $file) {
607 $template_id = $file['id'];
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>';
623 echo '<tr><td>' . $none_message . "</td></tr>\n";
632 <div
class='col col-12'>
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') ?
>
637 <!-- Assigned table
-->
638 <div
class='col col-12 table-responsive <?php echo attr(($_REQUEST['assigned_state
'] ?? '') ?: 'collapse
') ?>' id
="assigned_collapse">
640 // by categories and patient pid.
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";
651 foreach ($patient_templates as $name => $templates) {
653 $fetched_groups = $fetch_pid = null;
654 foreach ($templates as $c => $t) {
656 $fetch_pid = $t[0]['pid'];
657 if (empty($fetched_groups)) {
658 $fetched_groups = str_replace('|', ', ', $t[0]['patient_groups'] ??
'');
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>';
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') .
680 foreach ($templates as $cat => $files) {
682 $cat = xlt('General');
684 foreach ($files as $file) {
685 $template_id = $file['id'];
686 $audit_status = array (
688 'create_date' => ($file['profile_date'] ?
: $file['modified_date']) ??
'',
690 'patient_signed_time' => '',
691 'authorize_signed_time' => '',
692 'patient_signed_status' => '',
694 'denial_reason' => $file['status'] ??
'',
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);
704 if ($audit_status['denial_reason'] === 'In Review') {
705 $audit_status['denial_reason'] = xl('Scheduled') . ' ' . xl('but Needs Review');
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>';
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>';
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";