Skip to content

Instantly share code, notes, and snippets.

@bewest
Last active December 14, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bewest/5011908 to your computer and use it in GitHub Desktop.
Save bewest/5011908 to your computer and use it in GitHub Desktop.

which curves do I need to graph in order to visualize a bolus wizard?

I want to visualize what I believe will happen if I dose some insulin. This means two curves, correct?: a.) insulin action curve, b.) glucose [dis]appearance curve. From what I understand pump therapy exclusively focuses on these? Even though there are other important things happening? Doesn't the bolus wizard use both in order to suggest insulin? IE, the "sensitivity" is a prediction that glucose will disappear at a certain rate, correct? So graphing this is a linear curve? What about calculating remaining insulin, and active lifetime of insulin? From my reading, there are sophisticated functions for this, but graphing it for a bolus wizard should be a straightforward process, or involves a complicated prediction function(Yates-Fletcher)?

Perhaps a simpler question is just which curves do I need to graph in order to visualize a bolus wizard? Is it simply the standard known insulin action curve?

Bolus Wizard Setup

Carb Ratio: 13 grams
Sensitivity: 45 mg/dL
The appearance of insulin into the blood stream (pharmacokinetic) is different than the measurement of insulin action (pharmacodynamic). This figure is a representation of timing of insulin action for insulin aspart from euglycemic clamp (0.2 U/kg into the abdomen). Using this graph assists patients to avoid “insulin stacking”. For example, 3 hours after administration of 10 units of insulin aspart, one can estimate that there is still 40% of the 10 units, or 4 units of insulin remaining. By way of comparison, the pharmacodynamic duration of action of regular insulin is approximately twice that of insulin aspart or insulin lispro. Currently used insulin pumps keep track of this “insulin-on-board” to avoid insulin stacking.

Patients monitoring frequent between-meal glucose levels often learn quickly that if this concept is not appreciated hypoglycemia will result from overly aggressive insulin dosing from the stacking of the insulin. The fundamental problem with this entire strategy of between-meal adjustments from SMBG data is that even if one knows the amount of insulin-on-board, the direction of the glucose (glycemic trend) is not necessarily appreciated. As an example, a patient with a target of 100 mg/dL, an insulin sensitivity factor of 30 (i.e.. 1 unit for every mg/dL above target [in this case 100 mg/dL] and a blood glucose of 250 mg/dL gave 6 units of insulin aspart 2 hours previously. The patient needs to appreciate that well over 3 units of insulin are still active. However, if the meal happened to be a high carbohydrate, low protein/low fat meal, the glycemic trend two hours later is moving quickly downward, and giving the normal correction dose [(250-100)/30]- 3 = 2 units will likely be too much insulin since the glucose is trending down anyway. Often, the actual glycemic trend is not known, making any correction dose insulin difficult to estimate. This is the main advantage of the use of continuous glucose monitors (CGM). By knowing the glycemic trend, it is possible to much more safely add appropriate doses of correction dose insulin between meals.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
path.curve {
stroke: black;
stroke-width: .5ex;
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
<body>
<H1>curves</H1> (probably incorrect)
<script src="http://d3js.org/d3.v3.js"></script>
<script>
/*
http://dtc.ucsf.edu/types-of-diabetes/type2/treatment-of-type-2-diabetes/medications-and-therapies/type-2-insulin-rx/types-of-insulin/#fastacting
Table of Insulin Action
Type of Insulin Onset Peak Duration Appearance
Fast-acting
Regular ½-1 hr. 2-4 hr. 6-8 hr. clear
Lyspro/ Aspart/ Glulisine <15 min. 1-2 hr. 4-6 hr. clear
Intermediate-acting
NPH 1-2 hr. 6-10 hr. 12+ hr. cloudy
Long-acting
Detemir 1 hr. Flat, Max effect in 5 hrs. 12-24 hr. clear
Glargine 1.5 hr. Flat, Max effect in 5 hrs. 24 hr. clear
*/
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 500 - margin.left - margin.right,
height = 420 - margin.top - margin.bottom;
//var x = d3.time.scale()
var x = d3.scale.linear( )
.domain([0, 60*9])
.rangeRound([0, width])
;
var y = d3.scale.linear()
.domain([0, 100])
.rangeRound([height, 0]);
var z = d3.scale.linear()
.domain([0, 160])
.range(["white", "purple"])
.interpolate(d3.interpolateLab);
var formatTime = d3.time.format("%I %p"),
formatHour = function (d) {
return d;
if (d == 12) return "noon";
if (d == 24 || d == 0) return "midnight";
return formatTime(new Date(2013, 2, 9, d, 00));
};
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickFormat(formatHour)
;
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(d3.format("d"));
var svg = d3.select("body").append("svg:svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("svg:g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var line = d3.svg.line()
// .x(function(d) { console.log(d); return x(d.offset); })
// .y(function(d) { console.log(d); return y(d.remain); })
.x(function(d) { console.log(d); return x(d.offset); })
.y(function(d) { console.log(d); return y(d.efficacy); })
.interpolate('monotone')
;
var max = d3.max(x.domain( ));
// var data = fast;
d3.json("insulin.json", function(error, data) {
console.log(data.values);
var curve = svg.append("path")
.datum(data.values)
.attr("class", "curve")
.attr("d", line)
;
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
});
</script>
<p>
Probably incorrect.
The only data I could understand and have access to were simple
tables outlining <tt>onset</tt>, <tt>peak</tt>, and <tt>duration</tt>
events. I guessed at "percentages" roughly using Pareto's 80/20/10
as a guideline, and slapped "monotone" interpolation on the whole thing.
It's wrong, but at least serves as a starting point to correct the
technique.
</p>
{
"name": "fast acting",
"values": [
{ "offset": 0,
"label": "start",
"efficacy": 0
},
{ "offset": 90,
"label": "onset",
"efficacy": 20
},
{ "offset": 180,
"label": "peak",
"efficacy": 100
},
{ "offset": 360,
"label": "tail",
"efficacy": 10
},
{ "offset": 480,
"label": "clear",
"efficacy": 0
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment