Skip to content

Commit

Permalink
Potential fix for SpeziFirebase crash
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Jul 11, 2024
1 parent fdf1119 commit cc182db
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions LifeSpace/LifeSpaceStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ actor LifeSpaceStandard: Standard, EnvironmentAccessible, HealthKitConstraint, O
do {
let resource = try sample.resource

let data = HealthKitDataPoint(
studyID: studyID,
UpdatedBy: userId,
resource: resource
)
let data = try JSONEncoder().encode(resource)

try await healthKitDocument(id: sample.id).setData(from: data)
/// Convert the FHIR resource into a dictionary so we can add fields necessary for the backend
guard var dataDict = try JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) as? [String: Any] else {
logger.error("Cannot serialize data.")
return
}

/// The `UpdatedBy` field is checked by the mHealth platform security rules
dataDict["UpdatedBy"] = userId
dataDict["studyID"] = studyID

try await healthKitDocument(id: sample.id).setData(dataDict)
} catch {
logger.error("Could not store HealthKit sample: \(error)")
}
Expand Down

0 comments on commit cc182db

Please sign in to comment.