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);
Â
    Â
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 |
---|---|---|
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: |
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 |
---|---|---|
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 |
Â
Â