Getting exceptions with MrrtReportTemplateResource

Hi all

I implemented a rest resources using as my reference. But i had to change one thing. is a subclass of BaseOpenmrsData so its REST resource extended DataDelegatingCrudResource but since is a subclass of BaseOpenmrsObject, its rest resource could not extend DataDelegatingCrudResource so i went with DelegatingCrudResource. After finishing the resource, i tried to make a get call with this url, http://localhost:8080/openmrs/ws/rest/v1/mrrtreporttemplate/3180db84-b023-4412-b3a2-498a45e0c311. I get the following exceptions It says getMrrtReportTemplateByUniqueUuid() returns null but inside my unit tests it passes fine. What am i doing, wrong. Any help will be much appreciated. :slight_smile:

cc @teleivo

@ivange94 did you choose to make it a BaseOpenmrsData and not a BaseOpenmrsData? Because I would make it a BaseOpenmrsData so we get the benefit of having creator/dateCreated,… filled out for us. So I suggest you make it BaseOpenmrsData and then it should just be the same as the RadiologyOrderResource

@ivange94 and I just tried Autowiring the RadiologyOrderService in the RadiologyOrderResource which didnt work and threw an exception when deployed. So get your Service via the Context.getService(). See RadiologyOrderResource.

@ivange94 is RadiologyOrder a subclass of Order in core? If it is, then the resource for it should be implemented as subclass handler

I saw that. But i thought it only works with Services in core? RadiologyOrder is a subclass of Order which has a service registered in core. So i assumed thats why it worked for RadiologyOrder. But MrrtReportTemplate has no superclass in core. Will that also work for it too?

Can you please make your class extend BaseOpenmrsData

Since RadiologyOrder is a subclass of Order, it must be implemented as SubclassHandler, see TestSubclassHandler for an example

1 Like

Thanks for this hint @wyclif but this is another topic (which I will open later). This is topic is about MrrtReportTemplate which in my opinion should be BaseOpenmrsData and its REST resource can be implemented as RadiologyOrderResource is currently implemented and it sure will work fine :slight_smile:

Hi @teleivo

Whem i was extending BaseOpenmrsObject, i had to add “uuid” inside my hibernate mapping and also in my liquibase changeset. Now i have to extend BaseOpenmrsData and it has seven fields but you only added 4 in RadiologyStudy.hbm.xml . So am i doing the same or is that only for RadiologyStudy?

I didnt add the void fields in RadiologyStudy because currently you cannot void a RadiologyStudy.

I suggest you do the same because currently you dont support voiding either, but later when you support it you’ll add those fields too.

It’s nice to name things following conventions, this can be helpful to other devs looking through your code, i.e if you have a domain object named MrrtReportTemplate, it’s REST resource should be named MrrtReportTemplateResource and not RadiologyOrderResource, this will save you also from obscure bugs like I saw someone run into with a service method like saveStudy(RadiologyStudy) instead of saveRadiologyStudy(RadiologyStudy) where the save handler couldn’t work.

By the way, right now I’m confused by what issue you’re trying to solve

Hi @teleivo

REST seems to be working now for MrrtReportTemplate. I no longer get exceptions thrown after i extended BaseOpenmrsData. But i don’t get the output i was expecting(don’t know if thats how its suppose to be). i entered this url http://localhost:8080/openmrs/ws/rest/v1/mrrtreporttemplate/d0212687-c96a-4f2b-b842-016c6292b292 and i had the following output I was expecting to see the properties of MrrtReportTemplate but i don’t.

And yes, the uuid is for a valid template in the database. When i enter an invalid uuid, i get ObjectNotFoundException

@wyclif you got it wrong. MrrtReportTemplate and RadiologyOrder are different objects which each have their resource named MrrtReportTemplateResource and RadiologyOrderResource respectively.

Hi @teleivo, @wyclif

I finally got it to work.

@ivange94 I just built and ran your changes. I imported some templates from radreport.

I was also able to get the resource via REST GET uuid. The only issue is with the REPRESENTATION “full”. This one doesnt work. Do you have time to talk on IRC?

Hi @teleivo

I actually fixed that last night. But internet connections here have been unstable due to some accident with some fiber optics. So i have not pushed my changes yet. Even replying to talk posts is taking a lot of time. Here is a screenshot of rest working,

great can you please push! and come on IRC

am on irc now. And also, i’ve updated my pull request with the fix :slight_smile: