dosage

package
v0.0.0-...-29719d2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDoseMatched = errors.New("no dose matched")
)
View Source
var Module = fx.Module("dosage",
	fx.Decorate(func(slog *slog.Logger) *slog.Logger {
		return slog.With("module", "dosage")
	}),
	fx.Provide(
		NewExporterService,
	),
)

Functions

This section is empty.

Types

type CSVDoseRecord

type CSVDoseRecord struct {
	DeliveryMethod string  `csv:"deliveryMethod"`
	Dose           float32 `csv:"dose"`
	TakenAt        string  `csv:"takenAt"`    // RFC3339
	TakenOffAt     string  `csv:"takenOffAt"` // RFC3339 or ""
	Comment        string  `csv:"comment"`
}

CSVDoseRecord is a single dose record in a CSV file. This is version 1.

type Days

type Days float64

Days is a number of days. It acts as a duration of time, so 1.5 Days is 36 hours.

func (Days) ToDuration

func (d Days) ToDuration() time.Duration

ToDuration converts Days to time.Duration.

type DeliveryMethod

type DeliveryMethod = openapi.DeliveryMethod

DeliveryMethod describes a method of delivery for medication.

type Dosage

type Dosage struct {
	// UserSecret is the secret of the user who the schedule is for.
	UserSecret user.Secret
	// DeliveryMethod is the method of delivery for the medication.
	// Check the [delivery_methods] table.
	DeliveryMethod string
	// Dose is the amount of medication to be delivered/taken.
	Dose float32
	// Interval is the interval between doses in days.
	Interval Days
	// Concurrence is the number of estrogen patches that are on the body at
	// once. This is only relevant if DeliveryMethod is "patch".
	Concurrence *int
}

Dosage describes a dosage schedule.

type DosageStorage

type DosageStorage interface {
	// DeliveryMethods returns the available delivery methods.
	DeliveryMethods(ctx context.Context) ([]DeliveryMethod, error)
	// Dosage returns the dosage for a user.
	// If the user has no schedule yet, this returns nil.
	Dosage(ctx context.Context, secret user.Secret) (*Dosage, error)
	// SetDosage sets the dosage for a user.
	// The user secret is taken from the Schedule.
	SetDosage(ctx context.Context, s Dosage) error
	// ClearDosage clears the dosage for a user.
	ClearDosage(ctx context.Context, secret user.Secret) error
}

DosageStorage is a storage for dosage data.

type Dose

type Dose struct {
	// DeliveryMethod is the method of delivery for the medication
	// at the time the dose was taken.
	DeliveryMethod string
	// Dose is the amount of medication that was taken.
	Dose float32
	// TakenAt is the time the dose was taken.
	TakenAt time.Time
	// TakenOffAt is the time the dose was taken off the body.
	// This is only relevant if DeliveryMethod is "patch".
	TakenOffAt *time.Time
	// Comment is a comment about the dose.
	Comment string
}

Dose describes a dose of medication in time.

func (Dose) ToCSV

func (d Dose) ToCSV() CSVDoseRecord

func (Dose) ToOpenAPI

func (d Dose) ToOpenAPI() openapi.Dose

type DoseHistoryStorage

type DoseHistoryStorage interface {
	// RecordDose records a single dose. The dose observation's ID is returned.
	RecordDose(ctx context.Context, secret user.Secret, dose Dose) error
	// ImportDoses imports doses in bulk and returns the number of doses
	// imported.
	// This is a separate method from RecordDose to allow for more efficient
	// bulk imports.
	ImportDoses(ctx context.Context, secret user.Secret, doseSeq iter.Seq[Dose]) (int64, error)
	// EditDose edits a dose by the previous takenAt time.
	// All fields are updated.
	EditDose(ctx context.Context, secret user.Secret, doseTime time.Time, dose Dose) error
	// ForgetDoses forgets the given doses.
	ForgetDoses(ctx context.Context, secret user.Secret, doseTimes []time.Time) error
	// DoseHistory returns the history of a dosage schedule. If end is zero, it
	// is considered to be now. If begin is zero, it is considered to be
	// since the beginning of time.
	// The history is ordered by time taken, with the oldest dose first.
	// If there's an error, the returned sequence will yield the error with a
	// zero-value [Observation].
	DoseHistory(ctx context.Context, secret user.Secret, begin, end time.Time) iter.Seq2[Dose, error]
}

DoseHistoryStorage is a storage for dose history data.

type ExportDoseHistoryOptions

type ExportDoseHistoryOptions struct {
	Begin  time.Time // zero means from beginning of time
	End    time.Time // zero means until now
	Format ExportFormat
}

ExportDoseHistoryOptions are options for exporting dose history as a CSV file.

type ExportFormat

type ExportFormat string

ExportFormat is the format of the export.

const (
	ExportCSV  ExportFormat = "text/csv"
	ExportJSON ExportFormat = "application/json"
)

func (ExportFormat) AsMIME

func (f ExportFormat) AsMIME() string

AsMIME returns itself.

type ExporterService

type ExporterService struct {
	// contains filtered or unexported fields
}

ExporterService exports dosage data to various formats.

func NewExporterService

func NewExporterService(storage DoseHistoryStorage, lc fx.Lifecycle, logger *slog.Logger) *ExporterService

NewExporterService creates a new CSVExporterService.

func (*ExporterService) ExportDoseHistory

func (s *ExporterService) ExportDoseHistory(ctx context.Context, out io.Writer, secret user.Secret, o ExportDoseHistoryOptions) (int64, error)

ExportDoseHistory exports the dose history of the user as a CSV file into the given writer. It returns the number of records exported.

func (*ExporterService) ImportDoseHistory

ImportDoseHistory imports dose history from a CSV file.

type ImportDoseHistoryOptions

type ImportDoseHistoryOptions struct {
	Format ExportFormat
}

ImportDoseHistoryOptions are options for importing dose history from a file.

type ImportDoseHistoryResult

type ImportDoseHistoryResult struct {
	Records   int64
	Succeeded int64
}

ImportDoseHistoryResult is the result of importing dose history from a file.

type RecordedDosesResult

type RecordedDosesResult struct {
	// Created is the number of doses that were created.
	// This is the number of doses that were not already in the database.
	Created int
}

RecordedDosesResult is the result of recording doses.

Directories

Path Synopsis
Package openapi provides primitives to interact with the openapi HTTP API.
Package openapi provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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