diff --git a/CareKitStore/CareKitStore.xcodeproj/project.pbxproj b/CareKitStore/CareKitStore.xcodeproj/project.pbxproj index 9184a4aa4..952b06fc9 100644 --- a/CareKitStore/CareKitStore.xcodeproj/project.pbxproj +++ b/CareKitStore/CareKitStore.xcodeproj/project.pbxproj @@ -134,6 +134,7 @@ 51E663272887205C006197D3 /* OCKHealthKitPassthroughStore+FetchEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E663252887205C006197D3 /* OCKHealthKitPassthroughStore+FetchEvents.swift */; }; 51E663282887205C006197D3 /* OCKHealthKitPassthroughStore+FetchOutcomes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E663262887205C006197D3 /* OCKHealthKitPassthroughStore+FetchOutcomes.swift */; }; 51EB47532901AA2C00734820 /* CareTaskProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EB47522901AA2C00734820 /* CareTaskProgress.swift */; }; + 70A31BE52D6BD58000FA2EF7 /* OCKCDHealthKitOutcome.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A31BE42D6BD58000FA2EF7 /* OCKCDHealthKitOutcome.swift */; }; E7131DC12241FAA80001861B /* OCKTaskQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7131DC02241FAA80001861B /* OCKTaskQuery.swift */; }; E7131DC5224200640001861B /* OCKOutcomeQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7131DC4224200640001861B /* OCKOutcomeQuery.swift */; }; E7131DCB22420A520001861B /* OCKPatientQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7131DCA22420A520001861B /* OCKPatientQuery.swift */; }; @@ -146,7 +147,7 @@ E726C05422CFAE04001236E2 /* TestStore+Outcomes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E726C05322CFAE04001236E2 /* TestStore+Outcomes.swift */; }; E726C05622CFB825001236E2 /* TestStore+Notes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E726C05522CFB825001236E2 /* TestStore+Notes.swift */; }; E746049022385B8300A1B16B /* TestOutcomeValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = E746048F22385B8300A1B16B /* TestOutcomeValue.swift */; }; - E7460494223870C100A1B16B /* OCKObjectCompatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7460493223870C100A1B16B /* OCKObjectCompatible.swift */; }; + E7460494223870C100A1B16B /* OCKVersionedObjectCompatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7460493223870C100A1B16B /* OCKVersionedObjectCompatible.swift */; }; E747EC4822382BBC00775C0D /* OCKOutcomeValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = E747EC4722382BBC00775C0D /* OCKOutcomeValue.swift */; }; E760F75222F8C85A007FCB12 /* OCKBiologicalSex.swift in Sources */ = {isa = PBXBuildFile; fileRef = E760F75122F8C85A007FCB12 /* OCKBiologicalSex.swift */; }; E76FB6092267D89D00F5E1B8 /* OCKAdherenceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = E76FB6082267D89D00F5E1B8 /* OCKAdherenceQuery.swift */; }; @@ -334,6 +335,7 @@ 51E663252887205C006197D3 /* OCKHealthKitPassthroughStore+FetchEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OCKHealthKitPassthroughStore+FetchEvents.swift"; sourceTree = ""; }; 51E663262887205C006197D3 /* OCKHealthKitPassthroughStore+FetchOutcomes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OCKHealthKitPassthroughStore+FetchOutcomes.swift"; sourceTree = ""; }; 51EB47522901AA2C00734820 /* CareTaskProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CareTaskProgress.swift; sourceTree = ""; }; + 70A31BE42D6BD58000FA2EF7 /* OCKCDHealthKitOutcome.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKCDHealthKitOutcome.swift; sourceTree = ""; }; E7131DC02241FAA80001861B /* OCKTaskQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKTaskQuery.swift; sourceTree = ""; }; E7131DC4224200640001861B /* OCKOutcomeQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKOutcomeQuery.swift; sourceTree = ""; }; E7131DCA22420A520001861B /* OCKPatientQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKPatientQuery.swift; sourceTree = ""; }; @@ -346,7 +348,7 @@ E726C05322CFAE04001236E2 /* TestStore+Outcomes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TestStore+Outcomes.swift"; sourceTree = ""; }; E726C05522CFB825001236E2 /* TestStore+Notes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TestStore+Notes.swift"; sourceTree = ""; }; E746048F22385B8300A1B16B /* TestOutcomeValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestOutcomeValue.swift; sourceTree = ""; }; - E7460493223870C100A1B16B /* OCKObjectCompatible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKObjectCompatible.swift; sourceTree = ""; }; + E7460493223870C100A1B16B /* OCKVersionedObjectCompatible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKVersionedObjectCompatible.swift; sourceTree = ""; }; E747EC4722382BBC00775C0D /* OCKOutcomeValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKOutcomeValue.swift; sourceTree = ""; }; E760F75122F8C85A007FCB12 /* OCKBiologicalSex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKBiologicalSex.swift; sourceTree = ""; }; E76FB6082267D89D00F5E1B8 /* OCKAdherenceQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCKAdherenceQuery.swift; sourceTree = ""; }; @@ -773,7 +775,7 @@ 03678DEE2343B20B00E27926 /* Events */, E7AE85222232F24500AF7C32 /* OCKStoreProtocol.swift */, E7B7AF71226C26C300646A91 /* OCKStoreProtocol+Synchronous.swift */, - E7460493223870C100A1B16B /* OCKObjectCompatible.swift */, + E7460493223870C100A1B16B /* OCKVersionedObjectCompatible.swift */, ); path = Protocols; sourceTree = ""; @@ -807,34 +809,35 @@ E7AE852E2232F24600AF7C32 /* CoreData */ = { isa = PBXGroup; children = ( - 039FDF3425AFC345008F3684 /* Migrations */, 039FDEFB25AF6601008F3684 /* CareKitStore.xcdatamodeld */, - 03A156B824466B6800A3EEC0 /* Synchronization */, - E7AE853B2232F24600AF7C32 /* OCKStore.swift */, - 03ADE71525CDFC98008507BE /* OCKStore+Transactions.swift */, - E7AE85362232F24600AF7C32 /* OCKStore+Patients.swift */, - E7E6FF6122372B3600782246 /* OCKStore+CarePlans.swift */, - E7D671C12281F7380089E4B7 /* OCKStore+Contacts.swift */, - E7AE85322232F24600AF7C32 /* OCKStore+Tasks.swift */, - E7AE85332232F24600AF7C32 /* OCKStore+Outcomes.swift */, - 03ADE6F625CDCC00008507BE /* OCKStore+HealthKit.swift */, - E7AE85392232F24600AF7C32 /* OCKCDPatient.swift */, + 039FDF3425AFC345008F3684 /* Migrations */, E7E6FF56223716A900782246 /* OCKCDCarePlan.swift */, + 0322ED19245752CE0018FCEB /* OCKCDClock.swift */, E773748A228111BD00F31F94 /* OCKCDContact.swift */, - E7AE85382232F24600AF7C32 /* OCKCDTask.swift */, - E7AE852F2232F24600AF7C32 /* OCKCDScheduleElement.swift */, + 03459E7023393D1E001EB323 /* OCKCDHealthKitLinkage.swift */, + 70A31BE42D6BD58000FA2EF7 /* OCKCDHealthKitOutcome.swift */, + 03ADE6CA25CDBD5A008507BE /* OCKCDHealthKitTask.swift */, + 0326CE5C25C3903700C2553C /* OCKCDKnowledgeElement.swift */, + E7131DCE2242CF680001861B /* OCKCDNote.swift */, + E7AE85372232F24600AF7C32 /* OCKCDObject.swift */, E7AE85302232F24600AF7C32 /* OCKCDOutcome.swift */, E7AE85312232F24600AF7C32 /* OCKCDOutcomeValue.swift */, - E7AE85372232F24600AF7C32 /* OCKCDObject.swift */, - E7AE853A2232F24600AF7C32 /* OCKCDVersionedObject.swift */, - E7131DCE2242CF680001861B /* OCKCDNote.swift */, + E7AE85392232F24600AF7C32 /* OCKCDPatient.swift */, E7844F2D2290DE7900EE2E1C /* OCKCDPersonName.swift */, E7857A89229B5F1400FBEFAF /* OCKCDPostalAddress.swift */, - 03459E7023393D1E001EB323 /* OCKCDHealthKitLinkage.swift */, - 0322ED19245752CE0018FCEB /* OCKCDClock.swift */, - 0326CE5C25C3903700C2553C /* OCKCDKnowledgeElement.swift */, - 03ADE6CA25CDBD5A008507BE /* OCKCDHealthKitTask.swift */, + E7AE852F2232F24600AF7C32 /* OCKCDScheduleElement.swift */, 03A7841B25DB080E00D93EFB /* OCKCDTag.swift */, + E7AE85382232F24600AF7C32 /* OCKCDTask.swift */, + E7AE853A2232F24600AF7C32 /* OCKCDVersionedObject.swift */, + E7AE853B2232F24600AF7C32 /* OCKStore.swift */, + E7E6FF6122372B3600782246 /* OCKStore+CarePlans.swift */, + E7D671C12281F7380089E4B7 /* OCKStore+Contacts.swift */, + 03ADE6F625CDCC00008507BE /* OCKStore+HealthKit.swift */, + E7AE85332232F24600AF7C32 /* OCKStore+Outcomes.swift */, + E7AE85362232F24600AF7C32 /* OCKStore+Patients.swift */, + E7AE85322232F24600AF7C32 /* OCKStore+Tasks.swift */, + 03ADE71525CDFC98008507BE /* OCKStore+Transactions.swift */, + 03A156B824466B6800A3EEC0 /* Synchronization */, ); path = CoreData; sourceTree = ""; @@ -1068,6 +1071,7 @@ 51E6632328871F83006197D3 /* OCKReadOnlyEventStore+FetchPartialEvents.swift in Sources */, E7B5C0162299E22400451AA5 /* OCKAdherence.swift in Sources */, 03678DDF2342C08200E27926 /* OCKTaskStoreDelegate.swift in Sources */, + 70A31BE52D6BD58000FA2EF7 /* OCKCDHealthKitOutcome.swift in Sources */, 03CB6EBD2316EFEF0081AA7C /* OCKHealthKitPassthroughStore.swift in Sources */, 5122A2C129523754003B0B57 /* CareTaskProgressStrategy.swift in Sources */, 03534C1F2342B4CA00BA1C67 /* OCKAnyPatientStore.swift in Sources */, @@ -1110,8 +1114,9 @@ E7D671C22281F7380089E4B7 /* OCKStore+Contacts.swift in Sources */, 03678DDA2342BD2D00E27926 /* OCKAnyContactStore.swift in Sources */, 0339A0202316FCCA002F784A /* OCKEventStore.swift in Sources */, + E7460494223870C100A1B16B /* OCKVersionedObjectCompatible.swift in Sources */, 5173451428DA50DE006CA562 /* OCKAdherenceAggregator.swift in Sources */, - E7460494223870C100A1B16B /* OCKObjectCompatible.swift in Sources */, + E7460494223870C100A1B16B /* OCKVersionedObjectCompatible.swift in Sources */, 03BB28FD25D5C78A004498E0 /* OCKQueryProtocol.swift in Sources */, 03678DE82342C59200E27926 /* OCKLabeledValue.swift in Sources */, E7AE85532232F24600AF7C32 /* OCKCDOutcomeValue.swift in Sources */, diff --git a/CareKitStore/CareKitStore/CoreData/OCKCDHealthKitOutcome.swift b/CareKitStore/CareKitStore/CoreData/OCKCDHealthKitOutcome.swift new file mode 100644 index 000000000..39230fdd3 --- /dev/null +++ b/CareKitStore/CareKitStore/CoreData/OCKCDHealthKitOutcome.swift @@ -0,0 +1,79 @@ +// +/* + Copyright (c) 2022, Apple Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + + 3. Neither the name of the copyright holder(s) nor the names of any contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. No license is granted to the trademarks of + the copyright holders even if such marks are included in this software. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import CoreData +import Foundation + +@objc(OCKCDHealthKitOutcome) +class OCKCDHealthKitOutcome: OCKCDVersionedObject { + @NSManaged var taskOccurrenceIndex: Int64 + @NSManaged var task: OCKCDHealthKitTask + @NSManaged var values: Set + @NSManaged var startDate: Date + @NSManaged var endDate: Date + @NSManaged var isOwnedByApp: Bool + + convenience init(outcome: OCKHealthKitOutcome, context: NSManagedObjectContext) { + self.init(entity: Self.entity(), insertInto: context) + self.copyVersionedValue(value: outcome, context: context) + self.isOwnedByApp = outcome.isOwnedByApp + + let task: OCKCDHealthKitTask = try! context.fetchObject(uuid: outcome.taskUUID) + let schedule = OCKSchedule(composing: task.scheduleElements.map { $0.makeValue() }) + let event = schedule[outcome.taskOccurrenceIndex] + + self.task = task + self.taskOccurrenceIndex = Int64(outcome.taskOccurrenceIndex) + self.startDate = event.start + self.endDate = event.end + self.values = Set(outcome.values.map { + OCKCDOutcomeValue(value: $0, context: context) + }) + } + + override func makeValue() -> OCKVersionedObjectCompatible { + makeOutcome() + } + + func makeOutcome() -> OCKHealthKitOutcome { + + var outcome = OCKHealthKitOutcome( + taskUUID: task.uuid, + taskOccurrenceIndex: Int(taskOccurrenceIndex), + values: values.map { $0.makeValue() } + ) + + outcome.copyVersionedValues(from: self) + + return outcome + } +} + diff --git a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitOutcome.swift b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitOutcome.swift index 34fee0fa6..0d79c07ac 100644 --- a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitOutcome.swift +++ b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitOutcome.swift @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import CoreData import Foundation import HealthKit @@ -40,13 +41,28 @@ public struct OCKHealthKitOutcome: Codable, Equatable, Identifiable, OCKAnyOutco public let isOwnedByApp: Bool // MARK: OCKAnyOutcome - public var id: String { taskUUID.uuidString + "_\(taskOccurrenceIndex)" } + public var id: String = UUID().uuidString public var taskOccurrenceIndex: Int public var values: [OCKOutcomeValue] public var remoteID: String? public var groupIdentifier: String? public var notes: [OCKNote]? + // MARK: OCKVersionedObjectCompatible + public var effectiveDate: Date + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? + public var tags: [String]? + public var source: String? + public var userInfo: [String: String]? + public var asset: String? + public var timezone: TimeZone + /// A record of the HealthKit object that this outcome is derived from. Used for targeted deletions. /// A list of UUIDs at a particular index is associated with an outcome value at the same index in `values`. internal var healthKitUUIDs: [[UUID]] = [] @@ -62,6 +78,8 @@ public struct OCKHealthKitOutcome: Codable, Equatable, Identifiable, OCKAnyOutco self.taskOccurrenceIndex = taskOccurrenceIndex self.values = values self.isOwnedByApp = true + self.effectiveDate = Date() + self.timezone = TimeZone.current } internal init(taskUUID: UUID, taskOccurrenceIndex: Int, values: [OCKOutcomeValue], isOwnedByApp: Bool, healthKitUUIDs: [[UUID]]) { @@ -70,6 +88,8 @@ public struct OCKHealthKitOutcome: Codable, Equatable, Identifiable, OCKAnyOutco self.values = values self.isOwnedByApp = isOwnedByApp self.healthKitUUIDs = healthKitUUIDs + self.effectiveDate = Date() + self.timezone = TimeZone.current } public func belongs(to task: OCKAnyTask) -> Bool { @@ -77,3 +97,18 @@ public struct OCKHealthKitOutcome: Codable, Equatable, Identifiable, OCKAnyOutco return task.uuid == taskUUID } } + +extension OCKHealthKitOutcome: OCKVersionedObjectCompatible { + + static func entity() -> NSEntityDescription { + OCKCDHealthKitOutcome.entity() + } + + func entity() -> OCKEntity { + .healthKitOutcome(self) + } + + func insert(context: NSManagedObjectContext) -> OCKCDVersionedObject { + OCKCDHealthKitOutcome(outcome: self, context: context) + } +} diff --git a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore+Outcomes.swift b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore+Outcomes.swift index b2e8b61b3..1e98ede7d 100644 --- a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore+Outcomes.swift +++ b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore+Outcomes.swift @@ -43,11 +43,11 @@ public extension OCKHealthKitPassthroughStore { guard outcome.isOwnedByApp else { throw OCKStoreError.addFailed(reason: "Cannot persist an OCKHealthKitOutcome that is not owned by this app!") } guard outcome.values.count == 1 - else { throw OCKStoreError.addFailed(reason: "OCKHealthKitOutcomes must have exactly 1 value, but got \(outcome.values.count).") } + else { throw OCKStoreError.addFailed(reason: "OCKHealthKitOutcomes must have exactly 1 value, but attempting to add \(outcome.values.count).") } guard let value = outcome.values.first?.doubleValue else { throw OCKStoreError.addFailed(reason: "OCKHealthKitOutcome's value must be of type Double, but was not.") } guard let task = tasks.first(where: { $0.uuid == outcome.taskUUID }) - else { throw OCKStoreError.addFailed(reason: "No task could be for outcome") } + else { throw OCKStoreError.addFailed(reason: "No task could be found for outcome") } let unit = task.healthKitLinkage.unit let quantity = HKQuantity(unit: unit, doubleValue: value) diff --git a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitTask.swift b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitTask.swift index 8bd39d192..756aa6af0 100644 --- a/CareKitStore/CareKitStore/HealthKit/OCKHealthKitTask.swift +++ b/CareKitStore/CareKitStore/HealthKit/OCKHealthKitTask.swift @@ -51,14 +51,12 @@ public struct OCKHealthKitTask: Codable, Equatable, OCKAnyVersionableTask, OCKAn public var groupIdentifier: String? public var tags: [String]? - // MARK: OCKVersionable + // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date public internal(set) var deletedDate: Date? public internal(set) var uuid = UUID() public internal(set) var nextVersionUUIDs: [UUID] = [] public internal(set) var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible public internal(set) var createdDate: Date? public internal(set) var updatedDate: Date? public internal(set) var schemaVersion: OCKSemanticVersion? diff --git a/CareKitStore/CareKitStore/Protocols/OCKObjectCompatible.swift b/CareKitStore/CareKitStore/Protocols/OCKVersionedObjectCompatible.swift similarity index 100% rename from CareKitStore/CareKitStore/Protocols/OCKObjectCompatible.swift rename to CareKitStore/CareKitStore/Protocols/OCKVersionedObjectCompatible.swift diff --git a/CareKitStore/CareKitStore/Structs/OCKCarePlan.swift b/CareKitStore/CareKitStore/Structs/OCKCarePlan.swift index 494571c63..e17d8523b 100644 --- a/CareKitStore/CareKitStore/Structs/OCKCarePlan.swift +++ b/CareKitStore/CareKitStore/Structs/OCKCarePlan.swift @@ -44,17 +44,15 @@ public struct OCKCarePlan: Codable, Equatable, Identifiable, OCKAnyCarePlan { public var id: String public var title: String - // MARK: OCKVersionable + // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date - public var deletedDate: Date? - public var uuid = UUID() - public var nextVersionUUIDs: [UUID] = [] - public var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible - public var createdDate: Date? - public var updatedDate: Date? - public var schemaVersion: OCKSemanticVersion? + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? public var groupIdentifier: String? public var tags: [String]? public var remoteID: String? diff --git a/CareKitStore/CareKitStore/Structs/OCKContact.swift b/CareKitStore/CareKitStore/Structs/OCKContact.swift index 67781d4d4..02fd3541c 100644 --- a/CareKitStore/CareKitStore/Structs/OCKContact.swift +++ b/CareKitStore/CareKitStore/Structs/OCKContact.swift @@ -51,17 +51,15 @@ public struct OCKContact: Codable, Equatable, Identifiable, OCKAnyContact { public var role: String? public var category: OCKContactCategory? - // MARK: OCKVersionable + // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date - public var deletedDate: Date? - public var uuid = UUID() - public var nextVersionUUIDs: [UUID] = [] - public var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible - public var createdDate: Date? - public var updatedDate: Date? - public var schemaVersion: OCKSemanticVersion? + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? public var groupIdentifier: String? public var tags: [String]? public var remoteID: String? diff --git a/CareKitStore/CareKitStore/Structs/OCKEntity.swift b/CareKitStore/CareKitStore/Structs/OCKEntity.swift index 64ba07776..562e06a4b 100644 --- a/CareKitStore/CareKitStore/Structs/OCKEntity.swift +++ b/CareKitStore/CareKitStore/Structs/OCKEntity.swift @@ -51,6 +51,9 @@ public enum OCKEntity: Equatable, Codable { /// An outcome entity. case outcome(OCKOutcome) + /// A HealthKit outcome entity. + case healthKitOutcome(OCKHealthKitOutcome) + /// The type of the contained entity. public var entityType: EntityType { switch self { @@ -60,6 +63,7 @@ public enum OCKEntity: Equatable, Codable { case .task: return .task case .healthKitTask: return .healthKitTask case .outcome: return .outcome + case .healthKitOutcome: return .healthKitOutcome } } @@ -71,6 +75,7 @@ public enum OCKEntity: Equatable, Codable { case let .task(task): return task case let .healthKitTask(task): return task case let .outcome(outcome): return outcome + case let .healthKitOutcome(outcome): return outcome } } @@ -88,6 +93,7 @@ public enum OCKEntity: Equatable, Codable { case .task: self = .task(try container.decode(OCKTask.self, forKey: .object)) case .healthKitTask: self = .healthKitTask(try container.decode(OCKHealthKitTask.self, forKey: .object)) case .outcome: self = .outcome(try container.decode(OCKOutcome.self, forKey: .object)) + case .healthKitOutcome: self = .healthKitOutcome(try container.decode(OCKHealthKitOutcome.self, forKey: .object)) } } @@ -101,6 +107,7 @@ public enum OCKEntity: Equatable, Codable { case let .task(task): try container.encode(task, forKey: .object) case let .healthKitTask(task): try container.encode(task, forKey: .object) case let .outcome(outcome): try container.encode(outcome, forKey: .object) + case let .healthKitOutcome(outcome): try container.encode(outcome, forKey: .object) } } @@ -124,5 +131,8 @@ public enum OCKEntity: Equatable, Codable { /// The outcome entity type. case outcome + + /// The HealthKit outcome entity type. + case healthKitOutcome } } diff --git a/CareKitStore/CareKitStore/Structs/OCKOutcome.swift b/CareKitStore/CareKitStore/Structs/OCKOutcome.swift index 2b43d3615..cc603c59c 100644 --- a/CareKitStore/CareKitStore/Structs/OCKOutcome.swift +++ b/CareKitStore/CareKitStore/Structs/OCKOutcome.swift @@ -44,17 +44,15 @@ public struct OCKOutcome: Codable, Equatable, Identifiable, OCKAnyOutcome { public var taskOccurrenceIndex: Int public var values: [OCKOutcomeValue] - // MARK: OCKVersionable + // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date - public var deletedDate: Date? - public var uuid = UUID() - public var nextVersionUUIDs: [UUID] = [] - public var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible - public var createdDate: Date? - public var updatedDate: Date? - public var schemaVersion: OCKSemanticVersion? + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? public var remoteID: String? public var groupIdentifier: String? public var tags: [String]? diff --git a/CareKitStore/CareKitStore/Structs/OCKPatient.swift b/CareKitStore/CareKitStore/Structs/OCKPatient.swift index 93a2896c8..c08bf9e05 100644 --- a/CareKitStore/CareKitStore/Structs/OCKPatient.swift +++ b/CareKitStore/CareKitStore/Structs/OCKPatient.swift @@ -43,15 +43,13 @@ public struct OCKPatient: Codable, Equatable, Identifiable, OCKAnyPatient { // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date - public var deletedDate: Date? - public var uuid = UUID() - public var nextVersionUUIDs: [UUID] = [] - public var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible - public var createdDate: Date? - public var updatedDate: Date? - public var schemaVersion: OCKSemanticVersion? + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? public var groupIdentifier: String? public var tags: [String]? public var remoteID: String? diff --git a/CareKitStore/CareKitStore/Structs/OCKTask.swift b/CareKitStore/CareKitStore/Structs/OCKTask.swift index d74c5d71c..b103293be 100644 --- a/CareKitStore/CareKitStore/Structs/OCKTask.swift +++ b/CareKitStore/CareKitStore/Structs/OCKTask.swift @@ -48,17 +48,15 @@ public struct OCKTask: Codable, Equatable, OCKAnyVersionableTask, OCKAnyMutableT public var groupIdentifier: String? public var tags: [String]? - // MARK: OCKVersionable + // MARK: OCKVersionedObjectCompatible public var effectiveDate: Date - public var deletedDate: Date? - public var uuid = UUID() - public var nextVersionUUIDs: [UUID] = [] - public var previousVersionUUIDs: [UUID] = [] - - // MARK: OCKObjectCompatible - public var createdDate: Date? - public var updatedDate: Date? - public var schemaVersion: OCKSemanticVersion? + public internal(set) var deletedDate: Date? + public internal(set) var uuid = UUID() + public internal(set) var nextVersionUUIDs: [UUID] = [] + public internal(set) var previousVersionUUIDs: [UUID] = [] + public internal(set) var createdDate: Date? + public internal(set) var updatedDate: Date? + public internal(set) var schemaVersion: OCKSemanticVersion? public var remoteID: String? public var source: String? public var userInfo: [String: String]?