lara

package module
v0.0.0-...-6151759 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: GPL-2.0, GPL-3.0 Imports: 5 Imported by: 0

README

Lara

Build Status

Veterinary practice support software - back-end services.

Install

Requires go 1.9+

go install github.com/jkusniar/lara/cmd/lara
go install github.com/jkusniar/lara/cmd/lara-ctl

Run

Runtime requirements:

  • system timezone is used to translate date/time strings in application

Development

Requires make utility. Install build dependencies if building first time:

  • make build-deps
  • make

Will install build dependencies and run golint/go vet, unit tests and build binaries. Optionally install additional development dependencies using make dev-deps.

Tests

make test

In order to run tests on local machine a postgresql instance must be running. Following environment variables are honored for tests:

  • POSTGRES_HOST (default "localhost")
  • POSTGRES_DB (default "lara_test")
  • POSTGRES_USER (default "postgres")
  • POSTGRES_PASSWORD (default "")
  • POSTGRES_PORT (default 5432)

License

The project license is specified in LICENSE

Lara is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Lara is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPermissions = []PermissionType{ViewRecord}

DefaultPermissions is set of default permissions for new user

Functions

func ContextWithUser

func ContextWithUser(ctx context.Context, u *User) context.Context

ContextWithUser returns a new Context that carries User u.

func MakePermissions

func MakePermissions(perms []string) (map[PermissionType]bool, error)

MakePermissions converts string slice to PermissionType set

func NewCodedError

func NewCodedError(code int, err error) error

NewCodedError creates new CodedError instance

Types

type AddressService

type AddressService interface {
	SearchCity(ctx context.Context, query string) (*CityStreetList, error)
	SearchStreetForCity(ctx context.Context, cityID uint64, query string) (*CityStreetList, error)
}

AddressService manages addresses

type BreedService

type BreedService interface {
	GetAllBreedsBySpecies(ctx context.Context, speciesID uint64) (*LOVItemList, error)
}

BreedService manages breeds

type CityStreet

type CityStreet struct {
	ID   uint64 `json:"id"`
	Name string `json:"name"`
	ZIP  string `json:"zip"`
}

CityStreet is JSON encoded city or street structure

type CityStreetList

type CityStreetList struct {
	Total int          `json:"total"`
	Items []CityStreet `json:"items"`
}

CityStreetList is JSON encoded List of cities/streets

type CodedError

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

CodedError is an error with HTTP status code hint for error handler

func (CodedError) Code

func (ce CodedError) Code() int

Code returns HTTP error code

func (CodedError) Error

func (ce CodedError) Error() string

Error returns error string

func (CodedError) Format

func (ce CodedError) Format(s fmt.State, verb rune)

Format is used by fmt package when printing error

type CreateOwner

type CreateOwner struct {
	Owner
	Patient NewPatient `json:"patient"`
}

CreateOwner is JSON encoded create owner structure

type CreatePatient

type CreatePatient struct {
	OwnerID uint64 `json:"ownerId"`
	NewPatient
}

CreatePatient is JSON encoded create patient data

type CreateRecord

type CreateRecord struct {
	PatientID uint64 `json:"patientId"`
	NewRecord
}

CreateRecord is JSON encoded create record data

type CreateTag

type CreateTag struct {
	PatientID uint64 `json:"patientId"`
	Type      string `json:"type"`
	Value     string `json:"value"`
	Data      []byte `json:"data"`
}

CreateTag is JSON encoded create tag data

type CreatorModifier

type CreatorModifier struct {
	Creator  string    `json:"creator"`
	Created  time.Time `json:"created"`
	Modifier string    `json:"modifier"`
	Modified time.Time `json:"modified"`
}

CreatorModifier contains object's creator & modifier fields

type GenderService

type GenderService interface {
	GetAllGenders(ctx context.Context) (*LOVItemList, error)
}

GenderService manages genders

type GetOwner

type GetOwner struct {
	Versioned
	Owner
	Title  string `json:"title"`
	City   string `json:"city"`
	Street string `json:"street"`
	CreatorModifier
	Patients []OwnersPatient `json:"patients"`
}

GetOwner is JSON encoded retrievable owner data

type GetPatient

type GetPatient struct {
	Versioned
	CreatorModifier
	Patient
	Dead    bool             `json:"dead"`
	Species string           `json:"species"`
	Breed   string           `json:"breed"`
	Gender  string           `json:"gender"`
	Records []PatientsRecord `json:"records"`
	Tags    []PatientsTag    `json:"tags"`
}

GetPatient is JSON encoded retrievable patient data

type GetRecord

type GetRecord struct {
	Versioned
	CreatorModifier
	Date   time.Time       `json:"date"`
	Text   string          `json:"text"`
	Billed bool            `json:"billed"`
	Items  []GetRecordItem `json:"items"`
	Total  string          `json:"total"`
}

GetRecord is JSON encoded retrievable record data

type GetRecordItem

type GetRecordItem struct {
	ID uint64 `json:"id"`
	RecordItem
	Product string `json:"product"`
	Unit    string `json:"unit"`
	PLU     string `json:"plu"`
}

GetRecordItem is JSON encoded retrievable record item data

type GetTag

type GetTag struct {
	Versioned
	CreatorModifier
	Type  string `json:"type"`
	Value string `json:"value"`
	Data  []byte `json:"data"`
}

GetTag is JSON encoded retrievable tag data

type IncomeStatistics

type IncomeStatistics struct {
	Records         int    `json:"records"`         // count
	Income          string `json:"income"`          // currency (formatted decimal, precision: 8.2)
	IncomeBilled    string `json:"incomeBilled"`    // currency
	IncomeNotBilled string `json:"incomeNotBilled"` // currency
}

IncomeStatistics is JSON encoded income statistics report

type LOVItem

type LOVItem struct {
	ID   uint64 `json:"id"`
	Name string `json:"name"`
}

LOVItem is JSON encoded List-Of-Values item

type LOVItemList

type LOVItemList struct {
	Items []LOVItem `json:"items"`
}

LOVItemList is JSON encoded list of of LOVItems

type NewPatient

type NewPatient struct {
	Patient
	Record NewRecord `json:"record"`
}

NewPatient is JSON encoded data of a patient created together with an owner

type NewRecord

type NewRecord struct {
	Text   string       `json:"text"`
	Billed bool         `json:"billed"`
	Items  []RecordItem `json:"items"`
}

NewRecord is JSON encoded data of a record created together with an owner

type Owner

type Owner struct {
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	TitleID   uint64 `json:"titleId"`
	CityID    uint64 `json:"cityId"`
	StreetID  uint64 `json:"streetId"`
	HouseNo   string `json:"houseNo"`
	Phone1    string `json:"phone1"`
	Phone2    string `json:"phone2"`
	Email     string `json:"email"`
	Note      string `json:"note"`
	IC        string `json:"IC"`
	DIC       string `json:"DIC"`
	ICDPH     string `json:"ICDPH"`
}

Owner is JSON encoded updatable owner fields

type OwnerService

type OwnerService interface {
	Get(ctx context.Context, id uint64) (*GetOwner, error)
	Update(ctx context.Context, id uint64, o *UpdateOwner) error
	Create(ctx context.Context, o *CreateOwner) (uint64, error)
}

OwnerService manages owners

type OwnersPatient

type OwnersPatient struct {
	ID      uint64 `json:"id"`
	Name    string `json:"name"`
	Species string `json:"species"`
	Breed   string `json:"breed"`
	Gender  string `json:"gender"`
	Dead    bool   `json:"dead"`
}

OwnersPatient is JSON encoded owner's patient data

type Patient

type Patient struct {
	Name      string    `json:"name"`
	BirthDate time.Time `json:"birthDate"`
	SpeciesID uint64    `json:"speciesId"`
	BreedID   uint64    `json:"breedId"`
	GenderID  uint64    `json:"genderId"`
	Note      string    `json:"note"`
}

Patient is JSON encoded updatable patient fields

type PatientByTag

type PatientByTag struct {
	TagType      string `json:"tagType"`
	Name         string `json:"name"`
	Species      string `json:"species"`
	Breed        string `json:"breed"`
	Gender       string `json:"gender"`
	OwnerID      uint64 `json:"ownerId"`      // DB primary key
	OwnerName    string `json:"ownerName"`    // formatted owner name (first, last, title)
	OwnerAddress string `json:"ownerAddress"` // owner's address
}

PatientByTag is JSON encoded patient's data found by tag value

type PatientService

type PatientService interface {
	Get(ctx context.Context, id uint64) (*GetPatient, error)
	Update(ctx context.Context, id uint64, p *UpdatePatient) error
	Create(ctx context.Context, p *CreatePatient) (uint64, error)
}

PatientService manages patients

type PatientsRecord

type PatientsRecord struct {
	ID   uint64    `json:"id"`
	Date time.Time `json:"date"`
	Text string    `json:"text"`
}

PatientsRecord is JSON encoded patient's record data

type PatientsTag

type PatientsTag struct {
	ID    uint64 `json:"id"`
	Type  string `json:"type"`
	Value string `json:"value"`
}

PatientsTag is JSON encoded patient's tag data

type PermissionType

type PermissionType int

PermissionType defines user's permission requires golang.org/x/tools/cmd/stringer installed locally if new object permission added to enum, run "go generate"

const (
	ViewRecord PermissionType = iota
	EditRecord
	ViewReports
	EditProducts
)

Permission types enum

func (*PermissionType) FromString

func (i *PermissionType) FromString(perm string) error

FromString creates PermissionType from string

func (PermissionType) String

func (i PermissionType) String() string

type Product

type Product struct {
	ID    uint64 `json:"id"`    // DB primary key
	Name  string `json:"name"`  // product's name
	Unit  string `json:"unit"`  // product's unit of measure
	Price string `json:"price"` // product's price (formatted decimal, precision: 8.2)
}

Product is JSON encoded product structure

type ProductSearchRequest

type ProductSearchRequest struct {
	ValidTo time.Time `json:"validTo"`
	Query   string    `json:"query"`
}

ProductSearchRequest is JSON encoded search product request structure

type ProductSearchResult

type ProductSearchResult struct {
	Total    int       `json:"total"`
	Products []Product `json:"products"`
}

ProductSearchResult is JSON encoded search product result structure

type ProductService

type ProductService interface {
	Search(ctx context.Context, p *ProductSearchRequest) (*ProductSearchResult, error)
}

ProductService manages products

type RecordItem

type RecordItem struct {
	ProductID    uint64         `json:"productId"`
	ProductPrice string         `json:"productPrice"`
	Amount       string         `json:"amount"`
	ItemPrice    string         `json:"itemPrice"`
	ItemType     RecordItemType `json:"itemType"`
}

RecordItem is JSON encoded data od record's item containing all writable data

type RecordItemType

type RecordItemType int

RecordItemType is enum defining system permissions requires golang.org/x/tools/cmd/stringer installed locally

const (
	Labor RecordItemType = iota
	Material
)

RecordItemType enum

func (RecordItemType) MarshalJSON

func (i RecordItemType) MarshalJSON() ([]byte, error)

MarshalJSON is JSON marshaller implementation for RecordItemType

func (RecordItemType) String

func (i RecordItemType) String() string

func (*RecordItemType) UnmarshalJSON

func (i *RecordItemType) UnmarshalJSON(data []byte) error

UnmarshalJSON is JSON unmarshaller implementation for RecordItemType

type RecordService

type RecordService interface {
	Get(ctx context.Context, id uint64) (*GetRecord, error)
	Update(ctx context.Context, id uint64, r *UpdateRecord) error
	Create(ctx context.Context, r *CreateRecord) (uint64, error)
}

RecordService manages records

type ReportRequest

type ReportRequest struct {
	ValidFrom time.Time `json:"validFrom"`
	ValidTo   time.Time `json:"validTo"`
}

ReportRequest is JSON encoded request structure for various reports

type ReportService

type ReportService interface {
	GetIncomeStatistics(ctx context.Context, r *ReportRequest) (*IncomeStatistics, error)
}

ReportService generates data for various reports

type SearchRecord

type SearchRecord struct {
	ID      uint64 `json:"id"`      // DB primary key
	Name    string `json:"name"`    // formatted owner name (first, last, title)
	Address string `json:"address"` // owner's address
}

SearchRecord is JSON encoded search record (owner)

type SearchResult

type SearchResult struct {
	Total   int            `json:"total"`
	Records []SearchRecord `json:"records"`
}

SearchResult is JSON encoded search result structure

type SearchService

type SearchService interface {
	Search(ctx context.Context, q string) (*SearchResult, error)
}

SearchService searches owners

type SpeciesService

type SpeciesService interface {
	GetAllSpecies(ctx context.Context) (*LOVItemList, error)
}

SpeciesService manages species

type TagService

type TagService interface {
	Get(ctx context.Context, id uint64) (*GetTag, error)
	Update(ctx context.Context, id uint64, o *UpdateTag) error
	Create(ctx context.Context, o *CreateTag) (uint64, error)
	GetPatientByTag(ctx context.Context, tagValue string) (*PatientByTag, error)
}

TagService manages patient's tags

type TagType

type TagType int

TagType defines patient's tag type requires golang.org/x/tools/cmd/stringer installed locally if new object permission added to enum, run "go generate"

const (
	LyssaVirus  TagType = iota // Canine Rabies Tags, tag format: YYYY-SK-9999
	Tattoo                     // Pet tattoo, tag format: regular string
	PetPassport                // EU Pet Passport, tag format: SK999999999
	RFID                       // ISO 11784/11785 FDX-B RFID chip, tag format: 999999999999999
)

Tag types enum

func (*TagType) FromString

func (i *TagType) FromString(tt string) error

FromString creates TagType from string

func (TagType) String

func (i TagType) String() string

type TitleService

type TitleService interface {
	GetAllTitles(ctx context.Context) (*LOVItemList, error)
}

TitleService manages titles

type UnitService

type UnitService interface {
	GetAllUnits(ctx context.Context) (*LOVItemList, error)
}

UnitService manages units

type UpdateOwner

type UpdateOwner struct {
	Version uint64 `json:"version"`
	Owner
}

UpdateOwner is JSON encoded updatable owner data

type UpdatePatient

type UpdatePatient struct {
	Version uint64 `json:"version"`
	Patient
	Dead bool `json:"dead"`
}

UpdatePatient is JSON encoded update patient data

type UpdateRecord

type UpdateRecord struct {
	Version uint64       `json:"version"`
	Text    string       `json:"text"`
	Items   []RecordItem `json:"items"`
}

UpdateRecord is JSON encoded update record data

type UpdateTag

type UpdateTag struct {
	Version uint64 `json:"version"`
	Value   string `json:"value"`
	Data    []byte `json:"data"`
}

UpdateTag is JSON encoded update tag data

type User

type User struct {
	Login       string
	Permissions map[PermissionType]bool // map instead of slice, for fast searching
}

User is application user

func MakeUser

func MakeUser(login string, permissions []string) (u *User, err error)

MakeUser creates User from login and list of permissions

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

UserFromContext returns the User value stored in ctx, if any.

type UserService

type UserService interface {
	Authenticate(ctx context.Context, login, password string) (*User, error)
	Register(ctx context.Context, login, password string, permissions []PermissionType) error
	Grant(ctx context.Context, login string, permissions []PermissionType) error
	Revoke(ctx context.Context, login string, permissions []PermissionType) error
}

UserService manages application's users

type Versioned

type Versioned struct {
	ID      uint64 `json:"id"`
	Version uint64 `json:"version"`
}

Versioned contains common fields for versioned data objects

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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