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\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');
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.");
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']); ?
>
49 const profiles
= <?php
echo js_escape($profile_list); ?
>;
52 let templateEdit
= function (id
, flag
= '') {
54 handleTemplate(id
, 'get', '', flag
);
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?'); ?
>);
67 handleTemplate(id
, 'delete', '', false, template
, <?php
echo js_escape(CsrfUtils
::collectCsrfToken('import-template-delete')); ?
>)
72 function getSendChecks() {
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]);
79 checked
.push($
(this
).val());
86 function getSendCheckProfiles() {
88 $
('input:checked[name=send_profile]:checked').each(
90 let isProfile
= this
.dataset
.send_profile
;
91 if (isProfile
== 'yes') {
92 checked
.push($
(this
).val());
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');
110 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
136 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
158 }).then(rtn
=> rtn
.text()).then((rtn
) => {
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
);
178 if (isDocument
== true) {
179 dialog
.popUp(renderUrl
, null, ('edit' + id
));
183 renderUrl +
= '&dialog=true';
184 dlgopen(renderUrl
, 'pop-editor', 'modal-lg', 850, '', '', {
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}
189 resolvePromiseOn
: 'show',
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, '', '', {
220 function popPatientDialog() {
221 top
.restoreSession();
222 let url
= './lib/patient_groups.php';
223 dlgopen(url
, 'pop-profile', 'modal-lg', 850, '', '', {
230 function popGroupsDialog() {
231 let url
= './lib/patient_groups.php?render_group_assignments=true';
232 dlgopen(url
, 'pop-groups', 'modal-lg', 850, '', '', {
240 $
('.select-dropdown').removeClass('d-none');
241 $
('.select-dropdown').select2({
243 placeholder
: xl('Type to search.'),
245 dropdownAutoWidth
: true,
247 closeOnSelect
: false,
248 <?php
require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?
>
251 $
('#fetch_files').on('click touchstart', function () {
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');
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) {
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');
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();
335 caption
-side
: top
!important
;
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' />
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') ?
>
352 <button
class='btn btn-success' type
='button' onclick
="location.href='./patient/provider'">
353 <?php
echo xlt('Dashboard'); ?
>
357 <div
class='col col-12'>
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
>
367 $ppt = $templateService->fetchPortalAuthUsers();
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>';
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">
383 <a
class='btn-refresh ml-1' onclick
="$('#selected_patients').val(null).trigger('change');" role
="button"></a
>
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) {
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";
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 ?
>
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'); ?
>
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
>
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
') ?>' />
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'>
429 <div id
='upload_scope_category'></div
>
430 <div
class='mb-2' id
='upload_scope'></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
>
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); ?>' />
444 <div
class="alert alert-danger"><?php
echo xlt("Not Authorized to Upload Templates") ?
></div
>
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') ?
>
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
>
458 <!-- Repository table
-->
459 <div
class='col col-12 table-responsive <?php echo attr($_REQUEST['repository_send_state
'] ?? 'collapse
') ?>' id
="repository-collapse">
462 $show_cat_flag = false;
463 if (!empty($category)) {
464 $templates = $templateService->getTemplateListByCategory($category, -1);
466 $templates = $templateService->getTemplateListAllCategories(-1);
468 echo "<table class='table table-sm table-striped table-bordered'>\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>" .
479 foreach ($templates as $cat => $files) {
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) {
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";
495 $select_cat_options .= "<option value='" . attr($option_category['option_id']) . "'>" . text($option_category['title']) . "</option>\n";
499 if ($file['mime'] == 'application/pdf') {
500 $this_cat = xlt('PDF Document');
502 echo '<td>' . '*' . '</td>';
503 echo "<td>" . $this_cat . " Id: " . attr($template_id) . "</td>";
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>';
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']) .
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") .
520 echo "<td>" . text($file['size']) . "</td>";
521 echo "<td>" . text(date('m/d/Y H:i:s', strtotime($file['modified_date']))) . "</td>";
527 if (empty($template_id)) {
528 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
535 echo "<table class='table table-sm table-striped table-bordered'>\n";
536 echo '<caption>' . xlt('Profiles in Portal') . "</caption>";
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>' .
545 foreach ($profile_list as $profile => $profiles) {
547 $group_list_text = '';
548 $group_items_list = $templateService->getPatientGroupsByProfile($profile);
549 $profile_items_list = $templateService->getTemplateListByProfile($profile);
550 if (empty($profile_items_list)) {
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);
573 if (!empty($group_list_text)) {
574 $send = 'send_profile';
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>';
587 if (empty($profile_list)) {
588 echo '<tr><td></td><td>' . $none_message . "</td></tr>\n";
596 <!-- All Patients
-->
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
>
602 <div
class='col col-12 table-responsive <?php echo attr(($_REQUEST['all_state
'] ?? '') ?: 'collapse
') ?>' id
='template-collapse'>
605 $show_cat_flag = false;
606 if (!empty($category)) {
607 $templates = $templateService->getTemplateListByCategory($category);
609 $templates = $templateService->getTemplateListAllCategories();
611 echo "<table class='table table-sm table-striped table-bordered'>\n";
614 '<th>' . xlt('Category') . '</th>' .
615 '<th>' . xlt('Template Actions') . '</th>' .
616 '<th>' . xlt('Size') . '</th>' .
617 '<th>' . xlt('Last Modified') . '</th>' .
621 foreach ($templates as $cat => $files) {
623 $cat = xlt('General');
625 foreach ($files as $file) {
626 $template_id = $file['id'];
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>';
644 echo '<tr><td>' . $none_message . "</td></tr>\n";
653 <div
class='col col-12'>
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') ?
>
658 <!-- Assigned table
-->
659 <div
class='col col-12 table-responsive <?php echo attr(($_REQUEST['assigned_state
'] ?? '') ?: 'collapse
') ?>' id
="assigned_collapse">
661 // by categories and patient pid.
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";
672 foreach ($patient_templates as $name => $templates) {
674 $fetched_groups = $fetch_pid = null;
675 foreach ($templates as $c => $t) {
677 $fetch_pid = $t[0]['pid'];
678 if (empty($fetched_groups)) {
679 $fetched_groups = str_replace('|', ', ', $t[0]['patient_groups'] ??
'');
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>';
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') .
701 foreach ($templates as $cat => $files) {
703 $cat = xlt('General');
705 foreach ($files as $file) {
706 $template_id = $file['id'];
707 $audit_status = array (
709 'create_date' => ($file['profile_date'] ?
: $file['modified_date']) ??
'',
711 'patient_signed_time' => '',
712 'authorize_signed_time' => '',
713 'patient_signed_status' => '',
715 'denial_reason' => $file['status'] ??
'',
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);
725 if ($audit_status['denial_reason'] === 'In Review') {
726 $audit_status['denial_reason'] = xl('Scheduled') . ' ' . xl('but Needs Review');
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>';
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>';
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";