Error Saving a Drug Order with Non Coded Drug.

I am posting the following drug order payload using REST. The drug is non coded which means the drug is null makes the associated concept null as well.

[POST]  /ws/rest/v1/encounter
	"patient": "4389389b-8366-42fe-b38f-4d995cdf4b5a",
	"encounterType": "e22e39fd-7db2-45e7-80f1-60fa0d5a4378",
	"visit": null,
	"location": null,
	"encounterProviders": [{
		"provider": "f9badd80-ab76-11e2-9e96-0800200c9a66",
		"encounterRole": "240b26f9-dd88-4172-823d-4a8bfeb7841f"
	"orders": [{
		"action": "NEW",
		"type": "drugorder",
		"careSetting": "6f0c9a92-6f24-11e3-af88-005056821db0",
		"orderer": "f9badd80-ab76-11e2-9e96-0800200c9a66",
		"commentToFulfiller": "",
		"dosingType": "org.openmrs.FreeTextDosingInstructions",
		"numRefills": 0,
		"quantity": 0,
		"quantityUnits": null,
		"previousOrder": null,
		"dose": null,
		"doseUnits": null,
		"frequency": null,
		"asNeeded": false,
		"asNeededCondition": null,
		"route": null,
		"duration": null,
		"durationUnits": null,
		"dosingInstructions": "Take as much as you like",
		"autoExpireDate": null,
		"drugNonCoded": "This is not coded drug"

Unfortunately this is not valid as far as the API is concerned throwing the following error.

{ “error”: { “message”: “[‘DrugOrder(nullnull of this is not coded from null to null)’ failed to validate with reason: concept: Cannot be empty or null, quantityUnits: Quantity units is required when quantity is specified]”, “code”: “org.openmrs.validator.ValidateUtil:78”, “detail”: "org.openmrs.api.ValidationException: ‘DrugOrder(nullnull of this is not coded from null to null)’ failed to validate with reason: concept: Cannot be empty or null, quantityUnits: Quantity units is required when quantity is specified\n\tat org.openmrs.validator.ValidateUtil.validate(\n\tat org.openmrs.aop.RequiredDataAdvice.before(

The underlying drug_order table has been changed to allow non coded drug orders (see here). But this section of DrugOrderValidator still requires the drug and concept to be specified.

One way to make this work is to use a place holder drug which can be linked to concept non coded, but is this how it is supposed to work? I guess what I am asking is, is there a need to update the validator to take into account the non coded drug or is the current behavior intended by design?


@wyclif & @burke I have to call you guys here because you have a lot to do with the new order entry API.

I believe concept is required regardless, for drug orders you don’t have to set it since it can be inferred from the drug. To create a drug order with a non coded drug you would still need to set the concept but the only allowed concept in this case would be the ‘drug other’ concept which is defined by the drugOrder.drugOther global property, it takes a uuid as the value.

We can simplify this for clients by auto setting the concept to the value of the drugOrder.drugOther GP if non coded drug is specified and drug and concepts are not, this would need to be done in core but core release take time to come by, in the meantime the rest API can provide it.

Thanks Wyclif, nevertheless if you simply set the concept without the drug, I think the validator will still throw the same error because it checks for order.getDrug() == null first, which will be true when the drug is not set. That aside when you say the “rest API can provide this”, do you mean we need to modify the module or is it already done?


You’re right, that was supposed to be changed as part of TRUNK-4761, do you mind creating a ticket to fix it?

This if clause is the problem, it should check if concept is null instead otherwise it won’t let you create an drug order without a drug.

Done -->

Thanks @willa!

After looking closely, the code in DrugValidator just fine, it actually allows you create a drug order with no drug as long you specify the concept, so the solution to your problem is to set concept to the one that matches the drug other GP value.

We can close TRUNK-5233 or change the summary and description to say that the API should auto set the concept field for a drug order if none coded drug and the drug other GP are set while drug and concept are null. But I said earlier it might be nice to do this in the rest module too before a new version of core with the fix is out.

yeah I just saw that. I will change the summary and the description then. I decided to cancel the issue. I think a new issue addressing the requirement you suggested is more appropriate.