1 ![img](./public/images/openemr-rest-api.png)
5 This project aims to provide an easy-to-use JSON-based REST API for OpenEMR's most common functions. All code will be done in classes and separate from the view to help with codebase modernization efforts.
9 - [@matthewvita](https://github.com/matthewvita)
10 - [@sjpadgett](https://github.com/sjpadgett)
11 - [@juggernautsei](https://github.com/juggernautsei)
12 - [@kofiav](https://github.com/kofiav)
13 - [@bradymiller](https://github.com/bradymiller)
16 Enable this API service in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR REST API"
18 ### Using API Internally
19 There are several ways to make API calls from an authorized session and maintain security:
20 * See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
23 Note: FHIR endpoints follow normal FHIR REST endpoints. Use `https://domain/apis/fhir as base URI.`
25 _Example:_ `https://domain/apis/fhir/Patient` returns a Patients bundle resource and etc..
29 Obtain an API token with your login (returns an API token). For FHIR replace Uri component 'api' with 'fhir':
30 Scope must match a site that has been setup in OpenEMR in the /sites/ directory. If you haven't created additional sites
31 then 'default' should be the scope.
34 curl -X POST -H 'Content-Type: application/json' 'https://localhost:8300/apis/api/auth' \
36 "grant_type":"password",
37 "username": "ServiceUser",
38 "password": "password",
45 "token_type":"Bearer",
46 "access_token":"d2870cb522230dbb8946b2f47d2c7e6664656661756c74",
50 Each call must include the token:
53 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem' \
54 -H 'Authorization: Bearer d2870cb522230dbb8946b2f47d2c7e6664656661756c74'
57 #### POST /api/facility
60 curl -X POST 'http://localhost:8300/apis/api/facility' -d \
63 "phone": "808-606-3030",
64 "fax": "808-606-3031",
65 "street": "1337 Bit Shifter Ln",
66 "city": "San Lorenzo",
68 "postal_code": "54321",
69 "email": "foo@bar.com",
70 "service_location": "1",
71 "billing_location": "1",
76 #### PUT /api/facility/:fid
79 curl -X PUT 'http://localhost:8300/apis/api/facility/1' -d \
82 "phone": "808-606-3030",
83 "fax": "808-606-3031",
84 "street": "1337 Bit Shifter Ln",
85 "city": "San Lorenzo",
87 "postal_code": "54321",
88 "email": "foo@bar.com",
89 "service_location": "1",
90 "billing_location": "1",
95 #### GET /api/facility
98 curl -X GET 'http://localhost:8300/apis/api/facility'
101 #### GET /api/facility/:fid
104 curl -X GET 'http://localhost:8300/apis/api/facility/1'
107 #### GET /api/provider
110 curl -X GET 'http://localhost:8300/apis/api/provider'
113 #### GET /api/provider/:prid
116 curl -X GET 'http://localhost:8300/apis/api/provider/1'
119 #### POST /api/patient
122 curl -X POST 'http://localhost:8300/apis/api/patient' -d \
128 "street": "456 Tree Lane",
129 "postal_code": "08642",
132 "country_code": "US",
133 "phone_contact": "123-456-7890",
141 #### PUT /api/patient/:pid
144 curl -X PUT 'http://localhost:8300/apis/api/patient/1' -d \
150 "street": "456 Tree Lane",
151 "postal_code": "08642",
154 "country_code": "US",
155 "phone_contact": "123-456-7890",
163 #### GET /api/patient
166 curl -X GET 'http://localhost:8300/apis/api/patient'
170 curl -X GET 'http://localhost:8300/apis/api/patient&fname=...&lname=...&dob=...'
173 #### GET /api/patient/:pid
176 curl -X GET 'http://localhost:8300/apis/api/patient/1'
179 #### GET /api/patient/:pid/encounter
182 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter'
185 #### GET /api/patient/:pid/encounter/:eid
188 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1'
191 #### POST /api/patient/:pid/encounter/:eid/vital
194 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/vital' -d \
201 "temp_method": "Oral",
207 "oxygen_saturation": "80"
211 #### PUT /api/patient/:pid/encounter/:eid/vital/:vid
214 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1' -d \
221 "temp_method": "Oral",
227 "oxygen_saturation": "80"
231 #### GET /api/patient/:pid/encounter/:eid/vital
234 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital'
237 #### GET /api/patient/:pid/encounter/:eid/vital/:vid
240 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/vital/1'
243 #### POST /api/patient/:pid/encounter/:eid/soap_note
246 curl -X POST 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note' -d \
255 #### PUT /api/patient/:pid/encounter/:eid/soap_note/:sid
258 curl -X PUT 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1' -d \
267 #### GET /api/patient/:pid/encounter/:eid/soap_note
270 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note'
273 #### GET /api/patient/:pid/encounter/:eid/soap_note/:sid
276 curl -X GET 'http://localhost:8300/apis/api/patient/1/encounter/1/soap_note/1'
279 #### POST /api/patient/:pid/medical_problem
282 curl -X POST 'http://localhost:8300/apis/api/patient/1/medical_problem' -d \
284 "title": "Dermatochalasis",
285 "begdate": "2010-04-13",
287 "diagnosis": "ICD10:H02.839"
291 #### PUT /api/patient/:pid/medical_problem/:mid
294 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medical_problem/1' -d \
296 "title": "Dermatochalasis",
297 "begdate": "2010-04-13",
298 "enddate": "2018-03-12",
299 "diagnosis": "ICD10:H02.839"
303 #### GET /api/patient/:pid/medical_problem
306 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem'
309 #### GET /api/patient/:pid/medical_problem/:mid
312 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
315 #### DELETE /api/patient/:pid/medical_problem/:mid
318 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medical_problem/1'
321 #### POST /api/patient/:pid/allergy
324 curl -X POST 'http://localhost:8300/apis/api/patient/1/allergy' -d \
327 "begdate": "2010-10-13",
332 #### PUT /api/patient/:pid/allergy/:aid
335 curl -X PUT 'http://localhost:8300/apis/api/patient/1/allergy/1' -d \
338 "begdate": "2012-10-13",
343 #### GET /api/patient/:pid/allergy
346 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy'
349 #### GET /api/patient/:pid/allergy/:aid
352 curl -X GET 'http://localhost:8300/apis/api/patient/1/allergy/1'
355 #### DELETE /api/patient/:pid/allergy/:aid
358 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/allergy/1'
361 #### POST /api/patient/:pid/medication
364 curl -X POST 'http://localhost:8300/apis/api/patient/1/medication' -d \
367 "begdate": "2013-10-13",
372 #### PUT /api/patient/:pid/medication/:mid
375 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medication/1' -d \
378 "begdate": "2013-04-13",
383 #### GET /api/patient/:pid/medication
386 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication'
389 #### GET /api/patient/:pid/medication/:mid
392 curl -X GET 'http://localhost:8300/apis/api/patient/1/medication/1'
395 #### DELETE /api/patient/:pid/medication/:mid
398 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/medication/1'
401 #### POST /api/patient/:pid/surgery
404 curl -X POST 'http://localhost:8300/apis/api/patient/1/surgery' -d \
406 "title": "Blepharoplasty",
407 "begdate": "2013-10-13",
409 "diagnosis": "CPT4:15823-50"
413 #### PUT /api/patient/:pid/surgery/:sid
416 curl -X PUT 'http://localhost:8300/apis/api/patient/1/surgery/1' -d \
418 "title": "Blepharoplasty",
419 "begdate": "2013-10-14",
421 "diagnosis": "CPT4:15823-50"
425 #### GET /api/patient/:pid/surgery
428 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery'
431 #### GET /api/patient/:pid/surgery/:sid
434 curl -X GET 'http://localhost:8300/apis/api/patient/1/surgery/1'
437 #### DELETE /api/patient/:pid/surgery/:sid
440 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/surgery/1'
443 #### POST /api/patient/:pid/dental_issue
446 curl -X POST 'http://localhost:8300/apis/api/patient/1/dental_issue' -d \
448 "title": "Halitosis",
449 "begdate": "2015-03-17",
454 #### PUT /api/patient/:pid/dental_issue/:did
457 curl -X PUT 'http://localhost:8300/apis/api/patient/1/dental_issue/1' -d \
459 "title": "Halitosis",
460 "begdate": "2015-03-17",
461 "enddate": "2018-03-20"
465 #### GET /api/patient/:pid/dental_issue
468 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue'
471 #### GET /api/patient/:pid/dental_issue/:did
474 curl -X GET 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
477 #### DELETE /api/patient/:pid/dental_issue/:did
480 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/dental_issue/1'
483 #### GET /api/patient/:pid/insurance
486 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance'
489 #### GET /api/patient/:pid/insurance/:type
492 curl -X GET 'http://localhost:8300/apis/api/patient/1/insurance/secondary'
495 #### POST /api/patient/:pid/insurance/:type
498 curl -X POST 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
502 "plan_name": "Some Plan",
503 "policy_number": "12345",
504 "group_number": "252412",
505 "subscriber_lname": "Tester",
506 "subscriber_mname": "Xi",
507 "subscriber_fname": "Foo",
508 "subscriber_relationship": "other",
509 "subscriber_ss": "234231234",
510 "subscriber_DOB": "2018-10-03",
511 "subscriber_street": "183 Cool St",
512 "subscriber_postal_code": "23418",
513 "subscriber_city": "Cooltown",
514 "subscriber_state": "AZ",
515 "subscriber_country": "USA",
516 "subscriber_phone": "234-598-2123",
517 "subscriber_employer": "Some Employer",
518 "subscriber_employer_street": "123 Heather Lane",
519 "subscriber_employer_postal_code": "23415",
520 "subscriber_employer_state": "AZ",
521 "subscriber_employer_country": "USA",
522 "subscriber_employer_city": "Cooltown",
524 "date": "2018-10-15",
525 "subscriber_sex": "Female",
526 "accept_assignment": "TRUE",
532 - `provider` is the insurance company id
533 - `state` can be found by querying `resource=/api/list/state`
534 - `country` can be found by querying `resource=/api/list/country`
537 #### PUT /api/patient/:pid/insurance/:type
540 curl -X PUT 'http://localhost:8300/apis/api/patient/10/insurance/primary' -d \
544 "plan_name": "Some Plan",
545 "policy_number": "12345",
546 "group_number": "252412",
547 "subscriber_lname": "Tester",
548 "subscriber_mname": "Xi",
549 "subscriber_fname": "Foo",
550 "subscriber_relationship": "other",
551 "subscriber_ss": "234231234",
552 "subscriber_DOB": "2018-10-03",
553 "subscriber_street": "183 Cool St",
554 "subscriber_postal_code": "23418",
555 "subscriber_city": "Cooltown",
556 "subscriber_state": "AZ",
557 "subscriber_country": "USA",
558 "subscriber_phone": "234-598-2123",
559 "subscriber_employer": "Some Employer",
560 "subscriber_employer_street": "123 Heather Lane",
561 "subscriber_employer_postal_code": "23415",
562 "subscriber_employer_state": "AZ",
563 "subscriber_employer_country": "USA",
564 "subscriber_employer_city": "Cooltown",
566 "date": "2018-10-15",
567 "subscriber_sex": "Female",
568 "accept_assignment": "TRUE",
574 - `provider` is the insurance company id
575 - `state` can be found by querying `resource=/api/list/state`
576 - `country` can be found by querying `resource=/api/list/country`
578 #### GET /api/list/:list_name
581 curl -X GET 'http://localhost:8300/apis/api/list/medical_problem_issue_list'
584 #### GET /api/version
587 curl -X GET 'http://localhost:8300/apis/api/version'
590 #### GET /api/product
593 curl -X GET 'http://localhost:8300/apis/api/product'
596 #### GET /api/insurance_company
599 curl -X GET 'http://localhost:8300/apis/api/insurance_company'
602 #### GET /api/insurance_type
605 curl -X GET 'http://localhost:8300/apis/api/insurance_type'
608 #### POST /api/insurance_company
611 curl -X POST 'http://localhost:8300/apis/api/insurance_company' -d \
613 "name": "Cool Insurance Company",
616 "ins_type_code": "2",
617 "x12_receiver_id": null,
618 "x12_default_partner_id": null,
620 "line1": "123 Cool Lane",
621 "line2": "Suite 123",
629 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
631 #### PUT /api/insurance_company/:iid
634 curl -X PUT 'http://localhost:8300/apis/api/insurance_company/1' -d \
636 "name": "Super Insurance Company",
639 "ins_type_code": "2",
640 "x12_receiver_id": null,
641 "x12_default_partner_id": null,
643 "line1": "123 Cool Lane",
644 "line2": "Suite 123",
652 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
654 #### GET /api/appointment
657 curl -X GET 'http://localhost:8300/apis/api/appointment'
660 #### GET /api/appointment/:eid
663 curl -X GET 'http://localhost:8300/apis/api/appointment/1'
666 #### GET /api/patient/:pid/appointment
669 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment'
672 #### GET /api/patient/:pid/appointment/:eid
675 curl -X GET 'http://localhost:8300/apis/api/patient/1/appointment/1'
678 #### POST /api/patient/:pid/appointment
681 curl -X POST 'http://localhost:8300/apis/api/patient/1/appointment' -d \
685 "pc_title": "Office Visit",
686 "pc_duration": "900",
687 "pc_hometext": "Test",
688 "pc_apptstatus": "-",
689 "pc_eventDate": "2018-10-19",
690 "pc_startTime": "09:00",
692 "pc_billing_location": "10"
696 #### DELETE /api/patient/:pid/appointment/:eid
699 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/appointment/1' -d \
702 #### GET /api/patient/:pid/document
705 curl -X GET 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye'
708 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
710 - Spaces are represented with `_`
711 - All characters are lowercase
713 #### POST /api/patient/:pid/document
716 curl -X POST 'http://localhost:8300/apis/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye' \
717 -F document=@/home/someone/Desktop/drawing.jpg
720 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
722 - Spaces are represented with `_`
723 - All characters are lowercase
725 #### GET /api/patient/:pid/document/:did
728 curl -X GET 'http://localhost:8300/apis/api/patient/1/document/1'
731 #### POST /api/patient/:pid/message
734 curl -X POST 'http://localhost:8300/apis/api/patient/1/message' -d \
737 "groupname": "Default",
741 "message_status": "New"
746 - For `title`, use `resource=/api/list/note_type`
747 - For `message_type`, use `resource=/api/list/message_status`
749 #### PUT /api/patient/:pid/message/:mid
752 curl -X PUT 'http://localhost:8300/apis/api/patient/1/message/1' -d \
755 "groupname": "Default",
759 "message_status": "New"
764 - For `title`, use `resource=/api/list/note_type`
765 - For `message_type`, use `resource=/api/list/message_status`
767 #### DELETE /api/patient/:pid/message/:mid
770 curl -X DELETE 'http://localhost:8300/apis/api/patient/1/message/1'
775 - For business logic, make or use the services [here](https://github.com/openemr/openemr/tree/master/services)
776 - For controller logic, make or use the classes [here](https://github.com/openemr/openemr/tree/master/rest_controllers)
777 - For routing declarations, use the class [here](https://github.com/openemr/openemr/blob/master/_rest_routes.inc.php).
780 ### Project Management
782 - TODO(sherwin): Encounter POST
783 - TODO(?): Prevent `ListService` from using `enddate` of `0000-00-00` by default
784 - TODO(?): API for fee sheets
785 - TODO(?): API for pharmacies
786 - TODO(?): API for immunizations
787 - TODO(?): API for prescriptions
788 - TODO(?): Drug search API
789 - TODO(?): API for onotes
792 ### What is that dog drawing?
794 That is Peppy, an old OpenEMR mascot. Long live Peppy!
799 [GNU GPL](../LICENSE)