|
|
@@ -181,6 +181,46 @@ extension Onboarding {
|
|
|
return formatter
|
|
|
}
|
|
|
|
|
|
+ /// Remaps therapy items affected by a glucose unit change (mg/dL vs mmol/L).
|
|
|
+ ///
|
|
|
+ /// This function updates glucose target and insulin sensitivity (ISF) items to use the closest valid index
|
|
|
+ /// from the newly available rate arrays, preserving the original value intent.
|
|
|
+ ///
|
|
|
+ /// Call this after the user changes the unit selection.
|
|
|
+ ///
|
|
|
+ /// See also: `UnitSelectionStepView` `.onChange()` handlers.
|
|
|
+ func remapTherapyItemsForChangedUnits() {
|
|
|
+ // Targets
|
|
|
+ targetItems = targetItems.map { item in
|
|
|
+ let newLowIndex = closestIndex(for: targetRateValues[item.lowIndex], in: targetRateValues)
|
|
|
+ let newTimeIndex = closestIndex(for: targetTimeValues[item.timeIndex], in: targetTimeValues)
|
|
|
+ return TargetsEditor.Item(lowIndex: newLowIndex, highIndex: newLowIndex, timeIndex: newTimeIndex)
|
|
|
+ }
|
|
|
+
|
|
|
+ // ISF
|
|
|
+ isfItems = isfItems.map { item in
|
|
|
+ let newRateIndex = closestIndex(for: isfRateValues[item.rateIndex], in: isfRateValues)
|
|
|
+ let newTimeIndex = closestIndex(for: isfTimeValues[item.timeIndex], in: isfTimeValues)
|
|
|
+ return ISFEditor.Item(rateIndex: newRateIndex, timeIndex: newTimeIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Remaps therapy items affected by a pump model change.
|
|
|
+ ///
|
|
|
+ /// This function updates basal profile items to use the closest valid index
|
|
|
+ /// from the updated basal rate and time arrays, preserving the user's settings.
|
|
|
+ ///
|
|
|
+ /// Call this after the user selects a new pump model.
|
|
|
+ ///
|
|
|
+ /// See also: `UnitSelectionStepView` `.onChange()` handlers.
|
|
|
+ func remapTherapyItemsForChangedPumpModel() {
|
|
|
+ basalProfileItems = basalProfileItems.map { item in
|
|
|
+ let newRateIndex = closestIndex(for: basalProfileRateValues[item.rateIndex], in: basalProfileRateValues)
|
|
|
+ let newTimeIndex = closestIndex(for: basalProfileTimeValues[item.timeIndex], in: basalProfileTimeValues)
|
|
|
+ return BasalProfileEditor.Item(rateIndex: newRateIndex, timeIndex: newTimeIndex)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - Fetch existing therapy settings from file
|
|
|
|
|
|
/// Loads existing therapy settings from the provider and maps them into UI editor items.
|