Saturday, 20 August 2016

First 'Diaversary'

One year ago today (in fact, about this time as I write this post), my wife took our 1 year old son into the doctor's room. It was a routine (if slightly embarrassing) visit, Rose had brought him to the same GP that had recently seen him for a couple of relatively minor concerns that had turned out to be nothing. This was lined up to be another and Rose was lined up to look like the slightly neurotic vicarious hypochondriac mum. Our son had been drinking and peeing a lot. He was filling his nappy to overflowing by about 10pm and guzzled juice - he could down a beaker in one go. We knew this could be a symptom of diabetes, not that we knew much more than that, and had decided to take him in to be sure. The test is very simple, a test strip is dipped in a urine sample, if glucose (sugar) is present, it's a confirmed diagnosis.

As the doctor removed and looked at the test strip, he turned to Rose ready to give his usual reassurance. Then Rose noticed him catch himself. He took a breath. "He has diabetes, you need to take him to the hospital now."

My first notification was from my tearful wife over the phone a minute or two later. I was at work, I yelled something at my boss about my son and diabetes as I flew out of the office to cycle across town and meet my family at the hospital. Our son had to go straight to the children's ward and I'd need to look after our two daughters while Rose took him in. As the girls and I played at the park, Rose started to find out how serious this was. Our son had to have blood tests and injections and he hated being poked, pricked and squeezed by strangers. It turns out we were lucky, we'd caught it early. Many children are extremely ill at diagnosis. As cells in the body are unable to absorb sugar they burn protein and fat instead, the waste products make the blood acidic and hence toxic. This is called diabetic ketoacidosis (DKA) and can be fatal.

Later in the day the medics asked if I could come and join Rose at the hospital. Our friend Rhianne looked after the girls for us as I went in. We were sat down and given a whistle-stop introduction to type 1 diabetes. It's an auto-immune condition where the immune system attacks and destroys the cells in the pancreas that produce insulin. Insulin is a hormone that triggers cells to absorb glucose from the blood stream to burn for energy, our insulin concentration is varied to regulate our blood sugar in a narrow range. As insulin is released, cells absorb and use the glucose and the blood sugar level drops. With less insulin, cells stop absorbing glucose and the blood sugar level rises - both the food we eat and energy-storing tissues release sugar to the blood all the time so if it's not absorbed it builds up.

So we were packed off with two bags of blood sugar testing equipment (all relying on finger pricks to draw a drop of blood), inulin pens (two types!), a log book and 'sharps' boxes (to dispose of all those used needles, finger pricking lancets and blood test strips). And I learnt my first lesson about living with type 1 diabetes - it's a disease of numbers..

Numbers because you have to get the amount of insulin you deliver just right. It has to match the body's base output of sugar from the liver and muscles, and exactly what gets released from what the person with diabetes (in our case our 1 year old son) eats. It's all done by analysis and ratios, and counting the amount of carbohydrate (nutrition that gets converted to sugar) in food. Not easy, not at all easy, especially when it's 24 hours a day, but doable.

The second lesson is that it's exhausting! Type 1 diabetes is not tiring from it's physical effort (although waking up a few times each night to check blood sugar or correct it is very hard), it's primarily tiring because of the constant mental involvement. Every gram of food, minute of exercise, illness, emotional influence, growth spurt and one of seemingly a million other factors is constantly evaluated, weighed-up, estimated and accounted for in the mind of a type 1 treater. It's tiring. But, as I started to find out, it's right up the street of an engineer.

I work as a Research & Development engineer and I spend my days modelling and simulating systems and their control. I immediately saw my son's blood sugar as an engineering system control problem. My first task was to get good data. Insulin is easy to log, you just have to record what you've given with the insulin pens in your log book. Carbohydrate eaten is harder, so I built a little phone app to help my wife and I estimate our son's carb' intake. Bread sticks, yoghurts, rice cakes and party rings - even the non-sugar-free Calpol, all got included. I modified it to calculate how much insulin he would need for a meal, and this raised the next question, what's the ratio for insulin-to-carbohydrate we should be giving him? It was clear that the numbers the nurses had give us from a big table in a book weren't quite right. I use optimisation algorithms at work that can solve a problem backwards (kind of like getting the question from the answer) - I added one to my app to estimate the insulin ratio from a few meals and it seemed to work.

Now, this all sounds well and good, but it wasn't ideal. The smallest amount of insulin a pen can give is half a "unit". For a 1 year old that represents a large snack, and in terms of his base sugar output, it's more than his body releases at night. The result is that small snacks were generally out of the question (don't give any insulin and his blood sugar goes high, give the smallest amount and his blood sugar goes too low). The other problem is that at night his blood sugar could drop.

Now let me explain about low and high. 'High' is generally a problem long term. DKA is the severe case but long term slightly raised blood sugar causes problems with nerve damage, kidney problems, eyesight and feet. However, being a bit high short term isn't too much of a biggy. 'Low', however, is a problem straight away. Most tissues in the body can burn protein or fat if they can't absorb any sugar, but not so for the cells in our brains. Starve the brain of insulin and it's in trouble. The result; reasonably rapid decline from impaired function to coma to possible death. That's why we're up at night. That's what keeps all parents of children with type 1 up at night. It never goes away and you can never fully rest.

So bring in the next technology. Our son needed smaller doses of insulin and we have the capability. The solution is called an insulin pump. The user wears it (in our son's case in a pouch around his waist) and it delivers insulin via a thin flexible tube into a short cannula (in our son's bottom). The pump can deliver pulses of insulin 20 times smaller than the insulin pen could. Bring on the snack time biscuit!! Our son could browse again! We were given a pump after about 4 months of using injections. The first month was awful!! A pen has one setting: the amount of insulin you give in the evening for the base level ('basal') or the amount you give before food ('bolus'). The pump has almost infinite variation, you can tune the basal insulin down to half hour blocks through the day, you can set different ratios for food for all times of the day. Also the way the pump delivers basal insulin is different - with injections you use a special slow release form of insulin, with the pump you inject regular tiny pulses of fast insulin. This seemed to make the whole situation a bit more 'choppy' and hard to get set up right. But after a month of tinkering we were getting there, and we'd never go back!

However, this new 'choppy' reality had us up several times a night to check our son. His blood sugar can suddenly drop so we have to keep an eye on it. This is more likely after an active day so we gave him a pedometer (FitBit) to log his exercise and let us know if he had a higher risk. The "congratulations you've reached your step count target!" message actually meant "watch out it could be a 'low' night!" to us!!!

Bring on the next technology.. After six months we were allowed to try out continuous glucose monitoring (CGM). This is a game-changer. Unfortunately most people with type 1 don't get access to this. It's expensive and in the UK the NHS only funds it for people who don't have the ability to detect the sensation of low blood sugar ("hypo-awareness"). This is of course true for our little son (mind you I'd say it's true for anyone who's asleep at the time!), but it still took some time to get the equipment released. For all the difficulty in accessing it, the power of CGM is huge. A thin 1cm long film sits under the skin in our son's bottom (yes the bottom is the only fatty enough part of a toddler to use for all of this!) attached to a limpet-shell-sized transmitter stuck on like a plaster. This radios his glucose concentration out to his pump once every 5 minutes. Fantastic!! We can get an idea (just an idea, it's not as accurate as a finger prick) of our son's glucose levels, and just as importantly which way they're going, in real time without any pain (although inserting the sensor hurts, something we have to do every 5 days). This was great, especially as the pump has the ability to temporarily stop delivering insulin automatically when is predicts the our son's blood sugar is going low. The pump had this amazing data, but it was on our son, and at night time we were next door (still worrying!!).

Then I discovered that I was not the only techie coming up with tools to help manage type 1. There are a lot of us spread around the world, and thankfully a culture has emerged with two distinct philosophical principles. Firstly, that the medical equipment companies are slow and behind the capability of technology, but as patients and carers with technical skills, #wearenotwaiting. Secondly, that we can both benefit from the work of others and pay it forward. I discovered this amazing tool ('open source' which means the people who programmed it share it freely) called Nightscout - a way of putting your CGM data in the cloud and accessing it on all sorts of devices like phones and smart watches. Nightscout can warn us and wake us up when our son's glucose levels are moving out of range. No longer did we need to wake ourselves up to check, we could sleep and be woken only when needed!! Now it wasn't perfect.. You did still needed to keep an eye on the system to check it was working, and our pump's radio communication was protected by lots of encryption, so the only way we could get data off was to keep uploading it through the manufacturer's web portal and downloading it again as a spreadsheet. A couple of clever guys had built a tool to do it, but I could see that some of my programming experience could help to improve the website bit, so I got coding again. Soon I was working with another dad of a type 1 (who I now consider an important friend) to roll out an improved solution. We both found ourselves up late at night helping out other users who were setting up the solution. We didn't mind, we were grateful for all the work that had been freely shared with us and were happy to pay it forward by helping others who were not waiting!! But it was tiring along with the routine night time waking.

Now we're approaching the current day. A couple of months ago, yet another type 1 dad cracked part of the encryption for the pump and built an Android app to connect our pump model to Nightscout. Our old solution needed a tablet or computer so this suddenly meant that we could monitor our son out and about as well as at night. Let me tell you that the high activity of a soft play centre can cause major stress to a parent of a type 1 - there's a massive risk of rapid low blood sugar! Having live numbers on your watch or phone is amazing!

The next step is to see if we can automate the regulation of the pump's basal insulin delivery in response to blood sugar data from CGM. This would finally be some degree of automatic control and could give us nights of continuous sleep!! We are very grateful to the community of programmers (and their partners!) who are working on this as you read!! We are also grateful for the NHS, without which our son would either be dead (developing country scenario), or we would be broke (private healthcare scenario). Oh how wonderful the NHS is!!! We are grateful to God for our son, his health, the technology we have access to, and the odd nudge we feel he gives us from time to time to just do that extra check. We are grateful. We are parents. We are incredibly proud of our brave brave son. We are a gifted carer and an engineer. We are hopeful for more solutions to this condition and as you'd expect, #wearenotwaiting.

Monday, 23 May 2016

Local Instance of Nightscout on Windows 10 - How I Got There


To do some fast development of new Nightscout features, I wanted to work away from Azure. "Easy!" I thought, already sitting at a laptop with GitHub and Node.js installed. Well I'm afraid it wasn't so. With the help of some fab' people (not least @MilosKozak, thank you!), I got there. Here's how:

Prerequisites

This is what I needed to get going, versions are important!!
  • Node.js
  • Git (here?, I used Version 2.7)
  • Python (Version 2.x (no higher than 2!), I used 2.7.11 x64)
  • Microsoft Visual Studio Express 2013 (must be 2013)

Preparation

I had to make sure both npm (Node Package Manager) and Git were on the user path. I also added some system varibales for Nightscout
(Settings > System > About > System Info > Advanced system settings > Evironment Variables...):

User Variable
  • PATH = C:\Users\[MyUserName]\AppData\Roaming\npm;C:\Program Files\Git\bin
System Variables
  • API_SECRET = [MyNightscoutAPISecret]
  • DEVICESTATUS_ADVANCED = true
  • ENABLE = careportal iob cob openaps pump bwg rawbg basal
  • MONGO = [MyMongoconnectionString]
  • PORT = 80
  • PUMP_FIELDS = reservoir battery status
 

Installation 

I had to ensure npm used the correct compiler from Visual Studio 2013:
  • Open Command Prompt ([Windows] + [R] > "cmd")
  • Enter "npm config set msvs_version 2013 --global"
Having done all of this, installation was simple..
  • Create a local copy of cgm-remote-monitor on machine (in my case using GitHub)
  • Open Command Prompt ([Windows] + [R] > "cmd")
  • Enter "cd [cgm-remote-monitor directory path]"
  • Enter "npm install"

Running Nightscout

  • From the open Command Prompt, enter "node server" 

Developing in an IDE

  • I used NTVS (Node Tools for Visual Studio) and followed this awesome video: