sql-injection fix in demographics
[openemr.git] / library / ESign / Api.php
blob09a16680a7ab69055f50c4ac6c4c0992ab8186e0
1 <?php
3 namespace ESign;
5 /**
6 * Top-level API and helper functions for the ESign module
7 *
8 * Copyright (C) 2013 OEMR 501c3 www.oemr.org
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Ken Chapple <ken@mi-squared.com>
23 * @author Medical Information Integration, LLC
24 * @link http://www.open-emr.org
25 **/
27 require_once $GLOBALS['srcdir'].'/ESign/ESign.php';
28 require_once $GLOBALS['srcdir'].'/ESign/FactoryIF.php';
29 require_once $GLOBALS['srcdir'].'/ESign/ConfigurationIF.php';
30 require_once $GLOBALS['srcdir'].'/ESign/SignableIF.php';
31 require_once $GLOBALS['srcdir'].'/ESign/Form/Factory.php';
32 require_once $GLOBALS['srcdir'].'/ESign/Form/Configuration.php';
33 require_once $GLOBALS['srcdir'].'/ESign/Encounter/Factory.php';
34 require_once $GLOBALS['srcdir'].'/ESign/Encounter/Configuration.php';
36 class Api
38 public function lockEncounters()
40 return $GLOBALS['lock_esign_all'];
43 public function formConfigToJson()
45 $configuration = new Form_Configuration();
46 return $this->configToJson( $configuration );
49 public function createFormESign( $formId, $formDir, $encounterId )
51 $factory = new Form_Factory( $formId, $formDir, $encounterId );
52 $esign = $this->createESign( $factory );
53 return $esign;
56 public function encounterConfigToJson()
58 $configuration = new Encounter_Configuration();
59 return $this->configToJson( $configuration );
62 public function createEncounterESign( $encounterId )
64 $factory = new Encounter_Factory( $encounterId );
65 $esign = $this->createESign( $factory );
66 return $esign;
69 public function createEncounterSignable( $encounterId )
71 $signable = new Encounter_Signable( $encounterId );
72 return $signable;
75 public function createESign( FactoryIF $factory )
77 $configuration = $factory->createConfiguration();
78 $signable = $factory->createSignable();
79 $button = $factory->createButton();
80 $log = $factory->createLog();
81 $esign = new ESign( $configuration, $signable, $button, $log );
82 return $esign;
85 /**
86 * This contains the configuration for the esign javascript object
88 * @return string
90 public function configToJson( ConfigurationIF $configuration )
92 $params = array(
93 'baseUrl' => $configuration->getBaseUrl(),
94 'logViewAction' => $configuration->getLogViewAction(),
95 'formViewAction' => $configuration->getFormViewAction(),
96 'formSubmitAction' => $configuration->getFormSubmitAction(),
97 'module' => $configuration->getModule()
100 $json = json_encode( $params );
101 return $json;
104 public function sign( SignableIF $signable, $userId, $lock = false, $amendment = null )
106 try {
107 $ret = $signable->sign( $userId, $lock, $amendment );
108 return $ret;
109 } catch ( \Exception $e ) {
110 error_log( $e->getMessage() );
111 return false;
115 public function lock( SignableIF $signable, $userId, $amendment = null )
117 return $this->sign( $signable, $userId, true, $amendment );