PumpHistoryEvent.swift 2.1 KB

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