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

Allow to record meal data (macro nutrients) #679

Merged
merged 10 commits into from
Nov 13, 2023

Conversation

biklas7
Copy link
Contributor

@biklas7 biklas7 commented Mar 1, 2023

Closes #680

@JuanFcoRomero
Copy link

Wow! Cool improvement!!! What about read nutrition data? I only can see write that information.

@biklas7
Copy link
Contributor Author

biklas7 commented Mar 1, 2023

Wow! Cool improvement!!! What about read nutrition data? I only can see write that information.

Thanks! Didn't add read support on this pr, but it should be pretty straightforward to do it if you want to contribute as well. I think it's only a matter of adding the nutrition types you want to read and mapping then to units and the package should be able to parse them as numeric health values. What do you think?

@JuanFcoRomero
Copy link

JuanFcoRomero commented Mar 2, 2023

Wow! Cool improvement!!! What about read nutrition data? I only can see write that information.

Thanks! Didn't add read support on this pr, but it should be pretty straightforward to do it if you want to contribute as well. I think it's only a matter of adding the nutrition types you want to read and mapping then to units and the package should be able to parse them as numeric health values. What do you think?

I would love to be able to do that! Unfortunately, I'm a novice programmer and just starting to make my first apps 😔 .

Although I would be very grateful if you could add read and write the whole nutritional topic.

https://developer.apple.com/documentation/healthkit/data_types/nutrition_type_identifiers

@biklas7 biklas7 changed the title Allow to record meal data Allow to record meal data (macro nutrients) Mar 2, 2023
@biklas7
Copy link
Contributor Author

biklas7 commented Mar 2, 2023

I would love to be able to do that! Unfortunately, I'm a novice programmer and just starting to make my first apps 😔 .

Although I would be very grateful if you could add read and write the whole nutritional topic.

https://developer.apple.com/documentation/healthkit/data_types/nutrition_type_identifiers

Unfortunately, I don't have the time to add more features right now, maybe you should open an issue with that feature request?

Btw the package already supports reading the macronutrients at least on iOS:
https://github.com/cph-cachet/flutter-plugins/blob/master/packages/health/lib/src/data_types.dart#L15-L18

So it should be easy to add support for more types based on the existing code if you have time even if you're a novice... Just take a look at the source code 😉

@JuanFcoRomero
Copy link

I added it a month ago...

Thank you for that link. I see, so only needs to add the micronutrients.

Thank you for your time!

@biklas7
Copy link
Contributor Author

biklas7 commented Mar 2, 2023

@JuanFcoRomero you can see how those were added in the past: 668b419 and that should give you an insight on how to add more.

If you want to also take a look, for Android/Google Fit it works a bit different. There's only one type TYPE_NUTRITION that should give you all the nutrients. Check the docs Read food items eaten and Read Aggregate Daily Nutrition Data.

If you add more don't forget to contribute and open a pull request 👍

@JuanFcoRomero
Copy link

@JuanFcoRomero you can see how those were added in the past: 668b419 and that should give you an insight on how to add more.

If you want to also take a look, for Android/Google Fit it works a bit different. There's only one type TYPE_NUTRITION that should give you all the nutrients. Check the docs Read food items eaten and Read Aggregate Daily Nutrition Data.

If you add more don't forget to contribute and open a pull request 👍

Thank you so much! I will study the code!

@biklas7
Copy link
Contributor Author

biklas7 commented Apr 3, 2023

@MadsVSChristensen sorry to tag you, but just wanted to ask if it's possible to consider this pull request for future releases? Cheers

@hoffmatteo hoffmatteo self-assigned this Apr 9, 2023
@owjoh
Copy link

owjoh commented Jul 4, 2023

Any updates on this?

@hoffmatteo
Copy link
Contributor

Hello @biklas7,

thank you for the PR!
I have taken the PR and changed it a bit, including adding support for HealthConnect. I will push these changes soon, after which it will be included in the upcoming release.

@biklas7
Copy link
Contributor Author

biklas7 commented Sep 1, 2023

Thank you so much @hoffmatteo that's great news! ❤️

I don't want to sound pushy or bite the hand that feeds 😅 but if you could take a look into this one as well #675 it would be awesome! It just adds Insulin data type for iOS (not available for Android) so it's a really small PR and doesn't require too many changes on your side (I think) 🙏

This way we could stop using our outdated fork and finally use this package to it's full potential 👍

@hoffmatteo
Copy link
Contributor

@biklas7
Sadly I have bad news, due to circumstances out of our control the release will take at least another week or so, once it is done I will update the PR and request your feedback!

@biklas7
Copy link
Contributor Author

biklas7 commented Sep 6, 2023

@hoffmatteo Of course! No rush! Take whatever time you need 👍 The most important thing is that's on the roadmap!

@biklas7
Copy link
Contributor Author

biklas7 commented Oct 18, 2023

@hoffmatteo any idea when it's gonna be possible to close this?

}

if #available(iOS 15.0, *){
let meal = HKCorrelation.init(type: HKCorrelationType.init(HKCorrelationTypeIdentifier.food), start: dateFrom, end: dateTo, objects: nutrition, metadata: metadata)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let meal = HKCorrelation.init(type: HKCorrelationType.init(HKCorrelationTypeIdentifier.food), start: dateFrom, end: dateTo, objects: nutrition, metadata: metadata)
let type = HKCorrelationType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.food)!
let meal = HKCorrelation(type: type, start: dateFrom, end: dateTo, objects: nutrition, metadata: metadata)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discovered a crash on iOS 16 and this fixes it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoffmatteo Please confirm if you don't need this fix. This caused a crash on our fork.

packages/health/ios/Classes/SwiftHealthPlugin.swift Outdated Show resolved Hide resolved
@hoffmatteo
Copy link
Contributor

hoffmatteo commented Oct 23, 2023

@hoffmatteo any idea when it's gonna be possible to close this?

Hi!
Sorry for the long wait, I had to prioritise some other projects and I had to redo large parts of my earlier work due to IT issues.
I am in the finishing phases of getting it ready, I plan on releasing it this week. I will push my changes these days and look at your suggestions as well!

@biklas7
Copy link
Contributor Author

biklas7 commented Oct 30, 2023

@hoffmatteo any idea when it's gonna be possible to close this?

Hi! Sorry for the long wait, I had to prioritise some other projects and I had to redo large parts of my earlier work due to IT issues. I am in the finishing phases of getting it ready, I plan on releasing it this week. I will push my changes these days and look at your suggestions as well!

Hi @hoffmatteo glad to hear you're working on this. If you need something let me know! Hope your changes land soon 🤞

@hoffmatteo
Copy link
Contributor

@biklas7 I just pushed my changes, sorry for the long wait! Please feel free to review them and let me know your thoughts.

packages/health/android/build.gradle Outdated Show resolved Hide resolved
packages/health/example/android/app/build.gradle Outdated Show resolved Hide resolved
packages/health/lib/src/data_types.dart Outdated Show resolved Hide resolved
}

if #available(iOS 15.0, *){
let meal = HKCorrelation.init(type: HKCorrelationType.init(HKCorrelationTypeIdentifier.food), start: dateFrom, end: dateTo, objects: nutrition, metadata: metadata)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoffmatteo Please confirm if you don't need this fix. This caused a crash on our fork.

packages/health/ios/Classes/SwiftHealthPlugin.swift Outdated Show resolved Hide resolved
@biklas7
Copy link
Contributor Author

biklas7 commented Oct 31, 2023

@biklas7 I just pushed my changes, sorry for the long wait! Please feel free to review them and let me know your thoughts.

Thanks, everything looks good to me, I just pointed out a few things for you to double-check before merging this, but other than that, it looks good! Thanks for updating the code and working on this feature 👍

@hoffmatteo hoffmatteo changed the base branch from master to dev-health November 1, 2023 11:58
@hoffmatteo hoffmatteo merged commit a88ba2e into cph-cachet:dev-health Nov 13, 2023
1 check passed
@hoffmatteo hoffmatteo mentioned this pull request Nov 13, 2023
@biklas7 biklas7 deleted the feature/write-meal branch January 2, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants