PumpHistoryEvent.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import Foundation
  2. struct PumpHistoryEvent: JSON, Equatable {
  3. let id: String
  4. let type: EventType
  5. let timestamp: Date
  6. let amount: Decimal?
  7. let duration: Int?
  8. let durationMin: Int?
  9. let rate: Decimal?
  10. let temp: TempType?
  11. let carbInput: Int?
  12. let note: String?
  13. let isSMB: Bool?
  14. init(
  15. id: String,
  16. type: EventType,
  17. timestamp: Date,
  18. amount: Decimal? = nil,
  19. duration: Int? = nil,
  20. durationMin: Int? = nil,
  21. rate: Decimal? = nil,
  22. temp: TempType? = nil,
  23. carbInput: Int? = nil,
  24. note: String? = nil,
  25. isSMB: Bool? = nil
  26. ) {
  27. self.id = id
  28. self.type = type
  29. self.timestamp = timestamp
  30. self.amount = amount
  31. self.duration = duration
  32. self.durationMin = durationMin
  33. self.rate = rate
  34. self.temp = temp
  35. self.carbInput = carbInput
  36. self.note = note
  37. self.isSMB = isSMB
  38. }
  39. }
  40. enum EventType: String, JSON {
  41. case bolus = "Bolus"
  42. case mealBulus = "Meal Bolus"
  43. case correctionBolus = "Correction Bolus"
  44. case snackBolus = "Snack Bolus"
  45. case bolusWizard = "BolusWizard"
  46. case tempBasal = "TempBasal"
  47. case tempBasalDuration = "TempBasalDuration"
  48. case pumpSuspend = "PumpSuspend"
  49. case pumpResume = "PumpResume"
  50. case pumpAlarm = "PumpAlarm"
  51. case pumpBattery = "PumpBattery"
  52. case rewind = "Rewind"
  53. case prime = "Prime"
  54. case journalCarbs = "JournalEntryMealMarker"
  55. case nsTempBasal = "Temp Basal"
  56. case nsCarbCorrection = "Carb Correction"
  57. case nsTempTarget = "Temporary Target"
  58. case nsInsulinChange = "Insulin Change"
  59. case nsSiteChange = "Site Change"
  60. case nsBatteryChange = "Pump Battery Change"
  61. case nsAnnouncement = "Announcement"
  62. case nsSensorChange = "Sensor Start"
  63. }
  64. enum TempType: String, JSON {
  65. case absolute
  66. case percent
  67. }
  68. extension PumpHistoryEvent {
  69. private enum CodingKeys: String, CodingKey {
  70. case id
  71. case type = "_type"
  72. case timestamp
  73. case amount
  74. case duration
  75. case durationMin = "duration (min)"
  76. case rate
  77. case temp
  78. case carbInput = "carb_input"
  79. case note
  80. case isSMB
  81. }
  82. }