nightscout / nightguard

iOS and WatchOS Client for the Nightscout CGM System
GNU Affero General Public License v3.0
238 stars 158 forks source link

Apple Health integration #101

Closed derivadow closed 1 year ago

derivadow commented 4 years ago

Would be helpful / reduce the need for multiple logging of the same data to integrate carb and insulin data from Health kit.

dhermanns commented 4 years ago

Hi Tom!

I‘m using AAPS. And that‘s already tracking Carbs and Iob. So I‘m not sure what the benefit in that case is. AAPS is a game changer and I would recommend it for everyone who has a chance to get it up and running.

Tom Scott notifications@github.com schrieb am Mi. 29. Juli 2020 um 23:41:

Would be helpful / reduce the need for multiple logging of the same data to integrate carb and insulin data from Health kit.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nightscout/nightguard/issues/101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYPBFNUQDCCYSIEOCLFFQ3R6CJQBANCNFSM4PMDNA7A .

derivadow commented 4 years ago

Hi, I'm not sure I know the answer to that (only developed T1DM last year so still working out both my own chemistry and the technology to help)... is AAPS AndroidAPS?

If it is then the AppleHealth integration is helpful for: people using iOS and if you're not using a closed loop system (they scare me a bit). Sorry is wrong end of stick.

From my perspective I end up using a few apps to manage different aspects; AppleHealth provides a useful app independant data bridge + reduces my data reliance on any one app.

dhermanns commented 4 years ago

Yes - its Android APS. Don‘t be scared. Aaps comes close to a cure of T1D. It woth a million. You won‘t need anything else anymore. Runs absolutely amazing!!

Tom Scott notifications@github.com schrieb am Mi. 5. Aug. 2020 um 18:57:

Hi, I'm not sure I know the answer to that (only developed T1DM last year so still working out both my own chemistry and the technology to help)... is AAPS AndroidAPS?

If it is then the AppleHealth integration is helpful for: people using iOS and if you're not using a closed loop system (they scare me a bit). Sorry is wrong end of stick.

From my perspective I end up using a few apps to manage different aspects; AppleHealth provides a useful app independant data bridge + reduces my data reliance on any one app.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/nightscout/nightguard/issues/101#issuecomment-669310217, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYPBFPG4D5MFJLLX3QAISLR7GFPHANCNFSM4PMDNA7A .

tromanisagit commented 4 years ago

I too use apple healthkit to log carbs and insulin.
I actually use a apple shortcut to ask me various questions then log the carbs or insulin to healthkit, calendar (an event with the correct duration for the carb or insulin) and log to nightscout.

My request would be to either read healthkit data or display the nightscout treatment data or both!

Fab app.

JohnKitching commented 3 years ago

I'd find integration with Apple Health useful. I use AAPS but that and Dexcom are all my Android does. Everything else is Apple. I've been using Spike and Loop on my iPhone to enter carbs on my watch (Loop) and display BG (Spike). I'm in the process of dropping both of them in favour of NightGuard but not having carbs written to Health feels like a loss of functionality. In my perfect world NightGuard would sync carbs and insulin between Health and Nightscout.

dhermanns commented 3 years ago

What is the benefit of having these data in Healthkit?

JohnKitching commented 3 years ago

Can't speak for anyone else but for me ...

Having all health data in one place. Not having to go to Health for heart rate, fitness etc then NS or AAPS for carbs and insulin. Being able to see BG against activity ... was that hypo due to activity? It also opens the data up to other apps to analyse.

derivadow commented 3 years ago

Healthkit integration reduced the need to enter some data multiple times + provides additional data that is collected automatically. Healthkit acts as a data bridge much like Nightscout acts as a data bridge but for different albeit overlapping data.

For me it would provide data on: exercise, food (carbs, fat, protein etc.), insulin delivery etc... so generally it would massively reduce the burden + provide valuable data. As it stands I don't/ can't practically access much of the Nightscout functionality because of this.

I can't speak to AAPS, I don't use it nor do I use a pump and I suspect that's true for most people.

themartorana commented 2 years ago

For me, Apple Health access would allow a bunch of disparate data to sync with Nightscout. For instance, InPen writes to Apple Health, as does Dexcom, as does Dario. InPen and Dario do not integrate with Nightscout at all, but I would love those readings (and especially bolus and basal events) to be uploaded to Nightscout. Apple Health is an on-device collector of diabetes app data. Tidepool has done this very thing with their app to get access to data it doesn't have permissions to directly.

sebdei commented 2 years ago

I agree that the integration with Apple Health would be a nice feature. The reasons have already been mentioned. Therefore, I created a PR in #183.

timoschlueter commented 2 years ago

This is huge! Great work @sebdei. Since this is merged: When will it roll out to the App Store version? :)

dhermanns commented 2 years ago

Still having problems uploading it to the appstore. But I think a testflight should be available next week.

dhermanns commented 2 years ago

A testflight is ready now:

https://testflight.apple.com/join/Ub8WcpcE

Turns out that the feature has to be disabled to be enabled ;-). So if you disable the radio button, health sync should work.

sebdei commented 2 years ago

You have to enable it in order to activate it. It's not enabled by default.

IMG_0789293BC6B9-1

The radio button reflects the auth state of apple health. When at some point the user has denied access in Apple Health the button is set to false.

dhermanns commented 2 years ago

In my case I had to set it to disabled. When doing so, the question to enable health access popped up. When enabling it, it stopped syncing.

So looks wrong in my case.

sebdei commented 2 years ago

Interesting. Let's see if others will report on this.

BTW: Thanks for the deployment on testflight :-)

dhermanns commented 2 years ago

No problem. Thanks for your great contribution!

dhermanns commented 2 years ago

This way it seems to work for me: https://github.com/nightscout/nightguard/commit/d9f06db0dc8ce4d76123943c57253d2b5d38a3ae

sebdei commented 2 years ago

After your change a new user is not able to click on the switch due to the fact, that !AppleHealthService.singleton.isAuthorized() would evaluate to true -> The button is disabled, hence the user can not request the authorization and is not able to sync at all. (Which holds true after testing).

Please let me propose a new solution: https://github.com/sebdei/nightguard/commit/3c18bd672231b77c626369565463db3e75084d26

This would not disable the button and the switch would simply switch back to true with a hint, that the user has to disable the feature in Apple Health directly.

If you're agree, I can simply hand in another PR or you can simple copy paste it from my commit.

In any case: Sorry for the inconvenience. I've not worked with ios and swift before ;-)

dhermanns commented 2 years ago

Hi Sebastian! Already noticed that. Sounds great.

JohnKitching commented 2 years ago

I've just turned on integration. Thank you for your efforts. However, I seem to be getting mg/dl written as mmol/L image

dhermanns commented 2 years ago

I'm writing mg/dl, too. But it's displayed in health just fine!?

JohnKitching commented 2 years ago

I'm in mmol everywhere. It appears to be just the numbers written Health that aren't. image image

dhermanns commented 2 years ago

Ah ok. So it seems that mmol isn't working at all right now with health integration.

JohnKitching commented 2 years ago

I think (but I'm not certain) Health is receiving the right BG but it's in the wrong units.

sebdei commented 2 years ago

The Health Integration uses the unit set in the settings (which is determined automatically). Do the values in the cache or from nightscout have to be converted again @dhermanns ?

dhermanns commented 2 years ago

Yes - like nightscout, all values are kept internally as mg/dl.

sebdei commented 2 years ago

Ah ok. Didn't know that.

JohnKitching commented 2 years ago

I once had a bit of a play with sending data to Health and I seem to recall you could specify the units you're sending. Is it possible you just need to tell health you're sending mg/dl rather than trying to convert the data?

sebdei commented 2 years ago

yeah sure, I could specify the unit hardcoded and set it to mg/d. But then you would see your data in mg/dl in health too which is not not your desire, isn't it?

sebdei commented 2 years ago

186 should do the trick.

Honestly, I did not test it for mmol. It worked for mg/dl and since it just takes your function @dhermanns I'm certain it will work :-)

JohnKitching commented 2 years ago

yeah sure, I could specify the unit hardcoded and set it to mg/d. But then you would see your data in mg/dl in health too which is not not your desire, isn't it?

I'm not sure that's the case. I just manually changed units within Health and it did a conversion.

dhermanns commented 2 years ago

@sebdei : Thanks for the quick PR. New TestFlight will be ready soon...

sebdei commented 2 years ago

I'm not sure that's the case. I just manually changed units within Health and it did a conversion.

ahhhh that is a good point and also good to know! Apple Health is not that dump as I thought :-D Anyways, from a users perspective, it's better to provide the correct unit and format up front, so she/he do not have to switch in Apple Health. Thank you!

@sebdei : Thanks for the quick PR. New TestFlight will be ready soon...

You're welcome. Thanks!

dhermanns commented 2 years ago

New TestFlight is ready now. Let us know whether it is working now ;-)

JohnKitching commented 2 years ago

New version works perfectly. Thanks both of you. image

dhermanns commented 2 years ago

Great teamwork. #wearenotwaiting

sebdei commented 2 years ago

Awesome 👍

rubicon commented 2 years ago

This is a great TestFlight, thank you. Any plans to allow it to read from HealthKit other attributes into NightScout (e.g. Insulin, Carbs, etc)?

I know, users are never satisfied. 😁

sebdei commented 2 years ago

This is a great TestFlight, thank you. Any plans to allow it to read from HealthKit other attributes into NightScout (e.g. Insulin, Carbs, etc)?

I know, users are never satisfied. 😁

In general it seems a good idea. However, reading HK data requires additional permissions from the user. Currently, NG requires write permissions and IMHO we should only obtain permissions that are really useful. Moreover, reading data from HK and hence syncing in both directions may increase complexity.

Which apps are you using to log your carbs and insulin? Maybe it might be better to log the directly in NG?

dhermanns commented 2 years ago

Apple Health Update will be available in App Store soon. I suggest to close this. If more features should be implemented, please open a more specific ticket for that.