update functionality. (#1427)
[openemr.git] / phpfhir / libs / controller / ClientAppController.php
blob4d78aa76df463c2ace4d34b31ea0dff810db9869
1 <?php
2 /**
3 * clientController class
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Jerry Padgett <sjpadgett@gmail.com>
8 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
9 * @license https://www.gnu.org/licenses/agpl-3.0.en.html GNU Affero General Public License 3
12 require_once("oeDispatcher.php");
14 use oeFHIR\FetchLiveData;
15 use oeFHIR\oeFHIRHttpClient;
16 use oeFHIR\oeFHIRResource;
18 class clientController extends oeDispatchController
20 public function __construct()
22 parent::__construct();
25 public function indexAction()
27 if (!$this->getSession('pid', '')) {
28 $pid = $this->getRequest('patient_id');
29 $this->setSession('pid', $pid);
30 } else {
31 $pid = $this->getSession('pid', '');
34 return null;
37 public function createEncounterAllAction()
39 $pid = $this->getRequest(pid);
40 $oeid = $this->getRequest(oeid);
41 $type = $this->getRequest(type);
42 $fs = new FetchLiveData();
43 $oept = $fs->getEncounterIdList($pid);
44 $notify = '';
45 foreach ($oept as $e) {
46 $client = new oeFHIRHttpClient();
47 $id = 'encounter-' . $e['encounter'];
48 $rs = new oeFHIRResource();
49 $r = $rs->createEncounterResource($pid, $id, $e['encounter']);
50 $pt = $client->sendResource($type, $id, $r);
51 $notify .= '<strong>Sent:</strong></br>' . $r . '</br>' . $pt;
53 return $notify;
56 public function createAction()
58 $pid = $this->getRequest(pid);
59 $oeid = $this->getRequest(oeid);
60 $type = $this->getRequest(type);
61 $client = new oeFHIRHttpClient();
62 $id = strtolower($type) . '-' . $oeid;
63 $method = 'create' . $type . 'Resource';
64 $rs = new oeFHIRResource();
65 $r = $rs->$method($pid, $id);
66 $pt = $client->sendResource($type, $id, $r);
68 return '<strong>Sent:</strong></br>' . $r . '</br>' . $pt;
71 public function historyAction()
73 $pid = $this->getRequest(pid);
74 $oeid = $this->getRequest(oeid);
75 $type = $this->getRequest(type);
76 $client = new oeFHIRHttpClient();
77 $id = strtolower($type) . '-' . $oeid;
78 $pt = $client->requestResource($type, $id, 'history');
79 return $pt;
82 public function readAction()
84 $pid = $this->getRequest(pid);
85 $oeid = $this->getRequest(oeid);
86 $type = $this->getRequest(type);
87 $client = new oeFHIRHttpClient();
88 $id = strtolower($type) . '-' . $oeid;
89 $pt = $client->requestResource($type, $id, ''); // gets latest version.
90 return $pt;
93 public function searchAction()
95 $pid = $this->getRequest(pid);
96 $type = $this->getRequest(type);
97 if ($type === 'Patient') {
98 return xlt('Search Not Available');
100 $client = new oeFHIRHttpClient();
101 $id = 'patient-' . $pid;
102 $pt = $client->searchResource($type, $id, 'search');
103 return $pt;