PumpHistoryEvent.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. let isNonPumpInsulin: Bool?
  15. init(
  16. id: String,
  17. type: EventType,
  18. timestamp: Date,
  19. amount: Decimal? = nil,
  20. duration: Int? = nil,
  21. durationMin: Int? = nil,
  22. rate: Decimal? = nil,
  23. temp: TempType? = nil,
  24. carbInput: Int? = nil,
  25. note: String? = nil,
  26. isSMB: Bool? = nil,
  27. isNonPumpInsulin: Bool? = nil
  28. ) {
  29. self.id = id
  30. self.type = type
  31. self.timestamp = timestamp
  32. self.amount = amount
  33. self.duration = duration
  34. self.durationMin = durationMin
  35. self.rate = rate
  36. self.temp = temp
  37. self.carbInput = carbInput
  38. self.note = note
  39. self.isSMB = isSMB
  40. self.isNonPumpInsulin = isNonPumpInsulin
  41. }
  42. }
  43. enum EventType: String, JSON {
  44. case bolus = "Bolus"
  45. case smb = "SMB"
  46. case nonPumpInsulin = "Non-pump Insulin"
  47. case mealBolus = "Meal Bolus"
  48. case correctionBolus = "Correction Bolus"
  49. case snackBolus = "Snack Bolus"
  50. case bolusWizard = "BolusWizard"
  51. case tempBasal = "TempBasal"
  52. case tempBasalDuration = "TempBasalDuration"
  53. case pumpSuspend = "PumpSuspend"
  54. case pumpResume = "PumpResume"
  55. case pumpAlarm = "PumpAlarm"
  56. case pumpBattery = "PumpBattery"
  57. case rewind = "Rewind"
  58. case prime = "Prime"
  59. case journalCarbs = "JournalEntryMealMarker"
  60. case nsTempBasal = "Temp Basal"
  61. case nsCarbCorrection = "Carb Correction"
  62. case nsTempTarget = "Temporary Target"
  63. case nsInsulinChange = "Insulin Change"
  64. case nsSiteChange = "Site Change"
  65. case nsBatteryChange = "Pump Battery Change"
  66. case nsAnnouncement = "Announcement"
  67. case nsSensorChange = "Sensor Start"
  68. case capillaryGlucose = "BG Check"
  69. }
  70. enum TempType: String, JSON {
  71. case absolute
  72. case percent
  73. }
  74. extension PumpHistoryEvent {
  75. private enum CodingKeys: String, CodingKey {
  76. case id
  77. case type = "_type"
  78. case timestamp
  79. case amount
  80. case duration
  81. case durationMin = "duration (min)"
  82. case rate
  83. case temp
  84. case carbInput = "carb_input"
  85. case note
  86. case isSMB
  87. case isNonPumpInsulin
  88. }
  89. }