NightscoutTreatment.swift 1.5 KB

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