Greetings everyone,
Over the last couple of months, we have been integrating our 2.x pages with AngularJS.
The main problem we faced at the initial stages was to find a standardized-openmrs-way of writing and organizing modules.
We came up with a simple architecture that I’d like to describe and hopefully get your input.
PS: We realize that AngularJS is not Java, but we relied heavily on its Object Oriented features to fit our needs.
We have a reusable-components folder that has the following main “packages”:
CONTROLLERS – Generic Controller: Provides an abstraction for Controllers. Implementing controllers only have to pass basic configs (like the module name, version etc) to get basic functionality.
MODELS
- Generic Object – like a basic openmrs object.
- Generic Metadata Object – extends a generic object and defines basic fields (name, description, retireReason, purge, retired). Our models extend the Generic Metadata Object with an option of defining custom fields.
SERVICES – Any generic service (e.g restful, cookies) is bundled up here.
With the abstracted functionality in place, it becomes very easy to write a new module.
Code: Re-usable components
[Examples of modules which inherit and use the abstacted code] (https://github.com/OpenHMIS/openmrs-module-openhmis.inventory/tree/develop/omod_2.x/src/main/webapp/resources/scripts)
We used requireJS to load dependencies and initialize our application.
It would be nice to hear your thoughts on our design, and if anything is not clear kindly let me know!
Thanks
-Andrew, OpenHMIS Team