Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoDoseMatched = errors.New("no dose matched")
)
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 ¶
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
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" )
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 ¶
func (s *ExporterService) ImportDoseHistory(ctx context.Context, in io.Reader, secret user.Secret, o ImportDoseHistoryOptions) (ImportDoseHistoryResult, error)
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 ¶
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.