Skip to content

Commit

Permalink
Patient Age Group (#52)
Browse files Browse the repository at this point in the history
# Patient Age Group

## ♻️ Current situation & Problem
We need a way to determine whether a patient is part of the upcoming
pediatric study or the upcoming adult study so that UI can be updated
accordingly.


## ⚙️ Release Notes 
- Adds the logic for tagging patients for pediatric/adult study based on
date of birth and time of account creation. This information is stored
in Firebase for later use in layout of the UI.

## ✅ Testing
Because of the `guard` statement at the beginning of the function body
of interest, the bulk of the meaningful testing will be manual
inspections of Firebase.


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
MatthewTurk247 authored Mar 21, 2024
1 parent 2e271bb commit 5085051
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
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
}

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 @@ actor PAWSStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onboar
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")
}

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.")
}
}

0 comments on commit 5085051

Please sign in to comment.