Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions: Insulin Treatment Protocols + Reminders #718

Closed
Seithx opened this issue Dec 19, 2018 · 28 comments
Closed

Suggestions: Insulin Treatment Protocols + Reminders #718

Seithx opened this issue Dec 19, 2018 · 28 comments

Comments

@Seithx
Copy link

Seithx commented Dec 19, 2018

Hi,

Currently, there's only an option for putting one type of insulin, but if we allow for more, we can make xdrip predict blood sugars better. For example, there's a difference between Actrapid which is a regular and Humalog/Novorapid, which is a fast acting insulin.

Also, I always seem to get stuck without any sensors (libre system), due to the fact it doesn't give out any reminders / warning on the last day, for example.

On the reader itself, on the last day, it reminds you with every check (if I remember correctly, it's been awhile) on the last day. Maybe we can copy that feature in as well.

Just a thought,

thanks :)

@ANDREAPIPPI
Copy link

ANDREAPIPPI commented Dec 19, 2018

Hi.
Times ago I asked for the reminds of the Libre life (and the Bluereader life too, BTW) last two (one?) days, but without results, so I agree with Seithx's new request.
Even more I agree on the different Insulin types input.
Actually. I'm using FIASP Ultrarapid insulin instead of former Novorapid, and Fiasp starts working faster than Novorapid, giving incorrect results in blood sugar forecasts, so I think it could be very useful to add in xDrip+ the curves of the 5 (?) different types of available insulin, e.g. ultraslow (Tresiba?) , slow (Lantus?), normal (Lyspro?), rapid (Novorapid?), ultrarapid (Fiasp?).
Something like this...
image
Just a thought.
Pippo :-)

@Seithx
Copy link
Author

Seithx commented Dec 19, 2018

Glad to see other people think the same.

Eventually, we want to be able to rely / improve upon and create a better prediction mechanism so we can utilize the sensors to their best of their ability.

I'm not sure how the prediction mechanism works, but maybe the system can create averages and correlate them with the information put in, for example, Trebisa 11 units, then it creates an average of blood sugar levels, added physical activities to create a very accurate prediction model based on blood sugar levels in the following month.

So, yes, putting the different insulin types is a step towards a very accurate prediction, heck, if we could use Machine Learning (going far perhaps) and get like a big pool of users uploading their data with their full protocols (insulins used, sport activity done, food eaten) we could create something very amazing.

@stefanchavdarov
Copy link

+1 vote for the insulin types diff
+1 vote for the sport activity, start time + duration in add, new tab
+1 vote for diff food types - rapid (sugar), normal, slow (pizza)
and a better clock at 'when' tab

@Seithx
Copy link
Author

Seithx commented Dec 20, 2018

So, when is this going to be worked?

@doc77
Copy link

doc77 commented Dec 29, 2018

#706 also requests this enhancement.

@ANDREAPIPPI
Copy link

ANDREAPIPPI commented Jan 25, 2019

Reading the Novo page regarding the soon available NovoPen Echo Plus, given here
https://diatribe.org/novopen-6-and-novopen-echo-plus-connected-insulin-pens-launch-early-2019
if I understand correctly this pen will inform the related APP of the quantity AND the type of insulin just injected, as they say "will be compatible with both long-acting basal insulin (Levemir, Tresiba) and short-acting mealtime insulin (NovoLog, Fiasp). And supposing that as already done for PendiQ pen, NovoPen Echo Plus will be able to connect with xDrip+, it looks even more important the possibility to evaluate the predicted effect on the basis of the injected insulin type.
This IMO could give a very important addition to the glicemic prediction and treatment.
Opinions? :-)

@gruoner
Copy link
Contributor

gruoner commented Aug 18, 2019

Hi
i started working on this issue and changed the GUI and treatment classes to feed xdrip and nightscout with more than one single type of insulin. Currently lots of insulin profiles can be defined but just max. 3 can be used at the same time - one has to choose at least one up to tree profiles.
#973
BUT currently my change is just the foundation - because i don't know how the different insulin profiles will behave in combination (pippo provided a small picture describing the differences in basis), i just added an abstract compute function to each insulin profile class and someone has to aggregate the multiple injections to a single insulin level and attach the individual absorption rate.

To someone in this forum who is familiar in calculating the curve of different insulin profiles and aggregating different profiles:

  • can you provide a formula to calculate the glucose infusion for the most used insulin profiles (ATC codes
    • A10AC01 (long lasting insulines like insulatard)
    • A10AB01 (short lasting insulines like actrapid but much longer than novorapid)
    • A10AB05 (really short lasting insulines like novorapid but not FIASP)
  • how can we calculate the aggregation of more injections?
    • is it just an addition of the glucose infusions? or
    • do we have to put a (maybe negative) bias on the addition?
  • how do we have to handle the individual absorption rate? Is it quite the same for all profiles or do we have to define a rate for each profile?

@Seithx
Copy link
Author

Seithx commented Aug 18, 2019

Just to get a clearer picture, is Xdrip going to estimate lows / highs using this supposed formula? Why not just let users input whichever insulin they wish and let them handle all the rest?

@gruoner
Copy link
Contributor

gruoner commented Aug 18, 2019

oh yes - the user inputs the type of insulin he has injected and in which dose (done via Home screen and PhoneKeypadInputActivity).
The calculation problem belongs to the prediction logic / algorithm. For now the prediction considers just one type of insulin and i want to change this to x. But the calculation algorithm implemented by @jamorham is really complex and i don't fully understand it nor i can imagine whether we can generalize it to x types of insulin or we have to implement a complete new one.

@Seithx
Copy link
Author

Seithx commented Aug 18, 2019

Can you share @jamorham's calculation scheme here?

hopefully he can elaborate ...

@gruoner
Copy link
Contributor

gruoner commented Aug 20, 2019

OK; now it's getting mathematically....
@jamorham uses a very complicated algorithm (i don't know why but i'm sure he has his needs for that) to calculate an IOB and the currently active insulin dose for 5min wide timeslices.
The result is shows here - i wrote a short excel to calculate the diagram:
diagram
It is a combination of two linear curve

  • starting 10 minutes after injection
  • with a (positive) gain of 0.001852 (don't know how he has choosen this value)
  • reaching its maximum 75 minutes after injection
  • lowing with a negative gain of 0.001323 (also don't know how he has choosen this value)
  • reaching zero 180 minutes (3 hours) after injection
    When i compare this curve with the picture provided by @ANDREAPIPPI it seems to approximate a lispo aspart profile....

BUT this doesn't tell me anything who to handle other insulin profiles and how to combine simultaneous injections of diverged insulin types.
After reading the "timeslicewriter" i can imagine to simply add the active insulin dose (jActivity) of all (active or contributing) insulin injections (of diverged insulin types) at a dedicated timeslice (because jActivity is the first derivation of IOB and the first derivation of a sum if equal to the sum of the first derivations of the summands). BUT this approach should be verified by @jamorham.....

@gruoner
Copy link
Contributor

gruoner commented Aug 23, 2019

OK; as no one replies to my thoughts i will start implementing curves like those in the picture provided by @ANDREAPIPPI and simply add the IOB and activity for a given time slice.
@jamorham or any other contributor in this forum: correct me or intercept me when i bark up the wrong tree!

@gruoner
Copy link
Contributor

gruoner commented Aug 25, 2019

after some google'ing around i found out that all insulin profiles (except the composition insulin types) can be approximated to just one kind of curve:

  • after a dedicated amount of time it starts its activity (lets call this period "onset") and this period is just a timeshift so that our calculation can start at timestamp 0
  • then a linear ramp up starts until the insulin reaches its max activity (lets call this timestamp "t1")
  • the max activity will be hold for a dedicated period of time (lets call this timestamp "t2")
  • after leaving the max activity level a linear ramp down occurs until the insulin activity reaches its end (lets call this timestamp "t3")

Now its just mathematics (i wrote a short maxima script to calculate a dedictated insulin profile)
t1:75;
t2:75;
t3:180;
max:2/(t2-t1+t3);
IOB1(x):=1-max/(2t1)xx;
IOB2(x):=1+max
t1/2-maxx;
IOB3(x):=max/(2
(t3-t2))*(x-t3)^2;
IOB(x):=if (0<=x and x<t1) then IOB1(x) else if (t1<=x and x<t2) then IOB2(x) else if (t2<=x and x<t3) then IOB3(x) else 0;
dIOB1(x):=''(diff(IOB1(x), x, 1));
dIOB2(x):=''(diff(IOB2(x), x, 1));
dIOB3(x):=''(diff(IOB3(x), x, 1));
dIOB(x):=abs(if (0<=x and x<t1) then dIOB1(x) else if (t1<=x and x<t2) then dIOB2(x) else if (t2<=x and x<t3) then dIOB3(x) else 0);
wxplot2d([IOB(x)], [x,-50,230]);
wxplot2d([dIOB(x)], [x,-50,230]);
sum(dIOB(x), x, 0, t3);
That's the insulin profile implemented by @jamorham and it results in the following curves:
IOB:
IOB
Activity:
activity
The last line in the maxima script proves, that the area under the activity is exactly 1.

NOW we can define "onset", "t1", "t2" and "t3" for all required insulin profiles and we will have a calculation schema for xdrip+
I've done this for NPH insulatard:
IOB NPH
activity NPH

The only problem left is how to handle composite insulin profiles as there are so much diverse products on the market we can't add them to a static insulin profiles list......

@gruoner
Copy link
Contributor

gruoner commented Sep 2, 2019

after implementing the new prediction algorithm in xdrip+ i found a serious issue: the predictions weren't correct. Insulin activity seems always to low.
So i reviewed my calculations and found the mistake - my curves are 5 times lower as the original implemented by @jamorham; originally timeslices are 5 minutes wide and mine one minute....
I changed the calculation and now BG predictions seems much more better.

@ANDREAPIPPI
Copy link

Hi gruoner.
As you know I'm very interested to your results, and would like to have more details of the up-to-date situation.
I mean, are you full satisfied of the results?
If yes, as I think, can we test it on our systems, so check its behaviour under many different environments?
Your work is very appreciated, go on this way, please.
Pippo :-)

@Seithx
Copy link
Author

Seithx commented Sep 3, 2019

Sounds very promising, keep up the good work.

@gruoner
Copy link
Contributor

gruoner commented Sep 3, 2019

Hi Pippo,

we use a G6 and had some tests last few days. Now i'm pretty satisfied of the results.
One question is still open:

  • how do we have to handle the individual absorption rates? Can we use the original Sensitivity calculation or do we have to implement dedicated for each insulin profile?

I've checked in the code to my already opened pull request #973 but Travis is failing because of a failed :app:connectedAndroidTest. Maybe someone can help....

@ANDREAPIPPI
Copy link

Hi gruoner.
FWIW, due to the important improvement given by the insulin types differentiation and the use of their own curves, I think that now you should choose the original Sensitivity calculation.
Later on, if any need or problem due to this will should arise, then that will be the time to try a dedicated Sensitivity calculation. My opinion, obviously. Pippo

@gruoner
Copy link
Contributor

gruoner commented Sep 3, 2019

OK; so until someone requests a dedicated sensitivity calculation we will start the tests with the original one.
How can i "repair" the failing Travis CI checks? I haven't changed anything belonging to the test case classes.....

@ANDREAPIPPI
Copy link

Hi gruoner.
Could you please tell me if your improvement #718 has been issued in tonight's 20190907-66c8a5a.apk?
Thank you very much.
Pippo :-)

@gruoner
Copy link
Contributor

gruoner commented Sep 7, 2019 via email

@ANDREAPIPPI
Copy link

Hi gruoner, thank you for the quick reply and the offer, but I'm absolutely out with this job, I'm unable to do anything you suggest, so I'm obliged to wait for a "ready to install" apk release.
Cannot wait for that, and given it is not yet issued, can I ask your opinion on another improvement to the actual Version?
This one:as other people, I suppose, I make two blood tests each day, one in the morning before breakfast, say 8:00 AM, and another before going to sleep, about 1:00 A,M.
The problem is that many many times at those moments the glicemic line is NOT flat, but rising or descending.
My question: could be of interest for other people to have the possibility to set another alarm (too many?) that advises when the glicemic value is flat from ..... say e.g. .20 minutes, so that at that point it's worth making a blood check?
Your opinion, please, thank you very much.
Bye soon.
Pippo :-)

@gruoner
Copy link
Contributor

gruoner commented Sep 8, 2019

Hi Pippo

that's a really good point - as we are using a G6 we don't even really need such calibration points but when we want to calibrate (for whatever reason) we have to find a time period where BG line is mostly flat. So people who rely on such calibrations to get a valuable CGM whey would find such an alarm type very helpful. Is there still an issue open for such requirements / wishes?
But currently i'm not familiar with the BG prediction logic; i have to get a deep dive in the prediction code and the "more-insulin" patch must be completed first to get it in the master branch (there are two issues left - handle pendiq and pen and handle the communication to wearable and watches - and someone must help me to pass Travis CI because the test classes are failing without traceable reasons)

bye
Gruoner

@ANDREAPIPPI
Copy link

Hi gruoner.
I'm happy you too think that this could be an interesting issue, so I'll open it, and let's see what happens and if someone will take care of it.
Bye and thank you once again.
Pippo :-)

@ANDREAPIPPI
Copy link

Hi gruoner.
Just done, it's issue #1006
Bye

Pippo :-)

@ANDREAPIPPI
Copy link

Hi.
Just my opinion, but I think that #302 shoud be merged with this one.
Correct?
Bye

Pippo :-)

@Navid200
Copy link
Collaborator

Duplicate: #531

@Navid200
Copy link
Collaborator

I think the capability to add multiple insulin types already has been added to xDrip.
I am hence closing this issue. Please let me know if you think I have overlooked anything.

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

No branches or pull requests

7 participants