Logging symptoms associated with a medication
Fetch medications and dose events from the HealthKit store, and create symptom samples to associate with them.
Overview
Configure the sample code project
Before you run the sample code project:
Open the sample with the latest version of Xcode.
Set the developer team for the project target to let Xcode automatically manage the provisioning profile. For more information, see Preparing your app for distribution and Preparing your app for distribution.
To play with the sample app:
Launch the Health app on your iPhone, select the Browse tab, and tap Medications.
In the Medications view, add Acetaminophen 500 mg Oral Capsule, Carbinoxamine Maleate Biphasic Release Oral Capsule (10 mg), or Ciprofloxacin Injection 200 mg/20 mL as a sample medication. The sample app associates symptoms with these three medications using their RxNorm codes by mapping the codes to their symptoms in the
SideEffectsdictionary inSideEffects.swift.For each medication, log a dose as taken in the As Needed Medications section. The sample app forms a predicate to only look for doses marked as
taken.Build and run the sample app on the iPhone to see the medication list after providing authorization. Tap a medication to see the most-recent dose event and associated symptoms. When tapping a medication, an additional authorization sheet prompts for authorization to access symptoms data.
To add more medications in the Health app and view them in the sample app, add their RxNorm codes to the
SideEffectsdictionary, along with their associated symptoms. For instance, for piroxicam, the RxNorm code is 105929, and the symptoms can be headache, loss of appetite, and nausea. To view the symptoms, modifySideEffectsby adding the following code:
"105929": [SymptomModel(name: "Headache", categoryID: .headache),
SymptomModel(name: "Diarrhea", categoryID: .diarrhea),
SymptomModel(name: "Nausea", categoryID: .nausea)]Log doses for medications over time, and observe them in the Charts tab of the sample app.