Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 50 Next »

You can access the patient resource via the following URL:

http://localhost:8086/openmrs/ws/rest/v1/patient
http://<your domain ip: port>/{APP-NAME}/ws/rest/v1/patient

The patient resource has its own unique representation. The following properties are found in the patient resource representation. You can find more information about available properties at REST Web Service Resources in OpenMRS 1.8.

Property
Name

Value

Description

person
required 

object

Person object which is associated with this patient

identifiers
required

list of objects

List of unique patient identifiers

Identifiers can be expanded to:

Property 
Name

Member
Name

Value

Description

identifiers

identifier 
required

string

Unique ID

 

identifierType
required

object

Type of ID

 

location
required

string

 

 

preferred
optional

boolean

Person must have at least one preferred ID

Create patient

In order to create a patient you need to have an existing person or create one first with the following command:

POST /openmrs/ws/rest/v1/person
HEADER: Content-Type: application/json
BODY: {"gender": "M", "names": [{"givenName":"Joe", "familyName":"Smith"}]}
RESPONSE: a newly created person, e.g. with a generated UUID: "11f40a1b-0337-4652-86fa-18d4461e38a0"

From the above table you can also see that you will need to provide identifiers. Identifiers among other properties need to specify identifier type and location. You can find out about available patient identifier types requesting:

GET /openmrs/ws/rest/v1/patientidentifiertype
RESPONSE: a list of available identifier types, e.g. with UUIDs: "8d79403a-c2cc-11de-8d13-0010c6dffd0f", "f1b2e10e-035e-11e1-943f-ea16aa1464b8"

To find out about available locations request:

GET /openmrs/ws/rest/v1/location
RESPONSE: a list of locations, e.g. with UUIDs: "8d6c993e-c2cc-11de-8d13-0010c6dffd0f"

Finally you can create a patient for the existing person with UUID "11f40a1b-0337-4652-86fa-18d4461e38a0", identifierType "8d79403a-c2cc-11de-8d13-0010c6dffd0f" and location "8d6c993e-c2cc-11de-8d13-0010c6dffd0f" with the following command:

POST /openmrs/ws/rest/v1/patient
HEADER: Content-Type: application/json
BODY: {"person": "11f40a1b-0337-4652-86fa-18d4461e38a0", "identifiers": [{"identifier":"1234", "identifierType":"8d79403a-c2cc-11de-8d13-0010c6dffd0f", "location":"8d6c993e-c2cc-11de-8d13-0010c6dffd0f", "preferred":true}]}
RESPONSE: a newly created patient

You can test the above commands using a command line tool like curl. You will need to call it as follows:

echo '{

	"identifiers": [
		{
		  "identifier":"1234", 
		  "identifierType":"8d79403a-c2cc-11de-8d13-0010c6dffd0f", 
		  "location":"8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
		  "preferred":true
		} ],
	"person":"11f40a1b-0337-4652-86fa-18d4461e38a0"

}' | curl i -u admin:test -H "Content-type: application/json" -X POST -d @ http://localhost:8086/openmrs/ws/rest/v1/patient

Update patient

The patient resource allows only for editing identifiers. You cannot change the associated person to some other person or any of person's properties. That said if you want to update the birthdate or any other property of a person you need to POST to the person resource.

  • No labels