Skip to content

Commit

Permalink
Relax Dexcom API validations to match Tidepool data model validations
Browse files Browse the repository at this point in the history
* Relax Dexcom API validations to match Tidepool data model validations
* Rename insulin dose constants to properly include units
  • Loading branch information
Darin Krauss committed Dec 6, 2018
1 parent 4dee948 commit 942e0b4
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 247 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## HEAD

## v1.31.1

* Relax Dexcom API validations to match Tidepool data model validations
* Rename insulin dose constants to properly include units

## v1.30.0

* Fix Dexcom API v2 edge cases
Expand Down
26 changes: 13 additions & 13 deletions data/types/insulin/dose.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
)

const (
DoseActiveMaximum = 250.0
DoseActiveMinimum = 0.0
DoseCorrectionMaximum = 250.0
DoseCorrectionMinimum = -250.0
DoseFoodMaximum = 250.0
DoseFoodMinimum = 0.0
DoseTotalMaximum = 250.0
DoseTotalMinimum = 0.0
DoseUnitsUnits = "Units"
DoseActiveUnitsMaximum = 250.0
DoseActiveUnitsMinimum = 0.0
DoseCorrectionUnitsMaximum = 250.0
DoseCorrectionUnitsMinimum = -250.0
DoseFoodUnitsMaximum = 250.0
DoseFoodUnitsMinimum = 0.0
DoseTotalUnitsMaximum = 250.0
DoseTotalUnitsMinimum = 0.0
DoseUnitsUnits = "Units"
)

func DoseUnits() []string {
Expand Down Expand Up @@ -54,10 +54,10 @@ func (d *Dose) Parse(parser data.ObjectParser) {
}

func (d *Dose) Validate(validator structure.Validator) {
validator.Float64("active", d.Active).InRange(DoseActiveMinimum, DoseActiveMaximum)
validator.Float64("correction", d.Correction).InRange(DoseCorrectionMinimum, DoseCorrectionMaximum)
validator.Float64("food", d.Food).InRange(DoseFoodMinimum, DoseFoodMaximum)
validator.Float64("total", d.Total).Exists().InRange(DoseTotalMinimum, DoseTotalMaximum)
validator.Float64("active", d.Active).InRange(DoseActiveUnitsMinimum, DoseActiveUnitsMaximum)
validator.Float64("correction", d.Correction).InRange(DoseCorrectionUnitsMinimum, DoseCorrectionUnitsMaximum)
validator.Float64("food", d.Food).InRange(DoseFoodUnitsMinimum, DoseFoodUnitsMaximum)
validator.Float64("total", d.Total).Exists().InRange(DoseTotalUnitsMinimum, DoseTotalUnitsMaximum)
validator.String("units", d.Units).Exists().OneOf(DoseUnits()...)
}

Expand Down
32 changes: 16 additions & 16 deletions data/types/insulin/dose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ import (
)

var _ = Describe("Dose", func() {
It("DoseActiveMaximum is expected", func() {
Expect(insulin.DoseActiveMaximum).To(Equal(250.0))
It("DoseActiveUnitsMaximum is expected", func() {
Expect(insulin.DoseActiveUnitsMaximum).To(Equal(250.0))
})

It("DoseActiveMinimum is expected", func() {
Expect(insulin.DoseActiveMinimum).To(Equal(0.0))
It("DoseActiveUnitsMinimum is expected", func() {
Expect(insulin.DoseActiveUnitsMinimum).To(Equal(0.0))
})

It("DoseCorrectionMaximum is expected", func() {
Expect(insulin.DoseCorrectionMaximum).To(Equal(250.0))
It("DoseCorrectionUnitsMaximum is expected", func() {
Expect(insulin.DoseCorrectionUnitsMaximum).To(Equal(250.0))
})

It("DoseCorrectionMinimum is expected", func() {
Expect(insulin.DoseCorrectionMinimum).To(Equal(-250.0))
It("DoseCorrectionUnitsMinimum is expected", func() {
Expect(insulin.DoseCorrectionUnitsMinimum).To(Equal(-250.0))
})

It("DoseFoodMaximum is expected", func() {
Expect(insulin.DoseFoodMaximum).To(Equal(250.0))
It("DoseFoodUnitsMaximum is expected", func() {
Expect(insulin.DoseFoodUnitsMaximum).To(Equal(250.0))
})

It("DoseFoodMinimum is expected", func() {
Expect(insulin.DoseFoodMinimum).To(Equal(0.0))
It("DoseFoodUnitsMinimum is expected", func() {
Expect(insulin.DoseFoodUnitsMinimum).To(Equal(0.0))
})

It("DoseTotalMaximum is expected", func() {
Expect(insulin.DoseTotalMaximum).To(Equal(250.0))
It("DoseTotalUnitsMaximum is expected", func() {
Expect(insulin.DoseTotalUnitsMaximum).To(Equal(250.0))
})

It("DoseTotalMinimum is expected", func() {
Expect(insulin.DoseTotalMinimum).To(Equal(0.0))
It("DoseTotalUnitsMinimum is expected", func() {
Expect(insulin.DoseTotalUnitsMinimum).To(Equal(0.0))
})

It("DoseUnitsUnits is expected", func() {
Expand Down
8 changes: 4 additions & 4 deletions data/types/insulin/test/dose.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

func NewDose() *insulin.Dose {
datum := insulin.NewDose()
datum.Active = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseActiveMinimum, insulin.DoseActiveMaximum))
datum.Correction = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseCorrectionMinimum, insulin.DoseCorrectionMaximum))
datum.Food = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseFoodMinimum, insulin.DoseFoodMaximum))
datum.Total = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseTotalMinimum, insulin.DoseTotalMaximum))
datum.Active = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseActiveUnitsMinimum, insulin.DoseActiveUnitsMaximum))
datum.Correction = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseCorrectionUnitsMinimum, insulin.DoseCorrectionUnitsMaximum))
datum.Food = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseFoodUnitsMinimum, insulin.DoseFoodUnitsMaximum))
datum.Total = pointer.FromFloat64(test.RandomFloat64FromRange(insulin.DoseTotalUnitsMinimum, insulin.DoseTotalUnitsMaximum))
datum.Units = pointer.FromString(test.RandomStringFromArray(insulin.DoseUnits()))
return datum
}
Expand Down
127 changes: 37 additions & 90 deletions dexcom/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strconv"

dataTypesSettingsCgm "github.com/tidepool-org/platform/data/types/settings/cgm"
"github.com/tidepool-org/platform/errors"
"github.com/tidepool-org/platform/pointer"
"github.com/tidepool-org/platform/structure"
Expand Down Expand Up @@ -32,9 +33,29 @@ const (
AlertSettingAlertNameUrgentLow = "urgentLow"
AlertSettingAlertNameUrgentLowSoon = "urgentLowSoon"

AlertSettingSnoozeMinutesMaximum = dataTypesSettingsCgm.SnoozeDurationMinutesMaximum
AlertSettingSnoozeMinutesMinimum = dataTypesSettingsCgm.SnoozeDurationMinutesMinimum

AlertSettingUnitMinutes = "minutes"
AlertSettingUnitMgdL = "mg/dL"
AlertSettingUnitMgdLMinute = "mg/dL/min"

AlertSettingValueFallMgdLMinuteMaximum = dataTypesSettingsCgm.FallAlertRateMgdLMinuteMaximum
AlertSettingValueFallMgdLMinuteMinimum = dataTypesSettingsCgm.FallAlertRateMgdLMinuteMinimum
AlertSettingValueHighMgdLMaximum = dataTypesSettingsCgm.HighAlertLevelMgdLMaximum
AlertSettingValueHighMgdLMinimum = dataTypesSettingsCgm.HighAlertLevelMgdLMinimum
AlertSettingValueLowMgdLMaximum = dataTypesSettingsCgm.LowAlertLevelMgdLMaximum
AlertSettingValueLowMgdLMinimum = dataTypesSettingsCgm.LowAlertLevelMgdLMinimum
AlertSettingValueNoReadingsMgdLMaximum = dataTypesSettingsCgm.NoDataAlertDurationMinutesMaximum
AlertSettingValueNoReadingsMgdLMinimum = dataTypesSettingsCgm.NoDataAlertDurationMinutesMinimum
AlertSettingValueOutOfRangeMgdLMaximum = dataTypesSettingsCgm.OutOfRangeAlertDurationMinutesMaximum
AlertSettingValueOutOfRangeMgdLMinimum = dataTypesSettingsCgm.OutOfRangeAlertDurationMinutesMinimum
AlertSettingValueRiseMgdLMinuteMaximum = dataTypesSettingsCgm.RiseAlertRateMgdLMinuteMaximum
AlertSettingValueRiseMgdLMinuteMinimum = dataTypesSettingsCgm.RiseAlertRateMgdLMinuteMinimum
AlertSettingValueUrgentLowMgdLMaximum = dataTypesSettingsCgm.UrgentLowAlertLevelMgdLMaximum
AlertSettingValueUrgentLowMgdLMinimum = dataTypesSettingsCgm.UrgentLowAlertLevelMgdLMinimum
AlertSettingValueUrgentLowSoonMgdLMaximum = dataTypesSettingsCgm.UrgentLowAlertLevelMgdLMaximum
AlertSettingValueUrgentLowSoonMgdLMinimum = dataTypesSettingsCgm.UrgentLowAlertLevelMgdLMinimum
)

func AlertScheduleSettingsDays() []string {
Expand Down Expand Up @@ -87,108 +108,34 @@ func AlertSettingUnitFalls() []string {
return []string{AlertSettingUnitMgdLMinute}
}

func AlertSettingValueFallMgdLMinutes() []float64 {
return []float64{2, 3}
}

func AlertSettingSnoozeFalls() []int {
return []int{0, 30}
}

func AlertSettingUnitHighs() []string {
return []string{AlertSettingUnitMgdL}
}

func AlertSettingValueHighMgdLs() []float64 {
return alertSettingValueHighMgdLs
}

var alertSettingValueHighMgdLs = generateFloatRange(120, 400, 10)

func AlertSettingSnoozeHighs() []int {
return alertSettingSnoozeHighs
}

var alertSettingSnoozeHighs = append(append([]int{0}, generateIntegerRange(15, 240, 5)...), generateIntegerRange(255, 300, 15)...)

func AlertSettingUnitLows() []string {
return []string{AlertSettingUnitMgdL}
}

func AlertSettingValueLowMgdLs() []float64 {
return alertSettingValueLowMgdLs
}

var alertSettingValueLowMgdLs = generateFloatRange(60, 100, 5)

func AlertSettingSnoozeLows() []int {
return alertSettingSnoozeLows
}

var alertSettingSnoozeLows = append(append([]int{0}, generateIntegerRange(15, 240, 5)...), generateIntegerRange(255, 300, 15)...)

func AlertSettingUnitNoReadings() []string {
return []string{AlertSettingUnitMinutes}
}

func AlertSettingValueNoReadingsMinutes() []float64 {
return []float64{0, 20}
}

func AlertSettingSnoozeNoReadings() []int {
return []int{0, 20, 25, 30}
}

func AlertSettingUnitOutOfRanges() []string {
return []string{AlertSettingUnitMinutes}
}

func AlertSettingValueOutOfRangeMinutes() []float64 {
return alertSettingValueOutOfRangeMinutes
}

var alertSettingValueOutOfRangeMinutes = generateFloatRange(20, 240, 5)

func AlertSettingSnoozeOutOfRanges() []int {
return []int{0, 20, 25, 30}
}

func AlertSettingUnitRises() []string {
return []string{AlertSettingUnitMgdLMinute}
}

func AlertSettingValueRiseMgdLMinutes() []float64 {
return []float64{2, 3}
}

func AlertSettingSnoozeRises() []int {
return []int{0, 30}
}

func AlertSettingUnitUrgentLows() []string {
return []string{AlertSettingUnitMgdL}
}

func AlertSettingValueUrgentLowMgdLs() []float64 {
return []float64{55}
}

func AlertSettingSnoozeUrgentLows() []int {
return []int{0, 30}
}

func AlertSettingUnitUrgentLowSoons() []string {
return []string{AlertSettingUnitMgdL}
}

func AlertSettingValueUrgentLowSoonMgdLs() []float64 {
return []float64{55}
}

func AlertSettingSnoozeUrgentLowSoons() []int {
return []int{0, 30}
}

type AlertSchedules []*AlertSchedule

func ParseAlertSchedules(parser structure.ArrayParser) *AlertSchedules {
Expand Down Expand Up @@ -583,10 +530,10 @@ func (a *AlertSetting) validateFall(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdLMinute:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueFallMgdLMinutes()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueFallMgdLMinuteMinimum, AlertSettingValueFallMgdLMinuteMaximum)
}
}
validator.Int("snooze", a.Snooze).OneOf(AlertSettingSnoozeFalls()...)
validator.Int("snooze", a.Snooze).InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -595,10 +542,10 @@ func (a *AlertSetting) validateHigh(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdL:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueHighMgdLs()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueHighMgdLMinimum, AlertSettingValueHighMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).Exists().OneOf(AlertSettingSnoozeHighs()...)
validator.Int("snooze", a.Snooze).Exists().InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -607,10 +554,10 @@ func (a *AlertSetting) validateLow(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdL:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueLowMgdLs()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueLowMgdLMinimum, AlertSettingValueLowMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).Exists().OneOf(AlertSettingSnoozeLows()...)
validator.Int("snooze", a.Snooze).Exists().InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -619,10 +566,10 @@ func (a *AlertSetting) validateNoReadings(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMinutes:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueNoReadingsMinutes()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueNoReadingsMgdLMinimum, AlertSettingValueNoReadingsMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).OneOf(AlertSettingSnoozeNoReadings()...)
validator.Int("snooze", a.Snooze).InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -631,10 +578,10 @@ func (a *AlertSetting) validateOutOfRange(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMinutes:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueOutOfRangeMinutes()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueOutOfRangeMgdLMinimum, AlertSettingValueOutOfRangeMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).OneOf(AlertSettingSnoozeOutOfRanges()...)
validator.Int("snooze", a.Snooze).InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -643,10 +590,10 @@ func (a *AlertSetting) validateRise(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdLMinute:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueRiseMgdLMinutes()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueRiseMgdLMinuteMinimum, AlertSettingValueRiseMgdLMinuteMaximum)
}
}
validator.Int("snooze", a.Snooze).OneOf(AlertSettingSnoozeRises()...)
validator.Int("snooze", a.Snooze).InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand All @@ -660,10 +607,10 @@ func (a *AlertSetting) validateUrgentLow(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdL:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueUrgentLowMgdLs()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueUrgentLowMgdLMinimum, AlertSettingValueUrgentLowMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).Exists().OneOf(AlertSettingSnoozeUrgentLows()...)
validator.Int("snooze", a.Snooze).Exists().InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists().True()
}

Expand All @@ -672,10 +619,10 @@ func (a *AlertSetting) validateUrgentLowSoon(validator structure.Validator) {
if a.Unit != nil {
switch *a.Unit {
case AlertSettingUnitMgdL:
validator.Float64("value", a.Value).Exists().OneOf(AlertSettingValueUrgentLowSoonMgdLs()...)
validator.Float64("value", a.Value).Exists().InRange(AlertSettingValueUrgentLowSoonMgdLMinimum, AlertSettingValueUrgentLowSoonMgdLMaximum)
}
}
validator.Int("snooze", a.Snooze).Exists().OneOf(AlertSettingSnoozeUrgentLowSoons()...)
validator.Int("snooze", a.Snooze).Exists().InRange(AlertSettingSnoozeMinutesMinimum, AlertSettingSnoozeMinutesMaximum)
validator.Bool("enabled", a.Enabled).Exists()
}

Expand Down
Loading

0 comments on commit 942e0b4

Please sign in to comment.