TherapySetting.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // TherapySetting.swift
  3. // LoopKit
  4. //
  5. // Created by Rick Pasetto on 7/14/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. public enum TherapySetting {
  9. case glucoseTargetRange
  10. case preMealCorrectionRangeOverride
  11. case workoutCorrectionRangeOverride
  12. case suspendThreshold
  13. case basalRate(Int?)
  14. case deliveryLimits
  15. case insulinModel
  16. case carbRatio
  17. case insulinSensitivity
  18. case none
  19. }
  20. public extension TherapySetting {
  21. static var basalRate: TherapySetting {
  22. .basalRate(nil)
  23. }
  24. }
  25. extension TherapySetting: Equatable { }
  26. public extension TherapySetting {
  27. // The following comes from https://tidepool.atlassian.net/browse/IFU-24
  28. var title: String {
  29. switch self {
  30. case .glucoseTargetRange:
  31. return LocalizedString("Correction Range", comment: "Title text for glucose target range")
  32. case .preMealCorrectionRangeOverride:
  33. return String(format: LocalizedString("%@ Range", comment: "Format for correction range override therapy setting card"), CorrectionRangeOverrides.Preset.preMeal.title)
  34. case .workoutCorrectionRangeOverride:
  35. return String(format: LocalizedString("%@ Range", comment: "Format for correction range override therapy setting card"), CorrectionRangeOverrides.Preset.workout.title)
  36. case .suspendThreshold:
  37. return LocalizedString("Glucose Safety Limit", comment: "Title text for glucose safety limit")
  38. case .basalRate:
  39. return LocalizedString("Basal Rates", comment: "Title text for basal rates")
  40. case .deliveryLimits:
  41. return LocalizedString("Delivery Limits", comment: "Title text for delivery limits")
  42. case .insulinModel:
  43. return LocalizedString("Insulin Model", comment: "Title text for fast acting insulin model")
  44. case .carbRatio:
  45. return LocalizedString("Carb Ratios", comment: "Title text for carb ratios")
  46. case .insulinSensitivity:
  47. return LocalizedString("Insulin Sensitivities", comment: "Title text for insulin sensitivity")
  48. case .none:
  49. return ""
  50. }
  51. }
  52. var smallTitle: String {
  53. switch self {
  54. default:
  55. return title
  56. }
  57. }
  58. func descriptiveText(appName: String) -> String {
  59. switch self {
  60. case .glucoseTargetRange:
  61. return String(format: LocalizedString("Correction Range is the glucose value (or range of values) that you want %1$@ to aim for in adjusting your basal insulin and helping you calculate your boluses.", comment: "Descriptive text for glucose target range (1: app name)"), appName)
  62. case .preMealCorrectionRangeOverride:
  63. return LocalizedString("Temporarily lower your glucose target before a meal to impact post-meal glucose spikes.", comment: "Descriptive text for pre-meal correction range override")
  64. case .workoutCorrectionRangeOverride:
  65. return LocalizedString("Temporarily raise your glucose target before, during, or after physical activity to reduce the risk of low glucose events.", comment: "Descriptive text for workout correction range override")
  66. case .suspendThreshold:
  67. return String(format: LocalizedString("%1$@ will deliver basal and recommend bolus insulin only if your glucose is predicted to be above this limit for the next three hours.", comment: "Descriptive format string for glucose safety limit (1: app name)"), appName)
  68. case .basalRate:
  69. return LocalizedString("Your Basal Rate of insulin is the number of units per hour that you want to use to cover your background insulin needs.", comment: "Descriptive text for basal rate")
  70. case .deliveryLimits:
  71. return "\(DeliveryLimits.Setting.maximumBasalRate.localizedDescriptiveText(appName: appName))\n\n\(DeliveryLimits.Setting.maximumBolus.localizedDescriptiveText(appName: appName))"
  72. case .insulinModel:
  73. return String(format: LocalizedString("For fast acting insulin, %1$@ assumes it is actively working for 6 hours. You can choose from different models for the peak activity.", comment: "Descriptive text for fast acting insulin model (1: app name)"), appName)
  74. case .carbRatio:
  75. return LocalizedString("Your Carb Ratio is the number of grams of carbohydrates covered by one unit of insulin.", comment: "Descriptive text for carb ratio")
  76. case .insulinSensitivity:
  77. return LocalizedString("Your Insulin Sensitivities refer to the drop in glucose expected from one unit of insulin.", comment: "Descriptive text for insulin sensitivity")
  78. case .none:
  79. return ""
  80. }
  81. }
  82. }
  83. // MARK: Guardrails
  84. public extension TherapySetting {
  85. var guardrailCaptionForLowValue: String {
  86. switch self {
  87. case .glucoseTargetRange, .preMealCorrectionRangeOverride, .workoutCorrectionRangeOverride:
  88. return LocalizedString("A value you have entered is lower than what is typically recommended for most people.", comment: "Descriptive text for guardrail low value warning for schedule interface")
  89. default:
  90. return LocalizedString("The value you have entered is lower than what is typically recommended for most people.", comment: "Descriptive text for guardrail low value warning")
  91. }
  92. }
  93. var guardrailCaptionForHighValue: String {
  94. switch self {
  95. case .glucoseTargetRange, .preMealCorrectionRangeOverride, .workoutCorrectionRangeOverride:
  96. return LocalizedString("A value you have entered is higher than what is typically recommended for most people.", comment: "Descriptive text for guardrail high value warning for schedule interface")
  97. default:
  98. return LocalizedString("The value you have entered is higher than what is typically recommended for most people.", comment: "Descriptive text for guardrail high value warning")
  99. }
  100. }
  101. var guardrailCaptionForOutsideValues: String {
  102. switch self {
  103. case .deliveryLimits:
  104. return LocalizedString("The values you have entered are outside of what is typically recommended for most people.", comment: "Descriptive text for guardrail high value warning")
  105. default:
  106. return LocalizedString("Some of the values you have entered are outside of what is typically recommended for most people.", comment: "Descriptive text for guardrail high value warning for schedule interface")
  107. }
  108. }
  109. var guardrailSaveWarningCaption: String {
  110. switch self {
  111. default:
  112. return LocalizedString("One or more of the values you have entered is outside of what is typically recommended for most people.", comment: "Descriptive text for saving settings outside the recommended range")
  113. }
  114. }
  115. }