Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / API_README.md
blobb2ea3f276eeba1ab1e40bc061659202b86fdde65
1 ![img](./public/images/openemr-rest-api.png)
3 ### Goal
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.
7 ### Team
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)
15 ### Prerequsite
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.
22 ### Endpoints
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..
27 #### POST /api/auth
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.
33 ```
34 curl -X POST -H 'Content-Type: application/json' 'https://localhost:8300/apis/api/auth' \
35 -d '{
36     "grant_type":"password",
37     "username": "ServiceUser",
38     "password": "password",
39     "scope":"site id"
41 ```
42 Response:
43 ```
45 "token_type":"Bearer",
46 "access_token":"d2870cb522230dbb8946b2f47d2c7e6664656661756c74",
47 "expires_in":"3600"
49 ```
50 Each call must include the token:
52 ```
53 curl -X GET 'http://localhost:8300/apis/api/patient/1/medical_problem' \
54   -H 'Authorization: Bearer d2870cb522230dbb8946b2f47d2c7e6664656661756c74'
55 ```
57 #### POST /api/facility
59 ```
60 curl -X POST 'http://localhost:8300/apis/api/facility' -d \
62     "name": "Aquaria",
63     "phone": "808-606-3030",
64     "fax": "808-606-3031",
65     "street": "1337 Bit Shifter Ln",
66     "city": "San Lorenzo",
67     "state": "ZZ",
68     "postal_code": "54321",
69     "email": "foo@bar.com",
70     "service_location": "1",
71     "billing_location": "1",
72     "color": "#FF69B4"
74 ```
76 #### PUT /api/facility/:fid
78 ```
79 curl -X PUT 'http://localhost:8300/apis/api/facility/1' -d \
81     "name": "Aquaria",
82     "phone": "808-606-3030",
83     "fax": "808-606-3031",
84     "street": "1337 Bit Shifter Ln",
85     "city": "San Lorenzo",
86     "state": "AZ",
87     "postal_code": "54321",
88     "email": "foo@bar.com",
89     "service_location": "1",
90     "billing_location": "1",
91     "color": "#FF69B4"
93 ```
95 #### GET /api/facility
97 ```
98 curl -X GET 'http://localhost:8300/apis/api/facility'
99 ```
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 \
124     "title": "Mr",
125     "fname": "Foo",
126     "mname": "",
127     "lname": "Bar",
128     "street": "456 Tree Lane",
129     "postal_code": "08642",
130     "city": "FooTown",
131     "state": "FL",
132     "country_code": "US",
133     "phone_contact": "123-456-7890",
134     "dob": "1992-02-02",
135     "sex": "Male",
136     "race": "",
137     "ethnicity": ""
141 #### PUT /api/patient/:pid
144 curl -X PUT 'http://localhost:8300/apis/api/patient/1' -d \
146     "title": "Mr",
147     "fname": "Baz",
148     "mname": "",
149     "lname": "Bop",
150     "street": "456 Tree Lane",
151     "postal_code": "08642",
152     "city": "FooTown",
153     "state": "FL",
154     "country_code": "US",
155     "phone_contact": "123-456-7890",
156     "dob": "1992-02-03",
157     "sex": "Male",
158     "race": "",
159     "ethnicity": ""
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 \
196     "bps": "130",
197     "bpd": "80",
198     "weight": "220",
199     "height": "70",
200     "temperature": "98",
201     "temp_method": "Oral",
202     "pulse": "60",
203     "respiration": "20",
204     "note": "...",
205     "waist_circ": "37",
206     "head_circ": "22.2",
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 \
216     "bps": "140",
217     "bpd": "80",
218     "weight": "220",
219     "height": "70",
220     "temperature": "98",
221     "temp_method": "Oral",
222     "pulse": "60",
223     "respiration": "20",
224     "note": "...",
225     "waist_circ": "37",
226     "head_circ": "22.2",
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 \
248     "subjective": "...",
249     "objective": "...",
250     "assessment": "...",
251     "plan": "..."
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 \
260     "subjective": "...",
261     "objective": "...",
262     "assessment": "...",
263     "plan": "..."
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",
286     "enddate": null,
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 \
326     "title": "Iodine",
327     "begdate": "2010-10-13",
328     "enddate": null
332 #### PUT /api/patient/:pid/allergy/:aid
335 curl -X PUT 'http://localhost:8300/apis/api/patient/1/allergy/1' -d \
337     "title": "Iodine",
338     "begdate": "2012-10-13",
339     "enddate": null
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 \
366     "title": "Norvasc",
367     "begdate": "2013-10-13",
368     "enddate": null
372 #### PUT /api/patient/:pid/medication/:mid
375 curl -X PUT 'http://localhost:8300/apis/api/patient/1/medication/1' -d \
377     "title": "Norvasc",
378     "begdate": "2013-04-13",
379     "enddate": null
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",
408     "enddate": null,
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",
420     "enddate": null,
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",
450     "enddate": null
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 \
500     "type": "primary",
501     "provider": "33",
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",
523     "copay": "35",
524     "date": "2018-10-15",
525     "subscriber_sex": "Female",
526     "accept_assignment": "TRUE",
527     "policy_type": "a"
531 Notes:
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 \
542     "type": "primary",
543     "provider": "33",
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",
565     "copay": "35",
566     "date": "2018-10-15",
567     "subscriber_sex": "Female",
568     "accept_assignment": "TRUE",
569     "policy_type": "a"
573 Notes:
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",
614     "attn": null,
615     "cms_id": null,
616     "ins_type_code": "2",
617     "x12_receiver_id": null,
618     "x12_default_partner_id": null,
619     "alt_cms_id": "",
620     "line1": "123 Cool Lane",
621     "line2": "Suite 123",
622     "city": "Cooltown",
623     "state": "CA",
624     "zip": "12245",
625     "country": "USA"
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",
637     "attn": null,
638     "cms_id": null,
639     "ins_type_code": "2",
640     "x12_receiver_id": null,
641     "x12_default_partner_id": null,
642     "alt_cms_id": "",
643     "line1": "123 Cool Lane",
644     "line2": "Suite 123",
645     "city": "Cooltown",
646     "state": "CA",
647     "zip": "12245",
648     "country": "USA"
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 \
683     "pc_eid":"1",
684     "pc_catid": "5",
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",
691     "pc_facility": "9",
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 \
736     "body": "Test 123",
737     "groupname": "Default",
738     "from": "admin",
739     "to": "Matthew",
740     "title": "Other",
741     "message_status": "New"
745 Notes:
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 \
754     "body": "Test 456",
755     "groupname": "Default",
756     "from": "Matthew",
757     "to": "admin",
758     "title": "Other",
759     "message_status": "New"
763 Notes:
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'
773 ### Dev Notes
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!
797 ### License
799 [GNU GPL](../LICENSE)