Developing Pluggable Modules with AuShadha Open Source EMR – Part 2

Creating a fresh application

For the purpose of this we will create a demographics application with data collection as done is USA.

The end result is available at

After activating the virtual environment run

$ python startapp aushadha_demographics_us --template AuShadha/app_template

This will generate the application scaffold and populate it with basic import stubs. The folder structure will be as described in the PART 1.

1. Creating the model, views and

The models will be derived based on the US Demographics requirements here:  Demographics

The model class inherits from AuShadhaBaseModel and the model form class will inherit from AuShadhaBaseModelForm class, which gives them some useful methods which they inherit.

Additionally, the AuShadhaModelForm class generates Dijits for display. The Dijits have to be configured in the file which is a python dictionary. This is will give the necessary Dijit declarative directives for generating the form widgets.

Once the models are done, the views and have nothing AuShadha specific about them. Basically we need views to add, edit, delete, view, json export the objects. The same can be represented in the

2. Determining the registration of roles

The  file registers the role of a particular class in the application. Roles are purely arbitrarily made up by the developer. However, if he needs to register a class for a particualr role that has already been registered, he will need to use the same name so as to override the preexisting class.

For eg> a PatientRegistration model may do the role of Patient Registration in the application. Hence this can be registered for that role. AuShadhaUI class generates an instance per server run and this registers the classes for a particular role on startup.

Registration can be accomplished inside as

UI.register(<class_name>, <role_name_as_string> )

3. Finalise the UI layout with PyYAML

Earlier in AuShadha developement, Django Template with HTML, CSS, and JS was used to generate the layout. This sometimes requires extensive Dijit declarative HTML markup that was not easy on the eye. Additionally interspersed JS and CSS didnt help.

Hence a method of returning the UI layout as a JSON was devised using PyYAML library. On JSON return, this is parsed and the UI dynamically generated using Javascript. This has dramatically reduced the JS files required.

The required PyYAML file is located in the dijit_widgets directory. The pane.yaml  and  creates the necessary JSON

PyYAML directives are almost the same as Dijit declarative HTML markup except for the quotations and angled bracket distractions. I will devout an entire tutorial on this and how the JS file parses this. This is very early in AuShadha development so the markup, directive may change, but the principle is the same.

4. Study need for additional JS files

The add-on modules will have a media directory with sub-directories of js, styles, images  to house modules of JS, CSS and images. Dojo has the new AMD loader that encourages modular design and the dojoConfig variable can be changed at runtime allowing full flexibility to add modules as needed. This is demonstrated by the grids in the application (Contact, Phone and Guardian grid). The relevent module that should be called by the loader is specified in the pane.yaml under the grid directives as gridStrModule.

5. Integerate or install the application

The application itself needs to be added to the INSTALLED_APPS. Integrating the application (or installing ) requires changes in the to set the paths for templates, scripts, styles and media.  The Root needs to include the application as well. After the settings are done run syncdb to install the changes.

In case of Stock modules that clash with add-on modules, the stock modules will have to be removed, changes made to and to reflect this. This has to be done before syncdb is done.

The fully developed application for US demographics collection is at

Part 3 will deal with PyYAML and auto building the Dijit UI Widgets with PyYAML and Dojo


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s