How to use REST module to post/add an order?


(Joey Ponce) #1

Application Name: Platform 1.9.8

Question: Hello, I wanted to ask how to use the rest module to add an order in the simple lab entry module. i keep getting the

"ERROR - BaseRestController.handleException(106) |2016-02-20 09:42:29,271| When creating a resource that supports subclasses, you must indicate the particular subclass with a type property"

error in the system log and i can only assume that the “body content” is wrong in some way. Whether it’s the format or the lack of information. I was hoping to see an example of the rest module being used to post an order. Thank you very much


Creating a RadiologyOrder via REST
(Darius Jazayeri) #2

I have updated our REST API documentation and added a section about “Resources with Subtypes” to describe this.

In this case you need to add a t property to indicate what type of order you are creating (under the hood, what Java subclass will represent the order). So for a lab test you need to include a property like:

"t": "testorder"

(Joey Ponce) #3

Thank you for the reply. But I’m still unclear as to exactly where in the body content to insert it. and what the ‘test order’ value should be. is it text? or a uuid? is it the ordertype/drug order? Where in this sample post would that be added? and does it need [ ] like when posting a patient with diff names?

Type: POST
Uri: /openmrs198/ws/rest/v1/order

Body Content:
{
 "patient":"46003548-1ffd-4903-95cb-7c9c6056ae00", //UUID of the person (also a patient)
 "ordertype":"f7052b1d-639b-4053-8282-a006a06c3b1d", //UUID of the ordertype (value is 'radiology')
 "concept":"161478AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" //UUID of a concept from the dictionary (value is 'Anti-streptolysin O test')
}

Representation: full

In the ‘Add Order Module’, those are the three values that are required to post. So I’m keeping the post as minimal as needed until i succesfully make a post to add an order. Thank you


(Darius Jazayeri) #4

Add a "t":"testorder" property to your post body, exactly like I typed it in my message and see if that works…


(Joey Ponce) #5

Oh ok. I’ll try it once I get back in the office on Monday since I don’t have openmrs installed on my home pc. Thank you and I’ll update once I’ve tried it


(Joey Ponce) #6

Hello, I tried adding it and it still didn’t work

{
 "patient":"46003548-1ffd-4903-95cb-7c9c6056ae00", 
 "ordertype":"f7052b1d-639b-4053-8282-a006a06c3b1d", 
 "t":"testorder", 
 "concept":"161478AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
}

This is the system log:

WARN - ExtensionPointTag.doStartTag(136) |2016-02-22 09:21:32,811| Extensions at this point (org.openmrs.gutter.tools) are required to be of class org.openmrs.module.web.extension.LinkExt or a subclass. class org.openmrs.module.simplelabentry.extension.html.LabGutterItem is not.
ERROR - BaseRestController.handleException(106) |2016-02-22 09:21:44,740| When creating a resource that supports subclasses, you must indicate the particular subclass with a type property

(Darius Jazayeri) #7

@joy

Sorry for the long delay on this. I finally got a chance to test this out, and I was wrong: the property should have been “type”, not “t”. (I don’t know why we use different properties for when you’re doing a query (t) vs posting to create something (“type”).)

A full working example, tested against devtest02.openmrs.org, is:

{
    "type": "testorder",
    "patient": "1681f4b7-7f4d-4227-9562-718ee347bbd8",
    "concept": "840AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "encounter": "8a32e7cb-0bbb-4c4e-8ed4-fc982443859f", // orders must have an encounter
    "orderer": "9e28cb36-0df4-4972-b375-4a5ff88e39d9", // from the provider resource
    "careSetting": "c365e560-c3ec-11e3-9c1a-0800200c9a66" // from the caresetting resource
} 

See the response at:


(Darius Jazayeri) #8

Just after posting this, I realize that you’re asking about OpenMRS Platform 1.9.x. My example above uses the completely new order entry API introduced in Platform 1.10.

Even in earlier versions of the API, “type” is the property that you need to specify to get around the error you’re seeing.

Peeking at the REST web services module code, I see that “testorder” is not supported until Platform 1.10, even though test orders were added in 1.9.2 as part of TRUNK-3749.

So if you want to be able to do what you’re talking about here against the Platform 1.9.8 REST API, you will need to add support for this to the REST web services module, by adding an equivalent of org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10.TestOrderSubclassHandler1_10 for 1.9.


(Tim Nguyen) #9

Hi darius, i am a newbie to OpenMRS and would need some help with using the Rest services. Where can I review the values for Caresetting? I did not see it in the admin screens.

Thanks, Tim


(Darius Jazayeri) #10

@missilen

Have you looked at http://demo.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm (and then look at the caresetting resource)?

Also, read about the Order Entry API at https://wiki.openmrs.org/x/JoA5B


(Tim Nguyen) #11

thanks. Found it.


(Joey Ponce) #12

@darius wow I completely forgot about this… This project got put on hold and I was made to do something else. Once I’m made to continue it I’ll try this. thanks for the reply and sorry for not responding.


(Emmanuel Nyachoke) #13

Hi @darius I need to post a custom ordertype say procedureorder as part of an encounter payload

{
"type": "procedureorder",
"patient": "1681f4b7-7f4d-4227-9562-718ee347bbd8",
"concept": "840AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"encounter": "8a32e7cb-0bbb-4c4e-8ed4-fc982443859f", // orders must have an encounter
"orderer": "9e28cb36-0df4-4972-b375-4a5ff88e39d9", // from the provider resource
"careSetting": "c365e560-c3ec-11e3-9c1a-0800200c9a66" // from the caresetting resource

}

How can I go about this.