Clojure

University Health Network

11 April 2017

This interview is a discussion with Dmitri Sotnikov about his use of Clojure and ClojureScript at University Health Network (UHN).

UHN

How long have you been working with Clojure and ClojureScript?

My team started using Clojure about six years ago, and we integrated ClojureScript into our stack last year with our latest project.

How big is the team you have using Clojure or ClojureScript?

We have a team of about 30 developers, some of them are using Clojure while others are using other languages such as Java and C#. The number of people using Clojure has been steadily increasing as the benefits have become evident. My immediate team consists of eight developers working exclusively with Clojure.

What products or services are you building?

The clinicians at the University Health Network (UHN) operate in a complex healthcare environment where many aspects of patient care have to be coordinated between multiple disciplines. Our team builds products that help clinicians streamline their workflow.

An example of such a workflow is the one found at the Bariatric Clinic, where obese patients require assessments for weight loss surgery. Let’s take a look at the problem we faced and how we addressed it.

Assessments are conducted by professionals from across five disciplines. The assessment starts with a nurse consultation, followed by a visit with a social worker, then a dietitian, and then the psych team. Finally, patient is scheduled for the surgeon interview. The surgeon must have the information collected by other disciplines in condensed form.

The assessments must be completed in a specific order with each assessment being dependent on the results from the previous ones.

The task is further complicated by the fact that all the assessments work with a common set of data. Each discipline requires to see a subset of the data and uses a different set of terminologies when referring to the data elements.

When a piece of data is modified, it may trigger updates in the data model including those that aren’t part of the view that the user is working on. Since multiple users may be working on different parts of the assessment concurrently, we have to take extra care to ensure data integrity within the application.

The project aimed to provide a new kind of workflow for the users, and this implied having evolving requirements as we continued to receive user feedback.

The project team chose to use an agile development approach to allow for greater flexibility. The workflow was broken up into modules for each discipline. We would deploy each module as it was finished, and integrate user feedback into design of the system as further modules were developed.

The team created a Clojure DSL for writing screens and business logic for the application. These definitions are stored in a database, and are used to generate the views at runtime.

This model provides us with the ability to modify any aspect of the assessment without the need to redeploy either the client or the server portions of the application.

Why is using Clojure or ClojureScript valuable to your business?

Clojure allowed us to deliver an innovative product that provided the best possible workflow for the users. Our application was ultimately the recipient of the 2016 ITAC Ingenious Award.

Through the use of the of the application, the clinic dramatically reduced wait times for the patients from 128 to 63 days. While the dictation time used by clinicians fell by 80%, representing a total savings so far of $240,000.

What about working with Clojure and ClojureScript gives you the most value?

We really like working with the JVM, and wish to continue leveraging this platform for our projects. However, we also recognized the need for a language that facilitated both rapid development and prototyping while allowing us to produce robust and maintainable applications.

Our prior experience with Java projects showed that it was a poor fit for these requirements. Meanwhile, Clojure stood out as a strong technology choice for a variety of reasons.

The language lets us seamlessly use existing Java libraries and tools in our projects. This allowed for a gentle transition from our legacy stack towards a modern one based around Clojure.

Clojure allows us to develop the system interactively, and to quickly respond to changing needs of the project. The team is able to quickly prototype solutions without sacrificing code quality. The dynamic nature of the language allows for a cheaper and faster development process than what was available to us with Java.

REPL driven development provides us with the ability to explore the problem space interactively and come up with the best solution through experimentation. We find that the REPL workflow results in a better feedback loop than unit testing.

Clojure based solutions end up having a fraction of the code seen in the projects of similar scope that we previously built in Java. Not only that, but Clojure makes it much easier to separate the intent of the code from the implementation details. The ability to separate what is being done from how it is done results in code that’s much easier to maintain.

Clojure’s focus on immutability facilitates a natural decoupling between parts of the application. In absence of shared global state, it becomes possible to work on parts of the application in isolation. The resulting code requires fewer tests since the functions are pure and do not depend on the overall application state.

Since Clojure is a small and focused language, it made it easy to train new developers to become productive with it. Our partner CyLogix was able to train their contractors to work with Clojure in a short time.

Macros provided us with the ability to create domain specific abstractions. This let us express domain specific logic using the semantics of that domain.

Finally, Clojure proved to be a stable and reliable platform. We were able to upgrade the project to new versions of the language without any changes throughout the development cycle.

What is your stack?

We use the Luminus stack as the base for our projects. Some of the libraries that I’d like to mention specifically are:

If you'd like to share your Clojure story, please complete this form.