Skip to content

Instantly share code, notes, and snippets.

@mgranberry
Last active August 29, 2015 14:20
Show Gist options
  • Save mgranberry/6db8f728cb8390d294c6 to your computer and use it in GitHub Desktop.
Save mgranberry/6db8f728cb8390d294c6 to your computer and use it in GitHub Desktop.
Proposed protocol buffer spec for NightScout treatment data
option java_package = "com.nightscout.core.model";
option java_outer_classname = "Treatment";
// This is a naive conversion of NightScout's current treatments to protocol buffers
message Treatment {
optional EventType event_type = 1;
optional string entered_by = 2;
required string created_at = 3;
optional float insulin = 4;
optional int32 prebolus = 5;
optional float glucose = 6;
optional GlucoseUnit glucose_unit = 7;
optional GlucoseType glucose_type = 8;
}
// support enums for current treatments
enum EventType {
BG_CHECK = 0;
SNACK_BOLUS = 1;
MEAL_BOLUS = 2;
CORRECTION_BOLUS = 3;
CARB_CORRECTION = 4;
NOTE = 5;
QUESTION = 6;
EXERCISE = 7;
PUMP_SITE_CHANGE = 8;
DEXCOM_SENSOR_START = 9;
DAD_ALERT = 10;
BASAL_DOSE = 11;
TEMP_BASAL = 12;
}
enum GlucoseUnit {
MGDL = 0;
MMOL = 1;
}
enum GlucoseType {
FINGER = 0;
SENSOR = 1;
}
// support enums/messages for proposed model
enum Insulin {
HUMALOG = 0;
LIPROLOG = 1;
NOVOLOG = 2;
NOVORAPID = 3;
APIDRA = 4;
NOVOLIN_R = 5;
HUMALIN_R = 6;
ACTRAPID = 7;
INSUMAN_R = 8;
GENSULIN_R = 9;
U_500 = 10;
REGULAR = 11;
AFREZZA = 12;
LEVEMIR = 13;
NOVOLIN_N = 14;
HUMALIN_N = 15;
LANTUS = 16;
NPH = 17;
NOVOLOG_30_70 = 18;
NOVOLOG_50_50 = 19;
NOVOLOG_70_30 = 20;
NOVORAPID_70_30 = 21;
NOVOLIN_70_30 = 22;
NOVOMIX_30 = 23;
NOVOMIX_50 = 24;
NOVOMIX_70 = 25;
PROTAPHANE = 26;
TRESIBA = 27;
RYZODEG = 28;
INSUMAN_N = 29;
GENSULIN_N = 30;
INSULATARD = 31;
}
message BolusCalculatorResult {
optional float glucose = 0;
optional GlucoseUnit glucose_unit = 1;
optional int32 carbohydrates = 2;
optional float insulin_on_board = 3;
optional float total_recommendation = 3;
optional float correction_recommendation = 4;
optional float carbohydrate_recommendation = 5;
optional float isf = 6;
optional float carbRatio = 7;
optional float bgTarget = 8;
}
message Location {
optional float latitude = 0;
optional float longitude = 1;
optional string name = 2;
optional string id = 3; // I imagine this being useful for, eg, the google places API or Foursquare venues
}
message NutritionInfo {
optional string name = 0;
optional int32 carbs = 1;
optional int32 fat = 2;
optional int32 protein = 3;
optional int32 fat = 4; // perhaps this should be broken out into saturated/unsaturated/{mono,poly}unsaturated because the effect is not the same for all
optional float amount = 5;
optional string measure = 6;
}
message Meal {
required string time = 0;
optional NutritionInfo total = 1;
repeated NutritionInfo items = 2;
optional Location location = 3;
}
message Bolus {
required string time = 0;
optional float requested_normal = 1;
optional float delivered_normal = 2;
optional float requested_extended = 3;
optional float delivered_extended = 4;
optional int32 extended_duration = 5; // msecs
optional float injected = 6;
optional float total = 7;
optional BolusCalculatorResult recommendation = 6;
optional Insulin insulin = 7;
}
message Basal {
required string time = 0;
optional Insulin insulin = 1;
optional float injected = 2;
optional float rate = 3;
optional float temp_rate = 4;
optional int32 temp_duration = 5;
optional int32 temp_percent = 6;
}
@bewest
Copy link

bewest commented Apr 29, 2015

message Unabsorbed {

  optional float amount = 0;
  optional uint32 curve   = 1;
  optional uint32 age      = 2;
}

enum DeliveryType {
  BolusNormal = 0;
  BolusExtended = 1;
  Injection = 2;
  TempBasal = 3;
  // ...
}
message Bolus {
    required string time = 0;
    optional float requested = 1;
    optional float delivered = 2;
    optional uint32 duration = 3; // msecs
    optional Insulin insulin = 7;

    // consider a "joinKey" or something
    optional uint64 joinKey = 20;
    optional DeliveryType operation = 21;

   repeated Unabsorbed iob = 100;

}

message BolusCalculatorResult {
    optional float glucose = 0;
    optional GlucoseUnit glucose_unit = 1;
    optional uint32 carbohydrates = 2;

    optional float total_recommendation = 3;
    optional float correction_recommendation = 4;
    optional float carbohydrate_recommendation = 5;

    optional uint32 isf = 6;
    optional uint32 carbRatio = 7;
    optional BGTarget bgTarget = 8;

    optional uint64 joinKey = 20;

}

message BGTarget {
  optional uint32 low = 0;
  optional uint32 high = 1;
}

@bewest
Copy link

bewest commented May 3, 2015

https://github.com/bewest/openaps-example - here's some raw pump/cgm data :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment