PumpHistoryEvent.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 smb = "SMB"
  43. case mealBulus = "Meal Bolus"
  44. case correctionBolus = "Correction Bolus"
  45. case snackBolus = "Snack Bolus"
  46. case bolusWizard = "BolusWizard"
  47. case tempBasal = "TempBasal"
  48. case tempBasalDuration = "TempBasalDuration"
  49. case pumpSuspend = "PumpSuspend"
  50. case pumpResume = "PumpResume"
  51. case pumpAlarm = "PumpAlarm"
  52. case pumpBattery = "PumpBattery"
  53. case rewind = "Rewind"
  54. case prime = "Prime"
  55. case journalCarbs = "JournalEntryMealMarker"
  56. case nsTempBasal = "Temp Basal"
  57. case nsCarbCorrection = "Carb Correction"
  58. case nsTempTarget = "Temporary Target"
  59. case nsInsulinChange = "Insulin Change"
  60. case nsSiteChange = "Site Change"
  61. case nsBatteryChange = "Pump Battery Change"
  62. case nsAnnouncement = "Announcement"
  63. case nsSensorChange = "Sensor Start"
  64. case capillaryGlucose = "BG Check"
  65. }
  66. enum TempType: String, JSON {
  67. case absolute
  68. case percent
  69. }
  70. extension PumpHistoryEvent {
  71. private enum CodingKeys: String, CodingKey {
  72. case id
  73. case type = "_type"
  74. case timestamp
  75. case amount
  76. case duration
  77. case durationMin = "duration (min)"
  78. case rate
  79. case temp
  80. case carbInput = "carb_input"
  81. case note
  82. case isSMB
  83. }
  84. }