Documentation ¶
Index ¶
- Constants
- Variables
- func Logger() *logrus.Entry
- type ConsentRecord
- type ConsentStore
- func (cs *ConsentStore) Configure() error
- func (cs *ConsentStore) ConsentAuth(context context.Context, custodian string, subject string, actor string, ...) (bool, error)
- func (cs *ConsentStore) DeleteConsentRecordByHash(context context.Context, consentRecordHash string) (bool, error)
- func (cs *ConsentStore) Diagnostics() []core.DiagnosticResult
- func (cs *ConsentStore) FindConsentRecordByHash(context context.Context, consentRecordHash string, latest bool) (ConsentRecord, error)
- func (cs *ConsentStore) QueryConsent(context context.Context, _actor *string, _custodian *string, _subject *string, ...) ([]PatientConsent, error)
- func (cs *ConsentStore) RecordConsent(context context.Context, consent []PatientConsent) error
- func (cs *ConsentStore) RunMigrations(db *sql.DB) error
- func (cs *ConsentStore) Shutdown() error
- func (cs *ConsentStore) Start() error
- type ConsentStoreClient
- type ConsentStoreConfig
- type DataClass
- type PatientConsent
Constants ¶
const ConfigAddress = "address"
ConfigAddress is the config name for the api address when running in client mode
const ConfigConnectionString = "connectionstring"
ConfigConnectionString is the config name for the connection string
const ConfigConnectionStringDefault = ":memory:"
ConfigConnectionStringDefault is the default db connection string
const ConfigMode = "mode"
ConfigMode is the config name for the mode of the store (server, client)
Variables ¶
var ErrorConsentRecordNotLatest = errors.New("consent record for given hash is not the latest in the chain")
ErrorConsentRecordNotLatest is returned when the latest consent record for a chain is requested but given hash is not the latest
var ErrorInvalidValidTo = errors.New("ConsentRecord validation failed: ValidTo must come after ValidFrom")
ErrorInvalidValidTo is returned when the ValidTo from a ConsentRecord comes before the ValidFrom
var ErrorNotFound = errors.New("record not found")
ErrorNotFound is the same as Gorm.IsRecordNotFound
Functions ¶
Types ¶
type ConsentRecord ¶
type ConsentRecord struct { ID uint `gorm:"AUTO_INCREMENT"` PatientConsentID string ValidFrom time.Time `gorm:"not null"` ValidTo *time.Time Hash string `gorm:"not null"` PreviousHash *string Version uint `gorm:"DEFAULT:1"` UUID string `gorm:"column:uuid;not null"` DataClasses []DataClass }
ConsentRecord represents the individual records/attachments for a PatientConsent Changes to ConsentRecords are chained by PreviousHash pointing to Hash. All member of the chain can be found by the UUID The UUID remains internal
func (*ConsentRecord) BeforeDelete ¶
func (cr *ConsentRecord) BeforeDelete(tx *gorm.DB) (err error)
BeforeDelete makes sure the DataClasses of a ConsentRecords gets deleted too
func (ConsentRecord) TableName ¶
func (ConsentRecord) TableName() string
TableName returns the SQL table for this type
type ConsentStore ¶
type ConsentStore struct { Db *gorm.DB ConfigOnce sync.Once Config ConsentStoreConfig // contains filtered or unexported fields }
ConsentStore is the main data struct holding the config and references to the DB
func ConsentStoreInstance ¶
func ConsentStoreInstance() *ConsentStore
ConsentStoreInstance returns a singleton consent store
func (*ConsentStore) Configure ¶
func (cs *ConsentStore) Configure() error
Configure opens a DB connection and runs migrations
func (*ConsentStore) ConsentAuth ¶
func (cs *ConsentStore) ConsentAuth(context context.Context, custodian string, subject string, actor string, resourceType string, checkpoint *time.Time) (bool, error)
ConsentAuth checks if there is a consent for a given custodian, subject and actor for a certain resource at a given moment in time (checkpoint)
func (*ConsentStore) DeleteConsentRecordByHash ¶
func (cs *ConsentStore) DeleteConsentRecordByHash(context context.Context, consentRecordHash string) (bool, error)
DeleteConsentRecordByHash deletes a consent record by its hash. Returns boolean to indicate the success of the operation
func (*ConsentStore) Diagnostics ¶
func (cs *ConsentStore) Diagnostics() []core.DiagnosticResult
Diagnostics returns the slice of DiagnosticResults indicating the state of this engine
func (*ConsentStore) FindConsentRecordByHash ¶
func (cs *ConsentStore) FindConsentRecordByHash(context context.Context, consentRecordHash string, latest bool) (ConsentRecord, error)
FindConsentRecordByHash find a consent record given its hash, the latest flag indicates the requirement if the record is the latest in the chain.
func (*ConsentStore) QueryConsent ¶
func (cs *ConsentStore) QueryConsent(context context.Context, _actor *string, _custodian *string, _subject *string, _validAt *time.Time) ([]PatientConsent, error)
QueryConsent accepts actor, custodian and subject, if these are nil, it's not used in the query.
func (*ConsentStore) RecordConsent ¶
func (cs *ConsentStore) RecordConsent(context context.Context, consent []PatientConsent) error
RecordConsent records a list of PatientConsents, their records and their data classes. For consent records that are updates, this function finds the version number and UUID from the previous record
func (*ConsentStore) RunMigrations ¶
func (cs *ConsentStore) RunMigrations(db *sql.DB) error
RunMigrations runs all new migrations in order
func (*ConsentStore) Shutdown ¶
func (cs *ConsentStore) Shutdown() error
Shutdown closes the db connections
type ConsentStoreClient ¶
type ConsentStoreClient interface { // ConsentAuth checks if a record exists in the Db for the given combination and returns a bool. Checkpoint is optional and default to time.Now() ConsentAuth(context context.Context, custodian string, subject string, actor string, dataClass string, checkpoint *time.Time) (bool, error) // RecordConsent records a record in the Db, this is not to be used to create a new distributed consent record. It's only valid for the local node. // It should only be called by the consent logic component (or for development purposes) RecordConsent(context context.Context, consent []PatientConsent) error // QueryConsent can be used to query consent from a custodian/actor point of view. QueryConsent(context context.Context, actor *string, custodian *string, subject *string, validAt *time.Time) ([]PatientConsent, error) // DeleteConsentRecordByHash removes a ConsentRecord from the db. Returns true if the record was found and deleted. DeleteConsentRecordByHash(context context.Context, consentRecordHash string) (bool, error) // FindConsentRecordByHash find a consent record given its hash, the latest flag indicates the requirement if the record is the latest in the chain. FindConsentRecordByHash(context context.Context, consentRecordHash string, latest bool) (ConsentRecord, error) }
ConsentStoreClient defines all actions possible through a direct connection, command-line and REST api
type ConsentStoreConfig ¶
ConsentStoreConfig holds the config for the consent store
type DataClass ¶
DataClass defines struct for data_class table
func DataClassesFromStrings ¶
DataClassesFromStrings converts a slice of strings to a slice of Recources
type PatientConsent ¶
type PatientConsent struct { ID string `gorm:"primary_key"` Actor string `gorm:"not null"` Custodian string `gorm:"not null"` Records []ConsentRecord Subject string `gorm:"not null"` }
PatientConsent defines struct for patient_consent table. ID refers to the HMAC id for a custodian(subject-actor)
func (*PatientConsent) BeforeDelete ¶
func (pc *PatientConsent) BeforeDelete(tx *gorm.DB) (err error)
BeforeDelete makes sure the ConsentRecords of a PatientConsent gets deleted too
func (PatientConsent) DataClasses ¶
func (pc PatientConsent) DataClasses() []DataClass
DataClasses combines all consent data classes from all records
func (*PatientConsent) SameTriple ¶
func (pc *PatientConsent) SameTriple(other *PatientConsent) bool
SameTriple compares this PatientConsent with another one on just Actor, Custiodian and Subject
func (*PatientConsent) String ¶
func (pc *PatientConsent) String() string
func (PatientConsent) TableName ¶
func (PatientConsent) TableName() string
TableName returns the SQL table for this type