domain

package
v0.0.0-...-0d6b9d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GlucoseTypeHistorical = 0 // Historical measurement from /graph endpoint
	GlucoseTypeCurrent    = 1 // Current measurement from /connections endpoint
)

Glucose type constants

View Source
const (
	GlucoseColorNormal   = 1 // 🟢 Normal glucose levels
	GlucoseColorWarning  = 2 // 🟠 Warning - outside target range
	GlucoseColorCritical = 3 // 🔴 Critical - dangerous levels
)

GlucoseColor constants

View Source
const (
	TrendArrowFallingRapidly = 1 // ⬇️⬇️ Falling rapidly
	TrendArrowFalling        = 2 // ⬇️ Falling
	TrendArrowStable         = 3 // ➡️ Stable
	TrendArrowRising         = 4 // ⬆️ Rising
	TrendArrowRisingRapidly  = 5 // ⬆️⬆️ Rising rapidly
)

TrendArrow constants

View Source
const (
	GlucoseUnitsMmolL = 0 // mmol/L (millimoles per liter)
	GlucoseUnitsMgDl  = 1 // mg/dL (milligrams per deciliter)
)

GlucoseUnits constants

View Source
const UnresponsiveThreshold = 20 * time.Minute

UnresponsiveThreshold is the duration after which a sensor is considered unresponsive if no measurements have been received.

Variables

This section is empty.

Functions

func CalculateGMI

func CalculateGMI(averageMgDl float64) *float64

CalculateGMI computes the Glucose Management Indicator from average glucose in mg/dL. Formula: GMI(%) = 3.31 + 0.02392 × [mean glucose in mg/dL] Returns nil if averageMgDl <= 0.

func SensorDurationDays

func SensorDurationDays(sensorType int) int

SensorDurationDays returns the expected duration in days for a given sensor type.

Types

type DeviceInfo

type DeviceInfo struct {
	// Database fields
	ID        uint      `gorm:"primaryKey" json:"-"`
	UpdatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"updatedAt"`

	DeviceID      string `gorm:"type:varchar(100);uniqueIndex;not null" json:"deviceId"`   // did: Device ID
	DeviceTypeID  int    `gorm:"type:integer;not null" json:"deviceTypeId"`                // dtid: Device type ID (40068 for Libre 3?)
	AppVersion    string `gorm:"type:varchar(50)" json:"appVersion"`                       // v: LibreLink app version (e.g., "3.6.5")
	AlarmsEnabled bool   `gorm:"type:boolean;not null;default:false" json:"alarmsEnabled"` // alarms: Whether alarms are enabled

	// Threshold configuration (in mg/dL)
	HighLimit         int `gorm:"type:integer" json:"highLimit"`         // hl: High glucose limit threshold
	LowLimit          int `gorm:"type:integer" json:"lowLimit"`          // ll: Low glucose limit threshold
	FixedLowThreshold int `gorm:"type:integer" json:"fixedLowThreshold"` // fixedLowThreshold: Fixed low threshold value

	// Additional metadata
	LastUpdate   time.Time `gorm:"type:datetime" json:"lastUpdate"`                         // u: Last update timestamp (Unix)
	LimitEnabled bool      `gorm:"type:boolean;not null;default:false" json:"limitEnabled"` // l: Whether limits are enabled
}

DeviceInfo represents patient device information and configuration. Source: /llu/connections → data[0].patientDevice

func (DeviceInfo) TableName

func (DeviceInfo) TableName() string

TableName specifies the table name for GORM.

type FixedLowAlarmValues

type FixedLowAlarmValues struct {
	MgPerDl  int     // mgdl: Threshold in mg/dL
	MmolPerL float64 // mmoll: Threshold in mmol/L
}

FixedLowAlarmValues represents fixed alarm threshold values in both units. Source: /llu/connections → data[0].patientDevice.fixedLowAlarmValues Note: This is not persisted to the database, it's a transient value from the API

type GlucoseMeasurement

type GlucoseMeasurement struct {
	// Database fields
	ID        uint      `gorm:"primaryKey" json:"-"`
	CreatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"createdAt"`

	// Timestamps
	FactoryTimestamp time.Time `gorm:"type:datetime;not null;uniqueIndex:idx_unique_factory_ts" json:"factoryTimestamp"` // Timestamp from the sensor (factory time), used for deduplication
	Timestamp        time.Time `gorm:"type:datetime;not null;index:idx_timestamp" json:"timestamp"`                      // Real timestamp (phone time), stored in UTC

	// Glucose values
	Value          float64 `gorm:"type:decimal(10,2);not null" json:"value"`    // Glucose value in mmol/L
	ValueInMgPerDl int     `gorm:"type:integer;not null" json:"valueInMgPerDl"` // Glucose value in mg/dL

	// Trend indicators (optional - nil for historical data)
	TrendArrow   *int    `gorm:"type:integer" json:"trendArrow,omitempty"` // 1-5: direction indicator (1=⬇️⬇️, 2=⬇️, 3=➡️, 4=⬆️, 5=⬆️⬆️)
	TrendMessage *string `gorm:"type:text" json:"trendMessage,omitempty"`  // Textual trend message (rarely used)

	// Status indicators
	GlucoseColor int  `gorm:"type:integer;not null;index:idx_color;column:measurement_color" json:"measurementColor"` // 1=🟢 normal, 2=🟠 warning, 3=🔴 critical
	GlucoseUnits int  `gorm:"type:integer;not null" json:"glucoseUnits"`                                              // 0=mmol/L, 1=mg/dL
	IsHigh       bool `gorm:"type:boolean;not null;default:false" json:"isHigh"`                                      // Above high threshold
	IsLow        bool `gorm:"type:boolean;not null;default:false" json:"isLow"`                                       // Below low threshold
	Type         int  `gorm:"type:integer;not null;index:idx_type" json:"type"`                                       // 0=historical, 1=current measurement
}

GlucoseMeasurement represents a glucose measurement from the LibreView API.

Fields ending with "mmol" represent values in mmol/L Fields ending with "mgdl" represent values in mg/dL

TrendArrow and TrendMessage are pointers because they are absent in historical data (only present in current measurements from /llu/connections endpoint)

func (GlucoseMeasurement) TableName

func (GlucoseMeasurement) TableName() string

TableName specifies the table name for GORM.

type GlucoseTargets

type GlucoseTargets struct {
	// Database fields
	ID        uint      `gorm:"primaryKey" json:"-"`
	UpdatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"updatedAt"`

	TargetHigh    int `gorm:"type:integer;not null" json:"targetHigh"`    // targetHigh: High target threshold (in mg/dL)
	TargetLow     int `gorm:"type:integer;not null" json:"targetLow"`     // targetLow: Low target threshold (in mg/dL)
	UnitOfMeasure int `gorm:"type:integer;not null" json:"unitOfMeasure"` // uom: Unit of measurement (0=mmol/L, 1=mg/dL)
}

GlucoseTargets represents global glucose target thresholds. Source: /llu/connections → data[0].targetHigh, targetLow, uom

These are used for calculating "Time In Range" statistics.

func (GlucoseTargets) TableName

func (GlucoseTargets) TableName() string

TableName specifies the table name for GORM.

type IntArray

type IntArray []int

IntArray is a custom type for storing []int as JSON in the database.

func (*IntArray) Scan

func (a *IntArray) Scan(value interface{}) error

Scan implements the sql.Scanner interface for reading from the database.

func (IntArray) Value

func (a IntArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface for writing to the database.

type SensorConfig

type SensorConfig struct {
	// Database fields
	ID        uint      `gorm:"primaryKey" json:"-"`
	CreatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"createdAt"`
	UpdatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"updatedAt"`

	SerialNumber      string     `gorm:"type:varchar(50);uniqueIndex:idx_serial;not null" json:"serialNumber"` // sn: Serial number of the sensor
	Activation        time.Time  `gorm:"type:datetime;not null;index:idx_activation" json:"activation"`        // a: Activation timestamp
	ExpiresAt         time.Time  `gorm:"type:datetime;not null" json:"expiresAt"`                              // Calculated: Activation + DurationDays
	EndedAt           *time.Time `gorm:"type:datetime" json:"endedAt"`                                         // When sensor was replaced (nil = current sensor)
	LastMeasurementAt *time.Time `gorm:"type:datetime" json:"lastMeasurementAt"`                               // Timestamp of the last received measurement
	SensorType        int        `gorm:"type:integer;not null" json:"sensorType"`                              // pt: Sensor type (4 = Libre 3 Plus)
	DurationDays      int        `gorm:"type:integer;not null" json:"durationDays"`                            // Expected duration in days (15 for Libre 3 Plus)
	DetectedAt        time.Time  `gorm:"type:datetime;not null" json:"detectedAt"`                             // When this sensor was first detected by the daemon
}

SensorConfig represents glucose sensor information from the LibreView API. Source: /llu/connections → data[0].sensor

func (*SensorConfig) ActualDays

func (s *SensorConfig) ActualDays() *float64

ActualDays returns the actual duration the sensor was used. Returns nil if the sensor is still active.

func (*SensorConfig) ElapsedDays

func (s *SensorConfig) ElapsedDays() float64

ElapsedDays returns the number of days since the sensor was activated. For stopped sensors, this is bounded by EndedAt or ExpiresAt.

func (*SensorConfig) IsActive

func (s *SensorConfig) IsActive() bool

IsActive returns true if the sensor is currently active (not ended).

func (*SensorConfig) RemainingDays

func (s *SensorConfig) RemainingDays() float64

RemainingDays returns the number of days remaining until the sensor expires. Returns 0 if the sensor has already expired or ended.

func (*SensorConfig) Status

func (s *SensorConfig) Status() SensorStatus

Status returns the current operational status of the sensor.

  • "stopped": Sensor has been replaced (EndedAt set) or expired (now > ExpiresAt)
  • "unresponsive": Sensor is active but not sending data (no measurement for > 20 min)
  • "running": Sensor is active and within its lifetime

func (SensorConfig) TableName

func (SensorConfig) TableName() string

TableName specifies the table name for GORM.

type SensorStatus

type SensorStatus string

SensorStatus represents the operational state of the sensor.

const (
	// SensorStatusRunning indicates the sensor is active and within its lifetime.
	SensorStatusRunning SensorStatus = "running"
	// SensorStatusStopped indicates the sensor is no longer active (replaced or expired).
	SensorStatusStopped SensorStatus = "stopped"
	// SensorStatusUnresponsive indicates the sensor is not sending data (no measurement for > 20 min).
	SensorStatusUnresponsive SensorStatus = "unresponsive"
)

type UserPreferences

type UserPreferences struct {
	// Database fields
	ID        uint      `gorm:"primaryKey" json:"-"`
	UpdatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP" json:"updatedAt"`

	UserID      string    `gorm:"type:varchar(100);uniqueIndex;not null" json:"userId"` // id: Unique user ID
	FirstName   string    `gorm:"type:varchar(100)" json:"firstName"`                   // firstName: User's first name
	LastName    string    `gorm:"type:varchar(100)" json:"lastName"`                    // lastName: User's last name
	Email       string    `gorm:"type:varchar(255)" json:"email"`                       // email: User's email address
	Country     string    `gorm:"type:varchar(2)" json:"country"`                       // country: ISO 2-letter country code (e.g., "CH")
	AccountType string    `gorm:"type:varchar(50)" json:"accountType"`                  // accountType: Account type ("pat" = patient)
	DateOfBirth time.Time `gorm:"type:datetime" json:"dateOfBirth"`                     // dateOfBirth: Unix timestamp converted to time.Time
	Created     time.Time `gorm:"type:datetime" json:"created"`                         // created: Account creation timestamp
	LastLogin   time.Time `gorm:"type:datetime" json:"lastLogin"`                       // lastLogin: Last login timestamp

	// Display preferences
	UILanguage            string `gorm:"type:varchar(10)" json:"uiLanguage"`            // uiLanguage: UI language code ("fr", "en", etc.)
	CommunicationLanguage string `gorm:"type:varchar(10)" json:"communicationLanguage"` // communicationLanguage: Communication language
	UnitOfMeasure         int    `gorm:"type:integer" json:"unitOfMeasure"`             // uom: Unit of measurement (0=mmol/L, 1=mg/dL)
	DateFormat            int    `gorm:"type:integer" json:"dateFormat"`                // dateFormat: Preferred date format
	TimeFormat            int    `gorm:"type:integer" json:"timeFormat"`                // timeFormat: Preferred time format (2 = 24h?)

	// Additional metadata
	EmailDays IntArray `gorm:"type:text" json:"emailDays"` // emailDay: Days for email notifications (stored as JSON)
}

UserPreferences represents user preferences and account information. Source: /user → data.user

func (UserPreferences) TableName

func (UserPreferences) TableName() string

TableName specifies the table name for GORM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL