PumpHistoryEvent.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import Foundation
  2. import LoopKit
  3. struct PumpHistoryEvent: JSON, Equatable, Identifiable {
  4. let id: String
  5. let type: EventType
  6. let timestamp: Date
  7. let amount: Decimal?
  8. let duration: Int?
  9. let durationMin: Int?
  10. let rate: Decimal?
  11. let temp: TempType?
  12. let carbInput: Int?
  13. let fatInput: Int?
  14. let proteinInput: Int?
  15. let note: String?
  16. let isSMB: Bool?
  17. <<<<<<< HEAD
  18. let isExternal: Bool?
  19. =======
  20. let isExternalInsulin: Bool?
  21. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  22. init(
  23. id: String,
  24. type: EventType,
  25. timestamp: Date,
  26. amount: Decimal? = nil,
  27. duration: Int? = nil,
  28. durationMin: Int? = nil,
  29. rate: Decimal? = nil,
  30. temp: TempType? = nil,
  31. carbInput: Int? = nil,
  32. <<<<<<< HEAD
  33. note: String? = nil,
  34. isSMB: Bool? = nil,
  35. isExternal: Bool? = nil
  36. =======
  37. fatInput: Int? = nil,
  38. proteinInput: Int? = nil,
  39. note: String? = nil,
  40. isSMB: Bool? = nil,
  41. isExternalInsulin: Bool? = nil
  42. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  43. ) {
  44. self.id = id
  45. self.type = type
  46. self.timestamp = timestamp
  47. self.amount = amount
  48. self.duration = duration
  49. self.durationMin = durationMin
  50. self.rate = rate
  51. self.temp = temp
  52. self.carbInput = carbInput
  53. self.fatInput = fatInput
  54. self.proteinInput = proteinInput
  55. self.note = note
  56. self.isSMB = isSMB
  57. <<<<<<< HEAD
  58. self.isExternal = isExternal
  59. =======
  60. self.isExternalInsulin = isExternalInsulin
  61. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  62. }
  63. }
  64. enum EventType: String, JSON {
  65. case bolus = "Bolus"
  66. case smb = "SMB"
  67. <<<<<<< HEAD
  68. case isExternal = "External Insulin"
  69. =======
  70. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  71. case mealBolus = "Meal Bolus"
  72. case correctionBolus = "Correction Bolus"
  73. case snackBolus = "Snack Bolus"
  74. case bolusWizard = "BolusWizard"
  75. case tempBasal = "TempBasal"
  76. case tempBasalDuration = "TempBasalDuration"
  77. case pumpSuspend = "PumpSuspend"
  78. case pumpResume = "PumpResume"
  79. case pumpAlarm = "PumpAlarm"
  80. case pumpBattery = "PumpBattery"
  81. case rewind = "Rewind"
  82. case prime = "Prime"
  83. case journalCarbs = "JournalEntryMealMarker"
  84. case nsTempBasal = "Temp Basal"
  85. case nsCarbCorrection = "Carb Correction"
  86. case nsTempTarget = "Temporary Target"
  87. case nsInsulinChange = "Insulin Change"
  88. case nsSiteChange = "Site Change"
  89. case nsBatteryChange = "Pump Battery Change"
  90. case nsAnnouncement = "Announcement"
  91. case nsSensorChange = "Sensor Start"
  92. <<<<<<< HEAD
  93. case capillaryGlucose = "BG Check"
  94. =======
  95. case nsExternalInsulin = "External Insulin"
  96. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  97. }
  98. enum TempType: String, JSON {
  99. case absolute
  100. case percent
  101. }
  102. extension PumpHistoryEvent {
  103. private enum CodingKeys: String, CodingKey {
  104. case id
  105. case type = "_type"
  106. case timestamp
  107. case amount
  108. case duration
  109. case durationMin = "duration (min)"
  110. case rate
  111. case temp
  112. case carbInput = "carb_input"
  113. case fatInput
  114. case proteinInput
  115. case note
  116. case isSMB
  117. <<<<<<< HEAD
  118. case isExternal
  119. =======
  120. case isExternalInsulin
  121. }
  122. }
  123. extension EventType {
  124. func mapEventTypeToPumpEventType() -> PumpEventType? {
  125. switch self {
  126. case .prime:
  127. return PumpEventType.prime
  128. case .pumpResume:
  129. return PumpEventType.resume
  130. case .rewind:
  131. return PumpEventType.rewind
  132. case .pumpSuspend:
  133. return PumpEventType.suspend
  134. case .nsBatteryChange,
  135. .pumpBattery:
  136. return PumpEventType.replaceComponent(componentType: .pump)
  137. case .nsInsulinChange:
  138. return PumpEventType.replaceComponent(componentType: .reservoir)
  139. case .nsSiteChange:
  140. return PumpEventType.replaceComponent(componentType: .infusionSet)
  141. case .pumpAlarm:
  142. return PumpEventType.alarm
  143. default:
  144. return nil
  145. }
  146. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  147. }
  148. }