capability fhir fix (#4056)
[openemr.git] / API_README.md
bloba24fa4e84b54166f6377f8e02276bbc5d37ae474
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 -   [Authorization](API_README.md#authorization)
56 -   [Standard API Endpoints](API_README.md#api-endpoints)
57     -   [Facility API](API_README.md#post-apifacility)
58     -   [Practitioner API](API_README.md#get-apipractitioner)
59     -   [Patient API](API_README.md#post-apipatient)
60     -   [Immunization API](API_README.md#get-apiimmunization)
61     -   [Allergy API](API_README.md#get-apiallergy)
62     -   [Procedure API](API_README.md#get-apiprocedure)
63     -   [Drug API](API_README.md#get-apidrug)
64     -   [Prescription API](API_README.md#get-apiprescription)
65     -   [Insurance API](API_README.md#get-apipatientpidinsurance)
66     -   [Appointment API](API_README.md#get-apiappointment)
67     -   [Document API](API_README.md#get-apipatientpiddocument)
68     -   [Message API](API_README.md#post-apipatientpidmessage)
69 -   [Portal API Endpoints](API_README.md#portal-Endpoints)
70     -   [Patient API](API_README.md#get-portalpatient)
71 -   [FHIR API Endpoints](FHIR_README.md#fhir-endpoints)
72     -   [FHIR Capability Statement](FHIR_README.md#capability-statement)
73     -   [FHIR Patient](FHIR_README.md#patient-resource)
74     -   [FHIR Encounter](FHIR_README.md#encounter-resource)
75     -   [FHIR Practitioner](FHIR_README.md#practitioner-resource)
76     -   [FHIR PractitionerRole](FHIR_README.md#practitionerrole-resource)
77     -   [FHIR Immunization](FHIR_README.md#immunization-resource)
78     -   [FHIR AllergyIntolerance](FHIR_README.md#allergyintolerance-resource)
79     -   [FHIR Organization](FHIR_README.md#organization-resource)
80     -   [FHIR Observation](FHIR_README.md#observation-resource)
81     -   [FHIR QuestionnaireResponse](FHIR_README.md#questionnaireresponse-resource)
82     -   [FHIR Condition](FHIR_README.md#condition-resource)
83     -   [FHIR Procedure](FHIR_README.md#procedure-resource)
84     -   [FHIR MedicationRequest](FHIR_README.md#medicationrequest-resource)
85     -   [FHIR Medication](FHIR_README.md#medication-resource)
86     -   [FHIR Location](FHIR_README.md#location-resource)
87     -   [FHIR CareTeam](FHIR_README.md#careTeam-resource)
88     -   [FHIR Provenance](FHIR_README.md#Provenance-resources)
89 -   [Patient Portal FHIR API Endpoints](FHIR_README.md#patient-portal-fhir-endpoints)
90     -   [Patient Portal FHIR Patient](FHIR_README.md#patient-portal-patient-resource)
91 -   [Dev notes](API_README.md#dev-notes)
92 -   [Todos](API_README.md#project-management)
94 ### Prerequisite
96 Enable the Standard API service (/api/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Standard REST API"
98 Enable the Patient Portal API service (/portal/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Patient Portal REST API"
100 ### Using API Internally
102 There are several ways to make API calls from an authorized session and maintain security:
104 -   See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
106 ### Multisite Support
108 Multisite is supported by including the site in the endpoint. When not using multisite or using the `default` multisite site, then a typical path would look like `apis/default/api/patient`. If you are using multisite and using a site called `alternate`, then the path would look like `apis/alternate/api/patient`.
110 ### Authorization
112 OpenEMR uses OIDC compliant authorization for API. SSL is required and setting baseurl at Administration->Globals->Connectors->'Site Address (required for OAuth2 and FHIR)' is required.
114 #### Registration
116 Here is an example for registering a client. A client needs to be registered before applying for grant to obtain access/refresh tokens.
118 ```sh
119 curl -X POST -k -H 'Content-Type: application/json' -i https://localhost:9300/oauth2/default/registration --data '{
120    "application_type": "private",
121    "redirect_uris":
122      ["https://client.example.org/callback"],
123    "client_name": "A Private App",
124    "token_endpoint_auth_method": "client_secret_post",
125    "contacts": ["me@example.org", "them@example.org"]
126   }'
129 Response:
131 ```json
133     "client_id": "LnjqojEEjFYe5j2Jp9m9UnmuxOnMg4VodEJj3yE8_OA",
134     "client_secret": "j21ecvLmFi9HPc_Hv0t7Ptmf1pVcZQLtHjIdU7U9tkS9WAjFJwVMav0G8ogTJ62q4BATovC7BQ19Qagc4x9BBg",
135     "registration_access_token": "uiDSXx2GNSvYy5n8eW50aGrJz0HjaGpUdrGf07Agv_Q",
136     "registration_client_uri": "https:\/\/localhost:9300\/oauth2\/default\/client\/6eUVG0-qK2dYiwfYdECKIw",
137     "client_id_issued_at": 1604767861,
138     "client_secret_expires_at": 0,
139     "contacts": ["me@example.org", "them@example.org"],
140     "application_type": "private",
141     "client_name": "A Private App",
142     "redirect_uris": ["https:\/\/client.example.org\/callback"],
143     "token_endpoint_auth_method": "client_secret_post"
147 #### Authorization Code Grant
149 This is the recommended standard mechanism to obtain access/refresh tokens. This is done by using an OAuth2 client with provider url of `oauth2/<site>`; an example full path would be `https://localhost:9300/oauth2/default`.
151 #### Refresh Token Grant
153 Example:
155 ```sh
156 curl -X POST -k -H 'Content-Type: application/x-www-form-urlencoded'
157 -i 'https://localhost:9300/oauth2/default/token'
158 --data 'grant_type=refresh_token
159 &client_id=LnjqojEEjFYe5j2Jp9m9UnmuxOnMg4VodEJj3yE8_OA
160 &refresh_token=def5020089a766d16...'
163 Response:
165 ```json
167   "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJrYn...",
168   "token_type": "Bearer",
169   "expires_in": 3599,
170   "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJrYnl1RkRp...",
171   "refresh_token": "def5020017b484b0add020bf3491a8a537fa04eda12..."
175 #### Password Grant
177 Recommend not using this mechanism unless you know what you are doing. It is considered far less secure than the standard authorization code method. Because of security implications, it is not turned on by default. It can be turned on at Administration->Globals->Connectors->'Enable OAuth2 Password Grant (Not considered secure)'.
179 Example for `users` role:
180 ```sh
181 curl -X POST -k -H 'Content-Type: application/x-www-form-urlencoded'
182 -i 'https://localhost:9300/oauth2/default/token'
183 --data 'grant_type=password
184 &client_id=LnjqojEEjFYe5j2Jp9m9UnmuxOnMg4VodEJj3yE8_OA
185 &user_role=users
186 &username=admin
187 &password=pass'
190 Example for `patient` role:
191 ```sh
192 curl -X POST -k -H 'Content-Type: application/x-www-form-urlencoded'
193 -i 'https://localhost:9300/oauth2/default/token'
194 --data 'grant_type=password
195 &client_id=LnjqojEEjFYe5j2Jp9m9UnmuxOnMg4VodEJj3yE8_OA
196 &user_role=patient
197 &username=Phil1
198 &password=phil
199 &email=heya@invalid.email.com'
202 Response:
204 ```json
206   "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJrYn...",
207   "token_type": "Bearer",
208   "expires_in": 3599,
209   "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJrYnl1RkRp...",
210   "refresh_token": "def5020017b484b0add020bf3491a8a537fa04eda12..."
214 ### /api/ Endpoints
216 OpenEMR standard endpoints Use `http://localhost:8300/apis/default/api as base URI.`
218 Note that the `default` component can be changed to the name of the site when using OpenEMR's multisite feature.
220 _Example:_ `http://localhost:8300/apis/default/api/patient` returns a resource of all Patients.
222 The Bearer token is required for each OpenEMR API request, and is conveyed using an Authorization header. Note that the Bearer token is the access_token that is obtained in the above [Authorization](API_README.md#authorization) section.
224 Request:
226 ```sh
227 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/medical_problem' \
228   -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
231 #### POST /api/facility
233 Request:
235 ```sh
236 curl -X POST 'http://localhost:8300/apis/default/api/facility' -d \
238     "name": "Aquaria",
239     "phone": "808-606-3030",
240     "fax": "808-606-3031",
241     "street": "1337 Bit Shifter Ln",
242     "city": "San Lorenzo",
243     "state": "ZZ",
244     "postal_code": "54321",
245     "email": "foo@bar.com",
246     "service_location": "1",
247     "billing_location": "1",
248     "color": "#FF69B4"
252 #### PUT /api/facility/:fid
254 Request:
256 ```sh
257 curl -X PUT 'http://localhost:8300/apis/default/api/facility/1' -d \
259     "name": "Aquaria",
260     "phone": "808-606-3030",
261     "fax": "808-606-3031",
262     "street": "1337 Bit Shifter Ln",
263     "city": "San Lorenzo",
264     "state": "AZ",
265     "postal_code": "54321",
266     "email": "foo@bar.com",
267     "service_location": "1",
268     "billing_location": "1",
269     "color": "#FF69B4"
273 #### GET /api/facility
275 Request:
277 ```sh
278 curl -X GET 'http://localhost:8300/apis/default/api/facility'
281 #### GET /api/facility/:fid
283 Request:
285 ```sh
286 curl -X GET 'http://localhost:8300/apis/default/api/facility/1'
289 #### GET /api/practitioner
291 Request:
293 ```sh
294 curl -X GET 'http://localhost:8300/apis/default/api/practitioner'
297 #### GET /api/practitioner/:uuid
299 Request:
301 ```sh
302 curl -X GET 'http://localhost:8300/apis/default/api/practitioner/90cde167-7b9b-4ed1-bd55-533925cb2605'
305 #### POST /api/practitioner
307 Request:
309 ```sh
310 curl -X POST 'http://localhost:8300/apis/default/api/practitioner' -d \
312     "title": "Mrs.",
313     "fname": "Eduardo",
314     "mname": "Kathy",
315     "lname": "Perez",
316     "federaltaxid": "",
317     "federaldrugid": "",
318     "upin": "",
319     "facility_id": "3",
320     "facility": "Your Clinic Name Here",
321     "npi": "0123456789",
322     "email": "info@pennfirm.com",
323     "specialty": "",
324     "billname": null,
325     "url": null,
326     "assistant": null,
327     "organization": null,
328     "valedictory": null,
329     "street": "789 Third Avenue",
330     "streetb": "123 Cannaut Street",
331     "city": "San Diego",
332     "state": "CA",
333     "zip": "90210",
334     "phone": "(619) 555-9827",
335     "fax": null,
336     "phonew1": "(619) 555-7822",
337     "phonecell": "(619) 555-7821",
338     "notes": null,
339     "state_license_number": "123456"
343 Response:
345 ```json
347     "validationErrors": [],
348     "internalErrors": [],
349     "data": {
350         "id": 7,
351         "uuid": "90d453fb-0248-4c0d-9575-d99d02b169f5"
352     }
356 #### PATCH /api/practitioner/:uuid
358 Request:
360 ```sh
361 curl -X PATCH 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
363     "title": "Mr",
364     "fname": "Baz",
365     "mname": "",
366     "lname": "Bop",
367     "street": "456 Tree Lane",
368     "zip": "08642",
369     "city": "FooTown",
370     "state": "FL",
371     "phone": "123-456-7890"
375 Response:
377 ```json
379     "validationErrors": [],
380     "internalErrors": [],
381     "data": {
382         "id": "7",
383         "uuid": "90d453fb-0248-4c0d-9575-d99d02b169f5",
384         "title": "Mr",
385         "fname": "Baz",
386         "lname": "Bop",
387         "mname": "",
388         "federaltaxid": "",
389         "federaldrugid": "",
390         "upin": "",
391         "facility_id": "3",
392         "facility": "Your Clinic Name Here",
393         "npi": "0123456789",
394         "email": "info@pennfirm.com",
395         "active": "1",
396         "specialty": "",
397         "billname": "",
398         "url": "",
399         "assistant": "",
400         "organization": "",
401         "valedictory": "",
402         "street": "456 Tree Lane",
403         "streetb": "123 Cannaut Street",
404         "city": "FooTown",
405         "state": "FL",
406         "zip": "08642",
407         "phone": "123-456-7890",
408         "fax": "",
409         "phonew1": "(619) 555-7822",
410         "phonecell": "(619) 555-7821",
411         "notes": "",
412         "state_license_number": "123456",
413         "abook_title": null,
414         "physician_title": null,
415         "physician_code": null
416     }
420 #### POST /api/patient
422 Request:
424 ```sh
425 curl -X POST 'http://localhost:8300/apis/default/api/patient' -d \
427     "title": "Mr",
428     "fname": "Foo",
429     "mname": "",
430     "lname": "Bar",
431     "street": "456 Tree Lane",
432     "postal_code": "08642",
433     "city": "FooTown",
434     "state": "FL",
435     "country_code": "US",
436     "phone_contact": "123-456-7890",
437     "DOB": "1992-02-02",
438     "sex": "Male",
439     "race": "",
440     "ethnicity": ""
444 Response:
446 ```json
448     "validationErrors": [],
449     "internalErrors": [],
450     "data": {
451         "pid": 1
452     }
456 #### PUT /api/patient/:puuid
458 Request:
460 ```sh
461 curl -X PUT 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
463     "title": "Mr",
464     "fname": "Baz",
465     "mname": "",
466     "lname": "Bop",
467     "street": "456 Tree Lane",
468     "postal_code": "08642",
469     "city": "FooTown",
470     "state": "FL",
471     "country_code": "US",
472     "phone_contact": "123-456-7890",
473     "DOB": "1992-02-03",
474     "sex": "Male",
475     "race": "",
476     "ethnicity": ""
480 Response:
482 ```json
484     "validationErrors": [],
485     "internalErrors": [],
486     "data": {
487         "id": "193",
488         "pid": "1",
489         "pubpid": "",
490         "title": "Mr",
491         "fname": "Baz",
492         "mname": "",
493         "lname": "Bop",
494         "ss": "",
495         "street": "456 Tree Lane",
496         "postal_code": "08642",
497         "city": "FooTown",
498         "state": "FL",
499         "county": "",
500         "country_code": "US",
501         "drivers_license": "",
502         "contact_relationship": "",
503         "phone_contact": "123-456-7890",
504         "phone_home": "",
505         "phone_biz": "",
506         "phone_cell": "",
507         "email": "",
508         "DOB": "1992-02-03",
509         "sex": "Male",
510         "race": "",
511         "ethnicity": "",
512         "status": ""
513     }
517 #### GET /api/patient
519 Request:
521 ```sh
522 curl -X GET 'http://localhost:8300/apis/default/api/patient'
525 Response:
527 ```json
529     "validationErrors": [],
530     "internalErrors": [],
531     "data": [{ patientRecord }, { patientRecord }, etc]
535 Request:
537 ```sh
538 curl -X GET 'http://localhost:8300/apis/default/api/patient&fname=...&lname=...&dob=...'
541 Response:
543 ```json
545     "validationErrors": [],
546     "internalErrors": [],
547     "data": [{ patientRecord }, { patientRecord }, etc]
551 #### GET /api/patient/:puuid
553 Request:
555 ```sh
556 curl -X GET 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7'
559 Response:
561 ```json
563     "validationErrors": [],
564     "internalErrors": [],
565     "data": {
566         "id": "193",
567         "pid": "1",
568         "pubpid": "",
569         "title": "Mr",
570         "fname": "Baz",
571         "mname": "",
572         "lname": "Bop",
573         "ss": "",
574         "street": "456 Tree Lane",
575         "postal_code": "08642",
576         "city": "FooTown",
577         "state": "FL",
578         "county": "",
579         "country_code": "US",
580         "drivers_license": "",
581         "contact_relationship": "",
582         "phone_contact": "123-456-7890",
583         "phone_home": "",
584         "phone_biz": "",
585         "phone_cell": "",
586         "email": "",
587         "DOB": "1992-02-03",
588         "sex": "Male",
589         "race": "",
590         "ethnicity": "",
591         "status": ""
592     }
596 #### GET /api/immunization
598 Request:
600 ```sh
601 curl -X GET 'http://localhost:8300/apis/default/api/immunization'
604 #### GET /api/immunization/:uuid
606 Request:
608 ```sh
609 curl -X GET 'http://localhost:8300/apis/default/api/immunization/90cde167-7b9b-4ed1-bd55-533925cb2605'
612 #### POST /api/patient/:pid/encounter
614 Request:
616 ```sh
617 curl -X POST 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter' -d \
619     "date":"2020-11-10",
620     "onset_date": "",
621     "reason": "Pregnancy Test",
622     "facility": "Owerri General Hospital",
623     "pc_catid": "5",
624     "facility_id": "3",
625     "billing_facility": "3",
626     "sensitivity": "normal",
627     "referral_source": "",
628     "pos_code": "0",
629     "external_id": "",
630     "provider_id": "1",
631     "class_code" : "AMB"
635 Response:
637 ```json
639     "validationErrors": [],
640     "internalErrors": [],
641     "data": {
642         "encounter": 1,
643         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef"
644     }
648 #### PUT /api/patient/:pid/encounter/:eid
650 Request:
652 ```sh
653 curl -X POST 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter/90c196f2-51cc-4655-8858-3a80aebff3ef' -d \
655     "date":"2019-09-14",
656     "onset_date": "2019-04-20 00:00:00",
657     "reason": "Pregnancy Test",
658     "pc_catid": "5",
659     "facility_id": "3",
660     "billing_facility": "3",
661     "sensitivity": "normal",
662     "referral_source": "",
663     "pos_code": "0"
667 Response:
669 ```json
671     "validationErrors": [],
672     "internalErrors": [],
673     "data": {
674         "id": "1",
675         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef",
676         "date": "2019-09-14 00:00:00",
677         "reason": "Pregnancy Test",
678         "facility": "Owerri General Hospital",
679         "facility_id": "3",
680         "pid": "1",
681         "onset_date": "2019-04-20 00:00:00",
682         "sensitivity": "normal",
683         "billing_note": null,
684         "pc_catid": "5",
685         "last_level_billed": "0",
686         "last_level_closed": "0",
687         "last_stmt_date": null,
688         "stmt_count": "0",
689         "provider_id": "1",
690         "supervisor_id": "0",
691         "invoice_refno": "",
692         "referral_source": "",
693         "billing_facility": "3",
694         "external_id": "",
695         "pos_code": "0",
696         "class_code": "AMB",
697         "class_title": "ambulatory",
698         "pc_catname": "Office Visit",
699         "billing_facility_name": "Owerri General Hospital"
700     }
704 #### GET /api/patient/:pid/encounter
706 Request:
708 ```sh
709 curl -X GET 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter'
712 Response:
714 ```json
716     "validationErrors": [],
717     "internalErrors": [],
718     "data": [{ encounterRecord }, { encounterRecord }, etc]
722 #### GET /api/patient/:pid/encounter/:eid
724 Request:
726 ```sh
727 curl -X GET 'http://localhost:8300/apis/default/api/patient/90a8923c-0b1c-4d0a-9981-994b143381a7/encounter/90c196f2-51cc-4655-8858-3a80aebff3ef'
730 Response:
732 ```json
734     "validationErrors": [],
735     "internalErrors": [],
736     "data": {
737         "id": "1",
738         "uuid": "90c196f2-51cc-4655-8858-3a80aebff3ef",
739         "date": "2019-09-14 00:00:00",
740         "reason": "Pregnancy Test",
741         "facility": "Owerri General Hospital",
742         "facility_id": "3",
743         "pid": "1",
744         "onset_date": "2019-04-20 00:00:00",
745         "sensitivity": "normal",
746         "billing_note": null,
747         "pc_catid": "5",
748         "last_level_billed": "0",
749         "last_level_closed": "0",
750         "last_stmt_date": null,
751         "stmt_count": "0",
752         "provider_id": "1",
753         "supervisor_id": "0",
754         "invoice_refno": "",
755         "referral_source": "",
756         "billing_facility": "3",
757         "external_id": "",
758         "pos_code": "0",
759         "class_code": "AMB",
760         "class_title": "ambulatory",
761         "pc_catname": "Office Visit",
762         "billing_facility_name": "Owerri General Hospital"
763     }
767 #### POST /api/patient/:pid/encounter/:eid/vital
769 Request:
771 ```sh
772 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/encounter/1/vital' -d \
774     "bps": "130",
775     "bpd": "80",
776     "weight": "220",
777     "height": "70",
778     "temperature": "98",
779     "temp_method": "Oral",
780     "pulse": "60",
781     "respiration": "20",
782     "note": "...",
783     "waist_circ": "37",
784     "head_circ": "22.2",
785     "oxygen_saturation": "80"
789 #### PUT /api/patient/:pid/encounter/:eid/vital/:vid
791 Request:
793 ```sh
794 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/encounter/1/vital/1' -d \
796     "bps": "140",
797     "bpd": "80",
798     "weight": "220",
799     "height": "70",
800     "temperature": "98",
801     "temp_method": "Oral",
802     "pulse": "60",
803     "respiration": "20",
804     "note": "...",
805     "waist_circ": "37",
806     "head_circ": "22.2",
807     "oxygen_saturation": "80"
811 #### GET /api/patient/:pid/encounter/:eid/vital
813 Request:
815 ```sh
816 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/encounter/1/vital'
819 #### GET /api/patient/:pid/encounter/:eid/vital/:vid
821 Request:
823 ```sh
824 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/encounter/1/vital/1'
827 #### POST /api/patient/:pid/encounter/:eid/soap_note
829 Request:
831 ```sh
832 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/encounter/1/soap_note' -d \
834     "subjective": "...",
835     "objective": "...",
836     "assessment": "...",
837     "plan": "..."
841 #### PUT /api/patient/:pid/encounter/:eid/soap_note/:sid
843 Request:
845 ```sh
846 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/encounter/1/soap_note/1' -d \
848     "subjective": "...",
849     "objective": "...",
850     "assessment": "...",
851     "plan": "..."
855 #### GET /api/patient/:pid/encounter/:eid/soap_note
857 Request:
859 ```sh
860 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/encounter/1/soap_note'
863 #### GET /api/patient/:pid/encounter/:eid/soap_note/:sid
865 Request:
867 ```sh
868 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/encounter/1/soap_note/1'
871 #### GET /api/medical_problem
873 Request:
875 ```sh
876 curl -X GET 'http://localhost:8300/apis/default/api/medical_problem'
879 #### GET /api/medical_problem/:muuid
881 Request:
883 ```sh
884 curl -X GET 'http://localhost:8300/apis/default/api/medical_problem/9109890a-6756-44c1-a82d-bdfac91c7424'
887 #### GET /api/patient/:puuid/medical_problem
889 Request:
891 ```sh
892 curl -X GET 'http://localhost:8300/apis/default/api/patient/9101a093-da04-457f-a6a1-46ce93f0d629/medical_problem'
895 #### GET /api/patient/:puuid/medical_problem/:muuid
897 Request:
899 ```sh
900 curl -X GET 'http://localhost:8300/apis/default/api/patient/9101a093-da04-457f-a6a1-46ce93f0d629/medical_problem/91208832-47ab-4f65-ba44-08f57d4c028e'
903 #### POST /api/patient/:puuid/medical_problem
905 Request:
907 ```sh
908 curl -X POST 'http://localhost:8300/apis/default/api/patient/9101a093-da04-457f-a6a1-46ce93f0d629/medical_problem' -d \
910     "title": "Dermatochalasis",
911     "begdate": "2010-04-13",
912     "enddate": null,
913     "diagnosis": "ICD10:H02.839"
917 #### PUT /api/patient/:puuid/medical_problem/:muuid
919 Request:
921 ```sh
922 curl -X PUT 'http://localhost:8300/apis/default/api/patient/9101a093-da04-457f-a6a1-46ce93f0d629/medical_problem/91208832-47ab-4f65-ba44-08f57d4c028e' -d \
924     "title": "Dermatochalasis",
925     "begdate": "2010-04-13",
926     "enddate": "2018-03-12",
927     "diagnosis": "ICD10:H02.839"
931 #### DELETE /api/patient/:puuid/medical_problem/:muuid
933 Request:
935 ```sh
936 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/9101a093-da04-457f-a6a1-46ce93f0d629/medical_problem/91208832-47ab-4f65-ba44-08f57d4c028e'
939 #### GET /api/allergy
941 Request:
943 ```sh
944 curl -X GET 'http://localhost:8300/apis/default/api/allergy'
947 #### GET /api/allergy/:auuid
949 Request:
951 ```sh
952 curl -X GET 'http://localhost:8300/apis/default/api/allergy/90c196f2-51cc-4655-8858-3a80aebff3ef'
955 #### GET /api/patient/:puuid/allergy
957 Request:
959 ```sh
960 curl -X GET 'http://localhost:8300/apis/default/api/patient/90c196f2-51cc-4655-8858-3a80aebff3ef/allergy'
963 #### GET /api/patient/:puuid/allergy/:auuid
965 Request:
967 ```sh
968 curl -X GET 'http://localhost:8300/apis/default/api/patient/90c196f2-51cc-4655-8858-3a80aebff3ef/allergy/90c196f2-51cc-4655-8858-3a80aebff3ef'
971 #### POST /api/patient/:puuid/allergy
973 Request:
975 ```sh
976 curl -X POST 'http://localhost:8300/apis/default/api/patient/90c196f2-51cc-4655-8858-3a80aebff3ef/allergy' -d \
978     "title": "Iodine",
979     "begdate": "2010-10-13",
980     "enddate": null
984 #### PUT /api/patient/:puuid/allergy/:auuid
986 Request:
988 ```sh
989 curl -X PUT 'http://localhost:8300/apis/default/api/patient/90c196f2-51cc-4655-8858-3a80aebff3ef/allergy/90c196f2-51cc-4655-8858-3a80aebff3ef' -d \
991     "title": "Iodine",
992     "begdate": "2012-10-13",
993     "enddate": null
997 #### DELETE /api/patient/:puuid/allergy/:auuid
999 Request:
1001 ```sh
1002 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/90c196f2-51cc-4655-8858-3a80aebff3ef/allergy/90c196f2-51cc-4655-8858-3a80aebff3ef'
1005 #### GET /api/procedure
1007 Request:
1009 ```sh
1010 curl -X GET 'http://localhost:8300/apis/default/api/procedure'
1013 #### GET /api/procedure/:uuid
1015 Request:
1017 ```sh
1018 curl -X GET 'http://localhost:8300/apis/default/api/procedure/90c196f2-51cc-4655-8858-3a80aebff3ef'
1021 #### GET /api/drug
1023 Request:
1025 ```sh
1026 curl -X GET 'http://localhost:8300/apis/default/api/drug'
1029 #### GET /api/drug/:uuid
1031 Request:
1033 ```sh
1034 curl -X GET 'http://localhost:8300/apis/default/api/drug/90c196f2-51cc-4655-8858-3a80aebff3ef'
1037 #### GET /api/prescription
1039 Request:
1041 ```sh
1042 curl -X GET 'http://localhost:8300/apis/default/api/prescription'
1045 #### GET /api/prescription/:uuid
1047 Request:
1049 ```sh
1050 curl -X GET 'http://localhost:8300/apis/default/api/prescription/9128a1ec-95be-4649-8a66-d3686b7ab0ca'
1053 #### POST /api/patient/:pid/medication
1055 Request:
1057 ```sh
1058 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/medication' -d \
1060     "title": "Norvasc",
1061     "begdate": "2013-10-13",
1062     "enddate": null
1066 #### PUT /api/patient/:pid/medication/:mid
1068 Request:
1070 ```sh
1071 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/medication/1' -d \
1073     "title": "Norvasc",
1074     "begdate": "2013-04-13",
1075     "enddate": null
1079 #### GET /api/patient/:pid/medication
1081 Request:
1083 ```sh
1084 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/medication'
1087 #### GET /api/patient/:pid/medication/:mid
1089 Request:
1091 ```sh
1092 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/medication/1'
1095 #### DELETE /api/patient/:pid/medication/:mid
1097 Request:
1099 ```sh
1100 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/1/medication/1'
1103 #### POST /api/patient/:pid/surgery
1105 Request:
1107 ```sh
1108 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/surgery' -d \
1110     "title": "Blepharoplasty",
1111     "begdate": "2013-10-13",
1112     "enddate": null,
1113     "diagnosis": "CPT4:15823-50"
1117 #### PUT /api/patient/:pid/surgery/:sid
1119 Request:
1121 ```sh
1122 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/surgery/1' -d \
1124     "title": "Blepharoplasty",
1125     "begdate": "2013-10-14",
1126     "enddate": null,
1127     "diagnosis": "CPT4:15823-50"
1131 #### GET /api/patient/:pid/surgery
1133 Request:
1135 ```sh
1136 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/surgery'
1139 #### GET /api/patient/:pid/surgery/:sid
1141 Request:
1143 ```sh
1144 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/surgery/1'
1147 #### DELETE /api/patient/:pid/surgery/:sid
1149 Request:
1151 ```sh
1152 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/1/surgery/1'
1155 #### POST /api/patient/:pid/dental_issue
1157 Request:
1159 ```sh
1160 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/dental_issue' -d \
1162     "title": "Halitosis",
1163     "begdate": "2015-03-17",
1164     "enddate": null
1168 #### PUT /api/patient/:pid/dental_issue/:did
1170 Request:
1172 ```sh
1173 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/dental_issue/1' -d \
1175     "title": "Halitosis",
1176     "begdate": "2015-03-17",
1177     "enddate": "2018-03-20"
1181 #### GET /api/patient/:pid/dental_issue
1183 Request:
1185 ```sh
1186 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/dental_issue'
1189 #### GET /api/patient/:pid/dental_issue/:did
1191 Request:
1193 ```sh
1194 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/dental_issue/1'
1197 #### DELETE /api/patient/:pid/dental_issue/:did
1199 Request:
1201 ```sh
1202 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/1/dental_issue/1'
1205 #### GET /api/patient/:pid/insurance
1207 Request:
1209 ```sh
1210 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/insurance'
1213 #### GET /api/patient/:pid/insurance/:type
1215 Request:
1217 ```sh
1218 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/insurance/secondary'
1221 #### POST /api/patient/:pid/insurance/:type
1223 Request:
1225 ```sh
1226 curl -X POST 'http://localhost:8300/apis/default/api/patient/10/insurance/primary' -d \
1228     "type": "primary",
1229     "provider": "33",
1230     "plan_name": "Some Plan",
1231     "policy_number": "12345",
1232     "group_number": "252412",
1233     "subscriber_lname": "Tester",
1234     "subscriber_mname": "Xi",
1235     "subscriber_fname": "Foo",
1236     "subscriber_relationship": "other",
1237     "subscriber_ss": "234231234",
1238     "subscriber_DOB": "2018-10-03",
1239     "subscriber_street": "183 Cool St",
1240     "subscriber_postal_code": "23418",
1241     "subscriber_city": "Cooltown",
1242     "subscriber_state": "AZ",
1243     "subscriber_country": "USA",
1244     "subscriber_phone": "234-598-2123",
1245     "subscriber_employer": "Some Employer",
1246     "subscriber_employer_street": "123 Heather Lane",
1247     "subscriber_employer_postal_code": "23415",
1248     "subscriber_employer_state": "AZ",
1249     "subscriber_employer_country": "USA",
1250     "subscriber_employer_city": "Cooltown",
1251     "copay": "35",
1252     "date": "2018-10-15",
1253     "subscriber_sex": "Female",
1254     "accept_assignment": "TRUE",
1255     "policy_type": "a"
1259 Notes:
1261 -   `provider` is the insurance company id
1262 -   `state` can be found by querying `resource=/api/list/state`
1263 -   `country` can be found by querying `resource=/api/list/country`
1265 #### PUT /api/patient/:pid/insurance/:type
1267 Request:
1269 ```sh
1270 curl -X PUT 'http://localhost:8300/apis/default/api/patient/10/insurance/primary' -d \
1272     "type": "primary",
1273     "provider": "33",
1274     "plan_name": "Some Plan",
1275     "policy_number": "12345",
1276     "group_number": "252412",
1277     "subscriber_lname": "Tester",
1278     "subscriber_mname": "Xi",
1279     "subscriber_fname": "Foo",
1280     "subscriber_relationship": "other",
1281     "subscriber_ss": "234231234",
1282     "subscriber_DOB": "2018-10-03",
1283     "subscriber_street": "183 Cool St",
1284     "subscriber_postal_code": "23418",
1285     "subscriber_city": "Cooltown",
1286     "subscriber_state": "AZ",
1287     "subscriber_country": "USA",
1288     "subscriber_phone": "234-598-2123",
1289     "subscriber_employer": "Some Employer",
1290     "subscriber_employer_street": "123 Heather Lane",
1291     "subscriber_employer_postal_code": "23415",
1292     "subscriber_employer_state": "AZ",
1293     "subscriber_employer_country": "USA",
1294     "subscriber_employer_city": "Cooltown",
1295     "copay": "35",
1296     "date": "2018-10-15",
1297     "subscriber_sex": "Female",
1298     "accept_assignment": "TRUE",
1299     "policy_type": "a"
1303 Notes:
1305 -   `provider` is the insurance company id
1306 -   `state` can be found by querying `resource=/api/list/state`
1307 -   `country` can be found by querying `resource=/api/list/country`
1309 #### GET /api/list/:list_name
1311 Request:
1313 ```sh
1314 curl -X GET 'http://localhost:8300/apis/default/api/list/medical_problem_issue_list'
1317 #### GET /api/version
1319 Request:
1321 ```sh
1322 curl -X GET 'http://localhost:8300/apis/default/api/version'
1325 #### GET /api/product
1327 Request:
1329 ```sh
1330 curl -X GET 'http://localhost:8300/apis/default/api/product'
1333 #### GET /api/insurance_company
1335 Request:
1337 ```sh
1338 curl -X GET 'http://localhost:8300/apis/default/api/insurance_company'
1341 #### GET /api/insurance_type
1343 Request:
1345 ```sh
1346 curl -X GET 'http://localhost:8300/apis/default/api/insurance_type'
1349 #### POST /api/insurance_company
1351 Request:
1353 ```sh
1354 curl -X POST 'http://localhost:8300/apis/default/api/insurance_company' -d \
1356     "name": "Cool Insurance Company",
1357     "attn": null,
1358     "cms_id": null,
1359     "ins_type_code": "2",
1360     "x12_receiver_id": null,
1361     "x12_default_partner_id": null,
1362     "alt_cms_id": "",
1363     "line1": "123 Cool Lane",
1364     "line2": "Suite 123",
1365     "city": "Cooltown",
1366     "state": "CA",
1367     "zip": "12245",
1368     "country": "USA"
1372 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
1374 #### PUT /api/insurance_company/:iid
1376 Request:
1378 ```sh
1379 curl -X PUT 'http://localhost:8300/apis/default/api/insurance_company/1' -d \
1381     "name": "Super Insurance Company",
1382     "attn": null,
1383     "cms_id": null,
1384     "ins_type_code": "2",
1385     "x12_receiver_id": null,
1386     "x12_default_partner_id": null,
1387     "alt_cms_id": "",
1388     "line1": "123 Cool Lane",
1389     "line2": "Suite 123",
1390     "city": "Cooltown",
1391     "state": "CA",
1392     "zip": "12245",
1393     "country": "USA"
1397 Notes: `ins_type_code` can be found by inspecting the above route (/api/insurance_type).
1399 #### GET /api/appointment
1401 Request:
1403 ```sh
1404 curl -X GET 'http://localhost:8300/apis/default/api/appointment'
1407 #### GET /api/appointment/:eid
1409 Request:
1411 ```sh
1412 curl -X GET 'http://localhost:8300/apis/default/api/appointment/1'
1415 #### GET /api/patient/:pid/appointment
1417 Request:
1419 ```sh
1420 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/appointment'
1423 #### GET /api/patient/:pid/appointment/:eid
1425 Request:
1427 ```sh
1428 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/appointment/1'
1431 #### POST /api/patient/:pid/appointment
1433 Request:
1435 ```sh
1436 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/appointment' -d \
1438     "pc_eid":"1",
1439     "pc_catid": "5",
1440     "pc_title": "Office Visit",
1441     "pc_duration": "900",
1442     "pc_hometext": "Test",
1443     "pc_apptstatus": "-",
1444     "pc_eventDate": "2018-10-19",
1445     "pc_startTime": "09:00",
1446     "pc_facility": "9",
1447     "pc_billing_location": "10"
1451 #### DELETE /api/patient/:pid/appointment/:eid
1453 Request:
1455 ```sh
1456 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/1/appointment/1' -d \
1459 #### GET /api/patient/:pid/document
1461 Request:
1463 ```sh
1464 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye'
1467 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
1469 -   Spaces are represented with `_`
1470 -   All characters are lowercase
1472 #### POST /api/patient/:pid/document
1474 Request:
1476 ```sh
1477 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/document&path=/eye_module/imaging-eye/drawings-eye' \
1478  -F document=@/home/someone/Desktop/drawing.jpg
1481 Note: The `path` query string represents the OpenEMR documents paths with two exceptions:
1483 -   Spaces are represented with `_`
1484 -   All characters are lowercase
1486 #### GET /api/patient/:pid/document/:did
1488 Request:
1490 ```sh
1491 curl -X GET 'http://localhost:8300/apis/default/api/patient/1/document/1'
1494 #### POST /api/patient/:pid/message
1496 Request:
1498 ```sh
1499 curl -X POST 'http://localhost:8300/apis/default/api/patient/1/message' -d \
1501     "body": "Test 123",
1502     "groupname": "Default",
1503     "from": "admin",
1504     "to": "Matthew",
1505     "title": "Other",
1506     "message_status": "New"
1510 Notes:
1512 -   For `title`, use `resource=/api/list/note_type`
1513 -   For `message_type`, use `resource=/api/list/message_status`
1515 #### PUT /api/patient/:pid/message/:mid
1517 Request:
1519 ```sh
1520 curl -X PUT 'http://localhost:8300/apis/default/api/patient/1/message/1' -d \
1522     "body": "Test 456",
1523     "groupname": "Default",
1524     "from": "Matthew",
1525     "to": "admin",
1526     "title": "Other",
1527     "message_status": "New"
1531 Notes:
1533 -   For `title`, use `resource=/api/list/note_type`
1534 -   For `message_type`, use `resource=/api/list/message_status`
1536 #### DELETE /api/patient/:pid/message/:mid
1538 Request:
1540 ```sh
1541 curl -X DELETE 'http://localhost:8300/apis/default/api/patient/1/message/1'
1544 ### /portal/ Endpoints
1546 OpenEMR patient portal endpoints Use `http://localhost:8300/apis/default/portal as base URI.`
1548 Note that the `default` component can be changed to the name of the site when using OpenEMR's multisite feature.
1550 _Example:_ `http://localhost:8300/apis/default/portal/patient` returns a resource of the patient.
1552 The Bearer token is required for each OpenEMR API request, and is conveyed using an Authorization header. Note that the Bearer token is the access_token that is obtained in the above [Authorization](API_README.md#authorization) section.
1554 Request:
1556 ```sh
1557 curl -X GET 'http://localhost:8300/apis/default/portal/patient' \
1558   -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
1561 #### GET /portal/patient
1563 Request:
1565 ```sh
1566 curl -X GET 'http://localhost:8300/apis/default/portal/patient'
1569 Response:
1571 ```json
1573     "validationErrors": [],
1574     "internalErrors": [],
1575     "data": {
1576         "id": "193",
1577         "pid": "1",
1578         "pubpid": "",
1579         "title": "Mr",
1580         "fname": "Baz",
1581         "mname": "",
1582         "lname": "Bop",
1583         "ss": "",
1584         "street": "456 Tree Lane",
1585         "postal_code": "08642",
1586         "city": "FooTown",
1587         "state": "FL",
1588         "county": "",
1589         "country_code": "US",
1590         "drivers_license": "",
1591         "contact_relationship": "",
1592         "phone_contact": "123-456-7890",
1593         "phone_home": "",
1594         "phone_biz": "",
1595         "phone_cell": "",
1596         "email": "",
1597         "DOB": "1992-02-03",
1598         "sex": "Male",
1599         "race": "",
1600         "ethnicity": "",
1601         "status": ""
1602     }
1606 ### Dev Notes
1608 -   For business logic, make or use the services [here](src/Services)
1609 -   For controller logic, make or use the classes [here](src/RestControllers)
1610 -   For routing declarations, use the class [here](_rest_routes.inc.php).
1612 ### Project Management
1614 #### General API
1616 -   TODO(?): Prevent `ListService` from using `enddate` of `0000-00-00` by default
1617 -   TODO(?): API for fee sheets
1618 -   TODO(?): API for pharmacies
1619 -   TODO(?): API for immunizations
1620 -   TODO(?): API for prescriptions
1621 -   TODO(?): Drug search API
1622 -   TODO(?): API for onotes