Skip to content

Commit

Permalink
both bolus and boluses for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-bate committed Nov 7, 2023
1 parent fb3b9f7 commit e04413f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
12 changes: 11 additions & 1 deletion data/types/settings/pump/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
}

Expand Down Expand Up @@ -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"))
}
Expand Down
38 changes: 34 additions & 4 deletions data/types/settings/pump/pump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -277,21 +278,51 @@ 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 },
),
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"),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions data/types/settings/pump/test/bolus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func NewRandomBolus() *pump.Bolus {
datum := pump.NewBolus()
datum.AmountMaximum = NewBolusAmountMaximum()
datum.Extended = NewBolusExtended()
datum.Calculator = NewBolusCalculator()
return datum
}

Expand All @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions data/types/settings/pump/test/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e04413f

Please sign in to comment.