types

package
v0.0.0-...-b9b5e9f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatabaseGR = meta.GroupResource{
	Group:    group,
	Resource: databases,
}
View Source
var FolderGR = meta.GroupResource{
	Group:    group,
	Resource: folders,
}
View Source
var FormGR = meta.GroupResource{
	Group:    group,
	Resource: forms,
}
View Source
var RecordGR = meta.GroupResource{
	Group:    group,
	Resource: records,
}

Functions

This section is empty.

Types

type CaseDefinition

type CaseDefinition struct {
	// FormDefinition represents the specification of the form for collecting
	// data about this case.
	// We embed the FormDefinition here since a Case is also a Form.
	FormDefinition FormDefinition `json:"formDefinition"`
	// RecipientDefinitions represents the types of recipient that this case allows.
	// For example, if the CaseDefinition is Colombia Individual Intake, then
	// the RecipientDefinitions could be a link to a ColombiaIndividualRecipient form.
	RecipientDefinitions []CaseRecipientDefinition `json:"recipientDefinition"`
}

CaseDefinition represents a special type of FormDefinition that represents a Case. A Case is an instance of a service given to a person, household, group, ... A person, household, group, ... is the recipient of the Case

type CaseRecipientDefinition

type CaseRecipientDefinition struct {
	// FormRef indicates that the recipient is a record in the form referenced
	// by the FormRef.DatabaseID and FormRef.FormID
	FormRef *FormRef `json:"formRef,omitempty"`
}

CaseRecipientDefinition represents the specification for allowed recipients of a CaseDefinition Introducing a struct here since it would be possible to have recipients that are not records in other forms in the future. For example, we might have a recipient that is a link to multiple people (Extensibility)

type Database

type Database struct {
	// ID is the id of the Database
	ID string `json:"id"`
	// Name is the name of the database
	Name string `json:"name"`
	// CreatedAt is the creation time of the database
	CreatedAt time.Time `json:"createdAt"`
	// UpdatedAt is the last update time of the database
	UpdatedAt time.Time `json:"updatedAt"`
}

Database is a namespace for FormDefinition. It acts as a scope for Access Control. For example, an Organization might create a Database for a specific country, region, or thematic area.

type DatabaseList

type DatabaseList struct {
	Items []*Database `json:"items"`
}

DatabaseList represent a list of Database

type FieldDefinition

type FieldDefinition struct {
	// ID is the ID of the FieldDefinition
	ID string `json:"id" yaml:"id"`
	// Code is the unique Code of the FieldDefinition within the FormDefinition
	Code string `json:"code,omitempty" yaml:"code,omitempty"`
	// Name is the Name of the FieldDefinition
	Name string `json:"name" yaml:"name"`
	// Description is a helpful text helping the users to understand the question
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// Key indicates that the FieldDefinition is part of the Unique Keys for the FormDefinition.
	// When a FormDefinition is created with Key fields, this means that there will be no
	// two records with the same combination of Key field values.
	//
	// For example, if a FormDefinition has 2 key fields, "Year" and "Month", then there could
	// be no two records with "2021" and "January".
	Key bool `json:"key" yaml:"key"`
	// Required indicates that the user must enter data for that FieldDefinition
	Required bool `json:"required" yaml:"required"`
	// FieldType contains the type of FieldDefinition
	FieldType FieldType `json:"fieldType" yaml:"fieldType"`
}

FieldDefinition usually represents a question in a FormDefinition. A FieldDefinition defines the name, description, boundaries of data collection.

type FieldDefinitions

type FieldDefinitions []*FieldDefinition

FieldDefinitions represent a list of FieldDefinition

func (FieldDefinitions) GetFieldByName

func (f FieldDefinitions) GetFieldByName(name string) (*FieldDefinition, error)

type FieldKind

type FieldKind int

FieldKind is a struct that contains the different types of fields

const (
	FieldKindUnknown FieldKind = iota
	FieldKindText
	FieldKindSubForm
	FieldKindReference
	FieldKindMultilineText
	FieldKindDate
	FieldKindQuantity
	FieldKindMonth
	FieldKindWeek
	FieldKindSingleSelect
	FieldKindMultiSelect
	FieldKindCheckbox
)

func GetAllFieldKinds

func GetAllFieldKinds() []FieldKind

func (FieldKind) String

func (i FieldKind) String() string

type FieldType

type FieldType struct {
	// Text represents the configuration for a text field
	Text *FieldTypeText `json:"text,omitempty" yaml:"text,omitempty"`
	// Reference represents the configuration for a reference field
	Reference *FieldTypeReference `json:"reference,omitempty" yaml:"reference,omitempty"`
	// SubForm represents the configuration for a sub form field
	SubForm *FieldTypeSubForm `json:"subForm,omitempty" yaml:"subForm,omitempty"`
	// MultilineText represents the configuration for a multiline text field
	MultilineText *FieldTypeMultilineText `json:"multilineText,omitempty" yaml:"multilineText,omitempty"`
	// Date represents the configuration for a date field
	Date *FieldTypeDate `json:"date,omitempty" yaml:"date,omitempty"`
	// Quantity represents the configuration for a quantity field
	Quantity *FieldTypeQuantity `json:"quantity,omitempty" yaml:"quantity,omitempty"`
	// Week represents the configuration for a week field
	Week *FieldTypeWeek `json:"week,omitempty" yaml:"week,omitempty"`
	// Month represents the configuration for a month field
	Month *FieldTypeMonth `json:"month,omitempty" yaml:"month,omitempty"`
	// SingleSelect represents the configuration for a single select field
	SingleSelect *FieldTypeSingleSelect `json:"singleSelect,omitempty" yaml:"singleSelect,omitempty"`
	// SingleSelect represents the configuration for a single select field
	MultiSelect *FieldTypeMultiSelect `json:"multiSelect,omitempty" yaml:"multiSelect,omitempty"`
	// Checkbox represents the configuration for a yes/no boolean field
	Checkbox *FieldTypeCheckbox `json:"checkbox,omitempty" yaml:"checkbox,omitempty"`
}

FieldType is a struct that contains the FieldType for a given FieldDefinition Only one of the fields might be specified. For example, a FieldType cannot have both FieldType.Text and FieldType.Reference defined. Only one is allowed.

func (FieldType) GetFieldKind

func (f FieldType) GetFieldKind() (FieldKind, error)

func (FieldType) GetFieldType

func (f FieldType) GetFieldType(kind FieldKind) (interface{}, error)

func (FieldType) IsKind

func (f FieldType) IsKind(kind FieldKind) (bool, error)

type FieldTypeCheckbox

type FieldTypeCheckbox struct{}

type FieldTypeDate

type FieldTypeDate struct{}

FieldTypeDate represents a Date field (calendar date, no time/timezone)

type FieldTypeMonth

type FieldTypeMonth struct{}

FieldTypeMonth represents a Month field (YYYY-mm)

type FieldTypeMultiSelect

type FieldTypeMultiSelect struct {
	// Options represent the different options that the user can select from
	Options []*SelectOption `json:"options,omitempty" yaml:"options,omitempty"`
}

FieldTypeMultiSelect represents a field from which the user can select multiple options

type FieldTypeMultilineText

type FieldTypeMultilineText struct{}

FieldTypeMultilineText represents a multiline text field

type FieldTypeQuantity

type FieldTypeQuantity struct {
}

FieldTypeQuantity represents a quantity field. A quantity field is a "number" of something.

type FieldTypeReference

type FieldTypeReference struct {
	// DatabaseID represents the DatabaseID of the referenced FormDefinition
	DatabaseID string `json:"databaseId" yaml:"databaseId"`
	// FormID represents the FormID of the referenced FormDefinition
	FormID string `json:"formId" yaml:"formId"`
}

FieldTypeReference represents a field that is a reference to a record in another FormDefinition

For example, given a form "Countries" and a form "Projects". The "Projects" form might have a field "Country" that references the "Countries" form. In this case, when adding a record in the "Projects", the user would be prompted to select a country.

type FieldTypeSingleSelect

type FieldTypeSingleSelect struct {
	// Options represent the different options that the user can select from
	Options []*SelectOption `json:"options,omitempty" yaml:"options,omitempty"`
}

FieldTypeSingleSelect represents a field from which the user can select a single option

type FieldTypeSubForm

type FieldTypeSubForm struct {
	// Fields represent the fields for the SubForm
	Fields FieldDefinitions `json:"fields,omitempty" yaml:"fields,omitempty"`
}

FieldTypeSubForm represents a field that contains a nested form. A user could attach multiple records of that subform to the "parent" record.

For example, given a form "Projects", this form could have a subform "Monthly Deliveries". The "Monthly Deliveries". There could be multiple "Monthly Deliveries" for a single "Project".

func (*FieldTypeSubForm) GetFields

func (f *FieldTypeSubForm) GetFields() FieldDefinitions

GetFields returns the FieldDefinitions for the subform

type FieldTypeText

type FieldTypeText struct{}

FieldTypeText represents a textual field

type FieldTypeWeek

type FieldTypeWeek struct{}

FieldTypeWeek represents a Week field (YYYYKWww)

type FieldValue

type FieldValue struct {
	FieldID string        `json:"fieldId"`
	Value   StringOrArray `json:"value"`
}

func NewFieldArrayValue

func NewFieldArrayValue(fieldID string, value []string) FieldValue

func NewFieldNullValue

func NewFieldNullValue(fieldID string) FieldValue

func NewFieldStringValue

func NewFieldStringValue(fieldID string, value string) FieldValue

type FieldValues

type FieldValues []FieldValue

func (FieldValues) Find

func (f FieldValues) Find(fieldID string) (FieldValue, bool)

func (FieldValues) FindIndex

func (f FieldValues) FindIndex(fieldID string) int

func (FieldValues) SetValue

func (f FieldValues) SetValue(fieldID string, value StringOrArray) FieldValues

func (FieldValues) SetValueForFieldName

func (f FieldValues) SetValueForFieldName(formDefinition *FormDefinition, fieldName string, value StringOrArray) (FieldValues, error)

type Folder

type Folder struct {
	// ID represents the ID of the Folder
	ID string `json:"id"`
	// DatabaseID represents the ID of the Database
	DatabaseID string `json:"databaseId"`
	// ParentID represents the ID of the parent Folder
	// If the ParentID is empty, this means that the Folder exists
	// at the root of the Database
	ParentID string `json:"parentId,omitempty"`
	// Name of the folder
	Name string `json:"name"`
}

Folder is a namespace for Forms. Folder can be used to group FormDefinitions together.

type FolderList

type FolderList struct {
	Items []*Folder `json:"items"`
}

FolderList represents a list of Folder

func (*FolderList) HasFolderWithID

func (f *FolderList) HasFolderWithID(id string) bool

HasFolderWithID returns whether the FolderList contains a Folder with the given Folder.ID

type FormDefinition

type FormDefinition struct {
	// ID is the unique ID of the FormDefinition
	ID string `json:"id" yaml:"id"`
	// DatabaseID of the FormDefinition
	DatabaseID string `json:"databaseId" yaml:"databaseId"`
	// Fields that constitute the FormDefinition
	Fields FieldDefinitions `json:"fields" yaml:"fields"`
	// FolderID of the FormDefinition. If the FolderID is empty,
	// this means that the FormDefinition exists at the root
	// of the DatabaseID
	FolderID string `json:"folderId,omitempty" yaml:"folderId,omitempty"`
	// Type of FormDefinition
	// TODO: Ideally the "Recipient" forms, or other types of forms would
	// have own API instead of adding fields on the FormDefinition.
	Type FormType `json:"formType,omitempty" yaml:"formType,omitempty"`
	// Name of the FormDefinition
	Name string `json:"name" yaml:"name"`
}

FormDefinition represents the definition of a Form for data collection.

func (*FormDefinition) FindSubForm

func (f *FormDefinition) FindSubForm(subFormID string) (FormInterface, error)

FindSubForm implements FormInterface.FindFormInterface

func (FormDefinition) GetAllFormsAndSubFormIDs

func (f FormDefinition) GetAllFormsAndSubFormIDs() sets.String

GetAllFormsAndSubFormIDs returns the IDs of all the FormDefinition and their SubForms (recursively), if any

func (FormDefinition) GetDatabaseID

func (f FormDefinition) GetDatabaseID() string

GetDatabaseID implements FormInterface.GetDatabaseID

func (*FormDefinition) GetFields

func (f *FormDefinition) GetFields() FieldDefinitions

GetFields implements FormInterface.GetFields

func (FormDefinition) GetFormID

func (f FormDefinition) GetFormID() string

GetFormID implements FormInterface.GetFormID

func (*FormDefinition) GetFormOrSubForm

func (f *FormDefinition) GetFormOrSubForm(formOrSubFormID string) (FormInterface, error)

GetFormOrSubForm gets the form or subForm for the given id

func (*FormDefinition) RemoveFieldByID

func (f *FormDefinition) RemoveFieldByID(fieldID string) (*FieldDefinition, error)

RemoveFieldByID removes a field from the form

type FormDefinitionList

type FormDefinitionList struct {
	Items []*FormDefinition `json:"items" yaml:"items"`
}

FormDefinitionList represents a list of FormDefinition

func NewFormDefinitionList

func NewFormDefinitionList(items ...*FormDefinition) *FormDefinitionList

NewFormDefinitionList creates a new FormDefinitionList

func (*FormDefinitionList) GetAtIndex

func (f *FormDefinitionList) GetAtIndex(index int) *FormDefinition

GetAtIndex returns the FormDefinition at the given index

func (*FormDefinitionList) GetFormByID

func (f *FormDefinitionList) GetFormByID(formID string) (*FormDefinition, error)

GetFormByID finds a FormDefinition by ID

func (*FormDefinitionList) IsEmpty

func (f *FormDefinitionList) IsEmpty() bool

IsEmpty returns whether a FormDefinition is empty or not

func (*FormDefinitionList) Len

func (f *FormDefinitionList) Len() int

Len returns the length of the FormDefinitionList

type FormInterface

type FormInterface interface {
	FormReference

	// GetFields returns the form/subform fields
	GetFields() FieldDefinitions

	// FindSubForm will recursively try to find a form or subform
	// with the given ID
	// TODO remove this from the FormInterface. Add a method without received FindSubForm(f FormInterface) SubFormInterface
	// Also dont make it recursive
	FindSubForm(subFormId string) (FormInterface, error)
}

FormInterface is a common interface between a FormDefinition and a FieldTypeSubForm. This way, we can treat both the "root" FormDefinition and the child SubForm as a single type.

type FormRef

type FormRef struct {
	// DatabaseID represents the FormDefinition.DatabaseID
	DatabaseID string `json:"databaseId"`
	// FormID represents the FormDefinition.ID
	FormID string `json:"formId"`
}

FormRef represents a key that allows referencing a single FormDefinition.

func (FormRef) GetDatabaseID

func (f FormRef) GetDatabaseID() string

GetDatabaseID implements FormReference.GetDatabaseID

func (FormRef) GetFormID

func (f FormRef) GetFormID() string

GetFormID implements FormReference.GetFormID

type FormReference

type FormReference interface {
	// GetFormID returns the form ID
	GetFormID() string
	// GetDatabaseID returns the form Database ID
	GetDatabaseID() string
}

FormReference is an interface for accessing a form ID and DatabaseID

type FormType

type FormType string

FormType represents the type of Form

const (
	// DefaultFormType represents a generic form definition
	DefaultFormType FormType = "default"
	// RecipientFormType represents a form definition for a beneficiary
	RecipientFormType FormType = "recipient"
)

type IdentityProvider

type IdentityProvider struct {
	// ID of the IdentityProvider
	ID string `json:"id"`
	// Name of the IdentityProvider
	Name string `json:"name"`
	// OrganizationID owning this IdentityProvider
	OrganizationID string `json:"organizationId"`
	// Domain OIDC issuer
	Domain string `json:"domain"`
	// ClientID is the OAuth2 client id
	ClientID string `json:"clientId"`
	// ClientSecret is the OAuth2 client secret
	ClientSecret string `json:"clientSecret"`
	// EmailDomain is the email domain "nrc.no" bound to this IdentityProvider
	// TODO: add unique constraint for email domains
	// TODO: add support for multiple email domains for a single IdentityProvider
	EmailDomain string `json:"emailDomain"`
}

IdentityProvider represents an Organization trusted Identity Provider

type IdentityProviderList

type IdentityProviderList struct {
	Items []*IdentityProvider `json:"items"`
}

IdentityProviderList represents a list of IdentityProvider

type OAuth2Client

type OAuth2Client struct {
	// ID of the OAuth2Client (Client ID)
	ID string `json:"id"`
	// Name of the OAuth2Client
	Name string `json:"clientName"`
	// Secret of the OAuth2Client
	Secret string `json:"clientSecret"`
	// URI is the application main URI
	URI string `json:"uri"`
	// GrantTypes of the OAuth2Client
	// see https://oauth.net/2/grant-types/
	GrantTypes []string `json:"grantTypes"`
	// ResponseTypes of the OAuth2Client
	// see https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html
	ResponseTypes []string `json:"responseTypes"`
	// Scope is the OAuth2 scope
	// see https://oauth.net/2/scope/
	Scope string `json:"scope"`
	// RedirectURIs accepted by this OAuth2Client
	// see https://www.oauth.com/oauth2-servers/redirect-uris/
	RedirectURIs []string `json:"redirectUris"`
	// AllowedCorsOrigins for this OAuth2Client
	AllowedCorsOrigins []string `json:"allowedCorsOrigins"`
	// TokenEndpointAuthMethod fot this OAuth2Client
	TokenEndpointAuthMethod string `json:"tokenEndpointAuthMethod"`
}

OAuth2Client represents an OAuth2 client registered on Core. Each application that needs to authenticate users, or to authenticate itself, needs a dedicated OAuth2Client

type OAuth2ClientList

type OAuth2ClientList struct {
	Items []*OAuth2Client `json:"items"`
}

OAuth2ClientList represents a list of OAuth2Client

type Organization

type Organization struct {
	// ID of the Organization
	ID string `json:"id"`
	// Name of the Organization
	Name string `json:"name"`
}

Organization represents a "tenant" in Core.

type OrganizationList

type OrganizationList struct {
	Items []*Organization `json:"items"`
}

OrganizationList represents a list of Organization

type Record

type Record struct {
	// ID of the record
	ID string `json:"id"`
	// Seq of the Record. This value is automatically increased by the database.
	// The presence of this field allows us to sort the table by insertion order.
	Seq int64 `json:"seq"`
	// DatabaseID of the Record
	DatabaseID string `json:"databaseId"`
	// FormID of the Record. Represents in which Form this record belongs.
	FormID string `json:"formId"`
	// OwnerID represents the owner of the Record. In cases where
	// a Record is part of a SubForm, this field records the "Owner" form ID.
	OwnerID *string `json:"ownerId"`
	// Values is a list of values that correspond to the FormDefinition.Fields.
	Values FieldValues `json:"values"`
}

Record represents an entry in a Form.

type RecordList

type RecordList struct {
	Items []*Record `json:"items"`
}

RecordList represents a list of Record

type RecordListOptions

type RecordListOptions struct {
	DatabaseID string
	FormID     string
}

RecordListOptions represents the options for listing Record.

type RecordRef

type RecordRef struct {
	// ID is the Record.ID
	ID string `json:"id"`
	// DatabaseID is the Record.DatabaseID
	DatabaseID string `json:"databaseId"`
	// FormID is the Record.FormID
	FormID string `json:"formId"`
}

RecordRef represents a key that allows referencing a single Record.

type Records

type Records []Record

type SelectOption

type SelectOption struct {
	// ID of the option
	ID string `json:"id" yaml:"id"`
	// Name of the option
	Name string `json:"name" yaml:"name"`
}

SelectOption represent an option for a FieldTypeSingleSelect or FieldTypeMultiSelect

type StringOrArray

type StringOrArray struct {
	Kind        StringOrArrayValue
	StringValue string
	ArrayValue  []string
}

func NewArrayValue

func NewArrayValue(value []string) StringOrArray

func NewNullValue

func NewNullValue() StringOrArray

func NewStringValue

func NewStringValue(value string) StringOrArray

func (StringOrArray) GetValue

func (s StringOrArray) GetValue() interface{}

func (StringOrArray) MarshalJSON

func (s StringOrArray) MarshalJSON() ([]byte, error)

func (*StringOrArray) UnmarshalJSON

func (s *StringOrArray) UnmarshalJSON(b []byte) error

type StringOrArrayValue

type StringOrArrayValue uint8
const (
	StringValue StringOrArrayValue = iota + 1
	ArrayValue
	NullValue
)

type SubFormInterface

type SubFormInterface interface {
	FormInterface
	GetOwnerFormID() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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