Managing Diabetes with JAMstack

On the 23rd December 2003, at the age of 14, I became ill and ended up in hospital. I was very quickly diagnosed with Type 1 Diabetes. 2019 marked my 17th year with Diabetes and as I write this post I find myself reflecting over the years and realising how much technology has positively impacted people who suffer with Diabetes.

However, despite these revolutions there's still a problem...

But before we discuss the problem and look at how I want to help solve this problem let's take a quick biology lesson.

What is Diabetes?

According to the NHS Website:

Diabetes is a lifelong condition that causes a person's blood sugar level to become too high.

If you think back to Science lessons at school you will have learned about an organ called the Pancreas. The Pancreas is responsible for the generation of an enzyme called Insulin. Insulin is a hormone that our bodies use to breakdown sugars (a byproduct of Carbohydrates that we eat) in our bloodstream.

So when a person with a healthy pancreas eats a meal their body will release the exact amount of insulin needed to break down the sugars consumed in that meal. Those who suffer with Diabetes are either unable to produce the right amount of insulin (Type 2) or unable to produce any insulin at all (Type 1).

What's the difference between the two groups?

The main differences are the root causes and treatment.

  • type 1 diabetes – caused when the body's immune system attacks and destroys the cells that produce insulin. Type 1 diabetes is not reversible. Type 1 diabetes is treated by injecting insulin, with pen injections or an insulin pump, to replicate the pancreas' behaviour.
  • type 2 diabetes – caused when the body does not produce enough insulin, or the body's cells do not react to insulin. The exact reason for this is unknown but obesity, being inactive and genetics are often factors that are associated with this type. Type 2 diabetes is often treated by making lifestyle changes and the prescription of tablets. Type 2 diabetes is potentially reversible if diagnosed early enough and drastic lifestyle changes are made.

How is Type 1 Diabetes Managed?

Type 1 Diabetics manage the disease by carrying out several blood sugar tests every day, usually before a meal. Ths involves using a blood sugar monitor which returns a blood sugar count. Using this reading and a carbohydrate count from our meals, we have to calculate the amount of insulin we need to take.

We're only human so we're bound to get insulin amounts wrong. If we don't take enough insulin our blood sugar count rises and this is called Hyperglycemia. If we take too much insulin our blood sugar count drops and this is called Hypoglycemia.

I have no idea how Type 2 Diabetes is managed on a daily basis. If someone lives with Type 2 Diabetes and would like to make a contribution to this article then I'm all ears!

Which is Worse?

A common question I get asked by friends, co-workers etc is "Which is worse? Type 1 or type 2?". In my opinion, both can be as bad as each other. In the UK type 2 diabetes is a lot more common that type 1. The NHS website states that "around 90% of all adults with diabetes have type 2". But, regardless of the type, if diabetes is poorly managed and blood sugar levels aren't stable then complications can arise:

  • Problems with eyes, potentially resulting in loss of eye sight
  • Problems with legs and feet, potentially resulting in ampuation
  • High Cholesterol
  • High Blood Pressure
  • Cardiovascular Disease
  • Kidney Failure

In the UK these complications add serious stress to our National Health Service. Managing diabetes effectively can drastically reduce these potential complications.

The Problem

Hopefully I haven't bored you away from the article. If you're still with me then let's talk about the problem with technology in diabetes.

Technology is expensive and it isn't accessible to everyone who suffers with diabetes. As a Brit I am very thankful for the NHS. I treat my Diabetes with an Insulin Pump combined with a CGM (Continous Glucose Monitor) - both of which are funded by the NHS. With this technology I am able to look over previous readings on a graph and adjust medication levels accordingly.

However, there isn't enough funding for every diabetic to access this treatment. We also have to remember that not every country has a service like the NHS which means diabetics outside of the UK have to fund their own treatment. Those who don't use insulin pumps or CGM's are relying on the functionality of their blood glucose monitor, most of which are very good at reading blood sugars but not painting the bigger picture.

Got an Insulin Pump/CGM?

If you do have access to this technology then you should checkout the Nightscout Project. Nightscout is an Open Source, DIY project that helps you get your CGM data into the cloud. This allows for remote monitoring of blood sugars - great for parents!

There's an awesome talk by Scott Hanselman that was recorded in 2015. In this talk Scott showcases the Night Scout software and discusses CGM data in the cloud. Check out the video here

My Solution

Don't get me wrong. Nightscout is an awesome project but it seems very much geared towards diabetics with a CGM and an Insulin Pump. There's also an essence of hacking involved to make the hardware work with the software - this isn't ideal for those who receive pumps through the NHS (it'll void the warranty).

So what about those who are still taking injections for their insulin? Or those who use pumps that have been prescribed by the NHS? How can we provide these users with a similar experience?

I want to create a system that is easy to deploy, cheap to host, secure and fast. This is where JAMstack comes in!

Why JAMstack?

We've been doing a lot of work with JAMstack at Endeavour Digital and the more I work with it, the more potential I see with this architecture. More importantly there are services in this space that I can utilise to meet my criteria:

  • Netlify - An easy to use and affordable hosting solution for static websites and client side applications. The free tier comes with an environment for executing lambda functions which is perfect for what I have in mind. As for keeping deployments simple, their 'deploy to Netlify' button will be super useful here!
  • Update 18.05.2020 - Since posting this article I made the decision to store blood results on the Sanity platform, as oppose to Fauna. I wanted to get something online quickly and started to get distracted from my primary goal as I started developing the custom admin interface. Sanity provides a fantastic interface out of the box, that similar to a CMS, and it is very flexible. This means I can move my focus to the presentation layer whilst still delivering a great data entry experience for my users. However, this isn't the end of my journey with Fauna. There are other ideas that I want to explore which will work perfectly with the Fauna Platform. So, please check them out, it's really awesome, and stay posted for my other Jamstack ideas!!
  • Gatsby - I'll be using Gatsby to develop the UI. I love Gatsby and I find it's Hybrid Pages feature both useful and awesome.

The Boring Solution

My good friend Sam Beckham introduced me to the idea of starting with the "Boring Solution". In other words the minimum functionality required to get a job done. Naturally I have A LOT of ideas for this application but I need to prove the concept first.

So I'll start with the boring solution, this will let me:

  1. Publish data to FaunaDB via the Fauna dashboard. That's right, I'll not be bothering with a custom interface at this stage and why bother if there's one there for me to use?
  2. Trigger a gatsby build on Netlify when data is updated. I'm going to try and keep my site as static as possible and this includes pre-fetching Fauna data. Since data is inputted manually and via my CGM I don't need a real-time interface, nor will I be triggering hundreds of deploys each day.
  3. Display results in a graph on a basic front end built with Gatsby.

The Less Boring Solution

  1. If I find my proof of concept useful then I will continue to build on this idea. I already have some things in mind that I would like to try which include:
  2. Integrating a Netlify Function with iOS Shortcuts/IFTTT! This means I'll be able to publish results from my phone easily.
  3. Develop an authenticated application for posting data to Fauna. So I can publish data via a web application rather than the Fauna dashboard. It'll also make posting data easier for less technical users (I would like to Open Source something if this works out).

Wrapping Up

I'm sure more and more ideas will come up as I work through this. But I'm really excited to see how far I can go with JAMstack and learn more about what these services are capable of.

I intend to keep writing about my progress and hope that I can finish with something that I can showcase and talk about at meetups and conferences.

If you also suffer with diabetes and have some ideas you would like to share or would just like to chat to a fellow human with a silly pancreas, then please feel free to reach out to me on Twitter @jamiebradley234.