The Pocket Doc insulin calculator of 1985

Recently, I recreated the original Pocket Doc insulin calculator created way back in 1985 by Dr. Jovanovič (who I work with), Dr. Peterson, and Chanoch. Part of my continuing study of diabetes and partly a programming exercise, it’s reminded me how truly remarkable the advancements in diabetes management have been in the last few decades.

I’m lucky to be working at Sansum Diabetes Research Institute in Santa Barbara, where many breakthroughs in diabetes have happened over the years. In 1922, Dr. William Sansum administered insulin to the first American patient; some of the first insulin pumps were distributed here in the 1980s; we held some of the first continuous glucose monitor trials in the 2000s (and there are others I don’t know about, I’m sure). Our director is Dr. Lois Jovanovič, a titan in the world of diabetes care and who pretty much pioneered our study of gestational diabetes.

Dr. Jovanovič wasn’t at Sansum quite yet when she developed the Pocket Doc. In the 1980s, insulin pumps were just arriving; people were getting used to measuring blood glucose by fingerstick instead of urine. Diabetics still took two injections of long-acting insulin per day and maybe added a “bolus” dose per meal to account for the extra sugar from food. However, dosing was predetermined by doctors during office visits and had almost no bearing on the multitude of factors that diabetics today consider. The Pocket Doc was the first step toward self diabetes management, and it enabled patients to carry around with them cutting edge knowledge about insulin dosing.

pocket doc
a vintage pocket doc

It was a little pocket calculator reprogrammed with little protocols for personalized insulin bolus calculation. You could set it up with your weight, gender, and insulin sensitivity. It even asked for your name to personalize some messages (i.e. one message, but that’s okay)! Then, when mealtime came, you would do a fingerstick, type in your current blood glucose measurement, and the Pocket Doc would tell you, accurate to one decimal point, how many units of insulin to inject. And if you wanted, you could check in between mealtimes and, based on your blood sugar, it would tell you if you needed more insulin or if you needed to eat something to raise your blood sugar out of the dangerous range. It could count how many tests you’ve done in the past and the amount of insulin you’ve injected since you’ve turned on the system. This was the formula for bolus calculation:

bolus = 10 * adjustment * carbs * sensitivity / gender_coeff + (0.005143 * glucose – 0.48) * sensitivity * weight
sensitivity = 0.136 during the day, 0.17 between 4 am and 10 am
adjustment = .2533 + glucose / 187 from earlier blood measurement
gender_coeff = 12.7 if male, 11.34 if female

For 1985, it was amazing! Seriously, for us to know that males needed more insulin, that the “dawn phenomenon” makes us less sensitivie when waking up, and that there is a linear term and a constant term to carbohydrates… all this was remarkable.

But now, if a young diabetic today read that, they would be pretty disappointed. The bolus/rescue carb cutoffs were blindly preset at 70 and 111, too. These days, all of those are standard procedure, and bolus wizards and insulin pumps these days have fancier systems for calculations that account for periodic trends, insulin on board, and more. I mean seriously, you had to tell the Pocket Doc what time it was! Amazing how far technology has come, right? In fact, we at Sansum are developing an artificial pancreas system where a diabetic will just turn on an ultra-smart computer program that takes glucose measurements and decides on insulin dosage by itself. Now that will be awesome.

aww yeah, look at that periodic trend on the CGM.
modern tech. aww yeah, periodic trends on that CGM.


Anyway, I recreated it in python (2.7), and you can find it here! It’s a short 200-line program that interacts via the command line. In 1985, it was first implemented as a Basic program and described in this paper, but I remained faithful to almost every quirk, like the awkward “Y”/”N” confirmations.

This was a particularly fascinating endeavor for me because it let me go back to see what the programming style was like almost 30 years ago. I’m glad that we, as a programming culture, has gotten through using GOTOs (well, it still exists in assembly and stuff), because after wading through the maze of GOTOs, I found what I’m pretty sure was a bug in control flow. If you input a 0 blood glucose in any method, such as between-meal calculation or next bolus adjustment, it will input the sentinel value 93.33 and redirect you to the meal bolusing method. Oops?

Sorry I can’t let you play with it yourself on the browser. It’s kind of messy trying to imitate something like a command line in ajax, and it feels backwards going my way to emulate something this basic in complicated ways. I’d rather continue working on the artificial pancreas algorithms!