Skip to content

Commit

Permalink
Update Firebase paths for mHealth platform (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi authored Jun 13, 2024
1 parent 570213d commit 60970ca
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions StrokeCog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions StrokeCog/Onboarding/AccountOnboarding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
},
Expand Down
7 changes: 7 additions & 0 deletions StrokeCog/Onboarding/Consent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 9 additions & 7 deletions StrokeCog/StrokeCogStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)")
}
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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.
}

Expand Down Expand Up @@ -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)")
}
Expand Down

0 comments on commit 60970ca

Please sign in to comment.