Skip to content

Commit

Permalink
Questionnaire import utility (openemr#5805)
Browse files Browse the repository at this point in the history
* Bug fixes
- cleanup portal categories

* - fix alertMsg remove alert from form

* - save more form definition info from lh-form
- use lform first on new form or convert questionnaire to lform as backup

* - move dependencies so can be used elsewhere.

* - finish new manual imports and form conversions

* - fix encounter history tooltip
  • Loading branch information
sjpadgett authored Oct 8, 2022
1 parent 1c8137c commit 1475375
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 84 deletions.
16 changes: 16 additions & 0 deletions interface/forms/questionnaire_assessments/lform_webcomponents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// change root to public path when ready
$root = $GLOBALS['webroot'] . "/interface/forms/questionnaire_assessments";

$insert = <<< insert
<link href="$root/lforms/webcomponent/styles.css" media="screen" rel="stylesheet" />
<script src="$root/lforms/webcomponent/assets/lib/zone.min.js"></script>
<script src="$root/lforms/webcomponent/scripts.js"></script>
<script src="$root/lforms/webcomponent/runtime-es2015.js"></script>
<script src="$root/lforms/webcomponent/polyfills-es2015.js"></script>
<script src="$root/lforms/webcomponent/main-es2015.js"></script>
<script src="$root/lforms/fhir/R4/lformsFHIR.min.js"></script>
insert;

echo $insert;
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
$form['response_id'] = $qr['response_id'];
}
}

$q_json = '';
$lform = '';
$form_name = '';
Expand All @@ -77,6 +76,7 @@
$q_json = $q['questionnaire'] ?: '';
$lform = $q['lform'] ?: '';
$mode = 'new_form';
$form_name = $q['name'] ?: '';
}
// This is for newly selected questionnaire from repository dropdown.
if (!empty($repository_item) && $questionnaire_form == 'New Questionnaire') {
Expand Down Expand Up @@ -104,7 +104,6 @@
<?php Header::setupHeader(); ?>
<!--<link href="<?php /*echo $GLOBALS['assets_static_relative']; */?>/lforms/webcomponent/styles.css" media="screen" rel="stylesheet" />-->
<!-- TODO remove next release -->
<link href="./../../forms/questionnaire_assessments/lforms/webcomponent/styles.css" media="screen" rel="stylesheet" />
<script>
let isPortal = <?php echo js_escape($isPortal); ?>;
let portalOther = <?php echo js_escape($patientPortalOther); ?>;
Expand Down Expand Up @@ -145,7 +144,7 @@ function saveQR() {
}
let qr = LForms.Util.getFormFHIRData('QuestionnaireResponse', 'R4');
let formElement = document.getElementById("formContainer");
let data = LForms.Util.getUserData(formElement, true, true, true);
let data = LForms.Util.getUserData(formElement, false, true, true);
document.getElementById('lform_response').value = JSON.stringify(data);
document.getElementById('questionnaire_response').value = JSON.stringify(qr);
if (!document.getElementById('questionnaire').value) {
Expand Down Expand Up @@ -192,13 +191,13 @@ function initUpdate() {
function initNewForm(flag = false) {
let lform = <?php echo js_escape($lform); ?>;
let qFhir = <?php echo js_escape($q_json); ?>;
let formName = <?php echo js_escape($questionnaire_form); ?>;
let formName = <?php echo js_escape($form_name); ?>;
let data;
if (qFhir) {
if (lform) {
data = JSON.parse(lform);
} else if (qFhir) {
let qData = JSON.parse(qFhir);
data = LForms.Util.convertFHIRQuestionnaireToLForms(qData, 'R4');
} else if (lform) {
data = JSON.parse(lform);
} else {
alert(xl('Error Missing Form.'));
parent.closeTab(window.name, false);
Expand Down Expand Up @@ -398,12 +397,7 @@ function initSearchForm() {
<script src="<?php /*echo $GLOBALS['assets_static_relative']; */?>/lforms/fhir/R4/lformsFHIR.min.js"></script>-->

<!-- TODO Temporary dependencies location -->
<script src="./../../forms/questionnaire_assessments/lforms/webcomponent/assets/lib/zone.min.js"></script>
<script src="./../../forms/questionnaire_assessments/lforms/webcomponent/scripts.js"></script>
<script src="./../../forms/questionnaire_assessments/lforms/webcomponent/runtime-es2015.js"></script>
<script src="./../../forms/questionnaire_assessments/lforms/webcomponent/polyfills-es2015.js"></script>
<script src="./../../forms/questionnaire_assessments/lforms/webcomponent/main-es2015.js"></script>
<script src="./../../forms/questionnaire_assessments/lforms/fhir/R4/lformsFHIR.min.js"></script>
<?php require(__DIR__ . "/../../forms/questionnaire_assessments/lform_webcomponents.php") ?>
<!-- Dependency scopes seem strange using the way we have to implement the necessary web components. -->
<?php Header::setupAssets(['select2']); ?>
<script>
Expand Down
5 changes: 2 additions & 3 deletions interface/patient_file/history/encounters.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ function efmouseover(elem, ptid, encid, formname, formid) {
}

$rawdata = $result4['encounter'] . "~" . oeFormatShortDate($raw_encounter_date);
echo "<tr class='encrow text' id='" . attr($rawdata) .
"'>\n";
echo "<tr class='encrow text' id='" . attr($rawdata) . "'>\n";

// show encounter date
echo "<td class='align-top' data-toggle='tooltip' data-placement='top' title='" . attr(xl('View encounter') . ' ' . $pid . "." . $result4['encounter']) . "'>" . text(oeFormatShortDate($raw_encounter_date)) . "</td>\n";
Expand Down Expand Up @@ -837,7 +836,7 @@ function efmouseover(elem, ptid, encid, formname, formid) {

</div> <!-- end 'encounters' large outer DIV -->

<span class='position-absolute border border-danger w-auto jumbotron p-1 m-4' id='tooltipdiv' style='max-width: 75%; visibility: hidden;'></span>
<span class='position-absolute border border-danger w-auto jumbotron p-1 ml-4' id='tooltipdiv' style='max-width: 75%; visibility: hidden;'></span>

<script>
// jQuery stuff to make the page a little easier to use
Expand Down
8 changes: 7 additions & 1 deletion library/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,22 @@ if (typeof alertMsg !== "function") {
'<button type="button" class="btn btn-link ' + oHidden + '" id="dontShowAgain" data-dismiss="alert">' +
gotIt + '&nbsp;<i class="fa fa-thumbs-up"></i></button>' +
'<h4 class="alert-heading text-center">' + title + '!</h4><hr>' + '<p style="color:#000;">' + message + '</p>' +
'<button type="button" class="pull-right btn btn-link" data-dismiss="alert">' + dismiss + '</button><br /></div>';
'<button type="button" id="alertDismissButton" class="pull-right btn btn-link" data-dismiss="alert">' + dismiss + '</button><br /></div>';
$('#alert_box').append(mHtml);
$('#alertmsg').on('closed.bs.alert', function () {
clearTimeout(AlertMsg);
$('#alert_box').remove();
return false;
});
$('#dontShowAgain').on('click', function (e) {
clearTimeout(AlertMsg);
$('#alert_box').remove();
persistUserOption(persist, 1);
});
$('#alertDismissButton').on('click', function (e) {
clearTimeout(AlertMsg);
$('#alert_box').remove();
});
let AlertMsg = setTimeout(function () {
$('#alertmsg').fadeOut(800, function () {
$('#alert_box').remove();
Expand Down
2 changes: 0 additions & 2 deletions library/js/ajtooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,4 @@ function ttMouseOut() {
ttClearTimer();
var ttobject = document.getElementById("tooltipdiv");
ttobject.style.visibility='hidden';
ttobject.style.left = '-1000px';
}

107 changes: 71 additions & 36 deletions portal/import_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Core\Header;
use OpenEMR\Services\DocumentTemplates\DocumentTemplateService;
use OpenEMR\Services\QuestionnaireService;

if (!(isset($GLOBALS['portal_onsite_two_enable'])) || !($GLOBALS['portal_onsite_two_enable'])) {
echo xlt('Patient Portal is turned off');
Expand Down Expand Up @@ -148,7 +149,75 @@
exit;
}
die(xlt('Invalid Request Parameters'));
} elseif (count($_FILES['template_files']['name'] ?? []) > 0 && !empty($_FILES['template_files']['name'][0] ?? '') && !isset($_POST['blank-nav-button'])) {
}

if (isset($_POST['blank-nav-button'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"], 'import-template-upload')) {
CsrfUtils::csrfNotVerified();
}
if (!$authUploadTemplates) {
xlt("Not Authorized to Upload Templates");
exit;
}
$is_blank = isset($_POST['blank-nav-button']);
$upload_name = $_POST['upload_name'] ?? '';
$category = $_POST['template_category'] ?? '';
$patient = '-1';
if (!empty($upload_name)) {
$name = preg_replace("/[^A-Z0-9.]/i", " ", $upload_name);
try {
$content = "{ParseAsHTML}";
$success = $templateService->insertTemplate($patient, $category, $upload_name, $content, 'application/text');
if (!$success) {
header('refresh:3;url= import_template_ui.php');
echo "<h4 style='color:red;'>" . xlt("New template save failed. Try again.") . "</h4>";
exit;
}
} catch (Exception $e) {
header('refresh:3;url= import_template_ui.php');
echo '<h3>' . xlt('Error') . "</h3><h4 style='color:red;'>" .
text($e->getMessage()) . '</h4>';
exit;
}
}
header("location: " . $_SERVER['HTTP_REFERER']);
die();
}

if (isset($_REQUEST['q_mode']) && !empty($_REQUEST['q_mode'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"], 'import-template-upload')) {
CsrfUtils::csrfNotVerified();
}
if (!$authUploadTemplates) {
xlt("Not Authorized to Upload Templates");
exit;
}
$id = 0;
$q = $_POST['questionnaire'] ?? '';
$l = $_POST['lform'] ?? '';
if (!empty($q)) {
$service = new QuestionnaireService();
try {
$id = $service->saveQuestionnaireResource($q, null, null, null, $l);
} catch (Exception $e) {
header('refresh:3;url= import_template_ui.php');
echo '<h3>' . xlt('Error') . "</h3><h4 style='color:red;'>" .
text($e->getMessage()) . '</h4>';
exit;
}
if (empty($id)) {
header('refresh:3;url= import_template_ui.php');
echo '<h3>' . xlt('Error') . "</h3><h4 style='color:red;'>" .
xlt("Import failed to save.") . '</h4>';
exit;
}
}
header("location: " . $_SERVER['HTTP_REFERER']);
die();
}

// templates file import
if ((count($_FILES['template_files']['name'] ?? []) > 0) && !empty($_FILES['template_files']['name'][0] ?? '')) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"], 'import-template-upload')) {
CsrfUtils::csrfNotVerified();
}
Expand Down Expand Up @@ -233,41 +302,7 @@
die();
}

if (isset($_POST['blank-nav-button'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"], 'import-template-upload')) {
CsrfUtils::csrfNotVerified();
}
if (!$authUploadTemplates) {
xlt("Not Authorized to Upload Templates");
exit;
}
$is_blank = isset($_POST['blank-nav-button']);
$upload_name = $_POST['upload_name'] ?? '';
$category = $_POST['template_category'] ?? '';
$patient = '-1';
if (!empty($upload_name)) {
$name = preg_replace("/[^A-Z0-9.]/i", " ", $upload_name);
$name = ucwords(strtolower($name));
try {
$content = "{ParseAsHTML}";
$success = $templateService->insertTemplate($patient, $category, $upload_name, $content, 'application/text');
if (!$success) {
header('refresh:3;url= import_template_ui.php');
echo "<h4 style='color:red;'>" . xlt("New template save failed. Try again.") . "</h4>";
exit;
}
} catch (Exception $e) {
header('refresh:3;url= import_template_ui.php');
echo '<h3>' . xlt('Error') . "</h3><h4 style='color:red;'>" .
text($e->getMessage()) . '</h4>';
exit;
}
}
header("location: " . $_SERVER['HTTP_REFERER']);
die();
}

if ($_REQUEST['mode'] === 'editor_render_html') {
if (($_REQUEST['mode'] ?? '') === 'editor_render_html') {
if ($_REQUEST['docid']) {
$content = $templateService->fetchTemplate($_REQUEST['docid']);
$template_content = $content['template_content'];
Expand Down
Loading

0 comments on commit 1475375

Please sign in to comment.