Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Subresourcves code block reflects code in documentation, added "/openmrs" to the Resources with Subtypes code block

...

There are some objects that are not defined or do not make sense apart from their parent object. These we refer to as subresources. Examples are PersonNames, PersonAddresses, ConceptNames, etc. You can act on subresources under the parent url.
Examples:

Code Block
titleAdding Editing a person's name
POST /openmrs/ws/rest/v1/person/uuidofperson:target_person_uuid/name
Body content:
{{
	"givenName": "John",
	"familyName": "Smith"}
Code Block
titleEditing a person's name
POST /ws/rest/v1/person/uuidofperson/name/uuidofname
Body content:
{"givenName":
"Johnny"}

A subresource can have only one parent. If it seems like an object has two or more parents, then it is most likely a top-level resource. E.g. "encounters" should not be a subresource of "patient" and "location" (answering questions of both "all encounters of a patient" and "all encounters at a location"). Instead, these should be queries on the encounter resource: /ws/rest/v1/encounter?patient=349234-2349234 and /ws/rest/v1/encounter?location=3423482-34923-23

...

Some resources can have multiple subtypes, for example the order resource contains drugorder and testorder subtypes. When creating a resource that has subtypes via a POST, you must specify which subtype of the resource you are creating, with a special t property of the object. For example:

Code Block
POST /openmrs/ws/rest/v1/order
Body content:
{"t": "testorder", /*... and other properties */}

...

If you are looking for some sample REST calls, please see Sample REST calls. You can also explore controller tests to see which requests are possible: https://github.com/openmrs/openmrs-module-webservices.rest/search?q=Controller+test&type=Code

...