Skip to content

Commit

Permalink
Switching from smarty to twig templating for soap form (openemr#5984)
Browse files Browse the repository at this point in the history
  • Loading branch information
juggernautsei committed Jun 4, 2023
1 parent 9f8b410 commit d8478fb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 43 deletions.
65 changes: 44 additions & 21 deletions interface/forms/soap/C_FormSOAP.class.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
<?php

/**
/*
* soap form
*
* @package OpenEMR
* @link http:https://www.open-emr.org
* @author Brady Miller <[email protected]>
* @author Sherwin Gaddis <[email protected]>
* @copyright Copyright (c) 2019 Brady Miller <[email protected]>
* @copyright Copyright (c) 2022 Sherwin Gaddis <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

require_once($GLOBALS['fileroot'] . "/library/forms.inc.php");
require_once("FormSOAP.class.php");

use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Common\Twig\TwigContainer;

class C_FormSOAP extends Controller
{
var $template_dir;

function __construct($template_mod = "general")
private TwigContainer $twig;
public function __construct()
{
parent::__construct();
$this->template_mod = $template_mod;
$this->template_dir = dirname(__FILE__) . "/templates/";
$this->assign("FORM_ACTION", $GLOBALS['web_root']);
$this->assign("DONT_SAVE_LINK", $GLOBALS['form_exit_url']);
$this->assign("STYLE", $GLOBALS['style']);
$this->assign("CSRF_TOKEN_FORM", CsrfUtils::collectCsrfToken());
$path = $this->getTemplatePath();
$this->twig = new TwigContainer($path);
}

/**
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
* @throws \Twig\Error\LoaderError
*/
function default_action()
{
$form = new FormSOAP();
$this->assign("data", $form);
return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
return $this->twig->getTwig()->render(
'soap_form.twig',
[
"FORM_ACTION" => $GLOBALS['web_root'],
"DONT_SAVE_LINK" => $GLOBALS['form_exit_url'],
"data" => $form
]
);
}

function view_action($form_id)
Expand All @@ -45,9 +51,14 @@ function view_action($form_id)
$form = new FormSOAP();
}

$this->assign("data", $form);

return $this->fetch($this->template_dir . $this->template_mod . "_new.html");
return $this->twig->getTwig()->render(
'soap_form.twig',
[
"FORM_ACTION" => $GLOBALS['web_root'],
"DONT_SAVE_LINK" => $GLOBALS['form_exit_url'],
"data" => $form
]
);
}

function default_action_process()
Expand All @@ -65,10 +76,22 @@ function default_action_process()
}

if (empty($_POST['id'])) {
addForm($GLOBALS['encounter'], "SOAP", $this->form->id, "soap", $GLOBALS['pid'], $_SESSION['userauthorized']);
addForm(
$GLOBALS['encounter'],
"SOAP",
$this->form->id,
"soap",
$GLOBALS['pid'],
$_SESSION['userauthorized']
);
$_POST['process'] = "";
}

return;
}
/**
* @return string
*/
private function getTemplatePath(): string
{
return \dirname(__DIR__) . DIRECTORY_SEPARATOR . "soap/templates" . DIRECTORY_SEPARATOR;
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
<html>
<head>
<title>{xlt t='SOAP'}</title>
{headerTemplate}
<title>{{ 'SOAP'|xlt }}</title>
{{ setupHeader() }}
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12">
<h2>{xlt t='SOAP'}</h2>
<form name="soap" method="post" action="{$FORM_ACTION}/interface/forms/soap/save.php" onsubmit="return top.restoreSession()">
<input type="hidden" name="csrf_token_form" value="{$CSRF_TOKEN_FORM|attr}" />
<h2>{{'SOAP'|xlt}}</h2>
<form name="soap" method="post" action="{{ FORM_ACTION | attr }}/interface/forms/soap/save.php" onsubmit="return top.restoreSession()">
<input type="hidden" name="csrf_token_form" value="{{ csrfTokenRaw()|attr }}" />
<fieldset>
<legend>{xlt t='Subjective'}</legend>
<legend>{{ 'Subjective' | xlt }}</legend>
<div class="container">
<div class="form-group" >
<textarea name="subjective" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{$data->get_subjective()|text}</textarea>
<textarea name="subjective" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{{ data.get_subjective()|text }}</textarea>
</div>
</div>
</fieldset>
<fieldset>
<legend>{xlt t='Objective'}</legend>
<legend>{{ 'Objective' | xlt }}</legend>
<div class="container">
<div class="form-group">
<textarea name="objective" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{$data->get_objective()|text}</textarea>
<textarea name="objective" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{{ data.get_objective()|text }}</textarea>
</div>
</div>
</fieldset>
<fieldset>
<legend>{xlt t='Assessment'}</legend>
<legend>{{ 'Assessment'|xlt }}</legend>
<div class="container">
<div class="form-group">
<textarea name="assessment" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{$data->get_assessment()|text}</textarea>
<textarea name="assessment" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{{ data.get_assessment()|text }}</textarea>
</div>
</div>
</fieldset>
<fieldset>
<legend>{xlt t='Plan'}</legend>
<legend>{{ 'Plan'|xlt }}</legend>
<div class="container">
<div class="form-group">
<textarea name="plan" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{$data->get_plan()|text}</textarea>
<textarea name="plan" class="form-control" cols="60" rows="6" onkeyup="top.isSoapEdit = true;">{{ data.get_plan()|text }}</textarea>
</div>
</div>
</fieldset>
<div class="form-group">
<div class="btn-group" role="group">
<button type="submit" class="btn btn-primary btn-save" name="Submit">{xlt t='Save'}</button>
<button type="button" class="btn btn-secondary btn-cancel" id="btnClose">{xlt t='Cancel'}</button>
<button type="submit" class="btn btn-primary btn-save" name="Submit">{{ 'Save'|xlt }}</button>
<button type="button" class="btn btn-secondary btn-cancel" id="btnClose">{{ 'Cancel'|xlt }}</button>
</div>
<input type="hidden" name="id" value="{$data->get_id()|attr}" />
<input type="hidden" name="activity" value="{$data->get_activity()|attr}" />
<input type="hidden" name="pid" value="{$data->get_pid()|attr}" />
<input type="hidden" name="id" value="{{ data.get_id()|attr }}" />
<input type="hidden" name="activity" value="{{ data.get_activity()|attr }}" />
<input type="hidden" name="pid" value="{{ data.get_pid()|attr }}" />
<input type="hidden" name="process" value="true" />
</div>
</form>
Expand All @@ -60,12 +60,13 @@ <h2>{xlt t='SOAP'}</h2>
<script>
const close = function() {
if (top.isSoapEdit === true) {
dlgopen('', '', 450, 125, '', '<div class="text-danger">{xla t='Warning'}</div>', {
dlgopen('', '', 450, 125, '', '<div class="text-danger">{{'Warning'|xlt}}</div>',
{
type: 'Alert',
html: '<p>{xla t='Do you want to close the tabs?'}</p>',
html: '<p>{{'Do you want to close the tabs?'|xla}}</p>',
buttons: [
{ text: '{xla t='Cancel'}', close: true, style: 'default btn-sm' },
{ text: '{xla t='Close'}', close: true, style: 'danger btn-sm', click: closeSoap },
{ text: '{{'Cancel'|xla}}', close: true, style: 'default btn-sm' },
{ text: '{{'Close'|xla}}', close: true, style: 'danger btn-sm', click: closeSoap },
],
allowDrag: false,
allowResize: false,
Expand Down

0 comments on commit d8478fb

Please sign in to comment.