Blog

Moving to Gitlab

With the acquisition of Github by Microsoft, regardless of the promises made now, I thought it would be best to move my repos somewhere else. That somewhere right now seems to be GitLab. Im #MovingtoGitLab.

All my repos across GitHub and BitBucket have been moved there and I intend to continue development there.

AuShadha (Au) which I had worked on for so long had taken a back set for some years now as pressing personal and professional commitments caused interruptions.

ICD 10 parser, ICD10 PCS parser, FDA DrugBankCa medication list parser have all been moved there.

Three variants of AuShadha are being tried by me as I recode Au. These pertain to choices of the front end. All there are embryonic and will continue to remain so until I find more time.

When I started it in 2009 things were a lot different and Django was supreme choice in Python world. Things have gone more Javascript way with a confusing profusion of frontend frameworks , especially ones that play well with NodeJs but don’t play well or needs rewiring to play well with Django. Dojo which was my intial choice also has moved on from 1.7 when I started to 1.11 now and looking ahead at 2.0 with TypeScript usage.

I’ve chosen Dojo 2.0, EmberJS, Polymer as the three front ends to try and hang my hat on at the moment. The old Au with Django 1.7 and Dojo 1.10 would be kept but I don’t plan to update it to new the library versions as it’s too laborious.

I’ve moved Django to 2.x and Python to 3.5. This is a full rewrite. Infact if Django doesn’t play well with JS framework I am open to changing it some other backend.

To those who were wondering about Au and it’s fate -watch this space.

GitLab Repository

Advertisements
Making Media rich Medical Presentations using Emacs, Org-mode and Reveal.js – Part 1

Making Media rich Medical Presentations using Emacs, Org-mode and Reveal.js – Part 1

Scenario

As a practicing Paediatric Orthopaedic Surgeon, I am called to meeting to present my work. This involves presenting to peers, co-workers, patients and parents of children I care for. Each of these presentations will be with a different focus on a particular topic. 

While this is not an uncommon scenario, the solution to create a reusable presentation slides using #OpenSourceSoftware tailored to individual audience is. Most doctors are not familiar with programming environment  and shy away from anything that is not WYSIWYG. They rely on good old #PowerPoint / #Keynote to save them. At the most some of them may try and use the clunkly #LibreOffice or #OpenOffice if they want to stick to OpenSource. Recently with advent of tools like Prezi, media heavy interactive presentations have become popular. The popular presentation softwares of KeyNote, PowerPoint have also spruced up their animations and transitions to enable them to look more attractive. Still the WYSIWYG nature of these and point-and-click makes them very slow. We could achieve better, faster and more attractive results with using #FOSS tools. 

 

What I use now

For the past few years I’ve been using a combo of 

  1. #LaTeX via #beamer class 
  2. #RevealJS ,
  3. #Emacs, Org-Mode, org-reveal
  4. #HTML5 and #CSS3
  5. FOSS Image and Video editing softwares as required to arrange the media. I mainly use GIMP, InkScape, KdenLive, OpenShot, HandBrake to arrange my media and encode them. 

My choice depends on the demands of the presentation. 

For media heavy, especially video heavy presentations I use RevealJS. For presentations that are more of less static with few videos I tend to use Beamer / LaTeX. What I note below are my experiences as I tried to create a smooth workflow that could replace PowerPoint ( or KeyNote / LibreOffice ) as a tool to create #Medical Presentations. 

Overtime I have refined my workflow and now I find that I am far more productive and my slides can pack much more information than a power point slide. While the more advanced interactions would require some knowledge of JavaScript, and therefore would turn off most doctors, most of what follows require minimal programming use. 

I will detail my workflow to create simple fast layout using Emacs and RevealJS without handcoding of JS and HTML. We will be relying on the RevealJS, Emacs, Org-Mode and ox-reveal package to do the lifting. 

 

Disclaimer : Even though it doesn’t need programming knowledge, ability to use Emacs is a must for this workflow. It is preferable that one is on a Linux OS as the attempt is to go all #FOSS here. 

 

so, here goes ….

 

Aim

To create an visually impressive medical presentation using non Power Point open source (FOSS) softwares.

Tools

  1. Emacs (24.3 or greater)
  2. org-mode
  3. org-reveal
  4. Reveal.js
  5. Chrome Browser
  6. Open source video codecs on the system

Why this and not PowerPoint ?

Over the years Medical Conference presentations have got mature and old tools have got boring. Varied audiences, topics, media content , interactivity required, transitions and animations to keep audiences interested have all changed.

PowerPoint with it’s traditional set of tools is boring to say the least. The point and click interface is slow by comparison to plain text typing. This seems counter intuitive to PowerPoint pandits but I’ve found that once the media is arranged and readied, once can create more far more attractive presentations with the tools mentioned above. 

As far as medical presentations go, the video presentations embedded PowerPoint / LibreOffice have a habit of breaking on stage. I have seen numerous instances of this happening.

And, of course PowerPoint costs 💰💰

It is also Closed Source making it difficult to edit and reproduce when you are with a system where it is not installed.

 

Okay, but why Emacs, why indeed ?

Emacs is Open Source

Emacs is stable

Emacs is good

Emacs is better than #Vim

Emacs has un-paralleled number of extensions and programming support

Emacs has Org-mode… 

 

Okay, So why org-mode, what has that got to do with presentations ?

org-mode is cool

org-mode is simple text

org-mode can be manipulated anywhere with text-editor

Its FOSS

It can be extended with other tools like org-reveal

 

Hm, Okay, but why Reveal.js ?

An actively developed FOSS Tool with a community

Allows 2D stacking of slides permitting nesting

Plugins and all the JS/CSS/HTML5 goodies can be integrated

Very good slider-presenter notes

PDF export option for handouts

Very nice transitions and animations

Good builtin themes and literally infinite customisation options as per CSS

Works very well with slide-projectors and remote tools to advance slides

 

Okay, but why use org-mode / org-reveal with Reveal.js ?

Org-mode is cool, easy, transparent text typing

org-mode is structured and nested just like a regular presentations would be

One can easily do a text-only sketch of a presentations by typing out a few lines of text in org–mode formatting and out put a neatly animated stacked presentation in Reveal.js

If one were to code HTML and JS with Reveal.js, it would be considerably opaque, with HTML markup and JS obscuring the structural details of the presentation.

By integrating org-mode, org-reveal and reveal.js we are integrating all that is good in respective tools while sticking to what the non-programmer user ( an average medical professional ) would like to do – type text and structure the presentation.

 

So, How to go about making one ?

Part 1 : Preparing the ground

Step 1 :

Install GNU-Emacs > 24.3

 

Step 2 :

Update package-archives and use Melpa archive.

Update org-mode.

 

Step 3 :

Install ox-reveal package

 

Step 4 :

‘require(ox-reveal) in your .emacs file

 

Step 5 :

Download and keep the Reveal.js file in a folder.

Note down the path to the folder relative to the folder where the presentation will live.

If you have Bower installed you can just do bower install revealjs

 

Step 6 :

Create a folder where your presentation will live. 

Inside the folder create subfolders for Images, Videos, Scripts, CSS styles and other documents which may be needed for the presentation. 

Now we can create the main file of the presentation – the Org-mode file using Emacs.  Org-mode file is a simple text file which can be opened using any other text-editor. It has the extension of  “.org”

While using Emacs and Org-Mode, however, it provides lot of goodies. Org-Mode in Emacs has lot of extensions one can install that extends it functionality. One can for example use the same org-mode file to output HTML, LaTeX, and PDF. 

So let us create the main presentation file. I title my presentations the following way, giving it context, separated by underscores : <topic>_<audience>_<date>_<venue> . For example if I am giving a public talk on Cerebral Palsy at my home town of Palakkad, on July 30th,2019 , I would title my presentation like this : “CerebralPalsy_PublicTalk_Palakkad_30072019.org”

This allows me to keep separate org-mode files for different audience and keep using the same images, videos etc.. Therefore I am fully portable and self-contained when I have to whip up a presentation tailored to any particular audience – technical or non-technical. 

C-x C-f  in Emacs  to the file you want to create with .org extension.

C-C C-# to insert Template for a Reveal.JS presentation.

If you have ‘ox-reveal loaded it should be available as a choice.

Once chosen it will list some options at the top of the org-mode file.

We will need to provide the path to the REVEAL_ROOT directory to the place we have stored the reveal.js library. This path is relative to the folder where the file for presentation lives. 

Once these are done, It is important to get the images, videos ready. They have to be edited using FOSS tools for editing photos and videos. Once edited they’ve to be named properly so that we can reference them in our presentations. 

 

This completes the ground work required to start writing the presentation. While this may seem a lot of work, one must remember this is one time effort.

We will deal with the actual creation of  org-mode file, the options while using Reveal.JS in the next part ….

DDH –  Its June !! It’s Dysplasia Awareness Month

DDH – Its June !! It’s Dysplasia Awareness Month

DDH otherwise called Developmental Dysplasia of Hip is a condition where the ‘ball-and-socket-joint’ of the hip is not formed well at birth. It used to be called Congenital Dislocation of Hip.

The child is born with a slightly misfitting hip joint where the ball is slightly shifted out of cup or a hip joint where the ball is completely outside the cup and cup is also very shallow. This can occur on one side or both sides.

Developmental Dysplasia of Hip - Left hip is dislocated
Developmental Dysplasia of Hip – Left hip is dislocated

Why does it happen ?

Most times its ‘Idiopathic’ , a medical term which means – cause is not known. In many other patients, the child will be having one of the syndromes (a group of clinical features and disorders in other organs systems and external appearance) or neurological issues in the spine (like meningomyelocele) that also causes this. This second group is sometimes medically referred to as Teratogenic DDH and is much more difficult to treat.

We will discuss below the aspects as related to Idiopathic DDH. They don’t apply to Teratogenic or Neurological DDH.

How do we know the child has DDH ?

Most newborn screening procedures at the hospitals have doctors checking to see if the new born child has clinical signs of DDH. It is easiest to detect and treat it at that early stage.

Once a clinical suspicion of DDH is there the Neonatologist usually refers the child to a Pediatric Orthopedic Surgeon. In addition to establishing the clinical diagnosis by physical examination, the doctor will order an x-ray and an Ultrasound Scan of the Hips to check the dislocated hips. Several measurements need to be taken and ease of dislocation need to be established under Ultrasound scan by a procedure called Dynamic -Ultrasound. The treatment starts after these are done.

In many children, the initial diagnosis may not be made in the immediate post-delivery period. Children may be brought to the OPD by parents with complaints that the thigh skin fold dont look symmetrical and the hips don’t open out fully for parents to change diapers.

In older children parents may notice a limp when the child walks or a limb length difference may also be noted with the dislocated side being shorter.

Limb Length Difference in DDH
Limb Lengths may be noted to be different in DDH when child is older and walking. The limb with the dislocated hip will appear shorter.

How soon should the treatment start ?

As described in previous section, treatment should ideally start in neonatal period once the problem has been detected. After clinical examination and Ultrasound examination, your doctor will suggest usually a belt type device called Pavlik Harness to be applied on the child to keep the hip reduced inside the cup. This harness is to be worn full time. Parents are counselled on how this is applied and how the straps are tightened.

Ultrasound exam for a child with Hip and Knee dislocation
Ultrasound exam for a child with Hip and Knee dislocation

Once this harness has been applied, the hips are scanned with Ultrasound every 2 weeks to check for improvements. Ideally this has to be kept for about 3 months and taken off after the hip stabilizes inside the socket. A slow weaning period is there before the child can be fully taken off the Pavlik Harness. This is to ensure that the Ball ( head of femur ) stabilizes inside the socket (Acetabulum of Pelvis) and the hip is stable. The tissues around the hip also has to shrink and adapt to the new location of Head of Femur. Otherwise re-dislocation or partial slip (medically called subluxation) is a possibility.

In many cases the parents may not be willing for a device to be applied on the child full time post-delivery or the DDH itself may go undetected. This child eventually may be brought later in life by the parents with complaints necessitating surgical procedures.

What is the treatment options for DDH?

As previously described if the newborn is detected to have DDH the treatment is to apply Pavlik harness on the child after Ultrasound exam proves hip is reducible and stable in what is called a safe zone. Safe Zone is a zone where the position in which the harness has to be applied to the child does not compromise the blood supply the head of femur. This is very important decision to make.

Pavlik Harness for DDH hip needs to be fitted properly
Pavlik Harness for DDH hip needs to be fitted properly

Hip Spica Plaster in child with DDH
Hip Spica Plaster in child with DDH

Application of Hip Spica under anesthesia in DDH
Application of Hip Spica under anesthesia in DDH

If the child is brought later in life, before 1 year, the hip has to be checked for reducibility as the tissues around the hip would have become contracted and sometimes it is difficult to reduce the hip back into the socket. Usually anaesthesia would be required and the hip once reduced back into the socket is held there by application of the plaster of paris or POP called Hip Spica. This is kept for approximately 3 months until the hip has stabilised inside. A CT scan to verify whether the hip is reduced should be done while child is in POP as slippage of the hip socket is also seen when POP cast becomes loose with time.

Surgery is the only option in older children with DDH. These range from relatively simple procedures to complex hip reconstruction procedures depending on age of the child, slope of cup, angle of rotation of the neck of the thigh bone and shape of the head. These are best evaluated as per the needs of the child.

Arthrogram for DDH
Arthrogram for DDH

Generally these surgical procedures can be grouped into a few types :

  • Open Reduction of Hip and Capsulorraphy (medical term meaning stitching up of capsule or the covering around the joint)
    • This is basic necessity. Here the hip is reduced back into the socket and the covering, the capsule, which is loose is tightened with several sutures
  • Femur Derotation Osteotomy with shortening
    • This would involve a slight shortening of the hip bone and turning it around. The bone would then be stabilied with a metal plate and screws
    • The need for your child to have this done depends on the age of the child and the angle of the ‘neck of the femur’, something medically known as Anteversion. This procedure essentially de-rotates the femur neck and allows the head of femur (the Ball) to deeply sit inside the Acetabulum (the socket). A slight shortening of the thigh bone may be needed as the child , if old enough, would have developed tightness of the tissues and hip should be sitting inside the socket slightly loose than in tension.
  • Acetabular Osteotomy
    • In many children, when they present to the clinic their Acetabulum would be shallow and not deep enough to receive the Head of Femur. In such children deepening of the Acetabulum by a surgical procedure called Osteotomy (a type called Salter Osteotomy being the most popular) may be done.

The above procedures may be combined along with Open Reduction as the surgeon sees fit after evaulating the child. These options and its pros-and-cons would be discussed with the parents before the surgery.

What happens if we don’t treat DDH promptly ?

Best time to treat the child is in the newborn period. With time the tissues around the hip gets tighter and the bone structure of thigh bone and pelvis alters since the normal growth with moulding of the ball being inside the cup doesn’t happen.

This lack of moulding results in a shallow cup. Additionally the thigh bone’s upper end would be twisted out of shape and the ball also would be misshapen since it has not been moulded by the acetabulum.

All these result in a much more complex procedure to try and restore the hip.

Left untreated DDH causes osteoarthritis or the Hip joint and Hip pain in early adulthood often requiring complex reconstructive procedures.

It is best if the treatment is not postponed and done at the earliest.

Hip Dysplasia Awareness Month – June !!

The Hip Dysplasia Awareness Month of June is to educate parents on Hip Dysplasia and its treatment methods. We hope that parents would bring children to care centers at the earliest if suspicion of hip dysplasia is there.

For more information please visit : http://livingwithhipdysplasia.com/june/ or consult your Pediatric Orthopedic Surgeon.

World #Clubfoot Day is afoot ! – Free medical camp for children with Clubfoot

World #Clubfoot Day is afoot ! – Free medical camp for children with Clubfoot

I’m organising a free medical camp on June 4th at Palakkad Cooperative Hospital, Palakkad, Kerala on World Clubfoot Day.

Please do spread the news so that anybody interested can seek care.

Attaching below is a poster in local language Malayalam.

Interested patients may contact hospital Reception on following phone numbers for registration :

+91 491 252 0391

+91 491 252 2805

+91 491 253 6293

Clubfoot medical camp
World clubfoot day free medical camp

Osteogenesis Imperfecta

Osteogenesis Imperfecta is a congenital disorder of bones that has varied types and presentations. Severity varies based on the type of the genetic mutation that causes this disorder.

Regardless of the type the genetic modification cause malformed and weak bones and in some cases malformed teeth. Bone bend and deform or break easily and heals in deformed position. This results in cosmetic deformity along with issues with walking , standing for the child.

The bend of the bone if significant can cause repeated fractures either due to poor handling by caretakers or when child tries to bear weight and stand up.

Fortunately for the milder variants there’s are medications to make bones stronger and surgery to straighten bent bones. This allows child with help of walking aids and/or splints to ambulate.

For the very severe variants unfortunately clinical breakthrough is still awaited.

Cerebral Palsy Medical Camp at Shoranur, Kerala

Cerebral Palsy Medical Camp at Shoranur, Kerala

Cerebral Palsy is an medical disorder which requires prolonged care and proves to be a challenge of all resources both on the families and care givers. Key issues in caregiving should be discussed and simple , sustainable solutions arrived at.

AuShadha2.0

For all those who were following AuShadha Open Source EMR project hosted at GitHub there’s news. 

I had paused developing for sometime due to pressure of time. 

The development has restarted for past few months (no commits ) and am planning to branch of development into AuShadha2.0 with changes to the core, Dojo 1.12 JavaScript library, Django1.10 support and Python3.x support. 

This is a version written with lessons of what were not ideal practices in previous version. 

Watch this space. Will post more by the end of this month. 

Sanskritam at IIT

IITs has been asked to teach Samskritam … read all about it !

…..screamed our electronic media. The reaction has been mostly negative. Occasional person voicing some positive comments. Twitter has been abuzz, specifically with people and blogs quoting Deputy CM of Delhi, Mr. Manish Sisodia to the effect that whether the nex-gen JS version is really worth the upgrade over Samskritam. What better could one expect from a party whose leader is a self-confessed anarchist.

Armed with my usual salt ( a pinch is too small a dose. I take spoonfuls ) considering the state of our media I searched for the full press release of Ministry of HRD to find out what it actually said. Unfortunately there is no press release so far in public domain from Ministry of HRD on this. What was projected and decided without a debate was from her statements in Loksabha.

The most acceptable version seems to be …

Accordingly, IITs have been requested to teach Sanskrit language especially with reference to study of works which contain scientific knowledge,” Irani said

This is based on the report submitted by N. Gopalaswami, who headed a committee formed by Ministry of HRD in Nov. 2015 for promotion of Sanskritam as a language. This was set up to look into and recommend measures to integrate its  study with disciplines such as mathematics, physics, chemistry, medical science and law. It will suggest changes in Sanskrit education in schools and universities and modern ways to impart Sanskrit education.
Eventhough Ms. Smriti Irani has clarified that it would be an elective, the media is still abuzz with people commenting on this, each looking at it with their lenses.

I cannot understand…

How a language which has given birth to most of the Indian Languages we speak today in many states or influenced the rest heavily could be such a politically fought tool.
How Sanskrit the language cannot be decoupled from opression, cateism, exclusivity, hindutva, brahminism and aryan-dravidian politics. If it is because it brings back bad memories to some, why dosent the language English bring back memories of British Oppression, Elitism, Exclusivity, Divide and rule politics and Missionary work ? Why dosent Arabic/Persian raise questions about Islamic suppression and atrocities ?
You hate the oppressor, not the language that he/she speaks.

What’s in a name ?

The language is a language. The time when Sanskrit was widely used – nobody seems to know when this was – but lets assume a safe year of 1000 BC, there still seems to have other languages that drew from it and thrived. It was a pan-indic-religious languages. Lets face it.  Hinduism, Buddhism, Jainism have large volumes of works written in it. Its not this only-Brahmin heritage.
The so called Dravidian ( which itself is a Sanskrit word ) languages are all heavily drawing from Sanskrit. Being a native speaker of both Malayalam and Tamil and student of Sanskritam I can say that both these languages draw heavily from it. Its a myth that Tamil just grew alone and is untouched by Sanskrit. The poster boy of Tamil Literature, Thiruvalluvar and his Thirukkural itself has many Samskritam words in it.All the Thevarams praise the Vedic Gods and include plentiful Samskritam to convey  untranslatable concepts.
It is my regular question set to my tamilian friend when it comes to opposing anything Hindi/Samskritam:
If Thiruvalluvar himself did not want to cleanse non-Tamil words from Thirukkural, why do the tamil politicians bother to clean tamil of sanskrit/ north-indian influence ? Do the modern tamilians claim to be better tamil lovers than Thiruvalluvar ?
If tamil is really an independent language, how come tamil legends talk about Agasthiyar ( a vedic Rishi) as the one who created Tamil ?
How a vedic God Shiva become the first Tamil Sangam Leader ? 

 

Why .. Why … Why do people love to hate it ?

The answer is that Sanskritam hatred is convenient and beneficial.
Let see how many birds one can kill with one stone – just by opposing Sanskritam.
  • 1  : Hindutva lovers / Sanghis / BJP
  • 2 : Hail Dravidian Identity and Tamil nationalism
  • 3 : Project modernity and upwardly mobile culture
  • 4 : Hey, its not as if I dont get a job if i dont study it.
  • 5 : Brahmin:  you oppressor, take that

In short ..

It’s a soft target. It has ‘X’ marked on it for any passer-by’s convenience. A quick punch. The vent. The pleasure. Un matched for the number of political/philosophical schools it pleases at the same time – commies, aaptards, congis,dravidians, upwardly mobile…


So do we need to protect, revive and reinstate Samskritam ?

If India has to go back to the glory days when it attracted people from distant lands to come and learn at its Universities at Takshashila and Nalanda,  when its riches were stuff of lore told in other lands, when we were living in a different century than the rest of the planet, we need to first find out what worked for us. We need then to find out what went wrong. Then we can understand whether we can go back. If we already have it there is no need to reinvent the wheel, but to look at ourselves we need the lingua-franca of the golden ages to understand its literature.

I am not talking of searching for lost technology for building airplanes, of doing genetic works, but I am sure all those wise men who trooped to our famous universities did so for a very good reason. We’d be fools to not look into our own culture and history to get us back where we were, for that’d be the most natural step to take. We have already been there, done that. We can do it again.
Lets hope good sense dawns, once the dust settles and India can get back to where it was.

A gentle yet clear brushing off of the cobwebs of the so-called Aryan theory and all its vicious corollaries is therefore absolutely necessary, especially for the South, and a proper self-respect created by a knowledge of the past grandeur of one of the great ancestors of the Aryan race — the great Tamilians.

We stick, in spite of Western theories, to that definition of the word “Arya” which we find in our sacred books, and which includes only the multitude we now call Hindus. This Aryan race, itself a mixture of two great races, Sanskrit-speaking and Tamil-speaking, applies to all Hindus alike.

-Swami Vivekananda, Aryans and Tamilians

Would you wear a garment without a blouse?

At a politically tumultuous time when you’re not even sure what secularism, nationalism, sedition, freedom of speech in particular and freedom in general (aazaadi) is, we have here a  peice on what constitutes ….for want of better words , shall we say and in the process provoke a redefinition of the word ‘decently dressed’. Thought provoking for the impartial inquirer, revolting to the convent educated elite, too much for even the liberalism chanting neavueau-upworldly mobile, slap in the face for ultra-conservatives. All at the same time. Are we staring at the truth here – for isn’t not truth said to be unpleasant/uncomfortable ?

This piece was a reaction to seeing a room full of amazing black and white photos by Sunil Janah of women who were topless. Like the below photo of a Hill Maria Woman from Bastar.  Courtesy of the …

Source: Would you wear a garment without a blouse?

Interventional Pain management and Palliative Pain Care – a write up on Cancer Pain

Coimbatore Pain Clinic

 

Commemorative day for Cancer passed us by, mostly un-noticed amidst the din of modern self centered life. Here is an article by my dear friend and senior colleague Dr. Sekar Michael who runs a Coimbatore Pain Clinic at Coimbatore, Tamil Nadu, India and is actively involved in treating under priviliged cancer patients.

This was published in Times Of India, an Indian News Paper.

Developing Pluggable Modules with AuShadha Open Source EMR – UI building with PyYAML – Tutorial – Part 3

Building the Dijit – UI with PyYAML markup and Django Templating

Get the PyYAML file from Git Hub Repo : get it here.

This is the file that generates the Patient Pane which is brought up after searching.

This is the UI it generates:

Patient Pane
This Patient Pane’s UI widgets, layout etc is partly generated from the PyYAML

This pane.yaml file is a Django template that leverages Django’s templating features as well as PyYAML‘s object mark up to generate a rendered JSON. This JSON is then returned on AJAX call to help the UI building. JSON is parsed by the Javascript file here to help build the Dijit UI, Widgets etc…

PyYAML file

Let us examine the PyYAML file markup

Comments and Verbatim Code

At the top, {% verbatim %} Django Template tag allow the developer to put some code / comments

 Declaring Variables

Variables that can be used all over the YAML file can be declared at the top. This is where PyYAML markup scores over Django Template. Django Template restricts variable naming and prevents you from doing Python stuff inside the template.  This is ok for most templates that output HTML where the relevent code can be put inside the views.py. However, for it is also convenient if the option exists on the template. PyYAML allows us to call random python objects, declare variables that can be used through the template, use aliases in YAML file and even instantiate Python objects. Coupled with Django Template, it can be used powerfully.

# VARS

Variables can be declared with the expected type just to be sure. Aliases created can be used like Variables throughout the YAML file. Of Course we can just use {{{<some_var>}} Django template variable to do the substitution as well without creating any alias. 

VARS:
  clinic_id: &CLINIC_ID
     !!int {{clinic_id}}
  patient_id: &PATIENT_ID
     !!int {{patient_id}}
URLS:

This calls the Django reverse method and allows calling with arguments. The results is stored as the PATIENT_PANE_URL alias. 

pane: &PATIENT_PANE_URL 
 !!python/object/apply:django.core.urlresolvers.reverse
 args: [ render_patient_pane_with_id ]
 kwds: { kwargs : { patient_id: *PATIENT_ID } }

Using Django {%url%} template tag, the code below can be rewritten more elegantlyas:

pane: &PATIENT_PANE_URL  # creates the Alias of PATIENT_PANE_URL    
    {% url 'render_patient_pane_with_id' *PATIENT_ID %}

 YAML Header and Describing the Layout of the UI, widgets inside each DOM

YAML Header describes which module the pane belongs to, what are requisite modules to be loaded before this loads and whether this loads on AuShadha start. This is something like a basicinformation about the pane.

# YAML

depends_on: [ search ] #Requires that the Search Module
load_after: search #Requires that Search UI should be loaded before this
load_first: !!bool False #Prevents loading this first explicitly

#Following markup start the description of the Patient UI Pane

id : PATIENT     #ID of the DOM Element

type : bc        # Type of Dijit Layout Widget this is bc = Dijit BorderContainer

title : Patient         #Title Attribute

url : *PATIENT_PANE_URL #The URL attribute which equals href of the widget

closable : !!bool True  #Whether the tab is closable

widgets: []             #Whether there are child widgets (exludes layout widgets)

panes:                  #Describes the child layout Panes / DOM Nodes

  - id: PATIENT_DETAIL_ACTIONS_ICONS #DOM Element Id of the pane
    type: dom                        #Says that this is only a DOM Node not Dijit
    domType: div                     #Specifies the DOM node type
    style:                           #Specifies the CSS styles 
      position: relative
      top: 10
      zIndex: 1000
      float: right
      width: 200px
      height: 1.8em
- id : PATIENT_TOP_CP            #Describes a Dijit Layout Widget DOM Id
 region: top                     #Region attribute of the widget
 type: cp                        #Type of widget cp = dijit ContentPane
 splitter: False                 #Splitter attibute
 url: *PATIENT_INFO_URL          #href attribute
 widgets: []                     #Contained non-layout widgets
 panes: []                       #Contained Dijit panes, DOM nodes
 class: topContentPane selected  #CSS class 
 style:                          #CSS styles
   height: 1.8em

The resulting PyYAML file can be parsed and UI created by the Javascript file. As you can see the method is easy and the markup is certainly more readable than an HTML file with Dijit declarative markup interspersed with Django template markup etc..

It can certainly be argued about the need for a PyYAML use when HTML can be used. However, to change a layout and to see switching layout / per -user customisation it is much easier to move the YAML blocks to and fro the nested levels than to switch HTML blocks with all the declarative markups. Of course we can use Django Template {% include %} to create a basic HTML file that will do the job. It is up to developer preference. I found this much easier on the eye.

The current limitation is regarding inline javascript. This can be solved through custom Dojo Modules using AMD loader. Dojo’s dojoConfig attribute allows runtime loading. The pane’sattribute can allow import of specifically needed JS modules / classes. This is a thought. I have not implemented this fully. However, the proof of concept of this exists at the Pluggable module aushadha_demographics_us tree.yaml file.

More on that on a later post.

Next Tutorial will be based on the core of AuShadha and its bundled apps

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 http://github.com/dreaswar/Au-Pluggables

After activating the virtual environment run

$ python manage.py 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 urls.py

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 dijit_widgets_constants.py 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 urls.py 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 urls.py

2. Determining the registration of roles

The aushadha.py  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 aushadha.py 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  pane.py  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 settings.py to set the paths for templates, scripts, styles and media.  The Root urls.py 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 settings.py and urls.py to reflect this. This has to be done before syncdb is done.

The fully developed application for US demographics collection is at http://github.com/dreaswar/Au-Pluggables

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