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 6 Current »

In OpenMRS , Order can  be of three type : Order , DrugOrder and TestOrder. Order is parent class while other two are child classes of Order. 

If a module wants to provide resources to handle Drug and Test Orders using OpenMRS API. There can be two possible ways:

1. /api/order/drugorder and /api/order/testorder

2. /api/order?type=drugorder  and /api/order?type=testorder

 

In first case, each class will implement its own @Resource class for it. By implementing this method, a lot of the code is replicated as there is one parent who has most of the properties already. And changing in parent class ,we have to make changes to all the @Resource classes also. This would easier become complex after awhile.

 

In Second case, OpenMRS REST API provides a functionality for this using a single @Resource class for the parent and managing its child/other types using @SubClassHandler. Like in Order and DrugOrder case, this reduces a lot of work and complexity.


Sub Class Handler provides you the facility to add different child classes of single resource while handling all the complex work behind. You only need to provide annotation @SubClassHandler. For example, Order class has two child classes DrugOrder and TestOrder, but there is only one single  @Resource  class of OrderResource. The child classes have their @subclasshandler classes instead of separate resource.

In Order model, Rest Module has only used single @Resource for parent only. In  @Resource class , developer has to only implement hasTypesDefined()  to tell OpenMRS REST API that this has child classes too.

OrderResource
/**
 * Resource for {@link Order} and all of its subclasses
 */
@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "1.8.*",
        "1.9.*" }, order = 1)
public class OrderResource1_8 extends DataDelegatingCrudResource<Order> {


public boolean hasTypesDefined() {
    return true;
}

}


The Child classes of Order have annotated @SubClassHandler , extends BaseDelegatingSubclassHandler<parent, child> and implements DelegatingSubclassHandler<parent,child> .

DrugOrderSubclassHandler
@SubClassHandler(supportedClass = DrugOrder.class, supportedOpenmrsVersions = { "1.8.*", "1.9.*" })
public class DrugOrderSubclassHandler1_8 extends BaseDelegatingSubclassHandler<Order, DrugOrder> implements DelegatingSubclassHandler<Order, DrugOrder> {
	
	public DrugOrderSubclassHandler1_8() {
		//RESTWS-439
		//Order subclass fields
		allowedMissingProperties.add("dose");
		allowedMissingProperties.add("units");
		allowedMissingProperties.add("frequency");
		allowedMissingProperties.add("prn");
		allowedMissingProperties.add("complex");
		allowedMissingProperties.add("quantity");
		allowedMissingProperties.add("drug");
	}

}


This has resolved all the type and heritage issues and rest module take controls of all the rest.

  • No labels