Adding a new Resource in REST module

I’m using OpenMRS 1.11.4 and Reference Application 2.3.1 as my development environment.

I’ve used to consume REST services.

I want to add a new Resource for a newly created class ABC and perform various CRUD operations using REST.

Please guide me on how to achieve the same and consume the newly created resource on REST URL /ws/rest/v1/ABC.

Any resource in REST WS can be used as an example, as well as any new resource brought by any custom module.

This is an example of ours living outside REST WS (but that doesn’t make any difference): VisitDocumentResource1_10.

As soon as you make your resource class implement DataDelegatingCrudResource<ABC> you will be required to implement the CRUD methods:

  • save(..)
  • getByUniqueId(..)
  • delete(..)
  • purge(..)

Those methods just rely on usual Spring services to perform their inner cuisine.

@mksd I’ve already added a ABCResource1_11 under omod-1.11 as discussed by you and have mapped the resource to v1/ABC URL.

When I actually try to access the above URL from REST Web Service Test Page, I get the following error:

So RestServiceImpl creates two maps containing all the valid resources: one indexed by name (in fact by URI, so your v1/ABC) and the other indexed by underlying class name (so presumably something along the lines of ABC.class in your case).

There can be a few reasons to prevent the above code to ever be reached. Are you sure that you are running against a version of the Core/Platform that is legit for your resource? Is the same URI possibly already used somewhere else with the same order? … etc. If you can’t spot any obvious reason I would suggest to debug RestServiceImpl to understand why your resource is not retained into those maps in the end.

As a last resort you could setup a unit test provoking the exception, and push the code on a temp branch for others to replay it. Here is an example of such unit test.

Thanks for directions @mksd. Adding order parameter to @Resource annotation solved the problem.