/
Sample REST calls

Sample REST calls

Authenticate and get a session ID and whether the authentication was successful or not. This is useful to verify connectivity and credentials.

 

 

/ws/rest/v1/session

 

Create Person

   The minium required fields are gender and names

          PHP Code Example:-

  // PERSON $name = array(); $names = array();  $person_data = array(); $name['givenName'] = "givenName"; $name['middleName'] = "middleName"; $name['familyName'] = "familyName"; array_push($names,$name);   $person_data['gender'] = "gender"; // Say "M" $person_data['names'] = $names; $person_data = json_encode($person_data); $person_curL = curl_init('http://localhost/openmrs-standalone/ws/rest/v1/person'); curl_setopt($person_curL, CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($person_curL, CURLOPT_USERPWD,"admin:Admin123"); curl_setopt($person_curL, CURLOPT_RETURNTRANSFER,true); curl_setopt($person_curL, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); curl_setopt($person_curL, CURLOPT_POST,1); curl_setopt($person_curL, CURLOPT_POSTFIELDS,$person_data); $output = curl_exec($person_curL); $status = curl_getinfo($person_curL,CURLINFO_HTTP_CODE); curl_close($person_curL);

          

Create Patient

 

     To create a patient, we can use the existing person or we can create a new person

 

PHP Example:-

// PATIENT $identifiers = array(); $person_data = array(); $person_identification = array(); $identifiers['identifier'] = "identifier"; // user defined $identifiers['identifierType'] = "uuid of the identifier type"; // Either Old Identification number or OpenMRS Identification Number $identifiers['location'] = "uuid of the location"; $identifiers['preferred'] = true; array_push($person_identification,$identifiers); $patient_data['person'] = "uuid of the person"; // Existing person's uuid or newly created person's uuid $patient_data['identifiers'] = $person_identification; $patient_data = json_encode($patient_data); $patient_curL = curl_init('http://localhost/openmrs-standalone/ws/rest/v1/patient'); curl_setopt($patient_curL, CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($patient_curL, CURLOPT_USERPWD,"admin:Admin123"); curl_setopt($patient_curL, CURLOPT_RETURNTRANSFER,true); curl_setopt($patient_curL, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); curl_setopt($patient_curL, CURLOPT_POST,1); curl_setopt($patient_curL, CURLOPT_POSTFIELDS,$patient_data); $patientoutput = curl_exec($patient_curL); $patientstatus = curl_getinfo($patient_curL,CURLINFO_HTTP_CODE); curl_close($patient_curL);

 



     

  1. Get people by name

Please add your own REST calls that you find useful.

You can find more examples in our controller tests at https://github.com/openmrs/openmrs-module-webservices.rest/search?q=Controller+test&type=Code

 

Concept

Call Type

Sample URL

Output

Call Type

Sample URL

Output

GET

/ws/rest/v1/concept

Returns a list of top 50 (whatever is configured in settings (formerly Global Properties from 1.8 downwards)) concepts with uuid, display and links

GET

/ws/rest/v1/concept?v=custom:(uuid,name)

Returns a list of top 50 (whatever is configured in settings (formerly Global Properties from 1.8 downwards)) concepts

GET

/ws/rest/v1/concept/cbec024a-8bb4-4fcc-b59b-c7b706bb432e

Returns full description of a concept, including:
uuid, name, display, datatype, conceptClass, set, version, retired, names, mappings, etc.

GET

/ws/rest/v1/concept?q=Yes

Returns list of concepts matching "Yes" with uuid, display and links

GET

/ws/rest/v1/concept?q=COUGH&v=custom:(uuid,name)

Returns list of concepts matching "COUGH" with uuid and name

 

Encounter Type

Call Type

Sample URL

Output

Call Type

Sample URL

Output

GET

/ws/rest/v1/encountertype

Returns a list of top 50 encounter types with uuid, display and links

GET

/ws/rest/v1/encountertype?q=admission

Returns encounter type admission with uuid, display and links

 

 

Related content

Adding a Web Service Step by Step Guide for Core Developers
Adding a Web Service Step by Step Guide for Core Developers
More like this
REST Web Services API For Clients
REST Web Services API For Clients
More like this
REST Module
REST Module
More like this
User Interface Modules
User Interface Modules
Read with this
Adding a Web Service Step by Step Guide for Core Developers (REST 1.x)
Adding a Web Service Step by Step Guide for Core Developers (REST 1.x)
More like this
Adding a Web Service Step by Step Guide for Module Developers
Adding a Web Service Step by Step Guide for Module Developers
Read with this