PumpHistoryEvent.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 rewind = "Rewind"
  48. case prime = "Prime"
  49. case journalCarbs = "JournalEntryMealMarker"
  50. case nsTempBasal = "Temp Basal"
  51. case nsCarbCorrection = "Carb Correction"
  52. case nsTempTarget = "Temporary Target"
  53. case nsSiteChange = "Site Change"
  54. case nsSensorChange = "Sensor Start"
  55. }
  56. enum TempType: String, JSON {
  57. case absolute
  58. case percent
  59. }
  60. extension PumpHistoryEvent {
  61. private enum CodingKeys: String, CodingKey {
  62. case id
  63. case type = "_type"
  64. case timestamp
  65. case amount
  66. case duration
  67. case durationMin = "duration (min)"
  68. case rate
  69. case temp
  70. case carbInput = "carb_input"
  71. case note
  72. }
  73. }