Adding new table and use them with OWA module via REST

Hello, I am developing a new OWA module that will manage equipment and maintenance for example and for this module, we will need to add some new table inside the OpenMRS database. My Questions are:

  • How it is possible to add new tables to the OpenMRS database?
  • How can we communicate with those table from the OWA module using Rest API?
  • How can we customise the Rest API in the way to communicate with the database?

Thank you in advance.

1 Like

yes @anatoleabe its possible, can this help

1 Like

i think this is all about generating the endpoints that you need which will issue api calls to communicate tot the database for the needed info

Thank you @gcliff for your response. Does this mean that I need to create a new OpenMRS module and configure my tables inside as it is described here?

Can you explain more this part please? Where and how to generate the endpoints. Do I need to do this in my new created module?

not really , you can have at the details here Open Web Apps Module - Documentation - OpenMRS Wiki

you dont need to create new endpoits if theya re availbale already

you can look OpenMRS Docs & REST Web Services API For Clients - Documentation - OpenMRS Wiki to see if the available end pints cover what your needs

Thanks

@gcliff, what to do in case it doesn’t cover my needs? In my case, I have some new tables and wanted to expose them via Rest API and use those endpoints from my OWA module.

@anatoleabe the data that those tables are holding must have classes from which we can generate respective resource classes in rest api with their setters, getters and the representation forexample the patient tables in openmrs database has the patient class and the corresponding rest endpoint

@anatoleabe If you want to create your own tables and expose them through REST, there are quite a few steps. You are going to need a normal OpenMRS backend module in addition to the OWA.

The steps for adding a REST webservice in your module are to be found here. We generally add database tables using the module-specific liquibase file. You can then provide Hibernate mappings for your tables using either Hibernate mapping files or Hibernate or JPA annotations. I’d recommend using the annotations vs the XML file to configure the Hibernate mappings.

Generally, in addition to the database tables and the Hibernate mappings, you’ll have some OpenMRS services which encompass whatever business logic you need and the REST API generally talks to those services rather than directly to the database or to the DAO objects.

Thank you @ibacher for your answer. If I understand correctly, inside my newly created module, I add a controller and expose it as explained here, in order to have an endpoint available for use in my OWA module?

Yes, that’s the basic idea.

Thank you very much, that seems more feasible. Could you recommend an example of a module that has been developed using this approach?

The OpenConceptLab module is probably the best example:

1 Like

@ibacher, when having many tables, the liquibase file need to be edited manually of is there a way to do it automatically? Same question for entities creation using JPA annotations.

There are tools that can create a database schema from a JPA annotated entity class and a tool to generate a liquibase changelog from an existing table; there are probably also tools to create a JPA annotated entity from an existing table, but you’re going to need to create at least one of them. I don’t really do that so I don’t have any recommendations.