agencyenterprise / react-native-health

A React Native package to interact with Apple HealthKit
MIT License
889 stars 238 forks source link

Support for Reproductive Health #102

Open Johan-dutoit opened 3 years ago

Johan-dutoit commented 3 years ago

It seems Reproductive Health has completely been missed

I'm specifically interested in HKCategoryTypeIdentifierMenstrualFlow but the others missing are

  • HKQuantityTypeIdentifierBasalBodyTemperature A quantity sample type that records the user’s basal body temperature.
  • HKCategoryTypeIdentifierCervicalMucusQuality A category sample type that records the quality of the user’s cervical mucus.
  • HKCategoryTypeIdentifierContraceptive A category sample type that records the use of contraceptives.
  • HKCategoryTypeIdentifierIntermenstrualBleeding A category sample type that records spotting outside the normal menstruation period.
  • HKCategoryTypeIdentifierLactation A category type that records lactation.
  • HKCategoryTypeIdentifierOvulationTestResult A category sample type that records the result of an ovulation home test.
  • HKCategoryTypeIdentifierPregnancy A category type that records pregnancy.
  • HKCategoryTypeIdentifierSexualActivity A category sample type that records sexual activity.

I don't have much experience with Health Kit, but if someone can guide me on one, I can use that as a template for the rest.

fakeheal commented 3 years ago

Hello,

I started adding these data types to the package, however I cannot find any information as of why Apple allows only writing to Health for those data types.

What is your use case? Have you came across information as to why you can't read these data types from Health?

Johan-dutoit commented 3 years ago

Hey @fakeheal, I completely skipped checking PR's to see if someone has implemented this yet (my apologies).

My use case, is that I'm working on a fitness app that takes a users cycle into consideration. My guess was I had to query HKCategoryTypeIdentifierMenstrualFlow.

Based on https://github.com/skooal/HealthKitUsageDemo, it seems that it is readable?

Johan-dutoit commented 3 years ago

If it helps, here's the code

https://github.com/skooal/HealthKitUsageDemo/blob/91d77101d508774b9220a6b3f1fb51d5c5429105/skoal/skoal.m#L824-L841

fakeheal commented 3 years ago

Thank you so much for the clarification, @Johan-dutoit! Silly me, I have added the permissions in the getWritePermFromText, but not in getReadPermFromText in RCTAppleHealthKit+TypesAndPermissions.m.

I have fixed that mistake in my fork @ support-for-reproductive-health and I have added two methods:

You can test my changes by adding, my repo+branch as dependency in your project:

yarn add https://github.com/fakeheal/react-native-health#support-for-reproductive-health

I am fairly new in this as well, but if you follow my commits and the changed files in them, you can see the "steps":

In the example repository, go to example/ folder and do yarn add ../../react-native-health, this will add your local folder as dependency. Then you can edit files in react-native-health (and use git to keep track of your changes) and then do yarn add again, to update your example repository and build the app in xcode.


Also, this is my code that you can use to test the methods I added: App.tsx

Johan-dutoit commented 3 years ago

I'm going to give this a go right now, thanks for your efforts!

Johan-dutoit commented 3 years ago

Here is what I managed to do

After some testing, I got the following feedback

Missing types

Other

fakeheal commented 3 years ago

Hey, @Johan-dutoit,

Successfully queried data (well, I got an empty array), Successfully requested write permission (although couldn't find the write function, I was only going to use it to insert test data, used the health app to add test data instead)

You can add data manually using the Health app, to see if its fetched properly. Write functions are yet to be implemented, so this is the only way to add data right now (or use another app that writes those data types).

Missing types, Reproductive Function types, etc...

I think those are missing, because package's js/ts is yet to be bundled.

Johan-dutoit commented 3 years ago

I can confirm nothing but success for what I've tried. Thanks.

fakeheal commented 3 years ago

I am glad it works! Thank you for testing!

What other data types are you using in your project? Maybe we can split the work on adding the other functionality related to Reproductive Health? I can add methods for adding data for HKCategoryTypeIdentifierMenstrualFlow, so you can see it and use as template?

Or you can help with testing the methods I add?

Johan-dutoit commented 3 years ago

At the moment it's purely HKCategoryTypeIdentifierMenstrualFlow, however I'm more than happy to split it up once you have a template in place?

abarisic86 commented 2 years ago

@Johan-dutoit @fakeheal is there an update on this topic? is there a plan for it to be integrated at some point?

NTag commented 2 years ago

Hello 👋

For an app I did (My PrEP) I would also be very interested in being able to write sexual activity to Apple HealthKit 🙏 .

Thanks!

LuisDanielCova commented 3 months ago

Hello, I actually require this data type for my app.

Is the suggested method here the current solution? Or are there any plans to add it to the current library.

@GGGava @Johan-dutoit @fakeheal