Skip to content

Commit

Permalink
Update data model for RIT backend
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Jul 9, 2024
1 parent 9942413 commit 648862a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
10 changes: 7 additions & 3 deletions LifeSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
63A28D312C0580310025A1E0 /* RefreshIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63A28D302C0580310025A1E0 /* RefreshIcon.swift */; };
63A28D332C062E2E0025A1E0 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 63A28D322C062E2E0025A1E0 /* GoogleService-Info.plist */; };
63A8DB292C1FE81200939757 /* AppIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 63A8DB282C1FE81200939757 /* AppIcon.png */; };
63AB851F2C3DACA40011AEB6 /* HealthKitDataPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63AB851E2C3DACA40011AEB6 /* HealthKitDataPoint.swift */; };
63BBF8162BB8993B006890CE /* StudyIDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BBF8152BB8993B006890CE /* StudyIDView.swift */; };
63BBF8192BB89CF7006890CE /* studyIDs.csv in Resources */ = {isa = PBXBuildFile; fileRef = 63BBF8182BB89CF7006890CE /* studyIDs.csv */; };
63D86AD62C3B7F310096B9DB /* DocumentWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63D86AD52C3B7F310096B9DB /* DocumentWebView.swift */; };
Expand Down Expand Up @@ -145,6 +146,7 @@
63A28D302C0580310025A1E0 /* RefreshIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshIcon.swift; sourceTree = "<group>"; };
63A28D322C062E2E0025A1E0 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
63A8DB282C1FE81200939757 /* AppIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AppIcon.png; sourceTree = "<group>"; };
63AB851E2C3DACA40011AEB6 /* HealthKitDataPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitDataPoint.swift; sourceTree = "<group>"; };
63BBF8152BB8993B006890CE /* StudyIDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyIDView.swift; sourceTree = "<group>"; };
63BBF8182BB89CF7006890CE /* studyIDs.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = studyIDs.csv; sourceTree = "<group>"; };
63CC66972C204CC5001DCFDF /* LifeSpace.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = LifeSpace.xctestplan; sourceTree = "<group>"; };
Expand Down Expand Up @@ -300,6 +302,7 @@
2FE5DC4229EDD7F2004B9AB4 /* Binding+Negate.swift */,
2FE5DC4329EDD7F2004B9AB4 /* Bundle+Image.swift */,
63F4C39E2BBCCDB70033D985 /* Date+Helpers.swift */,
63AB851E2C3DACA40011AEB6 /* HealthKitDataPoint.swift */,
);
path = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -663,6 +666,7 @@
A9720E432ABB68CC00872D23 /* AccountSetupHeader.swift in Sources */,
2FE5DC4029EDD7EE004B9AB4 /* FeatureFlags.swift in Sources */,
2FE5DC4629EDD7F2004B9AB4 /* Bundle+Image.swift in Sources */,
63AB851F2C3DACA40011AEB6 /* HealthKitDataPoint.swift in Sources */,
2FE5DC4F29EDD7FA004B9AB4 /* EventContext.swift in Sources */,
6347EB642BBBA895008E0C4A /* LifeSpaceMapView.swift in Sources */,
63F4C3992BBCCC300033D985 /* MapboxView.swift in Sources */,
Expand Down Expand Up @@ -796,7 +800,7 @@
CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1000,7 +1004,7 @@
CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1047,7 +1051,7 @@
CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down
16 changes: 16 additions & 0 deletions LifeSpace/Helper/HealthKitDataPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// HealthKitDataPoint.swift
// LifeSpace
//
// Created by Vishnu Ravi on 7/9/24.
//

import Foundation
import ModelsR4


struct HealthKitDataPoint: Codable {
var studyID: String
var UpdatedBy: String // swiftlint:disable:this identifier_name
var resource: ResourceProxy
}
21 changes: 17 additions & 4 deletions LifeSpace/LifeSpaceStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,21 @@ actor LifeSpaceStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O


func add(sample: HKSample) async {
guard let details = await account.details else {
logger.error("User is not logged in.")
return
}

do {
try await healthKitDocument(id: sample.id).setData(from: sample.resource)
let resource = try sample.resource

let data = HealthKitDataPoint(
studyID: studyID,
UpdatedBy: details.accountId,
resource: resource
)

try await healthKitDocument(id: sample.id).setData(from: data)
} catch {
logger.error("Could not store HealthKit sample: \(error)")
}
Expand Down Expand Up @@ -117,7 +130,7 @@ actor LifeSpaceStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O
latitude: location.latitude,
longitude: location.longitude,
studyID: studyID,
updatedBy: details.accountId
UpdatedBy: details.accountId
)

try await userDocumentReference
Expand Down Expand Up @@ -172,7 +185,7 @@ actor LifeSpaceStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O

response.timestamp = Date()
response.studyID = studyID
response.updatedBy = details.accountId
response.UpdatedBy = details.accountId

try await userDocumentReference
.collection("ls_surveys")
Expand Down Expand Up @@ -201,7 +214,7 @@ actor LifeSpaceStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O

private func healthKitDocument(id uuid: UUID) async throws -> DocumentReference {
try await userDocumentReference
.collection("ls_healthkit") // Add all HealthKit sources in a /HealthKit collection.
.collection("ls_healthkit_new") // Add all HealthKit sources in a /HealthKit collection.
.document(uuid.uuidString) // Set the document identifier to the UUID of the document.
}

Expand Down
2 changes: 1 addition & 1 deletion LifeSpace/Location/LocationDataPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ struct LocationDataPoint: Codable {
var latitude: CLLocationDegrees
var longitude: CLLocationDegrees
var studyID: String = ""
var updatedBy: String = ""
var UpdatedBy: String = "" // swiftlint:disable:this identifier_name
}
2 changes: 1 addition & 1 deletion LifeSpace/Survey/DailySurveyResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct DailySurveyResponse: Codable {
var surveyName: String?
var surveyDate: String?
var studyID: String?
var updatedBy: String?
var UpdatedBy: String? // swiftlint:disable:this identifier_name
var timestamp: Date?
var socialInteractionQuestion: Int?
var leavingTheHouseQuestion: Int?
Expand Down

0 comments on commit 648862a

Please sign in to comment.