Add basic CRUD operations for the doselogging and a list command. Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
38 lines
896 B
Go
38 lines
896 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"flag"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func addDose(db *sql.DB, args []string) {
|
|
fs := flag.NewFlagSet("add", flag.ExitOnError)
|
|
substance := fs.String("substance", "", "Name of substance")
|
|
dose := fs.Float64("dose", 0, "Amount taken")
|
|
unit := fs.String("unit", "", "Unit of dose")
|
|
roa := fs.String("roa", "", "Route of administration")
|
|
notes := fs.String("notes", "", "Optional notes")
|
|
|
|
fs.Parse(args)
|
|
|
|
if *substance == "" || *dose <= 0 || *unit == "" || *roa == "" {
|
|
fmt.Println("Error: --substance, --dose, --unit, and --roa are required")
|
|
fs.Usage()
|
|
return
|
|
}
|
|
|
|
_, err := db.Exec(
|
|
"INSERT INTO doses (time, substance, dose, unit, roa, notes) VALUES (?, ?, ?, ?, ?, ?)",
|
|
time.Now().Format(time.RFC3339), *substance, *dose, *unit, *roa, *notes,
|
|
)
|
|
|
|
if err != nil {
|
|
fmt.Println("Failed to add dose:", err)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Dose added.")
|
|
}
|