Bump phpmailer/phpmailer from 6.1.5 to 6.1.6 (#3567)
[openemr.git] / _rest_routes.inc.php
blob58862e3e2f5372a4e8db0ed5f3a272bf254f9c11
1 <?php
3 /**
4 * Routes
5 * (All REST routes)
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Matthew Vita <matthewvita48@gmail.com>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
13 * @copyright Copyright (c) 2018-2020 Jerry Padgett <sjpadgett@gmail.com>
14 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 // Lets keep our controller classes with the routes.
20 use OpenEMR\Common\Uuid\UuidRegistry;
21 use OpenEMR\RestControllers\FacilityRestController;
22 use OpenEMR\RestControllers\VersionRestController;
23 use OpenEMR\RestControllers\ProductRegistrationRestController;
24 use OpenEMR\RestControllers\PatientRestController;
25 use OpenEMR\RestControllers\EncounterRestController;
26 use OpenEMR\RestControllers\ProviderRestController;
27 use OpenEMR\RestControllers\ListRestController;
28 use OpenEMR\RestControllers\InsuranceCompanyRestController;
29 use OpenEMR\RestControllers\AppointmentRestController;
30 use OpenEMR\RestControllers\AuthRestController;
31 use OpenEMR\RestControllers\ONoteRestController;
32 use OpenEMR\RestControllers\DocumentRestController;
33 use OpenEMR\RestControllers\InsuranceRestController;
34 use OpenEMR\RestControllers\MessageRestController;
36 // Note some Http clients may not send auth as json so a function
37 // is implemented to determine and parse encoding on auth route's.
39 RestConfig::$ROUTE_MAP = array(
40 "POST /api/auth" => function () {
41 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
42 return (new AuthRestController())->authenticate($data);
44 "GET /api/facility" => function () {
45 RestConfig::authorization_check("admin", "users");
46 return (new FacilityRestController())->getAll();
48 "GET /api/facility/:fid" => function ($fid) {
49 RestConfig::authorization_check("admin", "users");
50 return (new FacilityRestController())->getOne($fid);
52 "POST /api/facility" => function () {
53 RestConfig::authorization_check("admin", "super");
54 $data = (array)(json_decode(file_get_contents("php://input")));
55 return (new FacilityRestController())->post($data);
57 "PUT /api/facility/:fid" => function ($fid) {
58 RestConfig::authorization_check("admin", "super");
59 $data = (array)(json_decode(file_get_contents("php://input")));
60 $data["fid"] = $fid;
61 return (new FacilityRestController())->put($data);
63 "GET /api/provider" => function () {
64 RestConfig::authorization_check("admin", "users");
65 return (new ProviderRestController())->getAll();
67 "GET /api/provider/:prid" => function ($prid) {
68 RestConfig::authorization_check("admin", "users");
69 return (new ProviderRestController())->getOne($prid);
71 "GET /api/patient" => function () {
72 RestConfig::authorization_check("patients", "demo");
73 return (new PatientRestController())->getAll($_GET);
75 "POST /api/patient" => function () {
76 RestConfig::authorization_check("patients", "demo");
77 $data = (array)(json_decode(file_get_contents("php://input")));
78 return (new PatientRestController())->post($data);
80 "PUT /api/patient/:pid" => function ($pid) {
81 RestConfig::authorization_check("patients", "demo");
82 $data = (array)(json_decode(file_get_contents("php://input")));
83 return (new PatientRestController())->put($pid, $data);
85 "GET /api/patient/:pid" => function ($pid) {
86 RestConfig::authorization_check("patients", "demo");
87 return (new PatientRestController())->getOne($pid);
89 "GET /api/patient/:pid/encounter" => function ($pid) {
90 RestConfig::authorization_check("encounters", "auth_a");
91 return (new EncounterRestController())->getAll($pid);
93 "POST /api/patient/:pid/encounter" => function ($pid) {
94 RestConfig::authorization_check("encounters", "auth_a");
95 $data = (array)(json_decode(file_get_contents("php://input")));
96 return (new EncounterRestController())->post($pid, $data);
98 "PUT /api/patient/:pid/encounter/:eid" => function ($pid, $eid) {
99 RestConfig::authorization_check("encounters", "auth_a");
100 $data = (array)(json_decode(file_get_contents("php://input")));
101 return (new EncounterRestController())->put($pid, $eid, $data);
103 "GET /api/patient/:pid/encounter/:eid" => function ($pid, $eid) {
104 RestConfig::authorization_check("encounters", "auth_a");
105 return (new EncounterRestController())->getOne($pid, $eid);
107 "GET /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
108 RestConfig::authorization_check("encounters", "notes");
109 return (new EncounterRestController())->getSoapNotes($pid, $eid);
111 "POST /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
112 RestConfig::authorization_check("encounters", "notes");
113 $data = (array)(json_decode(file_get_contents("php://input")));
114 return (new EncounterRestController())->postVital($pid, $eid, $data);
116 "PUT /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
117 RestConfig::authorization_check("encounters", "notes");
118 $data = (array)(json_decode(file_get_contents("php://input")));
119 return (new EncounterRestController())->putVital($pid, $eid, $vid, $data);
121 "GET /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
122 RestConfig::authorization_check("encounters", "notes");
123 return (new EncounterRestController())->getVitals($pid, $eid);
125 "GET /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
126 RestConfig::authorization_check("encounters", "notes");
127 return (new EncounterRestController())->getVital($pid, $eid, $vid);
129 "GET /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
130 RestConfig::authorization_check("encounters", "notes");
131 return (new EncounterRestController())->getSoapNote($pid, $eid, $sid);
133 "POST /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
134 RestConfig::authorization_check("encounters", "notes");
135 $data = (array)(json_decode(file_get_contents("php://input")));
136 return (new EncounterRestController())->postSoapNote($pid, $eid, $data);
138 "PUT /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
139 RestConfig::authorization_check("encounters", "notes");
140 $data = (array)(json_decode(file_get_contents("php://input")));
141 return (new EncounterRestController())->putSoapNote($pid, $eid, $sid, $data);
143 "GET /api/patient/:pid/medical_problem" => function ($pid) {
144 RestConfig::authorization_check("encounters", "notes");
145 return (new ListRestController())->getAll($pid, "medical_problem");
147 "GET /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
148 RestConfig::authorization_check("patients", "med");
149 return (new ListRestController())->getOne($pid, "medical_problem", $mid);
151 "POST /api/patient/:pid/medical_problem" => function ($pid) {
152 RestConfig::authorization_check("patients", "med");
153 $data = (array)(json_decode(file_get_contents("php://input")));
154 return (new ListRestController())->post($pid, "medical_problem", $data);
156 "PUT /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
157 RestConfig::authorization_check("patients", "med");
158 $data = (array)(json_decode(file_get_contents("php://input")));
159 return (new ListRestController())->put($pid, $mid, "medical_problem", $data);
161 "DELETE /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
162 RestConfig::authorization_check("patients", "med");
163 return (new ListRestController())->delete($pid, $mid, "medical_problem");
165 "GET /api/patient/:pid/allergy" => function ($pid) {
166 RestConfig::authorization_check("patients", "med");
167 return (new ListRestController())->getAll($pid, "allergy");
169 "GET /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
170 RestConfig::authorization_check("patients", "med");
171 return (new ListRestController())->getOne($pid, "allergy", $aid);
173 "DELETE /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
174 RestConfig::authorization_check("patients", "med");
175 return (new ListRestController())->delete($pid, $aid, "allergy");
177 "POST /api/patient/:pid/allergy" => function ($pid) {
178 RestConfig::authorization_check("patients", "med");
179 $data = (array)(json_decode(file_get_contents("php://input")));
180 return (new ListRestController())->post($pid, "allergy", $data);
182 "PUT /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
183 RestConfig::authorization_check("patients", "med");
184 $data = (array)(json_decode(file_get_contents("php://input")));
185 return (new ListRestController())->put($pid, $aid, "allergy", $data);
187 "GET /api/patient/:pid/medication" => function ($pid) {
188 RestConfig::authorization_check("patients", "med");
189 return (new ListRestController())->getAll($pid, "medication");
191 "POST /api/patient/:pid/medication" => function ($pid) {
192 RestConfig::authorization_check("patients", "med");
193 $data = (array)(json_decode(file_get_contents("php://input")));
194 return (new ListRestController())->post($pid, "medication", $data);
196 "PUT /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
197 RestConfig::authorization_check("patients", "med");
198 $data = (array)(json_decode(file_get_contents("php://input")));
199 return (new ListRestController())->put($pid, $mid, "medication", $data);
201 "GET /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
202 RestConfig::authorization_check("patients", "med");
203 return (new ListRestController())->getOne($pid, "medication", $mid);
205 "DELETE /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
206 RestConfig::authorization_check("patients", "med");
207 return (new ListRestController())->delete($pid, $mid, "medication");
209 "GET /api/patient/:pid/surgery" => function ($pid) {
210 RestConfig::authorization_check("patients", "med");
211 return (new ListRestController())->getAll($pid, "surgery");
213 "GET /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
214 RestConfig::authorization_check("patients", "med");
215 return (new ListRestController())->getOne($pid, "surgery", $sid);
217 "DELETE /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
218 RestConfig::authorization_check("patients", "med");
219 return (new ListRestController())->delete($pid, $sid, "surgery");
221 "POST /api/patient/:pid/surgery" => function ($pid) {
222 RestConfig::authorization_check("patients", "med");
223 $data = (array)(json_decode(file_get_contents("php://input")));
224 return (new ListRestController())->post($pid, "surgery", $data);
226 "PUT /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
227 RestConfig::authorization_check("patients", "med");
228 $data = (array)(json_decode(file_get_contents("php://input")));
229 return (new ListRestController())->put($pid, $sid, "surgery", $data);
231 "GET /api/patient/:pid/dental_issue" => function ($pid) {
232 RestConfig::authorization_check("patients", "med");
233 return (new ListRestController())->getAll($pid, "dental");
235 "GET /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
236 RestConfig::authorization_check("patients", "med");
237 return (new ListRestController())->getOne($pid, "dental", $did);
239 "DELETE /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
240 RestConfig::authorization_check("patients", "med");
241 return (new ListRestController())->delete($pid, $did, "dental");
243 "POST /api/patient/:pid/dental_issue" => function ($pid) {
244 RestConfig::authorization_check("patients", "med");
245 $data = (array)(json_decode(file_get_contents("php://input")));
246 return (new ListRestController())->post($pid, "dental", $data);
248 "PUT /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
249 RestConfig::authorization_check("patients", "med");
250 $data = (array)(json_decode(file_get_contents("php://input")));
251 return (new ListRestController())->put($pid, $did, "dental", $data);
253 "GET /api/patient/:pid/appointment" => function ($pid) {
254 RestConfig::authorization_check("patients", "appt");
255 return (new AppointmentRestController())->getAllForPatient($pid);
257 "POST /api/patient/:pid/appointment" => function ($pid) {
258 RestConfig::authorization_check("patients", "appt");
259 $data = (array)(json_decode(file_get_contents("php://input")));
260 return (new AppointmentRestController())->post($pid, $data);
262 "GET /api/appointment" => function () {
263 RestConfig::authorization_check("patients", "appt");
264 return (new AppointmentRestController())->getAll();
266 "GET /api/appointment/:eid" => function ($eid) {
267 RestConfig::authorization_check("patients", "appt");
268 return (new AppointmentRestController())->getOne($eid);
270 "DELETE /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
271 RestConfig::authorization_check("patients", "appt");
272 return (new AppointmentRestController())->delete($eid);
274 "GET /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
275 RestConfig::authorization_check("patients", "appt");
276 return (new AppointmentRestController())->getOne($eid);
278 "GET /api/list/:list_name" => function ($list_name) {
279 RestConfig::authorization_check("lists", "default");
280 return (new ListRestController())->getOptions($list_name);
282 "GET /api/version" => function () {
283 return (new VersionRestController())->getOne();
285 "GET /api/product" => function () {
286 return (new ProductRegistrationRestController())->getOne();
288 "GET /api/insurance_company" => function () {
289 return (new InsuranceCompanyRestController())->getAll();
291 "GET /api/insurance_type" => function () {
292 return (new InsuranceCompanyRestController())->getInsuranceTypes();
294 "POST /api/insurance_company" => function () {
295 $data = (array)(json_decode(file_get_contents("php://input")));
296 return (new InsuranceCompanyRestController())->post($data);
298 "PUT /api/insurance_company/:iid" => function ($iid) {
299 $data = (array)(json_decode(file_get_contents("php://input")));
300 return (new InsuranceCompanyRestController())->put($iid, $data);
302 "POST /api/patient/:pid/document" => function ($pid) {
303 return (new DocumentRestController())->postWithPath($pid, $_GET['path'], $_FILES['document']);
305 "GET /api/patient/:pid/document" => function ($pid) {
306 return (new DocumentRestController())->getAllAtPath($pid, $_GET['path']);
308 "GET /api/patient/:pid/document/:did" => function ($pid, $did) {
309 return (new DocumentRestController())->downloadFile($pid, $did);
311 "GET /api/patient/:pid/insurance" => function ($pid) {
312 return (new InsuranceRestController())->getAll($pid);
314 "GET /api/patient/:pid/insurance/:type" => function ($pid, $type) {
315 return (new InsuranceRestController())->getOne($pid, $type);
317 "POST /api/patient/:pid/insurance/:type" => function ($pid, $type) {
318 $data = (array)(json_decode(file_get_contents("php://input")));
319 return (new InsuranceRestController())->post($pid, $type, $data);
321 "PUT /api/patient/:pid/insurance/:type" => function ($pid, $type) {
322 $data = (array)(json_decode(file_get_contents("php://input")));
323 return (new InsuranceRestController())->put($pid, $type, $data);
325 "POST /api/patient/:pid/message" => function ($pid) {
326 RestConfig::authorization_check("patients", "notes");
327 $data = (array)(json_decode(file_get_contents("php://input")));
328 return (new MessageRestController())->post($pid, $data);
330 "PUT /api/patient/:pid/message/:mid" => function ($pid, $mid) {
331 RestConfig::authorization_check("patients", "notes");
332 $data = (array)(json_decode(file_get_contents("php://input")));
333 return (new MessageRestController())->put($pid, $mid, $data);
335 "DELETE /api/patient/:pid/message/:mid" => function ($pid, $mid) {
336 RestConfig::authorization_check("patients", "notes");
337 return (new MessageRestController())->delete($pid, $mid);
342 use OpenEMR\RestControllers\FHIR\FhirAllergyIntoleranceRestController;
343 use OpenEMR\RestControllers\FHIR\FhirConditionRestController;
344 use OpenEMR\RestControllers\FHIR\FhirEncounterRestController;
345 use OpenEMR\RestControllers\FHIR\FhirObservationRestController;
346 use OpenEMR\RestControllers\FHIR\FhirImmunizationRestController;
347 use OpenEMR\RestControllers\FHIR\FhirMedicationRestController;
348 use OpenEMR\RestControllers\FHIR\FhirMedicationStatementRestController;
349 use OpenEMR\RestControllers\FHIR\FhirOrganizationRestController;
350 use OpenEMR\RestControllers\FHIR\FhirPatientRestController;
351 use OpenEMR\RestControllers\FHIR\FhirProcedureRestController;
352 use OpenEMR\RestControllers\FHIR\FhirQuestionnaireResponseController;
354 RestConfig::$FHIR_ROUTE_MAP = array(
355 "POST /fhir/auth" => function () {
356 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
357 return (new AuthRestController())->authenticate($data);
359 "POST /fhir/Patient" => function () {
360 RestConfig::authorization_check("patients", "demo");
361 $data = (array)(json_decode(file_get_contents("php://input"), true));
362 return (new FhirPatientRestController())->post($data);
364 "PUT /fhir/Patient/:id" => function ($id) {
365 RestConfig::authorization_check("patients", "demo");
366 $data = (array)(json_decode(file_get_contents("php://input"), true));
367 return (new FhirPatientRestController())->put($id, $data);
369 "PATCH /fhir/Patient/:id" => function ($id) {
370 RestConfig::authorization_check("patients", "demo");
371 $data = (array)(json_decode(file_get_contents("php://input"), true));
372 return (new FhirPatientRestController())->put($id, $data);
374 "GET /fhir/Patient" => function () {
375 RestConfig::authorization_check("patients", "demo");
376 return (new FhirPatientRestController())->getAll($_GET);
378 "GET /fhir/Patient/:id" => function ($id) {
379 RestConfig::authorization_check("patients", "demo");
380 return (new FhirPatientRestController())->getOne($id);
382 "GET /fhir/Encounter" => function () {
383 RestConfig::authorization_check("encounters", "auth_a");
384 return (new FhirEncounterRestController(null))->getAll($_GET);
386 "GET /fhir/Encounter/:eid" => function ($eid) {
387 RestConfig::authorization_check("encounters", "auth_a");
388 return (new FhirEncounterRestController())->getOne($eid);
390 "GET /fhir/Organization" => function () {
391 return (new FhirOrganizationRestController(null))->getAll($_GET);
393 "GET /fhir/Organization/:oid" => function ($oid) {
394 return (new FhirOrganizationRestController(null))->getOne($oid);
396 "GET /fhir/AllergyIntolerance" => function () {
397 RestConfig::authorization_check("patients", "med");
398 return (new FhirAllergyIntoleranceRestController(null))->getAll($_GET);
400 "GET /fhir/AllergyIntolerance/:id" => function ($id) {
401 RestConfig::authorization_check("patients", "med");
402 return (new FhirAllergyIntoleranceRestController(null))->getOne($id);
404 "GET /fhir/Observation/:id" => function ($id) {
405 RestConfig::authorization_check("patients", "med");
406 return (new FhirObservationRestController(null))->getOne($id);
408 "GET /fhir/Observation" => function () {
409 RestConfig::authorization_check("patients", "med");
410 return (new FhirObservationRestController(null))->getAll($_GET);
412 "POST /fhir/QuestionnaireResponse" => function () {
413 RestConfig::authorization_check("patients", "demo");
414 $data = (array)(json_decode(file_get_contents("php://input"), true));
415 return (new FhirQuestionnaireResponseController(null))->post($data);
417 "GET /fhir/Immunization" => function () {
418 RestConfig::authorization_check("patients", "med");
419 return (new FhirImmunizationRestController(null))->getAll($_GET);
421 "GET /fhir/Immunization/:id" => function ($id) {
422 RestConfig::authorization_check("patients", "med");
423 return (new FhirImmunizationRestController(null))->getOne($id);
425 "GET /fhir/Condition" => function () {
426 RestConfig::authorization_check("patients", "med");
427 return (new FhirConditionRestController(null))->getAll($_GET);
429 "GET /fhir/Condition/:id" => function ($id) {
430 RestConfig::authorization_check("patients", "med");
431 return (new FhirConditionRestController(null))->getOne($id);
433 "GET /fhir/Procedure" => function () {
434 RestConfig::authorization_check("patients", "med");
435 return (new FhirProcedureRestController(null))->getAll($_GET);
437 "GET /fhir/Procedure/:id" => function ($id) {
438 RestConfig::authorization_check("patients", "med");
439 return (new FhirProcedureRestController(null))->getOne($id);
441 "GET /fhir/MedicationStatement" => function () {
442 RestConfig::authorization_check("patients", "med");
443 return (new FhirMedicationStatementRestController(null))->getAll($_GET);
445 "GET /fhir/MedicationStatement/:id" => function ($id) {
446 RestConfig::authorization_check("patients", "med");
447 return (new FhirMedicationStatementRestController(null))->getOne($id);
449 "GET /fhir/Medication" => function () {
450 RestConfig::authorization_check("patients", "med");
451 return (new FhirMedicationRestController(null))->getAll();
453 "GET /fhir/Medication/:id" => function ($id) {
454 RestConfig::authorization_check("patients", "med");
455 return (new FhirMedicationRestController(null))->getOne($id);
459 // Patient portal api routes
460 RestConfig::$PORTAL_ROUTE_MAP = array(
461 "POST /portal/auth" => function () {
462 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
463 return (new AuthRestController())->authenticate($data);
465 "GET /portal/patient" => function () {
466 return (new PatientRestController())->getOne($_SESSION['pid']);
470 // Patient portal fhir api routes
471 RestConfig::$PORTAL_FHIR_ROUTE_MAP = array(
472 "POST /portalfhir/auth" => function () {
473 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
474 return (new AuthRestController())->authenticate($data);
476 "GET /portalfhir/Patient" => function () {
477 return (new FhirPatientRestController())->getOne(UuidRegistry::uuidToString($_SESSION['puuid']));