diff --git a/data/types/settings/pump/pump.go b/data/types/settings/pump/pump.go index bbd65d2be..f5e1396fa 100644 --- a/data/types/settings/pump/pump.go +++ b/data/types/settings/pump/pump.go @@ -41,6 +41,7 @@ type Pump struct { BloodGlucoseTargetPreprandial *dataBloodGlucose.Target `json:"bgTargetPreprandial,omitempty" bson:"bgTargetPreprandial,omitempty"` BloodGlucoseTargetSchedule *BloodGlucoseTargetStartArray `json:"bgTarget,omitempty" bson:"bgTarget,omitempty"` // TODO: Move into BolusCalculator struct; rename bloodGlucoseTarget BloodGlucoseTargetSchedules *BloodGlucoseTargetStartArrayMap `json:"bgTargets,omitempty" bson:"bgTargets,omitempty"` // TODO: Move into BolusCalculator struct; rename bloodGlucoseTargets + Bolus *Bolus `json:"bolus,omitempty" bson:"bolus,omitempty"` Boluses *BolusMap `json:"boluses,omitempty" bson:"boluses,omitempty"` CarbohydrateRatioSchedule *CarbohydrateRatioStartArray `json:"carbRatio,omitempty" bson:"carbRatio,omitempty"` // TODO: Move into BolusCalculator struct; rename carbohydrateRatio CarbohydrateRatioSchedules *CarbohydrateRatioStartArrayMap `json:"carbRatios,omitempty" bson:"carbRatios,omitempty"` // TODO: Move into BolusCalculator struct; rename carbohydrateRatios @@ -84,6 +85,7 @@ func (p *Pump) Parse(parser structure.ObjectParser) { p.BloodGlucoseTargetPreprandial = dataBloodGlucose.ParseTarget(parser.WithReferenceObjectParser("bgTargetPreprandial")) p.BloodGlucoseTargetSchedule = ParseBloodGlucoseTargetStartArray(parser.WithReferenceArrayParser("bgTarget")) p.BloodGlucoseTargetSchedules = ParseBloodGlucoseTargetStartArrayMap(parser.WithReferenceObjectParser("bgTargets")) + p.Bolus = ParseBolus(parser.WithReferenceObjectParser("bolus")) p.Boluses = ParseBolusMap(parser.WithReferenceObjectParser("boluses")) p.CarbohydrateRatioSchedule = ParseCarbohydrateRatioStartArray(parser.WithReferenceArrayParser("carbRatio")) p.CarbohydrateRatioSchedules = ParseCarbohydrateRatioStartArrayMap(parser.WithReferenceObjectParser("carbRatios")) @@ -148,7 +150,12 @@ func (p *Pump) Validate(validator structure.Validator) { p.BloodGlucoseTargetSchedules.Validate(validator.WithReference("bgTargets"), unitsBloodGlucose) } - if p.Boluses != nil { + if p.Bolus != nil { + p.Bolus.Validate(validator.WithReference("bolus")) + if p.Boluses != nil { + validator.WithReference("boluses").ReportError(structureValidator.ErrorValueExists()) + } + } else if p.Boluses != nil { p.Boluses.Validate(validator.WithReference("boluses")) } @@ -231,6 +238,9 @@ func (p *Pump) Normalize(normalizer data.Normalizer) { if p.BloodGlucoseTargetSchedules != nil { p.BloodGlucoseTargetSchedules.Normalize(normalizer.WithReference("bgTargets"), unitsBloodGlucose) } + if p.Bolus != nil { + p.Bolus.Normalize(normalizer.WithReference("bolus")) + } if p.Boluses != nil { p.Boluses.Normalize(normalizer.WithReference("boluses")) } diff --git a/data/types/settings/pump/pump_test.go b/data/types/settings/pump/pump_test.go index 863e6ed85..b96a6363f 100644 --- a/data/types/settings/pump/pump_test.go +++ b/data/types/settings/pump/pump_test.go @@ -43,6 +43,7 @@ var _ = Describe("Pump", func() { Expect(datum.BloodGlucoseTargetPreprandial).To(BeNil()) Expect(datum.BloodGlucoseTargetSchedule).To(BeNil()) Expect(datum.BloodGlucoseTargetSchedules).To(BeNil()) + Expect(datum.Bolus).To(BeNil()) Expect(datum.Boluses).To(BeNil()) Expect(datum.CarbohydrateRatioSchedule).To(BeNil()) Expect(datum.CarbohydrateRatioSchedules).To(BeNil()) @@ -277,6 +278,28 @@ var _ = Describe("Pump", func() { datum.BloodGlucoseTargetSchedules.Set("one", pumpTest.RandomBloodGlucoseTargetStartArray(unitsBloodGlucose)) }, ), + Entry("bolus missing", + pointer.FromString("mmol/L"), + func(datum *pump.Pump, unitsBloodGlucose *string) { + datum.Bolus = nil + }, + ), + Entry("bolus invalid", + pointer.FromString("mmol/L"), + func(datum *pump.Pump, unitsBloodGlucose *string) { + datum.Boluses = nil + datum.Bolus = pumpTest.NewRandomBolus() + datum.Bolus.Calculator.Enabled = nil + }, + errorsTest.WithPointerSourceAndMeta(structureValidator.ErrorValueNotExists(), "/bolus/calculator/enabled", pumpTest.NewMeta()), + ), + Entry("bolus valid", + pointer.FromString("mmol/L"), + func(datum *pump.Pump, unitsBloodGlucose *string) { + datum.Boluses = nil + datum.Bolus = pumpTest.NewRandomBolus() + }, + ), Entry("boluses missing", pointer.FromString("mmol/L"), func(datum *pump.Pump, unitsBloodGlucose *string) { datum.Boluses = nil }, @@ -284,14 +307,22 @@ var _ = Describe("Pump", func() { Entry("boluses invalid", pointer.FromString("mmol/L"), func(datum *pump.Pump, unitsBloodGlucose *string) { + datum.Bolus = nil datum.Boluses = pumpTest.NewRandomBolusMap(2, 2) - (*datum.Boluses)[pumpTest.BolusName(1)].Extended.Enabled = nil + (*datum.Boluses)[pumpTest.BolusName(1)].AmountMaximum.Units = nil + (*datum.Boluses)[pumpTest.BolusName(2)].Extended.Enabled = nil + (*datum.Boluses)[pumpTest.BolusName(1)].Calculator.Enabled = nil }, - errorsTest.WithPointerSourceAndMeta(structureValidator.ErrorValueNotExists(), fmt.Sprintf("/boluses/%s/extended/enabled", pumpTest.BolusName(1)), pumpTest.NewMeta()), + errorsTest.WithPointerSourceAndMeta(structureValidator.ErrorValueNotExists(), fmt.Sprintf("/boluses/%s/amountMaximum/units", pumpTest.BolusName(1)), pumpTest.NewMeta()), + errorsTest.WithPointerSourceAndMeta(structureValidator.ErrorValueNotExists(), fmt.Sprintf("/boluses/%s/calculator/enabled", pumpTest.BolusName(1)), pumpTest.NewMeta()), + errorsTest.WithPointerSourceAndMeta(structureValidator.ErrorValueNotExists(), fmt.Sprintf("/boluses/%s/extended/enabled", pumpTest.BolusName(2)), pumpTest.NewMeta()), ), Entry("boluses valid", pointer.FromString("mmol/L"), - func(datum *pump.Pump, unitsBloodGlucose *string) { datum.Boluses = pumpTest.NewRandomBolusMap(1, 5) }, + func(datum *pump.Pump, unitsBloodGlucose *string) { + datum.Bolus = nil + datum.Boluses = pumpTest.NewRandomBolusMap(1, 5) + }, ), Entry("carbohydrate ratio schedule and carbohydrate ratio schedules missing", pointer.FromString("mmol/L"), @@ -676,7 +707,6 @@ var _ = Describe("Pump", func() { datum.BloodGlucoseTargetSchedules = nil datum.BloodGlucoseTargetPhysicalActivity = dataBloodGlucose.NewTarget() datum.BloodGlucoseTargetPreprandial = dataBloodGlucose.NewTarget() - datum.BloodGlucoseTargetSchedules = nil invalidCarbohydrateRatioSchedule := pumpTest.NewCarbohydrateRatioStartArray() (*invalidCarbohydrateRatioSchedule)[0].Start = nil datum.CarbohydrateRatioSchedule = invalidCarbohydrateRatioSchedule diff --git a/data/types/settings/pump/test/bolus.go b/data/types/settings/pump/test/bolus.go index 526cdfd4d..2a24e39dd 100644 --- a/data/types/settings/pump/test/bolus.go +++ b/data/types/settings/pump/test/bolus.go @@ -11,6 +11,7 @@ func NewRandomBolus() *pump.Bolus { datum := pump.NewBolus() datum.AmountMaximum = NewBolusAmountMaximum() datum.Extended = NewBolusExtended() + datum.Calculator = NewBolusCalculator() return datum } @@ -21,6 +22,7 @@ func CloneBolus(datum *pump.Bolus) *pump.Bolus { clone := pump.NewBolus() clone.AmountMaximum = CloneBolusAmountMaximum(datum.AmountMaximum) clone.Extended = CloneBolusExtended(datum.Extended) + clone.Calculator = CloneBolusCalculator(datum.Calculator) return clone } diff --git a/data/types/settings/pump/test/pump.go b/data/types/settings/pump/test/pump.go index 903628b52..1f5314544 100644 --- a/data/types/settings/pump/test/pump.go +++ b/data/types/settings/pump/test/pump.go @@ -85,6 +85,7 @@ func ClonePump(datum *pump.Pump) *pump.Pump { clone.BloodGlucoseTargetPreprandial = dataBloodGlucoseTest.CloneTarget(datum.BloodGlucoseTargetPreprandial) clone.BloodGlucoseTargetSchedule = CloneBloodGlucoseTargetStartArray(datum.BloodGlucoseTargetSchedule) clone.BloodGlucoseTargetSchedules = CloneBloodGlucoseTargetStartArrayMap(datum.BloodGlucoseTargetSchedules) + clone.Bolus = CloneBolus(datum.Bolus) clone.Boluses = CloneBolusMap(datum.Boluses) clone.CarbohydrateRatioSchedule = CloneCarbohydrateRatioStartArray(datum.CarbohydrateRatioSchedule) clone.CarbohydrateRatioSchedules = CloneCarbohydrateRatioStartArrayMap(datum.CarbohydrateRatioSchedules)