Add portal flag and supervisor to users (#3646)
[openemr.git] / API_README.md
blob5aeb9b51348cf732968e49e6271e75d464d0338d
1 # OpenEMR REST API Documentation
3 ## Overview
5 Easy-to-use JSON-based REST API for OpenEMR. All code is done in classes and separate from the view to help with codebase modernization efforts. FHIR is also supported, see FHIR API documentation [here](FHIR_README.md)
7 ## Implementation
9 REST API endpoints are defined in the [primary routes file](_rest_routes.inc.php). The routes file maps an external, addressable
10 endpoint to the OpenEMR controller which handles the request, and also handles the JSON data conversions.
12 ```php
13 "POST /api/patient" => function () {
14     RestConfig::authorization_check("patients", "demo");
15     $data = (array)(json_decode(file_get_contents("php://input")));
16     return (new PatientRestController())->post($data);
18 ```
20 At a high level, the request processing flow consists of the following steps:
22 ```
23 JSON Request -> Controller Component -> Validation -> Service Component -> Database
24 ```
26 The logical response flow begins with the database result:
28 ```
29 Database Result -> Service Component -> Controller Component -> RequestControllerHelper -> JSON Response
30 ```
32 The [RequestControllerHelper class](./src/RestControllers/RestControllerHelper.php) evaluates the Service Component's
33 result and maps it to a http response code and response payload. Existing APIs should be updated to utilize the
34 `handleProcessingResult` method as it supports the [Validator](./src/Validators/BaseValidator.php) components.
36 The [PatientRestController](./src/RestControllers/PatientRestController.php) may be used as a reference to see how APIs are
37 integrated with `RequestControllerHelper::handleProcessingResult` and the `Validator` components.
39 Finally, APIs which are integrated with the new `handleProcessingResult` method utilize a common response format.
41 ```json
43     "validationErrors": [],
44     "internalErrors": [],
45     "data": < data payload >
47 ```
49 -   `validationErrors` contain "client based" data validation errors
50 -   `internalErrors` contain server related errors
51 -   `data` is the response payload, represented as an object/`{}` for single results or an array/`[]` for multiple results
53 ### Sections
55 -   [Standard API Endpoints](API_README.md#api-endpoints)
56     -   [Facility API](API_README.md#post-apifacility)
57     -   [Provider API](API_README.md#get-apiprovider)
58     -   [Patient API](API_README.md#post-apipatient)
59     -   [Insurance API](API_README.md#get-apipatientpidinsurance)
60     -   [Appointment API](API_README.md#get-apiappointment)
61     -   [Document API](API_README.md#get-apipatientpiddocument)
62     -   [Message API](API_README.md#post-apipatientpidmessage)
63 -   [Portal API Endpoints](API_README.md#portal-Endpoints)
64     -   [Patient API](API_README.md#get-portalpatient)
65 -   [FHIR API Endpoints](FHIR_README.md#fhir-endpoints)
66     -   [FHIR Patient API](FHIR_README.md#get-fhirpatient)
67     -   [FHIR Encounter API](FHIR_README.md#get-fhirencounter)
68     -   [FHIR Organization API](FHIR_README.md#get-fhirorganization)
69     -   [FHIR AllergyIntolerance API](FHIR_README.md#get-fhirallergyintolerance)
70     -   [FHIR Observation API](FHIR_README.md#get-fhirobservation)
71     -   [FHIR QuestionnaireResponse API](FHIR_README.md#get-fhirquestionnaireresponse)
72     -   [FHIR Immunization API](FHIR_README.md#get-fhirimmunization)
73     -   [FHIR Condition API](FHIR_README.md#get-fhircondition)
74     -   [FHIR Procedure API](FHIR_README.md#get-fhirprocedure)
75     -   [FHIR MedicationStatement API](FHIR_README.md#get-fhirmedicationstatement)
76     -   [FHIR Medication API](FHIR_README.md#get-fhirmedication)
77 -   [Portal FHIR API Endpoints](FHIR_README.md#portalfhir-endpoints)
78     -   [Patient API](FHIR_README.md#get-portalfhirpatient)
79 -   [Dev notes](API_README.md#dev-notes)
80 -   [Todos](API_README.md#project-management)
82 ### Prerequisite
84 Enable the Standard API service (/api/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Standard REST API"
85 Enable the Patient Portal API service (/portal/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Patient Portal REST API"
87 ### Using API Internally
89 There are several ways to make API calls from an authorized session and maintain security:
91 -   See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
93 ### /api/ Endpoints
95 OpenEMR standard endpoints Use `http://localhost:8300/apis/api as base URI.`
97 _Example:_ `http://localhost:8300/apis/api/patient` returns a resource of all Patients.
99 #### POST /api/auth
101 The OpenEMR API utilizes the OAuth2 password credential flow for authentication. To obtain an API token, submit your login credentials and requested scope. The scope must match a site that has been setup in OpenEMR, in the /sites/ directory. If additional sites have not been created, set the scope
102 to 'default'.
104 Request:
106 ```sh
107 curl -X POST -H 'Content-Type: application/json' 'http://localhost:8300/apis/api/auth' \
108 -d '{
109     "grant_type":"password",
110     "username": "ServiceUser",
111     "password": "password",
112     "scope":"site id"
116 Response:
118 ```json
120     "token_type": "Bearer",
121     "access_token": "eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ==",
122     "expires_in": "3600",
123     "user_data": {
124         "user_id": "1"
125     }
129 The Bearer token is required for each OpenEMR API request, and is conveyed using an Authorization header.
131 Request:
133 ```sh
134 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem' \
135   -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
138 #### POST /api/facility
140 Request:
142 ```sh
143 curl -X POST 'http://localhost:8300/apis/api/facility' -d \
145     "name": "Aquaria",
146     "phone": "808-606-3030",
147     "fax": "808-606-3031",
148     "street": "1337 Bit Shifter Ln",
149     "city": "San Lorenzo",
150     "state": "ZZ",
151     "postal_code": "54321",
152     "email": "foo@bar.com",
153     "service_location": "1",
154     "billing_location": "1",
155     "color": "#FF69B4"
159 #### PUT /api/facility/:fid
161 Request:
163 ```sh
164 curl -X PUT 'http://localhost:8300/apis/api/facility/1' -d \
166     "name": "Aquaria",
167     "phone": "808-606-3030",
168     "fax": "808-606-3031",
169     "street": "1337 Bit Shifter Ln",
170     "city": "San Lorenzo",
171     "state": "AZ",
172     "postal_code": "54321",
173     "email": "foo@bar.com",
174     "service_location": "1",
175     "billing_location": "1",
176     "color": "#FF69B4"
180 #### GET /api/facility
182 Request:
184 ```sh
185 curl -X GET 'http://localhost:8300/apis/api/facility'
188 #### GET /api/facility/:fid
190 Request:
192 ```sh
193 curl -X GET 'http://localhost:8300/apis/api/facility/1'
196 #### GET /api/provider
198 Request:
200 ```sh
201 curl -X GET 'http://localhost:8300/apis/api/provider'
204 #### GET /api/provider/:prid
206 Request:
208 ```sh
209 curl -X GET 'http://localhost:8300/apis/api/provider/1'
212 #### POST /api/patient
214 Request:
216 ```sh
217 curl -X POST 'http://localhost:8300/apis/api/patient' -d \
219     "title": "Mr",
220     "fname": "Foo",
221     "mname": "",
222     "lname": "Bar",
223     "street": "456 Tree Lane",
224     "postal_code": "08642",
225     "city": "FooTown",
226     "state": "FL",
227     "country_code": "US",
228     "phone_contact": "123-456-7890",
229     "DOB": "1992-02-02",
230     "sex": "Male",
231     "race": "",
232     "ethnicity": ""
236 Response:
238 ```json
240     "validationErrors": [],
241     "internalErrors": [],
242     "data": {
243         "pid": 1
244     }
248 #### PUT /api/patient/:puuid
250 Request:
252 ```sh
253 curl -X PUT 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
255     "title": "Mr",
256     "fname": "Baz",
257     "mname": "",
258     "lname": "Bop",
259     "street": "456 Tree Lane",
260     "postal_code": "08642",
261     "city": "FooTown",
262     "state": "FL",
263     "country_code": "US",
264     "phone_contact": "123-456-7890",
265     "DOB": "1992-02-03",
266     "sex": "Male",
267     "race": "",
268     "ethnicity": ""
272 Response:
274 ```json
276     "validationErrors": [],
277     "internalErrors": [],
278     "data": {
279         "id": "193",
280         "pid": "1",
281         "pubpid": "",
282         "title": "Mr",
283         "fname": "Baz",
284         "mname": "",
285         "lname": "Bop",
286         "ss": "",
287         "street": "456 Tree Lane",
288         "postal_code": "08642",
289         "city": "FooTown",
290         "state": "FL",
291         "county": "",
292         "country_code": "US",
293         "drivers_license": "",
294         "contact_relationship": "",
295         "phone_contact": "123-456-7890",
296         "phone_home": "",
297         "phone_biz": "",
298         "phone_cell": "",
299         "email": "",
300         "DOB": "1992-02-03",
301         "sex": "Male",
302         "race": "",
303         "ethnicity": "",
304         "status": ""
305     }
309 #### GET /api/patient
311 Request:
313 ```sh
314 curl -X GET 'http://localhost:8300/apis/api/patient'
317 Response:
319 ```json
321     "validationErrors": [],
322     "internalErrors": [],
323     "data": [{ patientRecord }, { patientRecord }, etc]
327 Request:
329 ```sh
330 curl -X GET 'http://localhost:8300/apis/api/patient&fname=...&lname=...&dob=...'
333 Response:
335 ```json
337     "validationErrors": [],
338     "internalErrors": [],
339     "data": [{ patientRecord }, { patientRecord }, etc]
343 #### GET /api/patient/:puuid
345 Request:
347 ```sh
348 curl -X GET 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7'
351 Response:
353 ```json
355     "validationErrors": [],
356     "internalErrors": [],
357     "data": {
358         "id": "193",
359         "pid": "1",
360         "pubpid": "",
361         "title": "Mr",
362         "fname": "Baz",
363         "mname": "",
364         "lname": "Bop",
365         "ss": "",
366         "street": "456 Tree Lane",
367         "postal_code": "08642",
368         "city": "FooTown",
369         "state": "FL",
370         "county": "",
371         "country_code": "US",
372         "drivers_license": "",
373         "contact_relationship": "",
374         "phone_contact": "123-456-7890",
375         "phone_home": "",
376         "phone_biz": "",
377         "phone_cell": "",
378         "email": "",
379         "DOB": "1992-02-03",
380         "sex": "Male",
381         "race": "",
382         "ethnicity": "",
383         "status": ""
384     }
388 #### POST /api/patient/:pid/encounter
390 Request:
392 ```sh
393 curl -X POST 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter' -d \
395     "date":"2020-11-10",
396     "onset_date": "",
397     "reason": "Pregnancy Test",
398     "facility": "Owerri General Hospital",
399     "pc_catid": "5",
400     "facility_id": "3",
401     "billing_facility": "3",
402     "sensitivity": "normal",
403     "referral_source": "",
404     "pos_code": "0",
405     "external_id": "",
406     "provider_id": "1",
407     "class_code" : "AMB"
411 Response:
413 ```json
415     "validationErrors": [],
416     "internalErrors": [],
417     "data": {
418         "encounter": 1,
419         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef"
420     }
424 #### PUT /api/patient/:pid/encounter/:eid
426 Request:
428 ```sh
429 curl -X POST 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter/90c196f2-51cc-4655-8858-3a80aebff3ef' -d \
431     "date":"2019-09-14",
432     "onset_date": "2019-04-20 00:00:00",
433     "reason": "Pregnancy Test",
434     "pc_catid": "5",
435     "facility_id": "3",
436     "billing_facility": "3",
437     "sensitivity": "normal",
438     "referral_source": "",
439     "pos_code": "0"
443 Response:
445 ```json
447     "validationErrors": [],
448     "internalErrors": [],
449     "data": {
450         "id": "1",
451         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef",
452         "date": "2019-09-14 00:00:00",
453         "reason": "Pregnancy Test",
454         "facility": "Owerri General Hospital",
455         "facility_id": "3",
456         "pid": "1",
457         "onset_date": "2019-04-20 00:00:00",
458         "sensitivity": "normal",
459         "billing_note": null,
460         "pc_catid": "5",
461         "last_level_billed": "0",
462         "last_level_closed": "0",
463         "last_stmt_date": null,
464         "stmt_count": "0",
465         "provider_id": "1",
466         "supervisor_id": "0",
467         "invoice_refno": "",
468         "referral_source": "",
469         "billing_facility": "3",
470         "external_id": "",
471         "pos_code": "0",
472         "class_code": "AMB",
473         "class_title": "ambulatory",
474         "pc_catname": "Office Visit",
475         "billing_facility_name": "Owerri General Hospital"
476     }
480 #### GET /api/patient/:pid/encounter
482 Request:
484 ```sh
485 curl -X GET 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter'
488 Response:
490 ```json
492     "validationErrors": [],
493     "internalErrors": [],
494     "data": [{ encounterRecord }, { encounterRecord }, etc]
498 #### GET /api/patient/:pid/encounter/:eid
500 Request:
502 ```sh
503 curl -X GET 'http://localhost:8300/apis/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter/90c196f2-51cc-4655-8858-3a80aebff3ef'
506 Response:
508 ```json
510     "validationErrors": [],
511     "internalErrors": [],
512     "data": {
513         "id": "1",
514         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef",
515         "date": "2019-09-14 00:00:00",
516         "reason": "Pregnancy Test",
517         "facility": "Owerri General Hospital",
518         "facility_id": "3",
519         "pid": "1",
520         "onset_date": "2019-04-20 00:00:00",
521         "sensitivity": "normal",
522         "billing_note": null,
523         "pc_catid": "5",
524         "last_level_billed": "0",
525         "last_level_closed": "0",
526         "last_stmt_date": null,
527         "stmt_count": "0",
528         "provider_id": "1",
529         "supervisor_id": "0",
530         "invoice_refno": "",
531         "referral_source": "",
532         "billing_facility": "3",
533         "external_id": "",
534         "pos_code": "0",
535         "class_code": "AMB",
536         "class_title": "ambulatory",
537         "pc_catname": "Office Visit",
538         "billing_facility_name": "Owerri General Hospital"
539     }
543 #### POST /api/patient/:pid/encounter/:eid/vital
545 Request:
547 ```sh
548 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/vital' -d \
550     "bps": "130",
551     "bpd": "80",
552     "weight": "220",
553     "height": "70",
554     "temperature": "98",
555     "temp_method": "Oral",
556     "pulse": "60",
557     "respiration": "20",
558     "note": "...",
559     "waist_circ": "37",
560     "head_circ": "22.2",
561     "oxygen_saturation": "80"
565 #### PUT /api/patient/:pid/encounter/:eid/vital/:vid
567 Request:
569 ```sh
570 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1' -d \
572     "bps": "140",
573     "bpd": "80",
574     "weight": "220",
575     "height": "70",
576     "temperature": "98",
577     "temp_method": "Oral",
578     "pulse": "60",
579     "respiration": "20",
580     "note": "...",
581     "waist_circ": "37",
582     "head_circ": "22.2",
583     "oxygen_saturation": "80"
587 #### GET /api/patient/:pid/encounter/:eid/vital
589 Request:
591 ```sh
592 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital'
595 #### GET /api/patient/:pid/encounter/:eid/vital/:vid
597 Request:
599 ```sh
600 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1'
603 #### POST /api/patient/:pid/encounter/:eid/soap_note
605 Request:
607 ```sh
608 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note' -d \
610     "subjective": "...",
611     "objective": "...",
612     "assessment": "...",
613     "plan": "..."
617 #### PUT /api/patient/:pid/encounter/:eid/soap_note/:sid
619 Request:
621 ```sh
622 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1' -d \
624     "subjective": "...",
625     "objective": "...",
626     "assessment": "...",
627     "plan": "..."
631 #### GET /api/patient/:pid/encounter/:eid/soap_note
633 Request:
635 ```sh
636 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note'
639 #### GET /api/patient/:pid/encounter/:eid/soap_note/:sid
641 Request:
643 ```sh
644 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1'
647 #### POST /api/patient/:pid/medical_problem
649 Request:
651 ```sh
652 curl -X POST 'http://localhost:8300/apis/api/patient/1/medical_problem' -d \
654     "title": "Dermatochalasis",
655     "begdate": "2010-04-13",
656     "enddate": null,
657     "diagnosis": "ICD10:H02.839"
661 #### PUT /api/patient/:pid/medical_problem/:mid
663 Request:
665 ```sh
666 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medical_problem/1' -d \
668     "title": "Dermatochalasis",
669     "begdate": "2010-04-13",
670     "enddate": "2018-03-12",
671     "diagnosis": "ICD10:H02.839"
675 #### GET /api/patient/:pid/medical_problem
677 Request:
679 ```sh
680 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem'
683 #### GET /api/patient/:pid/medical_problem/:mid
685 Request:
687 ```sh
688 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
691 #### DELETE /api/patient/:pid/medical_problem/:mid
693 Request:
695 ```sh
696 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
699 #### POST /api/patient/:pid/allergy
701 Request:
703 ```sh
704 curl -X POST 'http://localhost:8300/apis/api/patient/1/allergy' -d \
706     "title": "Iodine",
707     "begdate": "2010-10-13",
708     "enddate": null
712 #### PUT /api/patient/:pid/allergy/:aid
714 Request:
716 ```sh
717 curl -X PUT 'http://localhost:8300/apis/api/patient/1/allergy/1' -d \
719     "title": "Iodine",
720     "begdate": "2012-10-13",
721     "enddate": null
725 #### GET /api/patient/:pid/allergy
727 Request:
729 ```sh
730 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy'
733 #### GET /api/patient/:pid/allergy/:aid
735 Request:
737 ```sh
738 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy/1'
741 #### DELETE /api/patient/:pid/allergy/:aid
743 Request:
745 ```sh
746 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/allergy/1'
749 #### POST /api/patient/:pid/medication
751 Request:
753 ```sh
754 curl -X POST 'http://localhost:8300/apis/api/patient/1/medication' -d \
756     "title": "Norvasc",
757     "begdate": "2013-10-13",
758     "enddate": null
762 #### PUT /api/patient/:pid/medication/:mid
764 Request:
766 ```sh
767 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medication/1' -d \
769     "title": "Norvasc",
770     "begdate": "2013-04-13",
771     "enddate": null
775 #### GET /api/patient/:pid/medication
777 Request:
779 ```sh
780 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication'
783 #### GET /api/patient/:pid/medication/:mid
785 Request:
787 ```sh
788 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication/1'
791 #### DELETE /api/patient/:pid/medication/:mid
793 Request:
795 ```sh
796 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medication/1'
799 #### POST /api/patient/:pid/surgery
801 Request:
803 ```sh
804 curl -X POST 'http://localhost:8300/apis/api/patient/1/surgery' -d \
806     "title": "Blepharoplasty",
807     "begdate": "2013-10-13",
808     "enddate": null,
809     "diagnosis": "CPT4:15823-50"
813 #### PUT /api/patient/:pid/surgery/:sid
815 Request:
817 ```sh
818 curl -X PUT 'http://localhost:8300/apis/api/patient/1/surgery/1' -d \
820     "title": "Blepharoplasty",
821     "begdate": "2013-10-14",
822     "enddate": null,
823     "diagnosis": "CPT4:15823-50"
827 #### GET /api/patient/:pid/surgery
829 Request:
831 ```sh
832 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery'
835 #### GET /api/patient/:pid/surgery/:sid
837 Request:
839 ```sh
840 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery/1'
843 #### DELETE /api/patient/:pid/surgery/:sid
845 Request:
847 ```sh
848 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/surgery/1'
851 #### POST /api/patient/:pid/dental_issue
853 Request:
855 ```sh
856 curl -X POST 'http://localhost:8300/apis/api/patient/1/dental_issue' -d \
858     "title": "Halitosis",
859     "begdate": "2015-03-17",
860     "enddate": null
864 #### PUT /api/patient/:pid/dental_issue/:did
866 Request:
868 ```sh
869 curl -X PUT 'http://localhost:8300/apis/api/patient/1/dental_issue/1' -d \
871     "title": "Halitosis",
872     "begdate": "2015-03-17",
873     "enddate": "2018-03-20"
877 #### GET /api/patient/:pid/dental_issue
879 Request:
881 ```sh
882 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue'
885 #### GET /api/patient/:pid/dental_issue/:did
887 Request:
889 ```sh
890 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
893 #### DELETE /api/patient/:pid/dental_issue/:did
895 Request:
897 ```sh
898 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
901 #### GET /api/patient/:pid/insurance
903 Request:
905 ```sh
906 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance'
909 #### GET /api/patient/:pid/insurance/:type
911 Request:
913 ```sh
914 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance/secondary'
917 #### POST /api/patient/:pid/insurance/:type
919 Request:
921 ```sh
922 curl -X POST 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
924     "type": "primary",
925     "provider": "33",
926     "plan_name": "Some Plan",
927     "policy_number": "12345",
928     "group_number": "252412",
929     "subscriber_lname": "Tester",
930     "subscriber_mname": "Xi",
931     "subscriber_fname": "Foo",
932     "subscriber_relationship": "other",
933     "subscriber_ss": "234231234",
934     "subscriber_DOB": "2018-10-03",
935     "subscriber_street": "183 Cool St",
936     "subscriber_postal_code": "23418",
937     "subscriber_city": "Cooltown",
938     "subscriber_state": "AZ",
939     "subscriber_country": "USA",
940     "subscriber_phone": "234-598-2123",
941     "subscriber_employer": "Some Employer",
942     "subscriber_employer_street": "123 Heather Lane",
943     "subscriber_employer_postal_code": "23415",
944     "subscriber_employer_state": "AZ",
945     "subscriber_employer_country": "USA",
946     "subscriber_employer_city": "Cooltown",
947     "copay": "35",
948     "date": "2018-10-15",
949     "subscriber_sex": "Female",
950     "accept_assignment": "TRUE",
951     "policy_type": "a"
955 Notes:
957 -   `provider` is the insurance company id
958 -   `state` can be found by querying `resource=/api/list/state`
959 -   `country` can be found by querying `resource=/api/list/country`
961 #### PUT /api/patient/:pid/insurance/:type
963 Request:
965 ```sh
966 curl -X PUT 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
968     "type": "primary",
969     "provider": "33",
970     "plan_name": "Some Plan",
971     "policy_number": "12345",
972     "group_number": "252412",
973     "subscriber_lname": "Tester",
974     "subscriber_mname": "Xi",
975     "subscriber_fname": "Foo",
976     "subscriber_relationship": "other",
977     "subscriber_ss": "234231234",
978     "subscriber_DOB": "2018-10-03",
979     "subscriber_street": "183 Cool St",
980     "subscriber_postal_code": "23418",
981     "subscriber_city": "Cooltown",
982     "subscriber_state": "AZ",
983     "subscriber_country": "USA",
984     "subscriber_phone": "234-598-2123",
985     "subscriber_employer": "Some Employer",
986     "subscriber_employer_street": "123 Heather Lane",
987     "subscriber_employer_postal_code": "23415",
988     "subscriber_employer_state": "AZ",
989     "subscriber_employer_country": "USA",
990     "subscriber_employer_city": "Cooltown",
991     "copay": "35",
992     "date": "2018-10-15",
993     "subscriber_sex": "Female",
994     "accept_assignment": "TRUE",
995     "policy_type": "a"
999 Notes:
1001 -   `provider` is the insurance company id
1002 -   `state` can be found by querying `resource=/api/list/state`
1003 -   `country` can be found by querying `resource=/api/list/country`
1005 #### GET /api/list/:list_name
1007 Request:
1009 ```sh
1010 curl -X GET 'http://localhost:8300/apis/api/list/medical_problem_issue_list'
1013 #### GET /api/version
1015 Request:
1017 ```sh
1018 curl -X GET 'http://localhost:8300/apis/api/version'
1021 #### GET /api/product
1023 Request:
1025 ```sh
1026 curl -X GET 'http://localhost:8300/apis/api/product'
1029 #### GET /api/insurance_company
1031 Request:
1033 ```sh
1034 curl -X GET 'http://localhost:8300/apis/api/insurance_company'
1037 #### GET /api/insurance_type
1039 Request:
1041 ```sh
1042 curl -X GET 'http://localhost:8300/apis/api/insurance_type'
1045 #### POST /api/insurance_company
1047 Request:
1049 ```sh
1050 curl -X POST 'http://localhost:8300/apis/api/insurance_company' -d \
1052     "name": "Cool Insurance Company",
1053     "attn": null,
1054     "cms_id": null,
1055     "ins_type_code": "2",
1056     "x12_receiver_id": null,
1057     "x12_default_partner_id": null,
1058     "alt_cms_id": "",
1059     "line1": "123 Cool Lane",
1060     "line2": "Suite 123",
1061     "city": "Cooltown",
1062     "state": "CA",
1063     "zip": "12245",
1064     "country": "USA"
1068 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
1070 #### PUT /api/insurance_company/:iid
1072 Request:
1074 ```sh
1075 curl -X PUT 'http://localhost:8300/apis/api/insurance_company/1' -d \
1077     "name": "Super Insurance Company",
1078     "attn": null,
1079     "cms_id": null,
1080     "ins_type_code": "2",
1081     "x12_receiver_id": null,
1082     "x12_default_partner_id": null,
1083     "alt_cms_id": "",
1084     "line1": "123 Cool Lane",
1085     "line2": "Suite 123",
1086     "city": "Cooltown",
1087     "state": "CA",
1088     "zip": "12245",
1089     "country": "USA"
1093 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
1095 #### GET /api/appointment
1097 Request:
1099 ```sh
1100 curl -X GET 'http://localhost:8300/apis/api/appointment'
1103 #### GET /api/appointment/:eid
1105 Request:
1107 ```sh
1108 curl -X GET 'http://localhost:8300/apis/api/appointment/1'
1111 #### GET /api/patient/:pid/appointment
1113 Request:
1115 ```sh
1116 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment'
1119 #### GET /api/patient/:pid/appointment/:eid
1121 Request:
1123 ```sh
1124 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment/1'
1127 #### POST /api/patient/:pid/appointment
1129 Request:
1131 ```sh
1132 curl -X POST 'http://localhost:8300/apis/api/patient/1/appointment' -d \
1134     "pc_eid":"1",
1135     "pc_catid": "5",
1136     "pc_title": "Office Visit",
1137     "pc_duration": "900",
1138     "pc_hometext": "Test",
1139     "pc_apptstatus": "-",
1140     "pc_eventDate": "2018-10-19",
1141     "pc_startTime": "09:00",
1142     "pc_facility": "9",
1143     "pc_billing_location": "10"
1147 #### DELETE /api/patient/:pid/appointment/:eid
1149 Request:
1151 ```sh
1152 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/appointment/1' -d \
1155 #### GET /api/patient/:pid/document
1157 Request:
1159 ```sh
1160 curl -X GET 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye'
1163 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
1165 -   Spaces are represented with `_`
1166 -   All characters are lowercase
1168 #### POST /api/patient/:pid/document
1170 Request:
1172 ```sh
1173 curl -X POST 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye' \
1174  -F document=@/home/someone/Desktop/drawing.jpg
1177 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
1179 -   Spaces are represented with `_`
1180 -   All characters are lowercase
1182 #### GET /api/patient/:pid/document/:did
1184 Request:
1186 ```sh
1187 curl -X GET 'http://localhost:8300/apis/api/patient/1/document/1'
1190 #### POST /api/patient/:pid/message
1192 Request:
1194 ```sh
1195 curl -X POST 'http://localhost:8300/apis/api/patient/1/message' -d \
1197     "body": "Test 123",
1198     "groupname": "Default",
1199     "from": "admin",
1200     "to": "Matthew",
1201     "title": "Other",
1202     "message_status": "New"
1206 Notes:
1208 -   For `title`, use `resource=/api/list/note_type`
1209 -   For `message_type`, use `resource=/api/list/message_status`
1211 #### PUT /api/patient/:pid/message/:mid
1213 Request:
1215 ```sh
1216 curl -X PUT 'http://localhost:8300/apis/api/patient/1/message/1' -d \
1218     "body": "Test 456",
1219     "groupname": "Default",
1220     "from": "Matthew",
1221     "to": "admin",
1222     "title": "Other",
1223     "message_status": "New"
1227 Notes:
1229 -   For `title`, use `resource=/api/list/note_type`
1230 -   For `message_type`, use `resource=/api/list/message_status`
1232 #### DELETE /api/patient/:pid/message/:mid
1234 Request:
1236 ```sh
1237 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/message/1'
1240 ### /portal/ Endpoints
1242 OpenEMR patient portal endpoints Use `http://localhost:8300/apis/portal as base URI.`
1244 _Example:_ `http://localhost:8300/apis/portal/patient` returns a resource of the patient.
1246 #### POST /portal/auth
1248 The OpenEMR Patient Portal API utilizes the OAuth2 password credential flow for authentication. To obtain an API token, submit your login credentials and requested scope. The scope must match a site that has been setup in OpenEMR, in the /sites/ directory. If additional sites have not been created, set the scope
1249 to 'default'. If the patient portal is set to require email address on authenticate, then need to also include an `email` field in the request.
1251 Request:
1253 ```sh
1254 curl -X POST -H 'Content-Type: application/json' 'http://localhost:8300/apis/portal/auth' \
1255 -d '{
1256     "grant_type":"password",
1257     "username": "ServiceUser",
1258     "password": "password",
1259     "scope":"site id"
1263 Response:
1265 ```json
1267     "token_type": "Bearer",
1268     "access_token": "eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ==",
1269     "expires_in": "3600",
1270     "user_data": {
1271         "user_id": "1"
1272     }
1276 The Bearer token is required for each OpenEMR Patient Portal API request, and is conveyed using an Authorization header.
1278 Request:
1280 ```sh
1281 curl -X GET 'http://localhost:8300/apis/portal/patient' \
1282   -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
1285 #### GET /portal/patient
1287 Request:
1289 ```sh
1290 curl -X GET 'http://localhost:8300/apis/portal/patient'
1293 Response:
1295 ```json
1297     "validationErrors": [],
1298     "internalErrors": [],
1299     "data": {
1300         "id": "193",
1301         "pid": "1",
1302         "pubpid": "",
1303         "title": "Mr",
1304         "fname": "Baz",
1305         "mname": "",
1306         "lname": "Bop",
1307         "ss": "",
1308         "street": "456 Tree Lane",
1309         "postal_code": "08642",
1310         "city": "FooTown",
1311         "state": "FL",
1312         "county": "",
1313         "country_code": "US",
1314         "drivers_license": "",
1315         "contact_relationship": "",
1316         "phone_contact": "123-456-7890",
1317         "phone_home": "",
1318         "phone_biz": "",
1319         "phone_cell": "",
1320         "email": "",
1321         "DOB": "1992-02-03",
1322         "sex": "Male",
1323         "race": "",
1324         "ethnicity": "",
1325         "status": ""
1326     }
1330 ### Dev Notes
1332 -   For business logic, make or use the services [here](src/Services)
1333 -   For controller logic, make or use the classes [here](src/RestControllers)
1334 -   For routing declarations, use the class [here](_rest_routes.inc.php).
1336 ### Project Management
1338 #### General API
1340 -   TODO(?): Prevent `ListService` from using `enddate` of `0000-00-00` by default
1341 -   TODO(?): API for fee sheets
1342 -   TODO(?): API for pharmacies
1343 -   TODO(?): API for immunizations
1344 -   TODO(?): API for prescriptions
1345 -   TODO(?): Drug search API
1346 -   TODO(?): API for onotes