Highway to PSR2
[openemr.git] / library / ESign / Encounter / Controller.php
blobf5a76d9edf4692198eb3020a80786548aeddedc6
1 <?php
3 namespace ESign;
5 /**
6 * Encounter controller implementation
8 * Copyright (C) 2013 OEMR 501c3 www.oemr.org
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Ken Chapple <ken@mi-squared.com>
24 * @author Medical Information Integration, LLC
25 * @link http://www.open-emr.org
26 **/
28 require_once $GLOBALS['srcdir'].'/ESign/Abstract/Controller.php';
29 require_once $GLOBALS['srcdir'].'/ESign/Encounter/Configuration.php';
30 require_once $GLOBALS['srcdir'].'/ESign/Encounter/Signable.php';
31 require_once $GLOBALS['srcdir'].'/ESign/Encounter/Log.php';
33 class Encounter_Controller extends Abstract_Controller
35 public function esign_is_encounter_locked()
37 $encounterId = $this->getRequest()->getParam('encounterId', '');
38 $signable = new Encounter_Signable($encounterId);
39 echo json_encode($signable->isLocked());
40 exit;
43 public function esign_form_view()
45 $form = new \stdClass();
46 $form->table = 'form_encounter';
47 $form->encounterId = $this->getRequest()->getParam('encounterid', 0);
48 $form->userId = $GLOBALS['authUserID'];
49 $form->action = '#';
50 $signable = new Encounter_Signable($form->encounterId);
51 $form->showLock = false;
52 if ($signable->isLocked() === false &&
53 $GLOBALS['lock_esign_all'] &&
54 $GLOBALS['esign_lock_toggle'] ) {
55 $form->showLock = true;
58 $this->_view->form = $form;
59 $this->setViewScript('encounter/esign_form.php');
60 $this->render();
63 public function esign_log_view()
65 $encounterId = $this->getRequest()->getParam('encounterId', '');
66 $signable = new Encounter_Signable($encounterId); // Contains features that make object signable
67 $log = new Encounter_Log($encounterId); // Make the log behavior
68 $html = $log->getHtml($signable);
69 echo $html;
70 exit;
73 /**
75 * @return multitype:string
77 public function esign_form_submit()
79 $message = '';
80 $status = self::STATUS_FAILURE;
81 $password = $this->getRequest()->getParam('password', '');
82 $encounterId = $this->getRequest()->getParam('encounterId', '');
83 // Lock if 'Lock e-signed encounters and their forms' option is set,
84 // unless esign_lock_toggle option is enable in globals, then check the request param
85 $lock = false;
86 if ($GLOBALS['lock_esign_all']) {
87 $lock = true;
88 if ($GLOBALS['esign_lock_toggle']) {
89 $lock = ( $this->getRequest()->getParam('lock', '') == 'on' ) ? true : false;
93 $amendment = $this->getRequest()->getParam('amendment', '');
94 if (confirm_user_password($_SESSION['authUser'], $password)) {
95 $signable = new Encounter_Signable($encounterId);
96 if ($signable->sign($_SESSION['authUserID'], $lock, $amendment)) {
97 $message = xlt("Form signed successfully");
98 $status = self::STATUS_SUCCESS;
99 } else {
100 $message = xlt("An error occured signing the form");
102 } else {
103 $message = xlt("The password you entered is invalid");
106 $response = new Response($status, $message);
107 $response->encounterId = $encounterId;
108 $response->locked = $lock;
109 if ($lock) {
110 $response->editButtonHtml = "<a href=# class='css_button_small form-edit-button-locked'><span>".xlt('Locked')."</span></a>";
113 echo json_encode($response);
114 exit;