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

Patient Age Group #52

Merged
merged 9 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions PAWS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
A9D83F962B083794000D0C78 /* SpeziFirebaseAccountStorage in Frameworks */ = {isa = PBXBuildFile; productRef = A9D83F952B083794000D0C78 /* SpeziFirebaseAccountStorage */; };
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 */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -143,6 +144,7 @@
A9720E422ABB68CC00872D23 /* AccountSetupHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupHeader.swift; sourceTree = "<group>"; };
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>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -280,6 +282,7 @@
2FE5DC4229EDD7F2004B9AB4 /* Binding+Negate.swift */,
2FCC1DCA2B6A2B2700C686BE /* Date+RawRepresentable.swift */,
2FE5DC4329EDD7F2004B9AB4 /* Bundle+Image.swift */,
B28A0DDB2BA4AEDE0068258D /* Date+Bool.swift */,
2FE5DC4429EDD7F2004B9AB4 /* CodableArray+RawRepresentable.swift */,
);
path = Helper;
Expand Down Expand Up @@ -579,6 +582,7 @@
2FC975A82978F11A00BA99FE /* Home.swift in Sources */,
A9DFE8A92ABE551400428242 /* AccountButton.swift in Sources */,
2FE5DC3729EDD7CA004B9AB4 /* OnboardingFlow.swift in Sources */,
B28A0DDC2BA4AEDE0068258D /* Date+Bool.swift in Sources */,
2FF53D8D2A8729D600042B76 /* PAWSStandard.swift in Sources */,
2FE5DC4729EDD7F2004B9AB4 /* CodableArray+RawRepresentable.swift in Sources */,
A9720E432ABB68CC00872D23 /* AccountSetupHeader.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "4215a748079614ed67aab303326e024c420507be5020eb9239ee1daf68db0025",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down Expand Up @@ -50,17 +51,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "f91c8167141d0279726c6f6d9d4a47c026785cbc",
"version" : "10.21.0"
"revision" : "be49849dcba96f2b5ee550d4eceb2c0fa27dade4",
"version" : "10.22.1"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "cb8617fab75d181270a1d8f763f26b15c73e2e1e",
"version" : "10.21.0"
"revision" : "482cfa4e5880f0a29f66ecfd60c5a62af28bd1f0",
"version" : "10.22.1"
}
},
{
Expand Down Expand Up @@ -104,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/HealthKitOnFHIR.git",
"state" : {
"revision" : "825e96007d83ed83f81ee49eb3ebab29d7b7ba2f",
"version" : "0.2.5"
"revision" : "00d64d38a8f0d826ee9e27b6f3ce32314a29fd3e",
"version" : "0.2.6"
}
},
{
Expand Down Expand Up @@ -361,5 +362,5 @@
}
}
],
"version" : 2
"version" : 3
}
21 changes: 21 additions & 0 deletions PAWS/Helper/Date+Bool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// 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 Foundation


extension Date {
var isAdultDateOfBirth: Bool {
let ageComponents = Calendar.current.dateComponents([.year], from: self, to: .now)
guard let ageYears = ageComponents.year else {
return false

Check warning on line 16 in PAWS/Helper/Date+Bool.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/Helper/Date+Bool.swift#L16

Added line #L16 was not covered by tests
}

return ageYears >= 18
}
}
5 changes: 5 additions & 0 deletions PAWS/PAWSStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
guard let accountStorage else {
preconditionFailure("Account Storage was requested although not enabled in current configuration.")
}
if let dob = details.dateOfBrith {
// Store whether the participant is older or younger than 18.
try await userDocumentReference.getDocument().setValue(dob.isAdultDateOfBirth, forKey: "ageGroupIsAdult")
}

Check warning on line 238 in PAWS/PAWSStandard.swift

View check run for this annotation

Codecov / codecov/patch

PAWS/PAWSStandard.swift#L234-L238

Added lines #L234 - L238 were not covered by tests
try await accountStorage.create(identifier, details)
}

Expand Down
26 changes: 24 additions & 2 deletions PAWSTests/PAWSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,29 @@ import XCTest


class PAWSTests: XCTestCase {
func testExample() throws {
XCTAssertTrue(true)
func testAdultDateOfBirthTrue() throws {
var components = DateComponents()
components.year = 1970
components.month = 1
components.day = 1
components.hour = 0
components.minute = 0
components.second = 0

guard let dateOfBirth = Calendar.current.date(from: components) else {
XCTFail("Could not initialize date of birth.")
return
}

XCTAssertTrue(dateOfBirth.isAdultDateOfBirth, "Age is below 18 years.")
}

func testAdultDateOfBirthFalse() throws {
guard let dateOfBirth = Calendar.current.date(byAdding: .year, value: -12, to: .now) else {
XCTFail("Could not initialize date of birth.")
return
}

XCTAssertFalse(dateOfBirth.isAdultDateOfBirth, "Age is 18 years or older; expected younger.")
}
}
Loading