Bahmni EMR— 1 Million lines of Open Source Code

Gurpreet Luthra
Bahmni Blog
Published in
6 min readFeb 25, 2021

Bahmni, an open source hospital management system and EMR has over 1 Million lines of code (LoC)! Out of that over 164,000 LoC are in AngularJS (Angular 1.x). AngularJS is going to be end-of-life in Dec-2021, with no likely SLAs around fixes after Dec-2021. Yes!

Bahmni Clinical Dashboard (screenshot from Demo server) — AngularJS codebase

In this article, I would like to shed some light into what parts of Bahmni depend on AngularJS, what parts are already in React; and suggest some steps forward to remove dependence on AngularJS. Some of this feedback has come from the Bahmni community and we continue to be on the lookout for creative means to move away from AngularJS.

This is also another reminder of how a technology that shines today — could be forgotten and left behind in the future! Google — has a history of doing this multiple times. See a list here: https://killedbygoogle.com/.

This is also another reminder of how a technology that shines today — could be forgotten and left behind in the future!

The only saving grace is that there are still a huge number of projects and applications that depend on AngularJS (like OpenHIM, etc) and many cannot just afford a*rewrite* — with no apparent gain in business functionality. So, there is hope that fixes will still continue to be available, but not necessarily in a time-bound matter.

Angular is not AngularJS!

Note: AngularJS(1.x) is quite different from Angular. Don’t confuse the two. This unfortunately causes a lot of confusion since many articles use these words interchangeably — which makes Google Search results messy! Another mistake by the Angular team to name the project Angular (again!).

How does one count Lines of Code (LoC)?

I used a popular open source tool called tokei. See github page: https://github.com/XAMPPRocky/tokei

Just install the tool and run it on a directory. It printed this for Bahmni codebase(https://github.com/Bahmni):

Lines of Code — Full Codebase for Bahmni (1 M)

As you can see, the “code” LoC (excluding comments and blank lines) says: 1,145,503 LoC! Quite large!

  1. Backend: Java Code (LoC): 282K
  2. Frontend: Javascript Code (Loc): 256K
  3. Everything else(LoC): 600K

Now — lets analyse for AngularJS code

For this I had to go into each frontend repository and run the tool to pull LoC for AngularJS Code, and React Code — since we had started moving to React for most of our new modules almost 4 years ago. Here is the analysis:

Click to enlarge: Bahmni Frontend Code (AngularJS analysis)

Let’s zoom in:

By Repository (AngularJS codebase in Red, Blue represents total codebase)

What this means is:

  1. Bahmni EMR UI, Bahmni Connect App (offline app), Common Angular Components — contain most of the AngularJS Code. Others are mostly in React.
  2. Total Angular Frontend Code: 164K
  3. Quite a lot of code needs to be migrated. So, let us break it down further by functionality, to get an idea of which parts are critical vs complex, etc. The next chart shows that: breakdown of EMR UI (repository: bahmniapps)
bahmniapps codebase by functionality
  1. Common, Clinical, OT, and then Registration are the biggies.
  2. Code: 32K, and TestCode: 55K. Total code: 87K.
  3. The other modules are easier to re-write, but most value will come from refactoring and migrating the biggies. Those are also likely to be where future functionality additions will happen the most (clinical, appointment, OT, etc).

How much effort will it take to migrate over to React?

When I checked around it appears that for an AngularJS rewrite into React, with minimal functionality changes, it takes about 1/4th the original investment — which means: if it took a team 4 years to build an AngularJS product, it will likely take them about a year to rewrite in React. It is much faster the second time around because requirement analysis / meetings are no longer needed. Still, this means to rewrite Bahmni it will take a substantial team of 30 people 1–2 years (looking at investment done since 2014).

I then used a speed of 200 LoC/day, which is considered fast for production code (see this article: How much code can a coder code?) and added a calculated column in the sheet above. It said: 823 days for a pair coding at 200 Loc/day. That’s about 3 years for a dev-pair.

My gut feeling is this project will take a team of about 5 dev-pair and a QA-pair about 1.5 years — if they rewrote everything as-is. And what if React falls out of fashion?!(Yes. Unlikely!).

Path Forward Suggested by Bahmni Core Team and Community

  1. Remove deprecated AngularJS code: Like the appointments module and Forms1.x codebase from bahmniapps frontend repository.
  2. Ensure all new feature development continues to happen in React and not in AngularJS.
  3. Take community and volunteer help to quickly rewrite the smaller, less complex modules.
  4. Refactor and rewrite Bahmni clinical controls (widgets) and reuse them in Bahmni EMR, just as we have written the Form Designer in React and Form Controls are React controls running inside Angular Directives. This way a lot of complex functionality which depends on these controls can start becoming React-ified. And future extensions and controls can be written in this manner (lead by example).
  5. Ensure we split functionality into their own bundles / repositories to make it easy to migrate frontend stack later. For instance the new appointment module is its own repository. This allows for easier debugging, refactoring, etc. because developers only need to understand one sub-domain to make changes (similar analogy as micro-services vs monoliths — but not too micro!).
  6. What else? Do you have some suggestions?

As the author of this article What the Angularjs End-Of-Life Means for You says:

Unfortunately, there is not much more you can do. It is on the developers for your web applications and websites to make this update. It is important to note that even though this is a serious issue, there likely will not be any serious risks for some time after December 31st, 2021. Discovering vulnerabilities in frameworks can take large amounts of time and effort, and AngularJS will present a less attractive target as more web applications and websites move to other frameworks.

AngularJS team has suggested that one can consider paid support from XLTS.dev for post-2021 support, which comprises of a group of experienced developers from the core Angular community. They don’t currently have an offering for open source projects, because their solution requires using a proprietary license key. I understand that. But…

Read more about how Bahmni is improving the world here: https://www.bahmni.org/implementations

The discussion on Bahmni Talk forum for this topic is posted here.

Detect Front-end Stack Quickly!

You can use this cool bookmarklet (shortcut in browser) to detect which tech stack the current window is rendering: https://github.com/ticky/tech-audit-bookmarklet.

Further Reading

  1. Is 2021 the end of AngularJS?
  2. Security patches after 2021 (Github)
  3. The Past Present and Future of Angular (Amazing Overview!)
  4. Projects on Github using AngularJS (Link)

--

--