PersistedPumpEvent.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // PersistedPumpEvent.swift
  3. // LoopKit
  4. //
  5. // Created by Nate Racklyeft on 8/1/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import Foundation
  9. public struct PersistedPumpEvent {
  10. /// The date of the event
  11. public let date: Date
  12. /// The date the event was persisted
  13. public let persistedDate: Date
  14. /// The insulin dose described by the event, if applicable
  15. public let dose: DoseEntry?
  16. /// Whether the event has been successfully uploaded
  17. public let isUploaded: Bool
  18. /// The NSManagedObject identifier of the event used by the store
  19. public let objectIDURL: URL
  20. /// The opaque raw data representing the event
  21. public let raw: Data?
  22. /// A human-readable short description of the event
  23. public let title: String?
  24. /// The type of pump event
  25. public let type: PumpEventType?
  26. /// Whether the pump event is marked mutable
  27. public let automatic: Bool?
  28. /// The type of alarm, only valid if type == .alarm
  29. public let alarmType: PumpAlarmType?
  30. public init(date: Date,
  31. persistedDate: Date,
  32. dose: DoseEntry?,
  33. isUploaded: Bool,
  34. objectIDURL: URL,
  35. raw: Data?,
  36. title: String?,
  37. type: PumpEventType?,
  38. automatic: Bool? = nil,
  39. alarmType: PumpAlarmType? = nil) {
  40. self.date = date
  41. self.persistedDate = persistedDate
  42. self.dose = dose
  43. self.isUploaded = isUploaded
  44. self.objectIDURL = objectIDURL
  45. self.raw = raw
  46. self.title = title
  47. self.type = type
  48. self.automatic = automatic
  49. self.alarmType = alarmType
  50. }
  51. }
  52. extension PumpEvent {
  53. var persistedPumpEvent: PersistedPumpEvent {
  54. return PersistedPumpEvent(
  55. date: date,
  56. persistedDate: createdAt,
  57. dose: dose,
  58. isUploaded: isUploaded,
  59. objectIDURL: objectID.uriRepresentation(),
  60. raw: raw,
  61. title: title,
  62. type: type,
  63. automatic: automatic,
  64. alarmType: alarmType
  65. )
  66. }
  67. }