What if an algorithm could be your doctor? Living with Type 1 diabetes usually means making a lot of medical decisions on your own, sometimes daily. In this episode of ‘Fixed That For You’, you’ll hear about a problem millions of sick people face daily. It’s the story of Dana Lewis, a young woman who got tired of managing her disease, and decided to replace biology with data by creating an artificial pancreas. The results? Life changing.
In this episode, Dana talks about the Open Artificial Pancreas System project — here’s where you can read more about #OpenAPS.
Want to learn more about what continuous glucose monitoring is or how it works? Take a look at the CGM made by Dexcom.
Additionally, please visit the American Diabetes Association to learn more about how to manage diabetes.
Build something of your own with a Raspberry Pi. Lastly, check out Nightscout, the visualization app Dana mentioned in this episode.
Dana Lewis: It's so much work and so much guessing and that makes it really, really frustrating. It's really hard to get it right and the only positive feedback you get is that you didn't die.
Cara Santa Maria: When you have a Type 1 diabetes you're forced to become your own doctor. But what if there were an algorithm that could manage all of it for you?
Dana Lewis: That's what the system is doing for your diabetes, it's saying, "If you're gonna drop, I'm gonna practically take care of it, but if you're gonna rise, I'm gonna take care of it. You go sleep."
Cara Santa Maria: Welcome to Fixed That For You, an original podcast from Segment about solving problems with the data and algorithms. I'm Cara Santa Maria and in this episode we tackle a problem affecting more than a million Americans. It's the story of Dana Lewis, a young woman who got tired of managing her disease, so she decided to replace biology with data to create an artificial pancreas.
Dana Lewis: At the time, it was absolutely crazy for patients to be doing this themselves.
Cara Santa Maria: Absolutely crazy, but potentially life changing.
Dana Lewis: I had trained the computer to do it the way I would have.
Dr. Anne Peters: Type 1 diabetes is an autoimmune disease, which means the body destroys the insulin producing cells in the pancreas.
Cara Santa Maria: That's Dr. Anne Peters, one of the nation's top endocrinologists. She's the Director of the Clinical Diabetes Programs at the University of Southern California.
Dr. Anne Peters: The problem with Type 1 diabetes is the person with it has to be a pancreas.
Cara Santa Maria: Dana had to become her own pancreas at the age of 14.
Dana Lewis: Physically pricking my finger that first time was really, really hard because to me, that symbolized the start of something that would never end and in that moment, I instinctively knew this is going to be a lot of different.
Cara Santa Maria: Different because Dana had to start collecting data about her body a dozen times everyday. A single prick of blood to measure her blood sugar.
Dana Lewis: You have to carry around test strips and lancets and lancing devices in order to prick your finger. In addition to that, you have to carry a bottle of insulin and syringes, so there was a big physical burden of all the stuff that I had to carry with me.
Cara Santa Maria: It was analog data collection followed by complicated decisions.
Dana Lewis: What a lot of people don't realize is it's very hard to get the dosing of insulin right. In order to do anything, I had to begin to do a really big math calculation and this was all mental and all manual. Do you tweak what you're eating? Do you tweak the timing? Do you tweak the amount of insulin?
Cara Santa Maria: This calculation was happening 24/7.
Dana Lewis: I had to wake up every morning at seven or eight am and test my blood sugar and take insulin and eat 60g of carbs. It didn't matter if I wanted to sleep in, it didn't matter if I wasn't hungry.
Cara Santa Maria: Over the next several years, Dana went looking for anything that could streamline this manual cycle of check, inject, and repeat. Two pieces of technology helped. Insulin pumps that deliver smaller but more frequent doses of insulin and continuous glucose monitors, also known as CGMs, basically a sensor you put under your skin so you don't have to keep pricking yourself, which triggers and alarm if your blood sugar spikes or dips and it also collects your data for you.
Dana Lewis: The data is just a blood sugar data point every five minutes in a timestamp. It's very, very simplistic but the way a CGM is valuable is because instead of doing a finger stick and getting a timestamp and a data point and that's it, you couldn't see before or after, the CGM was measuring continuously every five minutes.
Cara Santa Maria: Helpful information, but it still required Dana's constant attention.
Dana Lewis: I couldn't get data off the device, so I would pull out my iPhone and take a picture and copy and paste that into Excel and then write side by side with what I was eating. That was the first digital data capture that I had access to in order to share my data with my clinician.
Dana Lewis: I was still having to do all the work of all that math of deciding what to do when and take action with my insulin pump or eating something if there was a problem.
Dr. Anne Peters: Research used to say that people with Type 1 diabetes had more depression than other people.
Cara Santa Maria: That's Dr. Peters again.
Dr. Anne Peters: But it turns out that it's not depression. It's something called diabetes distress.
Cara Santa Maria: Even with the help of technology, Dana grows up dealing with diabetes and diabetes distress and she's still struggling with it when she goes on to the University of Alabama to study Communications with a minor in Computer Studies.
Dana Lewis: I learned C++ and Fortran 90 and the idea of the program was really to teach you how to use computing technology and then apply it to the field of your interest.
Cara Santa Maria: After that, she moves to Seattle where she meets Scott Leibrand. Their first date was at a restaurant.
Scott Leibrand: Dana came in and we did the normal first date things, ordered our food, then when the food came, Dana pulled out a little device and I asked, "Why do you have a pager?"
Cara Santa Maria: It wasn't a pager. It was her insulin pump.
Scott Leibrand: I was asking really simple, dumb questions.
Cara Santa Maria: Scott asks a lot of questions.
Scott Leibrand: Like, you've got this continuous glucose monitor that measures your blood sugar and you've got this insulin pump that doses insulin. How do the two talk to each other? They don't. Why not? They don't, just because.
Cara Santa Maria: Maybe Scott asked so many questions 'cause he's an engineer and a network architect.
Scott Leibrand: I come to everything from a perspective of optimization. Looking at diabetes the same way gave me a lot of the perspective of being able to say here's a system, it's kinda random in a lot of ways and you still have to react but there are definitely some regularities and some things that maybe we can optimize around.
Dana Lewis: Because I grew up in a family of engineers essentially, that mindset was very, very common to me but I just wasn't used to outside of my family, having somebody ask questions and really wanna understand the cause and the effect of the things that we were doing.
Cara Santa Maria: Despite coming from an engineering household and having some basic programming skills, applying that stuff to her diabetes hadn't really occurred to Dana. She was super busy just managing and treating her condition.
Dana Lewis: I am very, very independent and I had been doing diabetes on my own for a dozen years and it was very interesting for me to think about if somebody did wanna help, how could I have them help me in a way that wasn't annoying, that wasn't him taking over or him doing something that I needed to do or needed to be able to do? But it was really, how do you take advantage of having two brains and two people to think about something? That was a very, very new relationship and a new phenomenon for me, 'cause nobody had been willing to do that before.
Cara Santa Maria: An artificial pancreas is a long way off. Right now, Dana and Scott have a more immediate goal. Improve the alarm on her CGM, the thing that warns her if her blood sugar is too high or too low.
Dana Lewis: It's very, very common for people with diabetes to get alarm fatigue from hearing that same alarm all the time. It actually wasn't that loud and it's very common for it to buzz itself off the nightstand and onto the carpet where you can't hear it if it's flipped over or it might fall into the bed and get covered by the bedcovers. I realized there has to be a better solution.
Dana Lewis: My phone can wake me up. My phone can have a variety of alarms. I can change the sound, I can make it louder. If only we could get the data off.
Cara Santa Maria: If Dana can get the data off the CGM and redirect it, it can trigger her phone's louder alarm. But the data's locked in the machine.
Cara Santa Maria: On the other side of the country, a guy named John Costick is tackling the same problem but for different reasons. He wants to monitor his five year old son's blood sugar while he's at school.
Cara Santa Maria: The CGM, made by a company called Dexcom, has proprietary software that outputs a report at the end of each month. But John hacked that function to issue the report every five minutes.
Scott Leibrand: What John had done is he had figured out how to take the library that powers that and instead of using the Dexcom app with that library, he made another app that was much simpler, just ran on the command line and wrote the data to a text file.
Dana Lewis: Once we succeeded, we had to then figure out how to build the rest of the system that I kinda designed in my head which was get the data to my phone.
Cara Santa Maria: They added a line of code to send the text file to a Dropbox folder that was synced to Dana's phone and laptop, then they used an app called Pushover to relay the alarms.
Scott Leibrand: We started out with just the simple alerts that would be able to send push notifications.
Dana Lewis: We didn't just want it to alarm me. We wanted it to also alarm a secondary person, so we basically had to build a tiered alarm system where it alarmed me first but if I didn't wake up and snooze the system, it would then alarm the next person, AKA Scott or my parents.
Dana Lewis: So, we built a basic web interface in I think PHP. It was very, very clunky, very, very basic.
Cara Santa Maria: It was clunky and basic, but it worked. Dana could now go to sleep confident that if her sugar levels crashed over night, she would wake up. In hindsight, the ineffective alarm on Dana's CGM was a good thing because in solving that problem, she and Scott had liberated the data and started their journey towards an automated system.
Cara Santa Maria: When Dana and Scott built that web interface to manage their new alarm system, they also included some digital buttons that allowed Dana to enter her response to the alarm, whether she took insulin, drank juice, or did nothing.
Dana Lewis: Because I was the world's best trained guinea pig at entering all my data in real time and we had access to the real time CGM data, we were able to build a really simple algorithm that tied in the timing of the insulin activity, but with the positive insulin activity and the negative insulin activity and forecast that out to the future along with the trend of the blood glucose to predict in the future what would happen.
Cara Santa Maria: It took a while before she could trust the system.
Dana Lewis: I remember it would tell me, hey, you need four carbs and I'd look at say no way. I need 15 carbs, no question. I would do 15 carbs and I would have a rise and I'd be like yeah, the system was right, I needed more like four carbs.
Cara Santa Maria: The algorithm was predictive and as a result, preventive.
Dana Lewis: We were able to build some really specific time alerts where it would say you're predicted to go low in 62 minutes but if you take four grams of carbohydrates right now, you will prevent that low from happening or make it less severe and then the data would feed back into the system every five minutes. It would rerun the algorithm, rerun the predictions and make new recommendations if needed.
Cara Santa Maria: Data to hack the alarm system, then data to build an algorithm. Dana and Scott were now using an iterative process. Build, test, and repeat.
Dana Lewis: I think I first learned HTML in order to make better web buttons, then we learned some PHP to help with the algorithm. It was both. We each had little bits of technical background. We had some experience with programming and building things, but we both had this mindset of we're gonna go learn what we need to do to solve a problem.
Dana Lewis: This was a huge step forward. It woke me up at night, it helped me, it cut down on the number of lows and highs I was having and I thought it was fantastic.
Cara Santa Maria: Their predictive algorithm is a huge step forward, but there's still one thing missing.
Dana Lewis: It wasn't until a couple of weeks or months later that a lightbulb really went off and we said, wait a second. The system we have right now still requires a human in the loop. It still requires me to do work.
Cara Santa Maria: Actually, let me rephrase that. There's still one thing present: Dana. Dana's still in the middle of all this.
Dana Lewis: It doesn't require as much of that mental manual calculation because the computer does the calculation but what if we replaced me as much as possible?
Cara Santa Maria: What Dana means is taking an open loop system and totally removing herself. Create a closed loop system.
Dana Lewis: If it predicts that my blood sugar's gonna go high or low, why don't we actually convert that into a recommendation for the insulin pump and say you need more or less insulin, get the insulin pump to do that delivery modification and read that back into the system.
Cara Santa Maria: Dana goes to a diabetes conference and starts telling people she wants to close the loop. She meets a guy named Ben West who's going after the same problem but from the other direction.
Scott Leibrand: What Ben figured out was he could communicate with the insulin pump to both read information about what insulin had already been dosed, also to read information about what the settings were in the pump, and most importantly, he figured out that you could remotely control the pump.
Cara Santa Maria: That was the missing piece, the connection between Dana's insulin pump and her predictive algorithm.
Scott Leibrand: They had a little USB stick that you would stick into your computer and it would communicate with the pump over that USB stick so that doctors could pull reports every time you went into the doctor's office.
Cara Santa Maria: Just like with the CGM.
Scott Leibrand: That same radio communication, using that same USB stick that the manufacturer gave out with the pumps could be plugged into a Raspberry Pi and then Ben's software could run on the Raspberry Pi and allow us to send these remote control commands to the pump.
Cara Santa Maria: Raspberry Pi. It's a small, inexpensive, single board computer.
Dana Lewis: We learned some Python to really understand what Ben was doing with the device driver and then we had the Raspberry Pi with the radio stick pulling data from the glucose monitor every five minutes, reading from the insulin pump every five minutes, doing the math, deciding what needed to be done, sending the command back to the insulin pump, reading that data, and doing it over and over again every five minutes.
Cara Santa Maria: Measure, calculate, administer insulin if needed, and repeat. But now, all automated.
Dana Lewis: That's what a closed loop system is, is basically syncing up the data between the pump, the CGM, feeding it in and out of the algorithm.
Cara Santa Maria: If you're a little puzzled about how a young couple in Seattle can create an artificial pancreas but the multi-billion dollar medical industry hasn't yet, you're not alone.
Dr. Anne Peters: The DIY movement is wonderful. To me, it shows me what's possibly. I say, why not experiment? It's your body. But I say experiment safely. I want my patients to tell me what they're doing and I'll work with them.
Cara Santa Maria: That's Dr. Peters again.
Dr. Anne Peters: Honestly, people are asked to be experimenting day in and day out. No doctor is sitting there with you holding your hand. I think Type 1 diabetes is something that people need to be empowered to make their own decisions.
Dr. Anne Peters: Just for the record, the best patients are engineers who live their life with a pattern. The same time, the same thing everyday. That's what Type 1 diabetes loves, but most people don't live their lives that way.
Cara Santa Maria: Dana and Scott build their artificial pancreas rig, connect all the components, and now it's time to test their system. Just picture this. For the first time in years, Dana's hoping to not have to wake up in the middle of the night to deal with her insulin.
Dana Lewis: At a certain point I said, you know what? I'm gonna fall asleep. Scott, you stay awake for a couple hours and wake me up if anything happens.
Scott Leibrand: I did that. I watched the logs and it was working really well and then I went to sleep.
Dana Lewis: In the morning, I woke up and I was like wow, I feel really good. I feel rested in a way that I have not in years. Then I checked my CGM and I said wow, I was in range all night. I remember getting up and asking Scott, okay, I don't remember waking up to the alarms to check it, so you must have set the alarms and checked. Did you?
Dana Lewis: And he was like, no, I let it run and it worked as planned all night long. It even gives me chills thinking about it now because that was the first time in 12 years or so that I didn't have to do the decision making related to my diabetes and what was gonna happen to my body.
Dana Lewis: Somebody has described the way we work as intuitive engineering. It doesn't have to be fancy. It doesn't have to be rocket science. It just has to work. It doesn't have to be pretty and that's kind of the design principles that we use along with iteration to make those small steps.
Dana Lewis: Both Scott and I would work together very, very closely and fill in each other's gaps in terms of technical knowledge or diabetes knowledge or our vision for how something would work.
Cara Santa Maria: Dana getting a good night sleep is great. But with over a million Americans managing Type 1 diabetes the old way, you know there's a bigger picture to all this.
Dana Lewis: We worked with Ben to basically figure out a way to take all of this code, both the device toolkits and the decision making algorithm and write up our safety design that we called our reference design of how we implemented the algorithm and present that to the world as an open source project we called Open APS which stands for the Open Source Artificial Pancreas System.
Cara Santa Maria: Thanks to Open APS, over 900 people have now built their own artificial pancreas and Dana continues to tweak how they can use their data to treat their diabetes, thanks to a visualization app called Nightscout.
Dana Lewis: When you add in Nightscout, it's not only a remote visualization of those as concrete things but it's a really nice useful visual for real time and retrospective look back at all of that information.
Dana Lewis: Then, when you added an Open APS rig, because it's reading the data from those two different sources, it's also doing a series of calculations and it's saying here's what the blood sugar is predicted to be into the future based on these different factors.
Dana Lewis: Here's what happens if your food goes away because you throw up or because you start walking and your digestion slows. Here's what happens if the current trend continues, et cetera. It does predictions about the blood sugar. It does calculations about how your insulin sensitivity is changing over time if you enable that feature in Open APS. We've got a bunch of advanced features that will basically say, hey, we know your insulin sensitivity is not static. It changes throughout the day.
Cara Santa Maria: Dana isn't done. She's now looking for ways to compile data from all those users so that researchers can make use of it. Open APS members can upload their anonymized data through something called Open Humans. But ...
Dana Lewis: A lot of the researchers are not familiar with the data formats that we use such as JSON. When the data comes down from Nightscout, it's giant gzipped JSON files, so I had to figure out how to help people convert this to something they could use like CSV to open in Excel.
Dana Lewis: It actually turns out that that was a more complicated problem than you'd expect. If you go search for JSON ...
Cara Santa Maria: But that was just another problem Dana Lewis figured out after a good long sleep in.
Dana Lewis: Yes, that was one of the first things that I did was really, on the weekends, I didn't wanna wake up, I didn't have to wake up and I got 12, 14 hours uninterrupted sleep.
Cara Santa Maria: Okay, you've been listening to Fixed That For You by Segment, a brand new podcast about challenging problems solved with data and algorithms. If you wanna find out more about Dana's story and Open APS, check the show notes. You can find us at segment.com/podcast and subscribe at Apple Podcast, Google Podcasts, Spotify or wherever you do that sort of thing.
Cara Santa Maria: We drop a new episode every two weeks. I'm Cara Santa Maria Santa Maria. Thanks for listening.