NightscoutTreatment.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Foundation
  2. struct NigtscoutTreatment: JSON, Hashable, Equatable {
  3. var duration: Int?
  4. var rawDuration: PumpHistoryEvent?
  5. var rawRate: PumpHistoryEvent?
  6. var absolute: Decimal?
  7. var rate: Decimal?
  8. var eventType: EventType
  9. var createdAt: Date?
  10. var enteredBy: String?
  11. var bolus: PumpHistoryEvent?
  12. var insulin: Decimal?
  13. var notes: String?
  14. var carbs: Decimal?
  15. var fat: Decimal?
  16. var protein: Decimal?
  17. var foodType: String?
  18. let targetTop: Decimal?
  19. let targetBottom: Decimal?
  20. var glucoseType: String?
  21. var glucose: String?
  22. var units: String?
  23. static let local = "iAPS"
  24. static let empty = NigtscoutTreatment(from: "{}")!
  25. static func == (lhs: NigtscoutTreatment, rhs: NigtscoutTreatment) -> Bool {
  26. (lhs.createdAt ?? Date()) == (rhs.createdAt ?? Date())
  27. }
  28. func hash(into hasher: inout Hasher) {
  29. hasher.combine(createdAt ?? Date())
  30. }
  31. }
  32. extension NigtscoutTreatment {
  33. private enum CodingKeys: String, CodingKey {
  34. case duration
  35. case rawDuration = "raw_duration"
  36. case rawRate = "raw_rate"
  37. case absolute
  38. case rate
  39. case eventType
  40. case createdAt = "created_at"
  41. case enteredBy
  42. case bolus
  43. case insulin
  44. case notes
  45. case carbs
  46. case fat
  47. case protein
  48. case foodType
  49. case targetTop
  50. case targetBottom
  51. case glucoseType
  52. case glucose
  53. case units
  54. }
  55. }