<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ben Spencer on Medium]]></title>
        <description><![CDATA[Stories by Ben Spencer on Medium]]></description>
        <link>https://medium.com/@ben.spencer_29253?source=rss-74751b6fa704------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Byh_GemhscBNStKR.jpg</url>
            <title>Stories by Ben Spencer on Medium</title>
            <link>https://medium.com/@ben.spencer_29253?source=rss-74751b6fa704------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 02:09:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ben.spencer_29253/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kaji: a general purpose FHIR clinical data repository]]></title>
            <link>https://medium.com/healthforge/kaji-a-general-purpose-fhir-clinical-data-repository-d56e4b99ef2d?source=rss-74751b6fa704------2</link>
            <guid isPermaLink="false">https://medium.com/p/d56e4b99ef2d</guid>
            <category><![CDATA[fhir]]></category>
            <category><![CDATA[interoperability]]></category>
            <category><![CDATA[healthcare-technology]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ben Spencer]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 10:00:04 GMT</pubDate>
            <atom:updated>2019-07-04T08:43:58.197Z</atom:updated>
            <content:encoded><![CDATA[<p>火事 kaji: (n) fire; conflagration</p><p>Kaji is a general purpose clinical data repository (CDR) implementing a large portion of the <a href="http://hl7.org/fhir/stu3/">FHIR STU3 spec</a>. It differs from other implementations in the space in various ways:</p><ul><li>general purpose: no specific use case envisaged</li><li>pragmatism: focus on developing features that are genuinely useful rather than blindly attempting to cover the entire standard</li><li>performance over deployment flexibility: use any database (as long as it’s postgres)</li><li>data integrity above all else: clinical data must not be lost (even if, as is often the case in real life, it is inconsistent)</li><li>multi-tenanted: we want to be able to support multiple datasets on the same hardware, particularly for test deployments</li></ul><p>We have deployed a sandbox instance at <a href="https://kaji.healthforge.io/">https://kaji.healthforge.io</a> to allow the public to experiment with the server and run the <a href="https://projectcrucible.org/servers/5c791f4404ebd07fa1000000">Crucible</a> test suite against it. We’ve also put the Docker container on <a href="https://hub.docker.com/r/healthforge/kaji">Docker Hub</a> (MIT license) for anyone who wants to deploy their own instance.</p><h3>Technology stack</h3><p>A requirement for the server was that it should run on the JVM, and this has influenced certain other decisions about the stack.</p><h4>HAPI</h4><p><a href="http://hapifhir.io/">HAPI FHIR</a> is the Java reference implementation for the standard, so it made sense to start here, but it is not without its issues, described later. We use its FHIR data model, marshalling and validation capabilities, but not any of its REST frontend or JPA backend support.</p><h4>Scala / Finagle</h4><p><a href="https://twitter.github.io/finagle/">Finagle</a> is a high-performance networking framework built by Twitter, on top of the popular <a href="https://netty.io/">netty</a> asynchronous I/O library. It is written in Scala, but provides APIs to be used from either Java or Scala. We prefer Scala as a language, mainly due to reduced verbosity and great support for functional programming constructs.</p><h4>PostgreSQL</h4><p><a href="https://www.postgresql.org/">PostgreSQL</a>, as (accurately) described by its developers, is “the world’s most advanced open source database”. At its core is the relational model, but the developers don’t shy away from providing object or document database features where they are useful. PostgreSQL is particularly suitable as the backend to a FHIR server. This can be attributed to many of its advanced features, but <a href="https://www.postgresql.org/docs/current/datatype-json.html">jsonb</a> is particularly prominent. I am not personally a fan of the <a href="https://www.hl7.org/fhir/json.html">JSON encoding</a> of FHIR resources — it involves some ugly kludges that belie the underlying XML-centric data model, — but the power of jsonb is sufficient to outweigh these concerns and so we use it as our primary storage format. The <a href="https://www.postgresql.org/docs/11/datatype-json.html#JSON-INDEXING">GIN index</a> support is extremely useful and allows us to optimise a wide range of FHIR queries out of the box.</p><h3>Deployment</h3><p>We deploy Kaji as a docker container based on the standard openjdk base. Current production deployments are based in Amazon ECS using an RDS backend and Google Kubernetes Engine using a Cloud SQL backend.</p><p>We have found Kubernetes preferable to ECS for a variety of reasons, but Amazon’s EKS service was not available when we first deployed.</p><h3>Challenges</h3><h4>HAPI</h4><p>HAPI (as a data model library) is not necessarily an ideal building block for a general purpose FHIR server. As a reference implementation, it is required to cater for all possible requirements, and as a result comes with a fair amount of baggage that we don’t need. A general purpose server isn’t that interested in the specifics of individual resources (except perhaps in some specialised cases such as audit records), so it is not particularly useful to have separate Java classes for each and every one (not to mention the fact that mutable classes with getters and setters don’t really fit our scala development style). What is really needed is a library that implements the underlying FHIR data model, supplemented with functionality for marshalling, validating etc, at a lower level.</p><h4>Scala</h4><p>The scala compiler is notoriously slow (it performs around <a href="https://typelevel.org/scala/docs/phases.html">25 passes</a> over the code), particularly when making heavy use of features such as implicits and macros. <a href="https://www.scala-lang.org/blog/2018/06/04/scalac-profiling.html">The codebase can be adapted</a> to improve matters somewhat, but that in itself requires a fair amount of work for diminishing returns. Scala IDEs tend to be sluggish for the same reason. Personally I cope with this by working on machines with the latest core i7s and 64G of RAM, but my colleagues insist on using macbooks and suffer as a result.</p><h4>Finagle</h4><p>Finagle is an industrial-grade RPC framework that provides sometimes deceptively simple abstractions over the complexity and power of both its internals and those of the underlying netty library. This makes it easily approachable for new users, but abstractions tend to leak and eventually it becomes necessary to dig deeper. For example, consider the default client stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o6H_q5JeTgI_eAH1BGdogQ.png" /><figcaption>Figure 1. Finagle default client stack</figcaption></figure><p>Each of these components (filters) provides useful functionality that users tend to take for granted, until something goes wrong. Similarly, the default LocalScheduler just works out of the box, but a deeper understanding of its internals is necessary to achieve optimal performance.</p><p>When things go wrong with finagle (and we have seen some strange interactions with other low-level networking software such as Amazon’s ELBs), it can be difficult to debug. Error messages are often unhelpful and you need both access to and a deep understanding of the vast wealth of <a href="https://twitter.github.io/finagle/guide/Metrics.html">metrics</a>that the framework provides.</p><h4>PostgreSQL</h4><p>A common complaint about postgres is that it is not as easy to horizontally scale as more recently developed distributed databases. It would be possible to implement manual sharding of the database in Kaji. Given the availability of vertical scaling (for example, AWS offers huge RDS servers such as the db.x1e.32xlarge), I don’t think this is a particularly high priority.</p><h3>Case study: Vision Coach</h3><p>Vision Coach is a novel digital platform for managing patients with diabetic macular edema. You can read a detailed description of it <a href="https://medium.com/healthforge/vision-coach-749d511881cc">here</a>. In short, the platform consists of a mobile app for patients with diabetic macular edema (DME, a form of diabetic eye disease), built using React Native for iOS and Android, and a web app for ophthalmologists managing DME patients, built using React. The main components are summarised in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWDxCGbCnlP1opCKL_qaDA.jpeg" /><figcaption>Figure 2. Vision Coach platform.</figcaption></figure><p>We took a FHIR-first approach to the design of the Vision Coach data model. Since interoperability in some form is an almost inevitable requirement for any healthcare app — for example, integration with other apps and tools, or even compliance with legal requirements such as the GDPR right to data portability — we regard this approach as justified. In the case of Vision Coach, an obvious early manifestation of this requirement was the need to avoid duplicating data entry, something busy clinicians simply don’t have time for.</p><p>Being forced to align your model with an interoperable standard from the start can save a lot of effort down the line when these requirements hit. It’s not a panacea: FHIR is merely a <a href="http://www.healthintersections.com.au/?p=2921">platform standard</a>, and there may well be some mapping work to do to comply with a target profile, but it’s a good starting point. The alternative is a custom database designed purely to meet the (initial) requirements of the app. This is certainly a lot faster to get going with, but it’s short-sighted, not only for interoperability reasons, but because requirements can and do change. Sure, you can migrate the data model as new requirements arise, but using a general-purpose CDR like Kaji from the start obviates this need in important ways. It’s also worth noting that (especially for newcomers to the healthcare domain), FHIR provides a baseline data model that is likely to be more in line with existing practice than something drawn up from a blank slate.</p><p>Figure 3. shows how the Vision Coach data model maps onto a selection of FHIR resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHUx4Q0XEWu_VxIzzmLYmg.png" /><figcaption>Figure 3. Vision Coach data model mapping to FHIR</figcaption></figure><p>As you can see, there is not a 1:1 mapping between entities from the UI point of view and resources in the FHIR database. I think this is likely to be a common problem in FHIR-capable apps and is another good reason to design the mapping up-front.</p><h3>Future work</h3><p>There are three obvious areas for future work on the project:</p><h4>FHIR R4</h4><p>Kaji currently implements FHIR STU3. It would definitely make sense to add support for R4, which is the current version of the standard and includes normative content.</p><h4>Missing features</h4><p>FHIR is a large standard, not typically intended to be implemented in its entirety outside reference implementations. We are missing a few broad areas which would be useful, such as transactions.</p><h4>Beyond the base standard</h4><p>There are various extensions to, profiles on, and draft additions to the base standard that would be useful to implement. For example: <a href="http://docs.smarthealthit.org/">SMART on FHIR</a>, <a href="https://wiki.ihe.net/index.php/Category:FHIR">various IHE standards</a>, <a href="http://hl7.org/fhir/us/sdc/STU2/">Structured Data Capture</a> and <a href="https://hl7.org/fhir/graphql.html">GraphQL</a>. It may also be useful to provide access to the same underlying clinical data using non-FHIR standards such as <a href="https://www.dicomstandard.org/dicomweb/">DICOMweb</a>, <a href="https://www.omg.org/cts2/index.htm">CTS2</a>, <a href="https://wiki.ihe.net/index.php/Healthcare_Provider_Directory">LDAP / IHE HPD</a> and <a href="https://openehr.atlassian.net/wiki/spaces/stds/pages/5373960/FHIR+for+openEHR">OpenEHR</a>.</p><p>Watch this space for more updates and releases over the course of 2019.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d56e4b99ef2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/healthforge/kaji-a-general-purpose-fhir-clinical-data-repository-d56e4b99ef2d">Kaji: a general purpose FHIR clinical data repository</a> was originally published in <a href="https://medium.com/healthforge">Healthforge</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>