1 # OpenEMR REST API Documentation
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)
8 * [facility API](API_README.md#post-apifacility)
9 * [provider API](API_README.md#get-apiprovider)
10 * [patient API](API_README.md#post-apipatient)
11 * [insurance API](API_README.md#get-apipatientpidinsurance)
12 * [appointment API](API_README.md#get-apiappointment)
13 * [document API](API_README.md#get-apipatientpiddocument)
14 * [message API](API_README.md#post-apipatientpidmessage)
15 * [dev notes](API_README.md#dev-notes)
16 * [todos](API_README.md#project-management)
19 Enable this API service in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR REST API"
21 ### Using API Internally
22 There are several ways to make API calls from an authorized session and maintain security:
23 * See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
26 OpenEMR standard endpoints Use `http://localhost:8300/apis/ as base URI.`
28 _Example:_ `http://localhost:8300/apis/api/patient` returns a resource of all Patients.
31 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
35 curl -X POST -H 'Content-Type: application/json' 'http://localhost:8300/apis/api/auth' \
37 "grant_type":"password",
38 "username": "ServiceUser",
39 "password": "password",
46 "token_type": "Bearer",
47 "access_token": "eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ==",
54 The Bearer token is required for each OpenEMR API request, and is conveyed using an Authorization header.
57 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem' \
58 -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
61 #### POST /api/facility
64 curl -X POST 'http://localhost:8300/apis/api/facility' -d \
67 "phone": "808-606-3030",
68 "fax": "808-606-3031",
69 "street": "1337 Bit Shifter Ln",
70 "city": "San Lorenzo",
72 "postal_code": "54321",
73 "email": "foo@bar.com",
74 "service_location": "1",
75 "billing_location": "1",
80 #### PUT /api/facility/:fid
83 curl -X PUT 'http://localhost:8300/apis/api/facility/1' -d \
86 "phone": "808-606-3030",
87 "fax": "808-606-3031",
88 "street": "1337 Bit Shifter Ln",
89 "city": "San Lorenzo",
91 "postal_code": "54321",
92 "email": "foo@bar.com",
93 "service_location": "1",
94 "billing_location": "1",
99 #### GET /api/facility
102 curl -X GET 'http://localhost:8300/apis/api/facility'
105 #### GET /api/facility/:fid
108 curl -X GET 'http://localhost:8300/apis/api/facility/1'
111 #### GET /api/provider
114 curl -X GET 'http://localhost:8300/apis/api/provider'
117 #### GET /api/provider/:prid
120 curl -X GET 'http://localhost:8300/apis/api/provider/1'
123 #### POST /api/patient
126 curl -X POST 'http://localhost:8300/apis/api/patient' -d \
132 "street": "456 Tree Lane",
133 "postal_code": "08642",
136 "country_code": "US",
137 "phone_contact": "123-456-7890",
145 #### PUT /api/patient/:pid
148 curl -X PUT 'http://localhost:8300/apis/api/patient/1' -d \
154 "street": "456 Tree Lane",
155 "postal_code": "08642",
158 "country_code": "US",
159 "phone_contact": "123-456-7890",
167 #### GET /api/patient
170 curl -X GET 'http://localhost:8300/apis/api/patient'
174 curl -X GET 'http://localhost:8300/apis/api/patient&fname=...&lname=...&dob=...'
177 #### GET /api/patient/:pid
180 curl -X GET 'http://localhost:8300/apis/api/patient/1'
183 #### POST /api/patient/:pid/encounter
186 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter' -d \
190 "reason": "Pregnancy Test",
191 "facility": "Owerri General Hospital",
194 "billing_facility": "3",
195 "sensitivity": "normal",
196 "referral_source": "",
204 #### PUT /api/patient/:pid/encounter/:eid
207 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1' -d \
210 "onset_date": "2019-04-20 00:00:00",
211 "reason": "Pregnancy Test",
214 "billing_facility": "3",
215 "sensitivity": "normal",
216 "referral_source": "",
222 #### GET /api/patient/:pid/encounter
225 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter'
228 #### GET /api/patient/:pid/encounter/:eid
231 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1'
234 #### POST /api/patient/:pid/encounter/:eid/vital
237 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/vital' -d \
244 "temp_method": "Oral",
250 "oxygen_saturation": "80"
254 #### PUT /api/patient/:pid/encounter/:eid/vital/:vid
257 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1' -d \
264 "temp_method": "Oral",
270 "oxygen_saturation": "80"
274 #### GET /api/patient/:pid/encounter/:eid/vital
277 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital'
280 #### GET /api/patient/:pid/encounter/:eid/vital/:vid
283 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1'
286 #### POST /api/patient/:pid/encounter/:eid/soap_note
289 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note' -d \
298 #### PUT /api/patient/:pid/encounter/:eid/soap_note/:sid
301 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1' -d \
310 #### GET /api/patient/:pid/encounter/:eid/soap_note
313 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note'
316 #### GET /api/patient/:pid/encounter/:eid/soap_note/:sid
319 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1'
322 #### POST /api/patient/:pid/medical_problem
325 curl -X POST 'http://localhost:8300/apis/api/patient/1/medical_problem' -d \
327 "title": "Dermatochalasis",
328 "begdate": "2010-04-13",
330 "diagnosis": "ICD10:H02.839"
334 #### PUT /api/patient/:pid/medical_problem/:mid
337 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medical_problem/1' -d \
339 "title": "Dermatochalasis",
340 "begdate": "2010-04-13",
341 "enddate": "2018-03-12",
342 "diagnosis": "ICD10:H02.839"
346 #### GET /api/patient/:pid/medical_problem
349 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem'
352 #### GET /api/patient/:pid/medical_problem/:mid
355 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
358 #### DELETE /api/patient/:pid/medical_problem/:mid
361 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
364 #### POST /api/patient/:pid/allergy
367 curl -X POST 'http://localhost:8300/apis/api/patient/1/allergy' -d \
370 "begdate": "2010-10-13",
375 #### PUT /api/patient/:pid/allergy/:aid
378 curl -X PUT 'http://localhost:8300/apis/api/patient/1/allergy/1' -d \
381 "begdate": "2012-10-13",
386 #### GET /api/patient/:pid/allergy
389 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy'
392 #### GET /api/patient/:pid/allergy/:aid
395 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy/1'
398 #### DELETE /api/patient/:pid/allergy/:aid
401 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/allergy/1'
404 #### POST /api/patient/:pid/medication
407 curl -X POST 'http://localhost:8300/apis/api/patient/1/medication' -d \
410 "begdate": "2013-10-13",
415 #### PUT /api/patient/:pid/medication/:mid
418 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medication/1' -d \
421 "begdate": "2013-04-13",
426 #### GET /api/patient/:pid/medication
429 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication'
432 #### GET /api/patient/:pid/medication/:mid
435 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication/1'
438 #### DELETE /api/patient/:pid/medication/:mid
441 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medication/1'
444 #### POST /api/patient/:pid/surgery
447 curl -X POST 'http://localhost:8300/apis/api/patient/1/surgery' -d \
449 "title": "Blepharoplasty",
450 "begdate": "2013-10-13",
452 "diagnosis": "CPT4:15823-50"
456 #### PUT /api/patient/:pid/surgery/:sid
459 curl -X PUT 'http://localhost:8300/apis/api/patient/1/surgery/1' -d \
461 "title": "Blepharoplasty",
462 "begdate": "2013-10-14",
464 "diagnosis": "CPT4:15823-50"
468 #### GET /api/patient/:pid/surgery
471 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery'
474 #### GET /api/patient/:pid/surgery/:sid
477 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery/1'
480 #### DELETE /api/patient/:pid/surgery/:sid
483 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/surgery/1'
486 #### POST /api/patient/:pid/dental_issue
489 curl -X POST 'http://localhost:8300/apis/api/patient/1/dental_issue' -d \
491 "title": "Halitosis",
492 "begdate": "2015-03-17",
497 #### PUT /api/patient/:pid/dental_issue/:did
500 curl -X PUT 'http://localhost:8300/apis/api/patient/1/dental_issue/1' -d \
502 "title": "Halitosis",
503 "begdate": "2015-03-17",
504 "enddate": "2018-03-20"
508 #### GET /api/patient/:pid/dental_issue
511 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue'
514 #### GET /api/patient/:pid/dental_issue/:did
517 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
520 #### DELETE /api/patient/:pid/dental_issue/:did
523 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
526 #### GET /api/patient/:pid/insurance
529 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance'
532 #### GET /api/patient/:pid/insurance/:type
535 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance/secondary'
538 #### POST /api/patient/:pid/insurance/:type
541 curl -X POST 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
545 "plan_name": "Some Plan",
546 "policy_number": "12345",
547 "group_number": "252412",
548 "subscriber_lname": "Tester",
549 "subscriber_mname": "Xi",
550 "subscriber_fname": "Foo",
551 "subscriber_relationship": "other",
552 "subscriber_ss": "234231234",
553 "subscriber_DOB": "2018-10-03",
554 "subscriber_street": "183 Cool St",
555 "subscriber_postal_code": "23418",
556 "subscriber_city": "Cooltown",
557 "subscriber_state": "AZ",
558 "subscriber_country": "USA",
559 "subscriber_phone": "234-598-2123",
560 "subscriber_employer": "Some Employer",
561 "subscriber_employer_street": "123 Heather Lane",
562 "subscriber_employer_postal_code": "23415",
563 "subscriber_employer_state": "AZ",
564 "subscriber_employer_country": "USA",
565 "subscriber_employer_city": "Cooltown",
567 "date": "2018-10-15",
568 "subscriber_sex": "Female",
569 "accept_assignment": "TRUE",
575 - `provider` is the insurance company id
576 - `state` can be found by querying `resource=/api/list/state`
577 - `country` can be found by querying `resource=/api/list/country`
580 #### PUT /api/patient/:pid/insurance/:type
583 curl -X PUT 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
587 "plan_name": "Some Plan",
588 "policy_number": "12345",
589 "group_number": "252412",
590 "subscriber_lname": "Tester",
591 "subscriber_mname": "Xi",
592 "subscriber_fname": "Foo",
593 "subscriber_relationship": "other",
594 "subscriber_ss": "234231234",
595 "subscriber_DOB": "2018-10-03",
596 "subscriber_street": "183 Cool St",
597 "subscriber_postal_code": "23418",
598 "subscriber_city": "Cooltown",
599 "subscriber_state": "AZ",
600 "subscriber_country": "USA",
601 "subscriber_phone": "234-598-2123",
602 "subscriber_employer": "Some Employer",
603 "subscriber_employer_street": "123 Heather Lane",
604 "subscriber_employer_postal_code": "23415",
605 "subscriber_employer_state": "AZ",
606 "subscriber_employer_country": "USA",
607 "subscriber_employer_city": "Cooltown",
609 "date": "2018-10-15",
610 "subscriber_sex": "Female",
611 "accept_assignment": "TRUE",
617 - `provider` is the insurance company id
618 - `state` can be found by querying `resource=/api/list/state`
619 - `country` can be found by querying `resource=/api/list/country`
621 #### GET /api/list/:list_name
624 curl -X GET 'http://localhost:8300/apis/api/list/medical_problem_issue_list'
627 #### GET /api/version
630 curl -X GET 'http://localhost:8300/apis/api/version'
633 #### GET /api/product
636 curl -X GET 'http://localhost:8300/apis/api/product'
639 #### GET /api/insurance_company
642 curl -X GET 'http://localhost:8300/apis/api/insurance_company'
645 #### GET /api/insurance_type
648 curl -X GET 'http://localhost:8300/apis/api/insurance_type'
651 #### POST /api/insurance_company
654 curl -X POST 'http://localhost:8300/apis/api/insurance_company' -d \
656 "name": "Cool Insurance Company",
659 "ins_type_code": "2",
660 "x12_receiver_id": null,
661 "x12_default_partner_id": null,
663 "line1": "123 Cool Lane",
664 "line2": "Suite 123",
672 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
674 #### PUT /api/insurance_company/:iid
677 curl -X PUT 'http://localhost:8300/apis/api/insurance_company/1' -d \
679 "name": "Super Insurance Company",
682 "ins_type_code": "2",
683 "x12_receiver_id": null,
684 "x12_default_partner_id": null,
686 "line1": "123 Cool Lane",
687 "line2": "Suite 123",
695 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
697 #### GET /api/appointment
700 curl -X GET 'http://localhost:8300/apis/api/appointment'
703 #### GET /api/appointment/:eid
706 curl -X GET 'http://localhost:8300/apis/api/appointment/1'
709 #### GET /api/patient/:pid/appointment
712 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment'
715 #### GET /api/patient/:pid/appointment/:eid
718 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment/1'
721 #### POST /api/patient/:pid/appointment
724 curl -X POST 'http://localhost:8300/apis/api/patient/1/appointment' -d \
728 "pc_title": "Office Visit",
729 "pc_duration": "900",
730 "pc_hometext": "Test",
731 "pc_apptstatus": "-",
732 "pc_eventDate": "2018-10-19",
733 "pc_startTime": "09:00",
735 "pc_billing_location": "10"
739 #### DELETE /api/patient/:pid/appointment/:eid
742 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/appointment/1' -d \
745 #### GET /api/patient/:pid/document
748 curl -X GET 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye'
751 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
753 - Spaces are represented with `_`
754 - All characters are lowercase
756 #### POST /api/patient/:pid/document
759 curl -X POST 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye' \
760 -F document=@/home/someone/Desktop/drawing.jpg
763 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
765 - Spaces are represented with `_`
766 - All characters are lowercase
768 #### GET /api/patient/:pid/document/:did
771 curl -X GET 'http://localhost:8300/apis/api/patient/1/document/1'
774 #### POST /api/patient/:pid/message
777 curl -X POST 'http://localhost:8300/apis/api/patient/1/message' -d \
780 "groupname": "Default",
784 "message_status": "New"
789 - For `title`, use `resource=/api/list/note_type`
790 - For `message_type`, use `resource=/api/list/message_status`
792 #### PUT /api/patient/:pid/message/:mid
795 curl -X PUT 'http://localhost:8300/apis/api/patient/1/message/1' -d \
798 "groupname": "Default",
802 "message_status": "New"
807 - For `title`, use `resource=/api/list/note_type`
808 - For `message_type`, use `resource=/api/list/message_status`
810 #### DELETE /api/patient/:pid/message/:mid
813 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/message/1'
818 - For business logic, make or use the services [here](src/Services)
819 - For controller logic, make or use the classes [here](src/RestControllers)
820 - For routing declarations, use the class [here](_rest_routes.inc.php).
823 ### Project Management
827 - TODO(?): Prevent `ListService` from using `enddate` of `0000-00-00` by default
828 - TODO(?): API for fee sheets
829 - TODO(?): API for pharmacies
830 - TODO(?): API for immunizations
831 - TODO(?): API for prescriptions
832 - TODO(?): Drug search API
833 - TODO(?): API for onotes