Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Bios #55

Merged
merged 46 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
87a18da
Add state for age group
MatthewTurk247 Mar 27, 2024
8e5a49b
Delete PAWS/Account/AccountAgeGroup.swift
MatthewTurk247 Mar 27, 2024
6131125
Update Contacts.swift
MatthewTurk247 Mar 28, 2024
b8fbb5d
Basic way to get `users` collection
MatthewTurk247 Mar 28, 2024
ad3fcda
Merge branch 'main' of https://github.com/StanfordBDHG/PediatricApple…
MatthewTurk247 Apr 9, 2024
5970349
Merge branch 'contacts' of https://github.com/StanfordBDHG/PediatricA…
MatthewTurk247 Apr 9, 2024
70f0d19
Init attempt at enrollment group
MatthewTurk247 Apr 10, 2024
825b8a8
Rename to `EnrollmentGroup`
MatthewTurk247 Apr 10, 2024
b3f7fcc
Remove leftover lines
MatthewTurk247 Apr 10, 2024
ca28a30
Adjust spacing
MatthewTurk247 Apr 10, 2024
79449b2
Remove leftover comments
MatthewTurk247 Apr 10, 2024
2fb7c40
Rename for clarity
MatthewTurk247 Apr 10, 2024
cf765bc
Remove extraneous line
MatthewTurk247 Apr 10, 2024
5605433
Update PAWS/Study Information/EnrollmentGroup.swift
MatthewTurk247 Apr 10, 2024
e21f490
Successfully added snapshot listener
MatthewTurk247 Apr 10, 2024
f8847f5
Minor refactoring
MatthewTurk247 Apr 10, 2024
911335a
Still doesn't update right away
MatthewTurk247 Apr 11, 2024
07cfce8
Update PAWS/Study Information/EnrollmentGroup.swift
MatthewTurk247 Apr 11, 2024
cd2a44d
Update PAWS/Study Information/EnrollmentGroup.swift
MatthewTurk247 Apr 11, 2024
d5b2e0b
Age group UI still gets stuck
MatthewTurk247 Apr 12, 2024
7c5845c
Almost ready for edits
MatthewTurk247 Apr 12, 2024
1d604c9
Minor refactoring
MatthewTurk247 Apr 12, 2024
55840f1
Refactor tests
MatthewTurk247 Apr 12, 2024
9e2ef04
Rerun tests
MatthewTurk247 Apr 12, 2024
bbb773a
Update Node modules
MatthewTurk247 Apr 15, 2024
cb7b34c
Cancel previous listener
MatthewTurk247 Apr 15, 2024
c4a1204
Return statement
MatthewTurk247 Apr 15, 2024
32aacbc
Return statement
MatthewTurk247 Apr 15, 2024
3ea11de
Use `return await`
MatthewTurk247 Apr 15, 2024
869391f
Rerun tests
MatthewTurk247 Apr 16, 2024
4553a38
Additional configuration
MatthewTurk247 Apr 16, 2024
80867aa
More log statements
MatthewTurk247 Apr 16, 2024
f7aaad6
Update `firebase-functions`
MatthewTurk247 Apr 16, 2024
a3384b8
Static constants for `Contact`
MatthewTurk247 Apr 17, 2024
800533d
To match function signature
MatthewTurk247 Apr 17, 2024
acb29b1
To match function signature
MatthewTurk247 Apr 17, 2024
6c0c23b
Use Firebase Token
PSchmiedmayer Apr 17, 2024
2bd0ee3
Test Token ...
PSchmiedmayer Apr 17, 2024
6f73f7b
Update Build
PSchmiedmayer Apr 17, 2024
9e6076c
Update Contact+PersonNameComponents.swift
PSchmiedmayer Apr 17, 2024
7f0cfd3
Update Contacts.swift
PSchmiedmayer Apr 17, 2024
c163423
Use v2
PSchmiedmayer Apr 17, 2024
3ca549d
Update PAWS/Study Information/EnrollmentGroup.swift
MatthewTurk247 Apr 17, 2024
1569d79
Update PAWS/Study Information/EnrollmentGroup.swift
MatthewTurk247 Apr 17, 2024
386f119
Remove leftover log statements
MatthewTurk247 Apr 17, 2024
d34951a
Adjust log statements
MatthewTurk247 Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PAWS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
A9DFE8A92ABE551400428242 /* AccountButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DFE8A82ABE551400428242 /* AccountButton.swift */; };
A9FE7AD02AA39BAB0077B045 /* AccountSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FE7ACF2AA39BAB0077B045 /* AccountSheet.swift */; };
B28A0DDC2BA4AEDE0068258D /* Date+Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = B28A0DDB2BA4AEDE0068258D /* Date+Bool.swift */; };
B2CF6EC12BC63CEB00F85C61 /* StudyType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2CF6EC02BC63CEB00F85C61 /* StudyType.swift */; };
B2CF6EC42BC63D9B00F85C61 /* EnrollmentGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2CF6EC32BC63D9B00F85C61 /* EnrollmentGroup.swift */; };
B2DB1AD32BB4BCB100B0F49B /* AccountCreationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2DB1AD22BB4BCB100B0F49B /* AccountCreationTests.swift */; };
B2F7F1DC2BA53F6400BE93BE /* InvitationCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F7F1DB2BA53F6400BE93BE /* InvitationCodeView.swift */; };
B2F7F1DF2BA540BB00BE93BE /* FirebaseFunctions in Frameworks */ = {isa = PBXBuildFile; productRef = B2F7F1DE2BA540BB00BE93BE /* FirebaseFunctions */; };
Expand Down Expand Up @@ -149,6 +151,8 @@
A9DFE8A82ABE551400428242 /* AccountButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountButton.swift; sourceTree = "<group>"; };
A9FE7ACF2AA39BAB0077B045 /* AccountSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSheet.swift; sourceTree = "<group>"; };
B28A0DDB2BA4AEDE0068258D /* Date+Bool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Bool.swift"; sourceTree = "<group>"; };
B2CF6EC02BC63CEB00F85C61 /* StudyType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyType.swift; sourceTree = "<group>"; };
B2CF6EC32BC63D9B00F85C61 /* EnrollmentGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnrollmentGroup.swift; sourceTree = "<group>"; };
B2DB1AD22BB4BCB100B0F49B /* AccountCreationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCreationTests.swift; sourceTree = "<group>"; };
B2F7F1DB2BA53F6400BE93BE /* InvitationCodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvitationCodeView.swift; sourceTree = "<group>"; };
B2F7F1E12BA549A900BE93BE /* InvitationCodeError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvitationCodeError.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -304,6 +308,8 @@
2FFD22FB2B59AED8005DD268 /* FAQ.swift */,
2FFD22FE2B59B158005DD268 /* StudyDescription.swift */,
2FFD23012B59B22C005DD268 /* StudyInformation.swift */,
B2CF6EC02BC63CEB00F85C61 /* StudyType.swift */,
B2CF6EC32BC63D9B00F85C61 /* EnrollmentGroup.swift */,
);
path = "Study Information";
sourceTree = "<group>";
Expand Down Expand Up @@ -588,6 +594,7 @@
2FE5DC3529EDD7CA004B9AB4 /* Consent.swift in Sources */,
2FE5DC4529EDD7F2004B9AB4 /* Binding+Negate.swift in Sources */,
2FFD23022B59B22C005DD268 /* StudyInformation.swift in Sources */,
B2CF6EC12BC63CEB00F85C61 /* StudyType.swift in Sources */,
2FCC1DBE2B6A1C9000C686BE /* ECGRecordingsList.swift in Sources */,
2FCC1DCB2B6A2B2700C686BE /* Date+RawRepresentable.swift in Sources */,
2FCC1DC12B6A1D4C00C686BE /* ECGModule.swift in Sources */,
Expand All @@ -596,6 +603,7 @@
2FE5DC3729EDD7CA004B9AB4 /* OnboardingFlow.swift in Sources */,
B28A0DDC2BA4AEDE0068258D /* Date+Bool.swift in Sources */,
2FF53D8D2A8729D600042B76 /* PAWSStandard.swift in Sources */,
B2CF6EC42BC63D9B00F85C61 /* EnrollmentGroup.swift in Sources */,
2FE5DC4729EDD7F2004B9AB4 /* CodableArray+RawRepresentable.swift in Sources */,
A9720E432ABB68CC00872D23 /* AccountSetupHeader.swift in Sources */,
2FE5DC4029EDD7EE004B9AB4 /* FeatureFlags.swift in Sources */,
Expand Down
29 changes: 22 additions & 7 deletions PAWS/Contacts/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SwiftUI

/// Displays the contacts for the PAWS.
struct Contacts: View {
@Environment(EnrollmentGroup.self) var enrollmentGroup
let contacts = [
Contact(
name: PersonNameComponents(
Expand All @@ -39,7 +40,7 @@ struct Contacts: View {
title: "Website",
action: {
if let url = URL(string: "https://profiles.stanford.edu/scott-ceresnak?tab=bio") {
UIApplication.shared.open(url)
UIApplication.shared.open(url)
}
}
)
Expand Down Expand Up @@ -70,27 +71,41 @@ struct Contacts: View {
title: "Website",
action: {
if let url = URL(string: "https://profiles.stanford.edu/aydin-zahedivash?tab=bio") {
UIApplication.shared.open(url)
UIApplication.shared.open(url)
}
}
)
]
)
]


@Binding var presentingAccount: Bool


var body: some View {
NavigationStack {
ScrollView {
VStack(spacing: 16) {
ForEach(contacts, id: \.name) { contact in
PAWSCard {
ContactView(contact: contact)
.buttonStyle(.plain) // ensure the whole list row doesn't render as a button
.padding()
switch enrollmentGroup.studyType {
case .pediatric:
ForEach(contacts, id: \.name) { contact in
PAWSCard {
ContactView(contact: contact)
.buttonStyle(.plain) // ensure the whole list row doesn't render as a button
.padding()
}
}
case .adult:
ForEach(contacts + [Contact(name: PersonNameComponents(givenName: "Brynne"))], id: \.name) { contact in
MatthewTurk247 marked this conversation as resolved.
Show resolved Hide resolved
PAWSCard {
ContactView(contact: contact)
.buttonStyle(.plain)
.padding()
}
}
default:
EmptyView()
}
}
.padding(.vertical)
Expand Down
1 change: 1 addition & 0 deletions PAWS/PAWSDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PAWSDelegate: SpeziAppDelegate {

PAWSScheduler()
OnboardingDataSource()
EnrollmentGroup()
}
}

Expand Down
54 changes: 54 additions & 0 deletions PAWS/Study Information/EnrollmentGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// This source file is part of the PAWS application based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//

import FirebaseAuth
import FirebaseFirestore
import Spezi
import SpeziAccount
import SpeziFirebaseConfiguration
import SwiftUI


@Observable
class EnrollmentGroup: Module, EnvironmentAccessible {
@ObservationIgnored @Dependency private var configureFirebaseApp: ConfigureFirebaseApp
private var dateOfBirth: Date?
private var authStateDidChangeListenerHandle: AuthStateDidChangeListenerHandle?

MatthewTurk247 marked this conversation as resolved.
Show resolved Hide resolved
var studyType: StudyType? {
guard let enrollmentDate = Auth.auth().currentUser?.metadata.creationDate,
let dateOfBirth,
let yearsOfAge = Calendar.current.dateComponents([.year], from: dateOfBirth, to: enrollmentDate).year else {
return nil
}
return yearsOfAge >= 18 ? .adult : .pediatric
}

MatthewTurk247 marked this conversation as resolved.
Show resolved Hide resolved
func configure() {
authStateDidChangeListenerHandle = Auth.auth().addStateDidChangeListener { [weak self] _, user in
self?.registerSnapshotListener(user: user)
}
self.registerSnapshotListener(user: Auth.auth().currentUser)
}

func registerSnapshotListener(user: User?) {
guard let uid = user?.uid else {
return
MatthewTurk247 marked this conversation as resolved.
Show resolved Hide resolved
}
Firestore
MatthewTurk247 marked this conversation as resolved.
Show resolved Hide resolved
.firestore()
.collection("users")
.document(uid)
.addSnapshotListener { documentSnapshot, _ in
if let data = documentSnapshot?.data() {
let dobTimestamp = data["DateOfBirthKey"] as? Timestamp
self.dateOfBirth = dobTimestamp?.dateValue()
}
}
}
}
13 changes: 13 additions & 0 deletions PAWS/Study Information/StudyType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// This source file is part of the PAWS application based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//


enum StudyType {
case adult
case pediatric
}
19 changes: 17 additions & 2 deletions PAWSUITests/AccountCreationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class AccountCreationTests: XCTestCase {
try app.navigateOnboardingFlow(email: email)

app.assertOnboardingComplete()
app.assertStudyGroupAdult()
try app.assertAccountInformation(email: email)
}
}
Expand Down Expand Up @@ -74,6 +75,8 @@ extension XCUIApplication {
try textFields["Invitation Code"].enter(value: "gdxRWF6G")
XCTAssertTrue(buttons["Redeem Invitation Code"].waitForExistence(timeout: 2))
buttons["Redeem Invitation Code"].tap()

sleep(10)
}

private func navigateOnboardingAccount(email: String) throws {
Expand All @@ -91,9 +94,14 @@ extension XCUIApplication {
try textFields["enter first name"].enter(value: "John")
try textFields["enter last name"].enter(value: "Doe")
let datePicker = datePickers.firstMatch
XCTAssertTrue(datePicker.waitForExistence(timeout: 2))
datePicker.tap()
datePicker.buttons.firstMatch.tap()
datePicker.pickerWheels.element(boundBy: 1).adjust(toPickerWheelValue: "1970")
let dateButton = datePicker.buttons.firstMatch
XCTAssertTrue(dateButton.waitForExistence(timeout: 2))
dateButton.tap()
let dateWheel = datePicker.pickerWheels.element(boundBy: 1)
XCTAssertTrue(dateWheel.waitForExistence(timeout: 2))
dateWheel.adjust(toPickerWheelValue: "1970")

XCTAssertTrue(collectionViews.buttons["Signup"].waitForExistence(timeout: 2))
collectionViews.buttons["Signup"].tap()
Expand Down Expand Up @@ -160,6 +168,13 @@ extension XCUIApplication {
XCTAssertTrue(tabBar.buttons["Infos"].waitForExistence(timeout: 2))
XCTAssertTrue(tabBar.buttons["Contacts"].waitForExistence(timeout: 2))
}

fileprivate func assertStudyGroupAdult() {
let tabBar = tabBars["Tab Bar"]
XCTAssertTrue(tabBar.buttons["Contacts"].waitForExistence(timeout: 2))
tabBar.buttons["Contacts"].tap()
XCTAssertTrue(staticTexts["Contact: Brynne"].waitForExistence(timeout: 10))
}

fileprivate func assertAccountInformation(email: String) throws {
XCTAssertTrue(navigationBars.buttons["Your PAWS Account"].waitForExistence(timeout: 2))
Expand Down
Loading