NightscoutTreatment.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Foundation
  2. struct NightscoutTreatment: 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: PumpEventStored.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. var id: String?
  24. var fpuID: String?
  25. static let local = "Trio"
  26. static let empty = NightscoutTreatment(from: "{}")!
  27. static func == (lhs: NightscoutTreatment, rhs: NightscoutTreatment) -> Bool {
  28. (lhs.createdAt ?? Date()) == (rhs.createdAt ?? Date())
  29. }
  30. func hash(into hasher: inout Hasher) {
  31. hasher.combine(createdAt ?? Date())
  32. }
  33. }
  34. extension NightscoutTreatment {
  35. private enum CodingKeys: String, CodingKey {
  36. case duration
  37. case rawDuration = "raw_duration"
  38. case rawRate = "raw_rate"
  39. case absolute
  40. case rate
  41. case eventType
  42. case createdAt = "created_at"
  43. case enteredBy
  44. case bolus
  45. case insulin
  46. case notes
  47. case carbs
  48. case fat
  49. case protein
  50. case foodType
  51. case targetTop
  52. case targetBottom
  53. case glucoseType
  54. case glucose
  55. case units
  56. case id
  57. case fpuID
  58. }
  59. }