add/edit event rework to get workable.
[openemr.git] / _rest_routes.inc.php
blob510a2b75af3210a9c826908909d470bd201020cb
1 <?php
2 /**
3 * Routes
4 * (All REST routes)
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Matthew Vita <matthewvita48@gmail.com>
9 * @author Jerry Padgett <sjpadgett@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
12 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
13 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 // Lets keep our controller classes with the routes.
19 use OpenEMR\RestControllers\FacilityRestController;
20 use OpenEMR\RestControllers\VersionRestController;
21 use OpenEMR\RestControllers\ProductRegistrationRestController;
22 use OpenEMR\RestControllers\PatientRestController;
23 use OpenEMR\RestControllers\EncounterRestController;
24 use OpenEMR\RestControllers\ProviderRestController;
25 use OpenEMR\RestControllers\ListRestController;
26 use OpenEMR\RestControllers\InsuranceCompanyRestController;
27 use OpenEMR\RestControllers\AppointmentRestController;
28 use OpenEMR\RestControllers\AuthRestController;
29 use OpenEMR\RestControllers\ONoteRestController;
30 use OpenEMR\RestControllers\DocumentRestController;
31 use OpenEMR\RestControllers\InsuranceRestController;
32 use OpenEMR\RestControllers\MessageRestController;
35 // Note some Http clients may not send auth as json so a function
36 // is implemented to determine and parse encoding on auth route's.
38 RestConfig::$ROUTE_MAP = array(
39 "POST /api/auth" => function () {
40 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
41 return (new AuthRestController())->authenticate($data);
43 "GET /api/facility" => function () {
44 RestConfig::authorization_check("admin", "users");
45 return (new FacilityRestController())->getAll();
47 "GET /api/facility/:fid" => function ($fid) {
48 RestConfig::authorization_check("admin", "users");
49 return (new FacilityRestController())->getOne($fid);
51 "POST /api/facility" => function () {
52 RestConfig::authorization_check("admin", "super");
53 $data = (array)(json_decode(file_get_contents("php://input")));
54 return (new FacilityRestController())->post($data);
56 "PUT /api/facility/:fid" => function ($fid) {
57 RestConfig::authorization_check("admin", "super");
58 $data = (array)(json_decode(file_get_contents("php://input")));
59 $data["fid"] = $fid;
60 return (new FacilityRestController())->put($data);
62 "GET /api/provider" => function () {
63 RestConfig::authorization_check("admin", "users");
64 return (new ProviderRestController())->getAll();
66 "GET /api/provider/:prid" => function ($prid) {
67 RestConfig::authorization_check("admin", "users");
68 return (new ProviderRestController())->getOne($prid);
70 "GET /api/patient" => function () {
71 RestConfig::authorization_check("patients", "demo");
72 return (new PatientRestController(null))->getAll($_GET);
74 "POST /api/patient" => function () {
75 RestConfig::authorization_check("patients", "demo");
76 $data = (array)(json_decode(file_get_contents("php://input")));
77 return (new PatientRestController(null))->post($data);
79 "PUT /api/patient/:pid" => function ($pid) {
80 RestConfig::authorization_check("patients", "demo");
81 $data = (array)(json_decode(file_get_contents("php://input")));
82 return (new PatientRestController(null))->put($pid, $data);
84 "GET /api/patient/:pid" => function ($pid) {
85 RestConfig::authorization_check("patients", "demo");
86 return (new PatientRestController($pid))->getOne();
88 "GET /api/patient/:pid/encounter" => function ($pid) {
89 RestConfig::authorization_check("encounters", "auth_a");
90 return (new EncounterRestController())->getAll($pid);
92 "GET /api/patient/:pid/encounter/:eid" => function ($pid, $eid) {
93 RestConfig::authorization_check("encounters", "auth_a");
94 return (new EncounterRestController())->getOne($pid, $eid);
96 "GET /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
97 RestConfig::authorization_check("encounters", "notes");
98 return (new EncounterRestController())->getSoapNotes($pid, $eid);
100 "POST /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
101 RestConfig::authorization_check("encounters", "notes");
102 $data = (array)(json_decode(file_get_contents("php://input")));
103 return (new EncounterRestController())->postVital($pid, $eid, $data);
105 "PUT /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
106 RestConfig::authorization_check("encounters", "notes");
107 $data = (array)(json_decode(file_get_contents("php://input")));
108 return (new EncounterRestController())->putVital($pid, $eid, $vid, $data);
110 "GET /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
111 RestConfig::authorization_check("encounters", "notes");
112 return (new EncounterRestController())->getVitals($pid, $eid);
114 "GET /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
115 RestConfig::authorization_check("encounters", "notes");
116 return (new EncounterRestController())->getVital($pid, $eid, $vid);
118 "GET /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
119 RestConfig::authorization_check("encounters", "notes");
120 return (new EncounterRestController())->getSoapNote($pid, $eid, $sid);
122 "POST /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
123 RestConfig::authorization_check("encounters", "notes");
124 $data = (array)(json_decode(file_get_contents("php://input")));
125 return (new EncounterRestController())->postSoapNote($pid, $eid, $data);
127 "PUT /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
128 RestConfig::authorization_check("encounters", "notes");
129 $data = (array)(json_decode(file_get_contents("php://input")));
130 return (new EncounterRestController())->putSoapNote($pid, $eid, $sid, $data);
132 "GET /api/patient/:pid/medical_problem" => function ($pid) {
133 RestConfig::authorization_check("encounters", "notes");
134 return (new ListRestController())->getAll($pid, "medical_problem");
136 "GET /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
137 RestConfig::authorization_check("patients", "med");
138 return (new ListRestController())->getOne($pid, "medical_problem", $mid);
140 "POST /api/patient/:pid/medical_problem" => function ($pid) {
141 RestConfig::authorization_check("patients", "med");
142 $data = (array)(json_decode(file_get_contents("php://input")));
143 return (new ListRestController())->post($pid, "medical_problem", $data);
145 "PUT /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
146 RestConfig::authorization_check("patients", "med");
147 $data = (array)(json_decode(file_get_contents("php://input")));
148 return (new ListRestController())->put($pid, $mid, "medical_problem", $data);
150 "DELETE /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
151 RestConfig::authorization_check("patients", "med");
152 return (new ListRestController())->delete($pid, $mid, "medical_problem");
154 "GET /api/patient/:pid/allergy" => function ($pid) {
155 RestConfig::authorization_check("patients", "med");
156 return (new ListRestController())->getAll($pid, "allergy");
158 "GET /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
159 RestConfig::authorization_check("patients", "med");
160 return (new ListRestController())->getOne($pid, "allergy", $aid);
162 "DELETE /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
163 RestConfig::authorization_check("patients", "med");
164 return (new ListRestController())->delete($pid, $aid, "allergy");
166 "POST /api/patient/:pid/allergy" => function ($pid) {
167 RestConfig::authorization_check("patients", "med");
168 $data = (array)(json_decode(file_get_contents("php://input")));
169 return (new ListRestController())->post($pid, "allergy", $data);
171 "PUT /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
172 RestConfig::authorization_check("patients", "med");
173 $data = (array)(json_decode(file_get_contents("php://input")));
174 return (new ListRestController())->put($pid, $aid, "allergy", $data);
176 "GET /api/patient/:pid/medication" => function ($pid) {
177 RestConfig::authorization_check("patients", "med");
178 return (new ListRestController())->getAll($pid, "medication");
180 "POST /api/patient/:pid/medication" => function ($pid) {
181 RestConfig::authorization_check("patients", "med");
182 $data = (array)(json_decode(file_get_contents("php://input")));
183 return (new ListRestController())->post($pid, "medication", $data);
185 "PUT /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
186 RestConfig::authorization_check("patients", "med");
187 $data = (array)(json_decode(file_get_contents("php://input")));
188 return (new ListRestController())->put($pid, $mid, "medication", $data);
190 "GET /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
191 RestConfig::authorization_check("patients", "med");
192 return (new ListRestController())->getOne($pid, "medication", $mid);
194 "DELETE /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
195 RestConfig::authorization_check("patients", "med");
196 return (new ListRestController())->delete($pid, $mid, "medication");
198 "GET /api/patient/:pid/surgery" => function ($pid) {
199 RestConfig::authorization_check("patients", "med");
200 return (new ListRestController())->getAll($pid, "surgery");
202 "GET /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
203 RestConfig::authorization_check("patients", "med");
204 return (new ListRestController())->getOne($pid, "surgery", $sid);
206 "DELETE /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
207 RestConfig::authorization_check("patients", "med");
208 return (new ListRestController())->delete($pid, $sid, "surgery");
210 "POST /api/patient/:pid/surgery" => function ($pid) {
211 RestConfig::authorization_check("patients", "med");
212 $data = (array)(json_decode(file_get_contents("php://input")));
213 return (new ListRestController())->post($pid, "surgery", $data);
215 "PUT /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
216 RestConfig::authorization_check("patients", "med");
217 $data = (array)(json_decode(file_get_contents("php://input")));
218 return (new ListRestController())->put($pid, $sid, "surgery", $data);
220 "GET /api/patient/:pid/dental_issue" => function ($pid) {
221 RestConfig::authorization_check("patients", "med");
222 return (new ListRestController())->getAll($pid, "dental");
224 "GET /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
225 RestConfig::authorization_check("patients", "med");
226 return (new ListRestController())->getOne($pid, "dental", $did);
228 "DELETE /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
229 RestConfig::authorization_check("patients", "med");
230 return (new ListRestController())->delete($pid, $did, "dental");
232 "POST /api/patient/:pid/dental_issue" => function ($pid) {
233 RestConfig::authorization_check("patients", "med");
234 $data = (array)(json_decode(file_get_contents("php://input")));
235 return (new ListRestController())->post($pid, "dental", $data);
237 "PUT /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
238 RestConfig::authorization_check("patients", "med");
239 $data = (array)(json_decode(file_get_contents("php://input")));
240 return (new ListRestController())->put($pid, $did, "dental", $data);
242 "GET /api/patient/:pid/appointment" => function ($pid) {
243 RestConfig::authorization_check("patients", "appt");
244 return (new AppointmentRestController())->getAllForPatient($pid);
246 "POST /api/patient/:pid/appointment" => function ($pid) {
247 RestConfig::authorization_check("patients", "appt");
248 $data = (array)(json_decode(file_get_contents("php://input")));
249 return (new AppointmentRestController())->post($pid, $data);
251 "GET /api/appointment" => function () {
252 RestConfig::authorization_check("patients", "appt");
253 return (new AppointmentRestController())->getAll();
255 "GET /api/appointment/:eid" => function ($eid) {
256 RestConfig::authorization_check("patients", "appt");
257 return (new AppointmentRestController())->getOne($eid);
259 "DELETE /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
260 RestConfig::authorization_check("patients", "appt");
261 return (new AppointmentRestController())->delete($eid);
263 "GET /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
264 RestConfig::authorization_check("patients", "appt");
265 return (new AppointmentRestController())->getOne($eid);
267 "GET /api/list/:list_name" => function ($list_name) {
268 RestConfig::authorization_check("lists", "default");
269 return (new ListRestController())->getOptions($list_name);
271 "GET /api/version" => function () {
272 return (new VersionRestController())->getOne();
274 "GET /api/product" => function () {
275 return (new ProductRegistrationRestController())->getOne();
277 "GET /api/insurance_company" => function () {
278 return (new InsuranceCompanyRestController())->getAll();
280 "GET /api/insurance_type" => function () {
281 return (new InsuranceCompanyRestController())->getInsuranceTypes();
283 "POST /api/insurance_company" => function () {
284 $data = (array)(json_decode(file_get_contents("php://input")));
285 return (new InsuranceCompanyRestController())->post($data);
287 "PUT /api/insurance_company/:iid" => function ($iid) {
288 $data = (array)(json_decode(file_get_contents("php://input")));
289 return (new InsuranceCompanyRestController())->put($iid, $data);
291 "POST /api/patient/:pid/document" => function ($pid) {
292 return (new DocumentRestController())->postWithPath($pid, $_GET['path'], $_FILES['document']);
294 "GET /api/patient/:pid/document" => function ($pid) {
295 return (new DocumentRestController())->getAllAtPath($pid, $_GET['path']);
297 "GET /api/patient/:pid/document/:did" => function ($pid, $did) {
298 return (new DocumentRestController())->downloadFile($pid, $did);
300 "GET /api/patient/:pid/insurance" => function ($pid) {
301 return (new InsuranceRestController())->getAll($pid);
303 "GET /api/patient/:pid/insurance/:type" => function ($pid, $type) {
304 return (new InsuranceRestController())->getOne($pid, $type);
306 "POST /api/patient/:pid/insurance/:type" => function ($pid, $type) {
307 $data = (array)(json_decode(file_get_contents("php://input")));
308 return (new InsuranceRestController())->post($pid, $type, $data);
310 "PUT /api/patient/:pid/insurance/:type" => function ($pid, $type) {
311 $data = (array)(json_decode(file_get_contents("php://input")));
312 return (new InsuranceRestController())->put($pid, $type, $data);
314 "POST /api/patient/:pid/message" => function ($pid) {
315 RestConfig::authorization_check("patients", "notes");
316 $data = (array)(json_decode(file_get_contents("php://input")));
317 return (new MessageRestController())->post($pid, $data);
319 "PUT /api/patient/:pid/message/:mid" => function ($pid, $mid) {
320 RestConfig::authorization_check("patients", "notes");
321 $data = (array)(json_decode(file_get_contents("php://input")));
322 return (new MessageRestController())->put($pid, $mid, $data);
324 "DELETE /api/patient/:pid/message/:mid" => function ($pid, $mid) {
325 RestConfig::authorization_check("patients", "notes");
326 return (new MessageRestController())->delete($pid, $mid);
331 use OpenEMR\RestControllers\FhirPatientRestController;
332 use OpenEMR\RestControllers\FhirEncounterRestController;
334 RestConfig::$FHIR_ROUTE_MAP = array(
335 "POST /fhir/auth" => function () {
336 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
337 return (new AuthRestController())->authenticate($data);
339 "GET /fhir/Patient" => function () {
340 RestConfig::authorization_check("patients", "demo");
341 return (new FhirPatientRestController(null))->getAll($_GET);
343 "GET /fhir/Patient/:pid" => function ($pid) {
344 RestConfig::authorization_check("patients", "demo");
345 return (new FhirPatientRestController($pid))->getOne();
347 "GET /fhir/Encounter" => function () {
348 RestConfig::authorization_check("encounters", "auth_a");
349 return (new FhirEncounterRestController(null))->getAll($_GET);
351 "GET /fhir/Encounter/:eid" => function ($eid) {
352 RestConfig::authorization_check("encounters", "auth_a");
353 return (new FhirEncounterRestController())->getOne($eid);