Order Group using Rest API

How do I create Order Group using rest API. Is there any rest resource for this.

Thanks.

@jaks80

We have a rest api documentation https://modules-refapp.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm#!/

Hi Eunice, This one is for single order. I want to save orders in a group.

@wyclif

Please advise on this one.

1 Like

The short answer is that currently the rest API has no support for order groups and sets.

The long answer is, order groups and sets were initially implemented in a module and I don’t think it had a rest API, they were moved to core in version 1.12 and no changes were made in the webservices.rest module to support them. @mseaton am I right?

@jaks80 do you mind creating a ticket to have them exposed via rest?

It seems like we have no REST resource for this. Yusuf, can you create a ticket for this at issues.openmrs.org in the RESTWS project? Are you in a position to have a Java developer work on this?

Hi, Wyclif @wyclif @darius
I have created an issue here.

Hi Darius I don’t have any developer at the moment (Except myself) to engage with Open MRS. I can start working on this with little bit of initial instructions.

@jaks80, where are you based (i.e. what time zone)? Depending, you might be in the best position to get an intro by pinging people on the IRC channel. (@dkayiwa is in Kampala, @wyclif is in Indianapolis, though there are others who can give an intro too)

I moved that ticket to the RESTWS project in JIRA, since it has to do with the https://github.com/openmrs/openmrs-module-webservices.rest module. The code in that module is a bit complex because there are a lot of abstract base classes that take a long time to learn about. But in terms of getting started, you would basically want to copy one of the existing resources, like for example the order resource (but you’d want to copy it into the 1.12 folder).

Here is a Step By Step tutorial for adding a REST resource: https://wiki.openmrs.org/x/NYQHAQ (it was last touched in 2013, but I assume it’s still accurate).

Hi Darius,

I am Based in London. I will start reading wiki and working with order resource. I will also visit IRC chanel to get @dkayiwa and @wyclif.

Thank you.

Hello, I was trying to get someone on IRC several times. Everyone seems very busy. Would you please explain what does this method do in resource classes(Encounter resource):

@PropertySetter("orders")
public static void setOrders(OrderGroup instance, List<Order> orders) {
    instance.setOrders(orders);
}


@PropertySetter("obs")
public static void setObs(Encounter instance, Set<Obs> obs) {
	for (Obs o : obs)
		instance.addObs(o);
}

On a side note, did you get a chance to look at this? https://wiki.openmrs.org/display/IRC/OpenMRS+Chat+Tips

Those methods are called by the rest framework’s conversion logic to set those fields on an Encounter instance rather it defaulting to calling their setters on the class. In theory, you should add such methods to a resource if you wish to do some custom stuff when setting a field’s value or if a property has no conventional setter.

Hi Daniel I did have a look at it. Link was in IRC page.

Hi Wyclif Thanks for the explanation. Also:

In this method getCREATEModel(Representation rep)

.property(“encounter”, new StringProperty()) .property(“encounter”, new StringProperty().example(“uuid”))

What are the difference between above lines.

In order to Place a new Group Order,

  1. Should Encounter be a new One, just for this group Order.
  2. If we are using a new Encounter, JSON will be
{
	"patient": "ed44ef93-8712-426d-8c73-5ce4aa83c0df",
	"encounter": {
		"encounterDatetime": "2017-10-12T13:58:20.212+0100",
		"encounterType": "f155ddc1-3efc-4d03-a21d-bc751e1734a7",
		"patient": "ed44ef93-8712-426d-8c73-5ce4aa83c0df",
		"visit": "fe50e3a2-d0bd-4a15-852b-f954c51b2f2a",
		"location": "2131aff8-2e2a-480a-b7ab-4ac53250262b"
	},
	"orders": [{
			"type": "drugorder",
			"patient": "ed44ef93-8712-426d-8c73-5ce4aa83c0df",
			"careSetting": "6f0c9a92-6f24-11e3-af88-005056821db0",
			"orderer": "f9badd80-ab76-11e2-9e96-0800200c9a66",
			"drug": "1774AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
			"dosingType": "org.openmrs.SimpleDosingInstructions",
			"dose": 1.0,
			"doseUnits": "1513AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
			"duration": 2,
			"durationUnits": "1073AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
			"frequency": "c288cb0d-6030-4d17-a11d-1c9d2e421c4f",
			"route": "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
			"dispenseAsWritten": true
		}
	]
}

In this case, each order inside Group does not have encounter initialized. How this method is going to handle this situation: public OrderGroup save(OrderGroup delegate) { return Context.getOrderService().saveOrderGroup(delegate); }

I have tries this json and getting “Column ‘encounter_id’ cannot be null” exception which make sense. Do I have to save new encounter first within save(OrderGroup delegate) nethid and then initialize encounter in orders and save orderGroup?

What is the procedure to update Core API. I had to add bellow method in HibernateOrderDAO.java

public List getOrderGroup(Patient patient, Encounter encounter) {}

And order.setOrderGroup(orderGroup); line was missing so order table did not have order_group_id foreign key in db.

public OrderGroup saveOrderGroup(OrderGroup orderGroup) throws APIException {
		if (orderGroup.getId() == null) {
			dao.saveOrderGroup(orderGroup);
		}
		List<Order> orders = orderGroup.getOrders();
		for (Order order : orders) {
                    
                    order.setOrderGroup(orderGroup);// This was missing
			if (order.getId() == null) {
				saveOrder(order, null);
			}
		}
		return orderGroup;
	}

I have placed updated jar in \Tomcat 9.0\webapps\openmrs\WEB-INF\lib folder but application was not deployed.

I have created couple of new issues for openmrs-core,

Hi @jaks80, sorry for the late response, I’ve been out of office for the past couple of days. [quote=“jaks80, post:15, topic:13466”] In this method getCREATEModel(Representation rep)

.property(“encounter”, new StringProperty()).property(“encounter”, new StringProperty().example(“uuid”))

What are the difference between above lines. [/quote]

I believe the first one just adds a property and the other adds a property along with an example for the reader of the generated swagger docs.

I believe the encounter should be the same as that of the individual orders and it should be an existing encounter, @darius can you confirm please?

I commented on the tickets you created.

Hi @jaks80, sorry for the late response, I’ve been out of office for the past couple of days. [quote=“jaks80, post:15, topic:13466”] In this method getCREATEModel(Representation rep)

.property(“encounter”, new StringProperty()).property(“encounter”, new StringProperty().example(“uuid”))

What are the difference between above lines. [/quote]

I believe the first one just adds a property and the other adds a property along with an example for the reader of the generated swagger docs.

I believe the encounter should be the same as that of the individual orders and it should be an existing encounter.

For the issue where Encounter for the Order Group Should be a new one or not:

Bellow is a scenario of outpatient for a single visit:

  1. Patient starts visit -> New Encounter Created “Check In”
  2. Some one is taking Vitals -> New Encounter Created “Vitals”
  3. Doctor Diagnose/ Write Clinical Notes -> New Encounter Created “Visit Note”
  4. Doctor is Doing Test Order -> New Encounter Created “Test Order”
  5. Doctor is Providing Durg Order -> Encounter is Created “Drug Order”
  6. Visit Ends. -> Encounter is Created “Check Out”

If flow of event is like above and if its correct then Encounter for “Order Group” suppose to be a new One.

The Other issue was

Get List of OrderGroups by patient or encounter is missing in openmrs-core.

2 Use case scenario that I can think of is (I might be wrong if I have wrong understanding and purpose of Order Group): Using a group of drug order as a prescription. Every time Doctor provides a prescription, he basically generates an order group. Printing a prescription is basically printing this order group (with active orders in the group).

Use case 1: Now when doctor loads this patients prescriptions (order groups) it will show list of order groups in prescription area. In order to load this list, we need to pass patient.

Use case 2: On the other hand when we load all the encounters for a particular visit it should load this Order Group in encounter list. Now if Doctor wants to see the details of this “Order Group Encounter” we have to find it by patient and encounter or only encounter.

There were some more comments regarding this was in Jeera Issue: