model

package
v0.0.0-...-db8de02 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPrescriptionsSummary

func GetPrescriptionsSummary(db *gorm.DB) pterm.TableData

GetPrescriptionsSummary returns a summary of all prescriptions

func LastRefresh

func LastRefresh(db *gorm.DB) string

LastRefresh returns the last time the logs were refreshed.

func Populate

func Populate(db *gorm.DB)

Populate creates the tables in the database and populates them with the necessary data

Types

type ActiveIngredient

type ActiveIngredient struct {
	gorm.Model
	Name string `gorm:"unique;not null"`
	ATC  string `gorm:"uniqueIndex;not null;size:7;check:length(ATC) = 7"`
	// Stock stores units of active principle x 1000 (e.g. 1 mg = 1000)
	Stock          int64 `gorm:"not null;default:0"`
	Unit           Unit  `gorm:"not null;default:'mg';check:unit in ('ml', 'mg', 'U', 'UI')"`
	LastConsumedAt sql.NullTime
	LastStockedAt  sql.NullTime
	Medicines      []Medicine     `gorm:"foreignKey:RelatedATC;references:ATC"`
	Prescriptions  []Prescription `gorm:"foreignKey:RelatedATC;references:ATC"`
	StockLogs      []StockLog     `gorm:"foreignKey:RelatedATC;references:ATC"`
	IntakeLogs     []IntakeLog    `gorm:"foreignKey:RelatedATC;references:ATC"`
}

ActiveIngredient represents an active ingredient in a medicine or in a prescription.

type IntakeLog

type IntakeLog struct {
	gorm.Model
	PrescriptionID uint      `gorm:"index;not null"`
	RelatedATC     string    `gorm:"index;not null"`
	ConsumedAt     time.Time `gorm:"index;not null;default:CURRENT_TIMESTAMP"`
	// Units stores active ingredient units comsumed x 1000 (e.g. 1 mg = 1000)
	Units int64 `gorm:"not null;check:units > 0"`
}

IntakeLog represents a log of a single prescription active ingredient intake.

type Medicine

type Medicine struct {
	gorm.Model
	Name       string `gorm:"unique;not null"`
	MAH        string
	RelatedATC string `gorm:"not null"`
	AIC        string `gorm:"unique;not null;size: 9;check:length(AIC) = 9"`
	// Dosage stores units of active ingredient for each unit of medicine x 1000 (e.g. 1 mg = 1000)
	Dosage    int64 `gorm:"not null;check:dosage > 0"`
	Package   string
	Form      string
	BoxSize   int `gorm:"not null;check:box_size > 0"`
	StockLogs []StockLog
}

Medicine represents a medicine that can be purchased.

type Prescription

type Prescription struct {
	gorm.Model
	RelatedATC string `gorm:"not null"`
	// Dosage store active ingredient units prescibed x 1000 (e.g. 1 mg = 1000)
	Dosage          int64 `gorm:"not null;check:dosage > 0"`
	DosingFrequency int   `gorm:"not null;check:dosing_frequency > 0;default: 1"` // Dosing frequency in days
	StartDate       sql.NullTime
	EndDate         sql.NullTime
	IntakeLogs      []IntakeLog
}

Prescription represents a prescription for a single active ingredient.

type StockLog

type StockLog struct {
	gorm.Model
	MedicineID uint      `gorm:"index;not null"`
	RelatedATC string    `gorm:"index;not null"`
	StockedAt  time.Time `gorm:"index;not null;default:CURRENT_TIMESTAMP"`
	Boxes      int       `gorm:"not null;check:boxes > 0"` // Boxes of medicine
	// Units stores active ingredient units stocked x 1000 (e.g. 1 mg = 1000)
	Units int64 `gorm:"not null;check:units > 0"`
}

StockLog represents a log of a single stocking of an active ingredient.

type Unit

type Unit string

Unit represents a unit of measurement.

Jump to

Keyboard shortcuts

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