diff --git a/StrokeCog.xcodeproj/project.pbxproj b/StrokeCog.xcodeproj/project.pbxproj index 7cf7669..6de409b 100644 --- a/StrokeCog.xcodeproj/project.pbxproj +++ b/StrokeCog.xcodeproj/project.pbxproj @@ -768,7 +768,7 @@ CODE_SIGN_ENTITLEMENTS = "StrokeCog/Supporting Files/StrokeCog.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -972,7 +972,7 @@ CODE_SIGN_ENTITLEMENTS = "StrokeCog/Supporting Files/StrokeCog.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -1019,7 +1019,7 @@ CODE_SIGN_ENTITLEMENTS = "StrokeCog/Supporting Files/StrokeCog.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; diff --git a/StrokeCog/Onboarding/AccountOnboarding.swift b/StrokeCog/Onboarding/AccountOnboarding.swift index 8c7038e..d840a87 100644 --- a/StrokeCog/Onboarding/AccountOnboarding.swift +++ b/StrokeCog/Onboarding/AccountOnboarding.swift @@ -24,12 +24,6 @@ struct AccountOnboarding: View { Task { // Placing the nextStep() call inside this task will ensure that the sheet dismiss animation is // played till the end before we navigate to the next step. - - // Now that the user is logged in, we will update the user document - if let studyID = UserDefaults.standard.string(forKey: StorageKeys.studyID) { - await standard.setStudyID(studyID) - } - onboardingNavigationPath.nextStep() } }, diff --git a/StrokeCog/Onboarding/Consent.swift b/StrokeCog/Onboarding/Consent.swift index e6a9f67..772299b 100644 --- a/StrokeCog/Onboarding/Consent.swift +++ b/StrokeCog/Onboarding/Consent.swift @@ -135,12 +135,19 @@ struct Consent: View { return } + // Start by updating the Study ID + if let studyID = UserDefaults.standard.string(forKey: StorageKeys.studyID) { + await standard.setStudyID(studyID) + } + + // Apply signatures to the consent documents let consentDocument = LifeSpaceConsent() signatureResult.apply(to: consentDocument) let hipaaConsentDocument = HIPAAAuthorization() hipaaSignatureResult.apply(to: hipaaConsentDocument) + // Create and upload PDFs for each document do { let consentPDFData = try await consentDocument.makePDF() await standard.store(consentData: consentPDFData, name: "consent") diff --git a/StrokeCog/StrokeCogStandard.swift b/StrokeCog/StrokeCogStandard.swift index 659e970..50f107e 100644 --- a/StrokeCog/StrokeCogStandard.swift +++ b/StrokeCog/StrokeCogStandard.swift @@ -29,7 +29,8 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O } private static var userCollection: CollectionReference { - Firestore.firestore().collection("users") + let bundleIdentifier = Bundle.main.bundleIdentifier ?? "edu.stanford.lifespace" + return Firestore.firestore().collection(bundleIdentifier).document("study").collection("ls_users") } @Dependency var accountStorage: FirestoreAccountStorage? @@ -55,7 +56,8 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O throw StrokeCogStandardError.userNotAuthenticatedYet } - return Storage.storage().reference().child("users/\(details.accountId)") + let bundleIdentifier = Bundle.main.bundleIdentifier ?? "edu.stanford.lifespace" + return Storage.storage().reference().child("\(bundleIdentifier)/study/ls_users/\(details.accountId)") } } @@ -115,7 +117,7 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O ) try await userDocumentReference - .collection("location_data") + .collection("ls_location_data") .document(UUID().uuidString) .setData(from: dataPoint) } @@ -129,7 +131,7 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O do { let snapshot = try await userDocumentReference - .collection("location_data") + .collection("ls_location_data") .whereField("currentDate", isGreaterThanOrEqualTo: startOfDay) .whereField("currentDate", isLessThan: endOfDay) .getDocuments() @@ -169,7 +171,7 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O response.updatedBy = details.accountId try await userDocumentReference - .collection("surveys") + .collection("ls_surveys") .document(UUID().uuidString) .setData(from: response) @@ -195,7 +197,7 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O private func healthKitDocument(id uuid: UUID) async throws -> DocumentReference { try await userDocumentReference - .collection("HealthKit") // Add all HealthKit sources in a /HealthKit collection. + .collection("ls_healthkit") // Add all HealthKit sources in a /HealthKit collection. .document(uuid.uuidString) // Set the document identifier to the UUID of the document. } @@ -261,7 +263,7 @@ actor StrokeCogStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O let metadata = StorageMetadata() metadata.contentType = "application/pdf" - _ = try await userBucketReference.child("consent/\(filename)").putDataAsync(consentData, metadata: metadata) + _ = try await userBucketReference.child("ls_consent/\(filename)").putDataAsync(consentData, metadata: metadata) } catch { logger.error("Could not store consent form: \(error)") }