PumpHistoryEvent.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 isExternalInsulin: 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. isExternalInsulin: 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.isExternalInsulin = isExternalInsulin
  38. }
  39. }
  40. enum EventType: String, JSON {
  41. case bolus = "Bolus"
  42. case externalInsulin = "External Insulin"
  43. case mealBolus = "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. }
  65. enum TempType: String, JSON {
  66. case absolute
  67. case percent
  68. }
  69. extension PumpHistoryEvent {
  70. private enum CodingKeys: String, CodingKey {
  71. case id
  72. case type = "_type"
  73. case timestamp
  74. case amount
  75. case duration
  76. case durationMin = "duration (min)"
  77. case rate
  78. case temp
  79. case carbInput = "carb_input"
  80. case note
  81. case isExternalInsulin
  82. }
  83. }