How OpenMRS Rest define/resolve Inheritance (child class ) @Resource and how is it restify ?

Hi All,

Currently, I am restifying on Facility data module. The main issue , currently facing is in
facilitydataQuestiontype . The FacilityDataQuestionType(Parent) is an abstract and entity class and it has four child classes. Codedfacilitydataquestiontype, numericFacilityDataQuestionType etc.

I have created @Resource of FacilityDataQuestionType but i am unable to implement fully newDelegate method as i dont know the actually implementation class for the delegation , as each child class has different attributes defined. so i found two solutions but somehow they are more tricky in my scenario.

  1. Define each child class as its @Resource
  2. Use @SubClassHandler

For 1 option , the issue comes where a different class has FacilityDataQuestionType(Parent) property and how it will know which implementation to call?. how its @resource class know to save/show which implementation of FacilityDataQuestionType and how should i define which child to save or show? As Parent class won’t define the actual attributes.

For second option, i tried to implement the @subclassHandler, as i have seen in Order(Parent) and DrugOrder(Child) but the main difference is that there Order isnot an abstract class and i have parent class as an abstract class. I am still confused about how @SubClassHandler do work . How i can implement this in my case?

Thanks, Muhammad Ahmed

@mseaton

Do u have any idea about this?

Do you mean that as per your findings for @SubClassHandler to work the parent class must have a resource implemented (which is not possible in your case since the parent class is abstract)?

@mksd

yes, this is not possible in my case but what if i turn this class into concrete class like in order , drugorder. For testing purpose , i have made FacilityDataQuestionType as an concrete class and implemented an single sub class using @SubClassHander . But it is not working and i am unable to find solution and main reason why it is not working. Is there any better way of doing this or any documentation of implementing subclass handler and how it works ? This would be a lot of help.

And what is that you experience that is not working?

although , all functions of @resource are working but when where i call or use type parameter in the get query it return json array of lenght 0 . It shows no data and no @SubClassHander function is called.

I would suggest to start from a simplified case based on the parent child Order/DrugOrder example (since that’s the only example around that is available.)

Could you setup something including unit tests for a simple working case, verifying that you can get a resource for the class and the subclass by UUID for example? Either through your own module or on a fork of REST WS.

And from there, I would try to complexify things step by step to see how far one can go.

Thank you @mksd for your adivce and help. My issue got resolved, In @Resource Class ,newdelegate method returns ResourceDoesNotSupportOperationExceptio , as parent class is abstract. Now Client has to define type into json to save it.

another thing i realised that For @SubClassHandler to work properly, the @Resource class has to implement hasTypesDefined() method and return true into it. By this API would know that the @Resource has SubClasses also.

I also have written documentation for this. Your review is would be alot of help in this documentation. Document is here

And where is the code that processes that type included in the posted JSON? Can you show an example (hopefully in a unit test)?

@mksd ,

actually this thing is handle by @SubClassHandler , i haven’t checked how. But sure i will write an test case that it is working just like it.