From c4572dd0c581997e2ea0b70398b48d2cb515e3b2 Mon Sep 17 00:00:00 2001 From: Kate Callon <70660419+kcallon@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:18:13 -0800 Subject: [PATCH] Task3 (#5) # *Configuring HealthKit Data and Removing Notification Permissions* ## :recycle: Current situation & Problem - The app currently does not request all the health data types needed - The app currently has an onboarding step for notification permissions, which is not required ## :gear: Release Notes - Updated HealthKit configurations to collect allergy, clinical note, condition, coverage, immunization, lab result, medication, procedure and vital sign records. - deleted notification permissions in onboarding ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [ ] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). --- Intake.xcodeproj/project.pbxproj | 4 - Intake/IntakeDelegate.swift | 21 ++++- .../Onboarding/NotificationPermissions.swift | 77 ------------------- Intake/Onboarding/OnboardingFlow.swift | 9 --- Intake/Resources/Localizable.xcstrings | 45 +---------- 5 files changed, 20 insertions(+), 136 deletions(-) delete mode 100644 Intake/Onboarding/NotificationPermissions.swift diff --git a/Intake.xcodeproj/project.pbxproj b/Intake.xcodeproj/project.pbxproj index 31169f8..81ab7a5 100644 --- a/Intake.xcodeproj/project.pbxproj +++ b/Intake.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ 2F4FC8D729EE69D300BFFE26 /* MockUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */; }; 2F5E32BD297E05EA003432F8 /* IntakeDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F5E32BC297E05EA003432F8 /* IntakeDelegate.swift */; }; 2F6025CB29BBE70F0045459E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */; }; - 2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */; }; 2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */; }; 2FB099AF2A875DF100B20952 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099AE2A875DF100B20952 /* FirebaseAuth */; }; 2FB099B12A875DF100B20952 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099B02A875DF100B20952 /* FirebaseFirestore */; }; @@ -101,7 +100,6 @@ 2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUpload.swift; sourceTree = ""; }; 2F5E32BC297E05EA003432F8 /* IntakeDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntakeDelegate.swift; sourceTree = ""; }; 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; - 2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPermissions.swift; sourceTree = ""; }; 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; 2FAEC07F297F583900C11C42 /* Intake.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Intake.entitlements; sourceTree = ""; }; 2FC94CD4298B0A1D009C8209 /* Intake.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Intake.xctestplan; sourceTree = ""; }; @@ -230,7 +228,6 @@ 2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */, 2FE5DC2F29EDD7CA004B9AB4 /* Consent.swift */, 2FE5DC3029EDD7CA004B9AB4 /* HealthKitPermissions.swift */, - 2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */, ); path = Onboarding; sourceTree = ""; @@ -602,7 +599,6 @@ A9FE7AD02AA39BAB0077B045 /* AccountSheet.swift in Sources */, 653A2551283387FE005D4D48 /* Intake.swift in Sources */, 2FE5DC3629EDD7CA004B9AB4 /* HealthKitPermissions.swift in Sources */, - 2F65B44E2A3B8B0600A36932 /* NotificationPermissions.swift in Sources */, 5661552E2AB854C000209B80 /* PackageHelper.swift in Sources */, 27FA29902A388E9B009CAC45 /* ModalView.swift in Sources */, 2FE5DC2629EDD38A004B9AB4 /* Contacts.swift in Sources */, diff --git a/Intake/IntakeDelegate.swift b/Intake/IntakeDelegate.swift index 5c8ab9f..6d7023c 100644 --- a/Intake/IntakeDelegate.swift +++ b/Intake/IntakeDelegate.swift @@ -75,9 +75,24 @@ class IntakeDelegate: SpeziAppDelegate { private var healthKit: HealthKit { HealthKit { - CollectSample( - HKQuantityType(.stepCount), - deliverySetting: .anchorQuery(.afterAuthorizationAndApplicationWillLaunch) + CollectSamples( + [ + HKClinicalType(.allergyRecord), + HKClinicalType(.clinicalNoteRecord), + HKClinicalType(.conditionRecord), + HKClinicalType(.coverageRecord), + HKClinicalType(.immunizationRecord), + HKClinicalType(.labResultRecord), + HKClinicalType(.medicationRecord), + HKClinicalType(.procedureRecord), + HKClinicalType(.vitalSignRecord) + ], + predicate: HKQuery.predicateForSamples( + withStart: Date.distantPast, + end: nil, + options: .strictEndDate + ), + deliverySetting: .anchorQuery(saveAnchor: false) ) } } diff --git a/Intake/Onboarding/NotificationPermissions.swift b/Intake/Onboarding/NotificationPermissions.swift deleted file mode 100644 index ef25899..0000000 --- a/Intake/Onboarding/NotificationPermissions.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// This source file is part of the Intake based on the Stanford Spezi Template Application project -// -// SPDX-FileCopyrightText: 2023 Stanford University -// -// SPDX-License-Identifier: MIT -// - -import SpeziOnboarding -import SpeziScheduler -import SwiftUI - - -struct NotificationPermissions: View { - @Environment(IntakeScheduler.self) private var scheduler - @Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath - - @State private var notificationProcessing = false - - - var body: some View { - OnboardingView( - contentView: { - VStack { - OnboardingTitleView( - title: "NOTIFICATION_PERMISSIONS_TITLE", - subtitle: "NOTIFICATION_PERMISSIONS_SUBTITLE" - ) - Spacer() - Image(systemName: "bell.square.fill") - .font(.system(size: 150)) - .foregroundColor(.accentColor) - .accessibilityHidden(true) - Text("NOTIFICATION_PERMISSIONS_DESCRIPTION") - .multilineTextAlignment(.center) - .padding(.vertical, 16) - Spacer() - } - }, actionView: { - OnboardingActionsView( - "NOTIFICATION_PERMISSIONS_BUTTON", - action: { - do { - notificationProcessing = true - // Notification Authorization is not available in the preview simulator. - if ProcessInfo.processInfo.isPreviewSimulator { - try await _Concurrency.Task.sleep(for: .seconds(5)) - } else { - try await scheduler.requestLocalNotificationAuthorization() - } - } catch { - print("Could not request notification permissions.") - } - notificationProcessing = false - - onboardingNavigationPath.nextStep() - } - ) - } - ) - .navigationBarBackButtonHidden(notificationProcessing) - // Small fix as otherwise "Login" or "Sign up" is still shown in the nav bar - .navigationTitle(Text(verbatim: "")) - } -} - - -#if DEBUG -#Preview { - OnboardingStack { - NotificationPermissions() - } - .previewWith { - IntakeScheduler() - } -} -#endif diff --git a/Intake/Onboarding/OnboardingFlow.swift b/Intake/Onboarding/OnboardingFlow.swift index a4e9210..c36f292 100644 --- a/Intake/Onboarding/OnboardingFlow.swift +++ b/Intake/Onboarding/OnboardingFlow.swift @@ -20,8 +20,6 @@ struct OnboardingFlow: View { @AppStorage(StorageKeys.onboardingFlowComplete) private var completedOnboardingFlow = false - @State private var localNotificationAuthorization = false - private var healthKitAuthorization: Bool { // As HealthKit not available in preview simulator @@ -49,14 +47,7 @@ struct OnboardingFlow: View { if HKHealthStore.isHealthDataAvailable() && !healthKitAuthorization { HealthKitPermissions() } - - if !localNotificationAuthorization { - NotificationPermissions() - } } - .task { - localNotificationAuthorization = await scheduler.localNotificationAuthorization - } .interactiveDismissDisabled(!completedOnboardingFlow) } } diff --git a/Intake/Resources/Localizable.xcstrings b/Intake/Resources/Localizable.xcstrings index 0baa572..b454b44 100644 --- a/Intake/Resources/Localizable.xcstrings +++ b/Intake/Resources/Localizable.xcstrings @@ -149,7 +149,7 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "This onboarding step allows you to customize the onboarding flow to explain how the application uses the HealhtKit data and allows a user to cusomize the selection." + "value" : "Intake will use your different types of your health records in order to most effectively aid you with your intake form." } } } @@ -159,7 +159,7 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Spezi can access data from HealthKit using the HealthKitDataSource module." + "value" : "Intake would like to access to your health records to fill out your intake form." } } } @@ -317,47 +317,6 @@ } } }, - "NOTIFICATION_PERMISSIONS_BUTTON" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Allow Notifications" - } - } - } - }, - "NOTIFICATION_PERMISSIONS_DESCRIPTION" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "The Spezi Scheduler module enables to send out local notifications when a new event of a task is scheduled." - } - } - } - }, - "NOTIFICATION_PERMISSIONS_SUBTITLE" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Spezi Scheduler Notifications." - } - } - } - }, - "NOTIFICATION_PERMISSIONS_TITLE" : { - "comment" : "MARK: Notifications", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Notifications" - } - } - } - }, "PROJECT_LICENSE_DESCRIPTION" : { "localizations" : { "en" : {