InsulinModelProvider.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // InsulinModelProvider.swift
  3. // LoopKit
  4. //
  5. // Copyright © 2017 LoopKit Authors. All rights reserved.
  6. //
  7. public protocol InsulinModelProvider {
  8. func model(for type: InsulinType?) -> InsulinModel
  9. }
  10. public struct PresetInsulinModelProvider: InsulinModelProvider {
  11. var defaultRapidActingModel: InsulinModel?
  12. public init(defaultRapidActingModel: InsulinModel?) {
  13. self.defaultRapidActingModel = defaultRapidActingModel
  14. }
  15. public func model(for type: InsulinType?) -> InsulinModel {
  16. switch type {
  17. case .fiasp:
  18. return ExponentialInsulinModelPreset.fiasp
  19. case .lyumjev:
  20. return ExponentialInsulinModelPreset.lyumjev
  21. case .afrezza:
  22. return ExponentialInsulinModelPreset.afrezza
  23. default:
  24. return defaultRapidActingModel ?? ExponentialInsulinModelPreset.rapidActingAdult
  25. }
  26. }
  27. }
  28. // Provides a fixed model, ignoring insulin type
  29. public struct StaticInsulinModelProvider: InsulinModelProvider {
  30. var model: InsulinModel
  31. public init(_ model: InsulinModel) {
  32. self.model = model
  33. }
  34. public func model(for type: InsulinType?) -> InsulinModel {
  35. return model
  36. }
  37. }