Best Approach to consume custom API code in modules

I’m using OpennMRS Core 1.11.4 and Reference Application 2.3.1 (along with bundled modules) as my development environment.

Now, I’ve implemented some custom code in the platform api (few entity classes and services) and want to consume the same code in the bundled modules.

I looked into the code base and found that all the modules use openrms-api code for different OpenMRS version using maven dependency (pointing to openmrs public repository)

As a quick fix, I’ve build the platform to get openmrs-api.jar and have placed it in lib directory in various modules. I refer to the openmrs-api.jar by changing the maven dependency to point to system path of the jar.

Is the above approach any good? What should be the best approach to implement the same?

It is not recommended to add custom code to the platform api. It is better to do that in a module and then have it as a dependency in the consuming modules. An example of this is the emrapi module which is consumed as a dependency by other modules like coreapps.

I totally get that @dkayiwa.

Considering your suggestion, I’ve some special cases to tackle: What if I need to add a service method to existing api code and consume it in other module?

Also, how can I use custom code from module A in module B. For instance, I need to use code changes from appointmentscheduling module in appointmentschedulingui module. How can I do this?

If you need to add new functionality, that is what module services are for? Your module can have a service to add a new functionality that you need. If you want to modify an existing platform service method, then you can use AOP as explained here:

For the second question, you just need to add a dependency for module A in module B. Here is an example of where i add an appframework (module A) dependency in the xforms module (module B)

Will look into this and get back to you with further issues if any :slight_smile:

Which appframework-api.jar will the maven dependency point to?? The jar present under .m2 directory pulled from openmrs public repository online OR The jar of recently built appframework module

In my case above, i specified the version as 2.0, it will look for it in my local .m2 directory, and it it does not find it, it will pull it from the openmrs public onlin repository and cache it locally.

That’s where I’m struggling. I do not want to use the module dependency to use the module fetched from openmrs public repository and instead use my own version of module as dependency.

Use Case: Module registrationapp is dependent on registrationcore for various api related service method invocations.

  • I’ve added some custom methods in the service classes of registrationcore module
  • Now, I want to call these custom implemented service methods from registrationapp module. I certainly cannot use the module jar coming from public repository online as that won’t have my custom code.

Just change the version of the module with your custom modifications. Ensure that your dependant module points to this version. Since this version is not yet released or uploaded to the public online module repository, it will only come from your local .m2

Thanks for the guidance @dkayiwa :smile: