dialog enhancements (#3351)
[openemr.git] / _rest_routes.inc.php
blobed7bbb05d7c91b4c811f4ce1fddf2c693be484fb
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-2020 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;
34 // Note some Http clients may not send auth as json so a function
35 // is implemented to determine and parse encoding on auth route's.
37 RestConfig::$ROUTE_MAP = array(
38 "POST /api/auth" => function () {
39 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
40 return (new AuthRestController())->authenticate($data);
42 "GET /api/facility" => function () {
43 RestConfig::authorization_check("admin", "users");
44 return (new FacilityRestController())->getAll();
46 "GET /api/facility/:fid" => function ($fid) {
47 RestConfig::authorization_check("admin", "users");
48 return (new FacilityRestController())->getOne($fid);
50 "POST /api/facility" => function () {
51 RestConfig::authorization_check("admin", "super");
52 $data = (array)(json_decode(file_get_contents("php://input")));
53 return (new FacilityRestController())->post($data);
55 "PUT /api/facility/:fid" => function ($fid) {
56 RestConfig::authorization_check("admin", "super");
57 $data = (array)(json_decode(file_get_contents("php://input")));
58 $data["fid"] = $fid;
59 return (new FacilityRestController())->put($data);
61 "GET /api/provider" => function () {
62 RestConfig::authorization_check("admin", "users");
63 return (new ProviderRestController())->getAll();
65 "GET /api/provider/:prid" => function ($prid) {
66 RestConfig::authorization_check("admin", "users");
67 return (new ProviderRestController())->getOne($prid);
69 "GET /api/patient" => function () {
70 RestConfig::authorization_check("patients", "demo");
71 return (new PatientRestController(null))->getAll($_GET);
73 "POST /api/patient" => function () {
74 RestConfig::authorization_check("patients", "demo");
75 $data = (array)(json_decode(file_get_contents("php://input")));
76 return (new PatientRestController(null))->post($data);
78 "PUT /api/patient/:pid" => function ($pid) {
79 RestConfig::authorization_check("patients", "demo");
80 $data = (array)(json_decode(file_get_contents("php://input")));
81 return (new PatientRestController(null))->put($pid, $data);
83 "GET /api/patient/:pid" => function ($pid) {
84 RestConfig::authorization_check("patients", "demo");
85 return (new PatientRestController($pid))->getOne();
87 "GET /api/patient/:pid/encounter" => function ($pid) {
88 RestConfig::authorization_check("encounters", "auth_a");
89 return (new EncounterRestController())->getAll($pid);
91 "POST /api/patient/:pid/encounter" => function ($pid) {
92 RestConfig::authorization_check("encounters", "auth_a");
93 $data = (array)(json_decode(file_get_contents("php://input")));
94 return (new EncounterRestController())->post($pid, $data);
96 "PUT /api/patient/:pid/encounter/:eid" => function ($pid, $eid) {
97 RestConfig::authorization_check("encounters", "auth_a");
98 $data = (array)(json_decode(file_get_contents("php://input")));
99 return (new EncounterRestController())->put($pid, $eid, $data);
101 "GET /api/patient/:pid/encounter/:eid" => function ($pid, $eid) {
102 RestConfig::authorization_check("encounters", "auth_a");
103 return (new EncounterRestController())->getOne($pid, $eid);
105 "GET /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
106 RestConfig::authorization_check("encounters", "notes");
107 return (new EncounterRestController())->getSoapNotes($pid, $eid);
109 "POST /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
110 RestConfig::authorization_check("encounters", "notes");
111 $data = (array)(json_decode(file_get_contents("php://input")));
112 return (new EncounterRestController())->postVital($pid, $eid, $data);
114 "PUT /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
115 RestConfig::authorization_check("encounters", "notes");
116 $data = (array)(json_decode(file_get_contents("php://input")));
117 return (new EncounterRestController())->putVital($pid, $eid, $vid, $data);
119 "GET /api/patient/:pid/encounter/:eid/vital" => function ($pid, $eid) {
120 RestConfig::authorization_check("encounters", "notes");
121 return (new EncounterRestController())->getVitals($pid, $eid);
123 "GET /api/patient/:pid/encounter/:eid/vital/:vid" => function ($pid, $eid, $vid) {
124 RestConfig::authorization_check("encounters", "notes");
125 return (new EncounterRestController())->getVital($pid, $eid, $vid);
127 "GET /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
128 RestConfig::authorization_check("encounters", "notes");
129 return (new EncounterRestController())->getSoapNote($pid, $eid, $sid);
131 "POST /api/patient/:pid/encounter/:eid/soap_note" => function ($pid, $eid) {
132 RestConfig::authorization_check("encounters", "notes");
133 $data = (array)(json_decode(file_get_contents("php://input")));
134 return (new EncounterRestController())->postSoapNote($pid, $eid, $data);
136 "PUT /api/patient/:pid/encounter/:eid/soap_note/:sid" => function ($pid, $eid, $sid) {
137 RestConfig::authorization_check("encounters", "notes");
138 $data = (array)(json_decode(file_get_contents("php://input")));
139 return (new EncounterRestController())->putSoapNote($pid, $eid, $sid, $data);
141 "GET /api/patient/:pid/medical_problem" => function ($pid) {
142 RestConfig::authorization_check("encounters", "notes");
143 return (new ListRestController())->getAll($pid, "medical_problem");
145 "GET /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
146 RestConfig::authorization_check("patients", "med");
147 return (new ListRestController())->getOne($pid, "medical_problem", $mid);
149 "POST /api/patient/:pid/medical_problem" => function ($pid) {
150 RestConfig::authorization_check("patients", "med");
151 $data = (array)(json_decode(file_get_contents("php://input")));
152 return (new ListRestController())->post($pid, "medical_problem", $data);
154 "PUT /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
155 RestConfig::authorization_check("patients", "med");
156 $data = (array)(json_decode(file_get_contents("php://input")));
157 return (new ListRestController())->put($pid, $mid, "medical_problem", $data);
159 "DELETE /api/patient/:pid/medical_problem/:mid" => function ($pid, $mid) {
160 RestConfig::authorization_check("patients", "med");
161 return (new ListRestController())->delete($pid, $mid, "medical_problem");
163 "GET /api/patient/:pid/allergy" => function ($pid) {
164 RestConfig::authorization_check("patients", "med");
165 return (new ListRestController())->getAll($pid, "allergy");
167 "GET /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
168 RestConfig::authorization_check("patients", "med");
169 return (new ListRestController())->getOne($pid, "allergy", $aid);
171 "DELETE /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
172 RestConfig::authorization_check("patients", "med");
173 return (new ListRestController())->delete($pid, $aid, "allergy");
175 "POST /api/patient/:pid/allergy" => function ($pid) {
176 RestConfig::authorization_check("patients", "med");
177 $data = (array)(json_decode(file_get_contents("php://input")));
178 return (new ListRestController())->post($pid, "allergy", $data);
180 "PUT /api/patient/:pid/allergy/:aid" => function ($pid, $aid) {
181 RestConfig::authorization_check("patients", "med");
182 $data = (array)(json_decode(file_get_contents("php://input")));
183 return (new ListRestController())->put($pid, $aid, "allergy", $data);
185 "GET /api/patient/:pid/medication" => function ($pid) {
186 RestConfig::authorization_check("patients", "med");
187 return (new ListRestController())->getAll($pid, "medication");
189 "POST /api/patient/:pid/medication" => function ($pid) {
190 RestConfig::authorization_check("patients", "med");
191 $data = (array)(json_decode(file_get_contents("php://input")));
192 return (new ListRestController())->post($pid, "medication", $data);
194 "PUT /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
195 RestConfig::authorization_check("patients", "med");
196 $data = (array)(json_decode(file_get_contents("php://input")));
197 return (new ListRestController())->put($pid, $mid, "medication", $data);
199 "GET /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
200 RestConfig::authorization_check("patients", "med");
201 return (new ListRestController())->getOne($pid, "medication", $mid);
203 "DELETE /api/patient/:pid/medication/:mid" => function ($pid, $mid) {
204 RestConfig::authorization_check("patients", "med");
205 return (new ListRestController())->delete($pid, $mid, "medication");
207 "GET /api/patient/:pid/surgery" => function ($pid) {
208 RestConfig::authorization_check("patients", "med");
209 return (new ListRestController())->getAll($pid, "surgery");
211 "GET /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
212 RestConfig::authorization_check("patients", "med");
213 return (new ListRestController())->getOne($pid, "surgery", $sid);
215 "DELETE /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
216 RestConfig::authorization_check("patients", "med");
217 return (new ListRestController())->delete($pid, $sid, "surgery");
219 "POST /api/patient/:pid/surgery" => function ($pid) {
220 RestConfig::authorization_check("patients", "med");
221 $data = (array)(json_decode(file_get_contents("php://input")));
222 return (new ListRestController())->post($pid, "surgery", $data);
224 "PUT /api/patient/:pid/surgery/:sid" => function ($pid, $sid) {
225 RestConfig::authorization_check("patients", "med");
226 $data = (array)(json_decode(file_get_contents("php://input")));
227 return (new ListRestController())->put($pid, $sid, "surgery", $data);
229 "GET /api/patient/:pid/dental_issue" => function ($pid) {
230 RestConfig::authorization_check("patients", "med");
231 return (new ListRestController())->getAll($pid, "dental");
233 "GET /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
234 RestConfig::authorization_check("patients", "med");
235 return (new ListRestController())->getOne($pid, "dental", $did);
237 "DELETE /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
238 RestConfig::authorization_check("patients", "med");
239 return (new ListRestController())->delete($pid, $did, "dental");
241 "POST /api/patient/:pid/dental_issue" => function ($pid) {
242 RestConfig::authorization_check("patients", "med");
243 $data = (array)(json_decode(file_get_contents("php://input")));
244 return (new ListRestController())->post($pid, "dental", $data);
246 "PUT /api/patient/:pid/dental_issue/:did" => function ($pid, $did) {
247 RestConfig::authorization_check("patients", "med");
248 $data = (array)(json_decode(file_get_contents("php://input")));
249 return (new ListRestController())->put($pid, $did, "dental", $data);
251 "GET /api/patient/:pid/appointment" => function ($pid) {
252 RestConfig::authorization_check("patients", "appt");
253 return (new AppointmentRestController())->getAllForPatient($pid);
255 "POST /api/patient/:pid/appointment" => function ($pid) {
256 RestConfig::authorization_check("patients", "appt");
257 $data = (array)(json_decode(file_get_contents("php://input")));
258 return (new AppointmentRestController())->post($pid, $data);
260 "GET /api/appointment" => function () {
261 RestConfig::authorization_check("patients", "appt");
262 return (new AppointmentRestController())->getAll();
264 "GET /api/appointment/:eid" => function ($eid) {
265 RestConfig::authorization_check("patients", "appt");
266 return (new AppointmentRestController())->getOne($eid);
268 "DELETE /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
269 RestConfig::authorization_check("patients", "appt");
270 return (new AppointmentRestController())->delete($eid);
272 "GET /api/patient/:pid/appointment/:eid" => function ($pid, $eid) {
273 RestConfig::authorization_check("patients", "appt");
274 return (new AppointmentRestController())->getOne($eid);
276 "GET /api/list/:list_name" => function ($list_name) {
277 RestConfig::authorization_check("lists", "default");
278 return (new ListRestController())->getOptions($list_name);
280 "GET /api/version" => function () {
281 return (new VersionRestController())->getOne();
283 "GET /api/product" => function () {
284 return (new ProductRegistrationRestController())->getOne();
286 "GET /api/insurance_company" => function () {
287 return (new InsuranceCompanyRestController())->getAll();
289 "GET /api/insurance_type" => function () {
290 return (new InsuranceCompanyRestController())->getInsuranceTypes();
292 "POST /api/insurance_company" => function () {
293 $data = (array)(json_decode(file_get_contents("php://input")));
294 return (new InsuranceCompanyRestController())->post($data);
296 "PUT /api/insurance_company/:iid" => function ($iid) {
297 $data = (array)(json_decode(file_get_contents("php://input")));
298 return (new InsuranceCompanyRestController())->put($iid, $data);
300 "POST /api/patient/:pid/document" => function ($pid) {
301 return (new DocumentRestController())->postWithPath($pid, $_GET['path'], $_FILES['document']);
303 "GET /api/patient/:pid/document" => function ($pid) {
304 return (new DocumentRestController())->getAllAtPath($pid, $_GET['path']);
306 "GET /api/patient/:pid/document/:did" => function ($pid, $did) {
307 return (new DocumentRestController())->downloadFile($pid, $did);
309 "GET /api/patient/:pid/insurance" => function ($pid) {
310 return (new InsuranceRestController())->getAll($pid);
312 "GET /api/patient/:pid/insurance/:type" => function ($pid, $type) {
313 return (new InsuranceRestController())->getOne($pid, $type);
315 "POST /api/patient/:pid/insurance/:type" => function ($pid, $type) {
316 $data = (array)(json_decode(file_get_contents("php://input")));
317 return (new InsuranceRestController())->post($pid, $type, $data);
319 "PUT /api/patient/:pid/insurance/:type" => function ($pid, $type) {
320 $data = (array)(json_decode(file_get_contents("php://input")));
321 return (new InsuranceRestController())->put($pid, $type, $data);
323 "POST /api/patient/:pid/message" => function ($pid) {
324 RestConfig::authorization_check("patients", "notes");
325 $data = (array)(json_decode(file_get_contents("php://input")));
326 return (new MessageRestController())->post($pid, $data);
328 "PUT /api/patient/:pid/message/:mid" => function ($pid, $mid) {
329 RestConfig::authorization_check("patients", "notes");
330 $data = (array)(json_decode(file_get_contents("php://input")));
331 return (new MessageRestController())->put($pid, $mid, $data);
333 "DELETE /api/patient/:pid/message/:mid" => function ($pid, $mid) {
334 RestConfig::authorization_check("patients", "notes");
335 return (new MessageRestController())->delete($pid, $mid);
340 use OpenEMR\RestControllers\FHIR\FhirAllergyIntoleranceRestController;
341 use OpenEMR\RestControllers\FHIR\FhirPatientRestController;
342 use OpenEMR\RestControllers\FHIR\FhirEncounterRestController;
343 use OpenEMR\RestControllers\FHIR\FhirOrganizationRestController;
344 use OpenEMR\RestControllers\FHIR\FhirQuestionnaireResponseController;
346 RestConfig::$FHIR_ROUTE_MAP = array(
347 "POST /fhir/auth" => function () {
348 $data = (array) RestConfig::getPostData((file_get_contents("php://input")));
349 return (new AuthRestController())->authenticate($data);
351 "GET /fhir/Patient" => function () {
352 RestConfig::authorization_check("patients", "demo");
353 return (new FhirPatientRestController(null))->getAll($_GET);
355 "GET /fhir/Patient/:pid" => function ($pid) {
356 RestConfig::authorization_check("patients", "demo");
357 return (new FhirPatientRestController($pid))->getOne();
359 "GET /fhir/Encounter" => function () {
360 RestConfig::authorization_check("encounters", "auth_a");
361 return (new FhirEncounterRestController(null))->getAll($_GET);
363 "GET /fhir/Encounter/:eid" => function ($eid) {
364 RestConfig::authorization_check("encounters", "auth_a");
365 return (new FhirEncounterRestController())->getOne($eid);
367 "POST /fhir/Patient" => function () {
368 RestConfig::authorization_check("patients", "demo");
369 $data = (array)(json_decode(file_get_contents("php://input"), true));
370 return (new FhirPatientRestController(null))->post($data);
372 "PUT /fhir/Patient/:pid" => function ($pid) {
373 RestConfig::authorization_check("patients", "demo");
374 $data = (array)(json_decode(file_get_contents("php://input"), true));
375 return (new FhirPatientRestController(null))->put($pid, $data);
377 "PATCH /fhir/Patient/:pid" => function ($pid) {
378 RestConfig::authorization_check("patients", "demo");
379 $data = (array)(json_decode(file_get_contents("php://input"), true));
380 return (new FhirPatientRestController(null))->put($pid, $data);
382 "GET /fhir/Organization" => function () {
383 return (new FhirOrganizationRestController(null))->getAll($_GET);
385 "GET /fhir/Organization/:oid" => function ($oid) {
386 return (new FhirOrganizationRestController(null))->getOne($oid);
388 "GET /fhir/AllergyIntolerance" => function () {
389 RestConfig::authorization_check("patients", "med");
390 return (new FhirAllergyIntoleranceRestController(null))->getAll($_GET);
392 "GET /fhir/AllergyIntolerance/:id" => function ($id) {
393 RestConfig::authorization_check("patients", "med");
394 return (new FhirAllergyIntoleranceRestController(null))->getOne($id);
396 "POST /fhir/QuestionnaireResponse" => function () {
397 RestConfig::authorization_check("patients", "demo");
398 $data = (array)(json_decode(file_get_contents("php://input"), true));
399 return (new FhirQuestionnaireResponseController(null))->post($data);