public
import "github.com/prescriptoo/prescriptoo-api/services/organization/public"Package public exposes curated organization-owned contracts to other services.
Package public defines the curated API other services may use to interact with organizations. It intentionally exposes no repositories or internals.
Index
- Constants
- Variables
- func AssignmentEligibility(accountStatus, organizationStatus string, assigned bool) (bool, *string)
- func ValidOrganizationType(value string) bool
- type AdminDoctorAffiliations
- type AdminOrganizationService
- type AffiliationQuery
- type AssignDoctorsInput
- type AuthorizationMembership
- type AuthorizationMembershipReader
- type BillingOrganization
- type BillingOrganizations
- type ChangeDoctorAffiliationStatusInput
- type ChangeOrganizationStatusInput
- type CreateMemberInput
- type CreateOrganizationInput
- type DoctorAffiliation
- type DoctorAffiliationReader
- type DoctorAffiliationStatusWriter
- type DoctorInvitation
- type DoctorInvitationRedeemer
- type DoctorJoinRequest
- type Insights
- type InvitationPreview
- type ListOrganizationsQuery
- type Member
- type MemberRole
- type Organization
- type OrganizationDoctor
- type OrganizationDoctorItem
- type OrganizationDoctorReader
- type OrganizationDoctorsPage
- type OrganizationDoctorsQuery
- type OrganizationPage
- type OrganizationStatus
- type OrganizationSummary
- type OrganizationUsage
- type PatientAccess
- type PatientAccessReader
- type PatientAccessTransactions
- type PatientDoctorAffiliation
- type UpdateOrganizationInput
Constants
Assignment sources identify the workflow that most recently activated a relationship.
const (
AssignmentSourceLegacy = "legacy"
AssignmentSourceAdmin = "super_admin_portal"
AssignmentSourceRegistration = "doctor_registration"
)Organization types are the supported classification values.
const (
OrganizationTypeHospital = "Hospital"
OrganizationTypePharmaceuticals = "Pharmaceuticals"
OrganizationTypePartner = "Partner"
)Variables
var (
// ErrInvalidDoctorQuery indicates invalid scoped filters or continuation input.
ErrInvalidDoctorQuery = errors.New("invalid organization doctor query")
// ErrDoctorAffiliationNotFound indicates no relationship for the organization/doctor pair.
ErrDoctorAffiliationNotFound = errors.New("doctor affiliation not found")
)var (
// ErrOrganizationNotFound indicates that an organization does not exist.
ErrOrganizationNotFound = errors.New("organization not found")
// ErrOrganizationAlreadyExists indicates that an organization already exists.
ErrOrganizationAlreadyExists = errors.New("organization already exists")
// ErrInvalidOrganizationState indicates an invalid organization state or mutation.
ErrInvalidOrganizationState = errors.New("invalid organization state")
// ErrMemberNotFound indicates that an organization membership does not exist.
ErrMemberNotFound = errors.New("organization member not found")
// ErrMemberAlreadyExists indicates that an organization membership already exists.
ErrMemberAlreadyExists = errors.New("organization member already exists")
)ErrInvalidDoctorInvitation covers unknown, expired, consumed, revoked or mismatched invitations.
var ErrInvalidDoctorInvitation = errors.New("invalid doctor invitation")ErrUnavailable indicates that an organization capability is unavailable.
var ErrUnavailable = errors.New("organization service unavailable")func AssignmentEligibility
func AssignmentEligibility(accountStatus, organizationStatus string, assigned bool) (bool, *string)AssignmentEligibility computes picker state for one target organization using current account state and whether an active target affiliation already exists. Reasons are ordered: inactive organization, suspended account, other inactive account, then already assigned. Verification and other organizations' affiliations are intentionally absent from this active-account-only policy.
A false result for already_assigned disables repeat selection in the picker; the assignment command still treats an existing active affiliation as idempotent. A true result has a nil reason, which the target-aware HTTP response renders as null.
func ValidOrganizationType
func ValidOrganizationType(value string) boolValidOrganizationType accepts only the current named classification constants. Wire values intentionally retain their title case; storage and HTTP validation must extend the same allowed set when another organization type is introduced.
type AdminDoctorAffiliations
AdminDoctorAffiliations owns organization-side professional affiliation writes and reads.
type AdminDoctorAffiliations interface {
AssignDoctors(context.Context, AssignDoctorsInput) ([]DoctorAffiliation, error)
ListDoctorAffiliations(context.Context, []string) ([]DoctorAffiliation, error)
}type AdminOrganizationService
AdminOrganizationService exposes organization and membership operations used by Admin.
type AdminOrganizationService interface {
CreateOrganization(context.Context, CreateOrganizationInput) (*Organization, error)
GetOrganization(context.Context, string) (*Organization, error)
ListOrganizations(context.Context, ListOrganizationsQuery) (*OrganizationPage, error)
UpdateOrganization(context.Context, UpdateOrganizationInput) (*Organization, error)
ChangeOrganizationStatus(context.Context, ChangeOrganizationStatusInput) (*Organization, error)
CreateMember(context.Context, CreateMemberInput) (*Member, error)
GetMemberByUserID(context.Context, string, string) (*Member, error)
}type AffiliationQuery
AffiliationQuery scopes relationship reads; an empty scope is not permitted.
type AffiliationQuery struct{ OrganizationID, DoctorID string }type AssignDoctorsInput
AssignDoctorsInput creates or reactivates separate professional affiliations.
type AssignDoctorsInput struct {
Audit audit.OperationContext
OrganizationID string
DoctorIDs []string
// AccountUserIDs are resolved by the trusted caller from Doctor profiles and
// checked under Identity row locks during assignment, not accepted from HTTP input.
AccountUserIDs []string
}type AuthorizationMembership
AuthorizationMembership is a current organization-owned access relationship. Doctor-affiliation persistence can implement this same boundary without manufacturing ordinary memberships.
type AuthorizationMembership struct {
ID string
Active bool
IsOwner bool
}type AuthorizationMembershipReader
AuthorizationMembershipReader exposes pure membership lookups without permission callbacks.
type AuthorizationMembershipReader interface {
GetOrganizationAuthorizationMembership(context.Context, string, string) (AuthorizationMembership, error)
}type BillingOrganization
BillingOrganization is read only after acquiring the shared organization row lock.
type BillingOrganization struct {
TotalMembers int
Status string
ActiveMembers, ActiveDoctors int
}type BillingOrganizations
BillingOrganizations preserves Organization's ownership of relationship counts.
type BillingOrganizations interface {
LockForBilling(context.Context, pgx.Tx, string) (BillingOrganization, error)
}type ChangeDoctorAffiliationStatusInput
ChangeDoctorAffiliationStatusInput changes an existing professional relationship.
type ChangeDoctorAffiliationStatusInput struct {
Audit audit.OperationContext
OrganizationID string
DoctorID string
Status string
// AccountUserID is resolved through Doctor by the trusted caller for activation.
AccountUserID string
}type ChangeOrganizationStatusInput
ChangeOrganizationStatusInput selects an organization and target status with audit context.
type ChangeOrganizationStatusInput struct {
Audit audit.OperationContext `json:"-"`
OrganizationID string
Status OrganizationStatus
}type CreateMemberInput
CreateMemberInput selects a user, organization, and role with audit context.
type CreateMemberInput struct {
Audit audit.OperationContext `json:"-"`
OrganizationID string
UserID string
Role MemberRole
}type CreateOrganizationInput
CreateOrganizationInput contains new organization details and audit context.
type CreateOrganizationInput struct {
Type *string
Audit audit.OperationContext `json:"-"`
Name, Slug, Description, Phone, Email, Address string
}type DoctorAffiliation
DoctorAffiliation is organization-owned and separate from ordinary membership. A member role never creates a doctor profile or affiliation.
type DoctorAffiliation struct {
OrganizationType *string `json:"organization_type"`
OrganizationStatus string `json:"organization_status"`
AssignedAt time.Time `json:"assigned_at"`
AssignedByUserID *string `json:"assigned_by_user_id"`
AssignmentSource string `json:"assignment_source" enum:"legacy,super_admin_portal,doctor_registration"`
OrganizationName string `json:"organization_name"`
OrganizationSlug string `json:"organization_slug"`
ID string `json:"id"`
OrganizationID string `json:"organization_id"`
DoctorID string `json:"doctor_id"`
Status string `json:"status" enum:"active,inactive"`
JoinedAt time.Time `json:"joined_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type DoctorAffiliationReader
DoctorAffiliationReader reads affiliations without account or professional-directory enrichment.
type DoctorAffiliationReader interface {
GetDoctorAffiliation(context.Context, string, string) (PatientDoctorAffiliation, error)
}type DoctorAffiliationStatusWriter
DoctorAffiliationStatusWriter owns transactional relationship status changes.
type DoctorAffiliationStatusWriter interface {
ChangeDoctorAffiliationStatus(context.Context, ChangeDoctorAffiliationStatusInput) (*DoctorAffiliation, error)
}type DoctorInvitation
DoctorInvitation describes an organization-owned registration invitation without exposing its secret token.
type DoctorInvitation struct {
ID string `json:"id"`
OrganizationID string `json:"organization_id"`
Email string `json:"email" format:"email"`
Status string `json:"status" enum:"pending,accepted,revoked,expired"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type DoctorInvitationRedeemer
DoctorInvitationRedeemer consumes an invitation and affiliates the new doctor inside the caller's registration transaction. It never commits that transaction.
type DoctorInvitationRedeemer interface {
RedeemDoctorInvitation(context.Context, pgx.Tx, string, string, string) (*DoctorAffiliation, error)
}type DoctorJoinRequest
DoctorJoinRequest describes an organization-owned doctor affiliation request.
type DoctorJoinRequest struct {
ID string `json:"id"`
DoctorID string `json:"doctor_id"`
OrganizationID string `json:"organization_id"`
Status string `json:"status" enum:"pending,accepted,rejected,canceled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type Insights
Insights exposes organization-owned aggregate and affiliation reads.
type Insights interface {
// OrganizationUsage returns explicit zero-count entries for requested IDs with
// no relationships. Consumers establish resource existence before using counts.
OrganizationUsage(context.Context, []string) (map[string]OrganizationUsage, error)
// ListAffiliations requires at least one scope ID and returns all matching
// relationship states for application-level search, enrichment, and pagination.
ListAffiliations(context.Context, AffiliationQuery) ([]DoctorAffiliation, error)
}type InvitationPreview
InvitationPreview does not expose internal IDs or unrelated organization data.
type InvitationPreview struct {
Organization OrganizationSummary `json:"organization"`
Email string `json:"email" format:"email"`
Status string `json:"status" enum:"pending,accepted,revoked,expired"`
ExpiresAt time.Time `json:"expires_at"`
}type ListOrganizationsQuery
ListOrganizationsQuery selects organization filters, ordering, and pagination.
type ListOrganizationsQuery struct {
Limit int
Cursor string
Search string
Status *OrganizationStatus
Sort string
Order string
}type Member
Member exposes organization membership details shared with other services.
type Member struct {
ID string `json:"id"`
UserID string `json:"user_id"`
OrganizationID string `json:"organization_id"`
Role MemberRole `json:"role"`
Status string `json:"status"`
JoinedAt time.Time `json:"joined_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type MemberRole
MemberRole identifies a member's role within an organization.
type MemberRole stringMemberRoleAdmin identifies an organization administrator.
const MemberRoleAdmin MemberRole = "admin"type Organization
Organization exposes organization details shared with other services.
type Organization struct {
Type *string `json:"type" enum:"Hospital,Pharmaceuticals,Partner" nullable:"true"`
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
Phone string `json:"phone"`
Email string `json:"email"`
Address string `json:"address"`
Status OrganizationStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}type OrganizationDoctor
OrganizationDoctor exposes professional display data and current account/review state.
type OrganizationDoctor struct {
ID string `json:"id"`
Name string `json:"name"`
LicenseNumber string `json:"license_number"`
Speciality doctor.CatalogEntry `json:"speciality"`
Specialization []doctor.CatalogEntry `json:"specialization" nullable:"false"`
VerificationStatus string `json:"verification_status"`
AccountStatus string `json:"account_status"`
}type OrganizationDoctorItem
OrganizationDoctorItem combines an affiliation with its doctor display data.
type OrganizationDoctorItem struct {
DoctorAffiliation
Doctor OrganizationDoctor `json:"doctor"`
}type OrganizationDoctorReader
OrganizationDoctorReader supplies scoped reads after the caller authorizes access and establishes organization existence. It does not grant portal or Admin access.
type OrganizationDoctorReader interface {
ListOrganizationDoctors(context.Context, OrganizationDoctorsQuery) (*OrganizationDoctorsPage, error)
GetOrganizationDoctor(context.Context, string, string) (*OrganizationDoctorItem, error)
}type OrganizationDoctorsPage
OrganizationDoctorsPage contains filtered relationships and cursor metadata.
type OrganizationDoctorsPage struct {
Items []OrganizationDoctorItem
Pagination types.Pagination
}type OrganizationDoctorsQuery
OrganizationDoctorsQuery always scopes the list to one organization.
type OrganizationDoctorsQuery struct {
OrganizationID, Search, Status, Cursor string
Limit int
}type OrganizationPage
OrganizationPage contains organization results and pagination metadata.
type OrganizationPage struct {
Items []Organization `json:"items"`
NextCursor string `json:"next_cursor,omitempty"`
CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"`
TotalPages int `json:"total_pages"`
TotalItems int `json:"total_items"`
}type OrganizationStatus
OrganizationStatus represents an organization's lifecycle state.
type OrganizationStatus stringconst (
// OrganizationStatusActive marks an active organization.
OrganizationStatusActive OrganizationStatus = "active"
// OrganizationStatusSuspended marks a suspended organization.
OrganizationStatusSuspended OrganizationStatus = "suspended"
// OrganizationStatusDeleted marks an organization as deleted.
OrganizationStatusDeleted OrganizationStatus = "deleted"
)type OrganizationSummary
OrganizationSummary is the discovery surface for registered doctors.
type OrganizationSummary struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
Address string `json:"address"`
Status OrganizationStatus `json:"status" enum:"active"`
}type OrganizationUsage
OrganizationUsage counts ordinary memberships separately from professional affiliations.
type OrganizationUsage struct {
TotalMembers int `json:"total_members"`
ActiveMembers int `json:"active_members"`
TotalDoctors int `json:"total_doctors"`
ActiveDoctors int `json:"active_doctors"`
}type PatientAccess
PatientAccess retains ordinary membership precedence for grant incarnation IDs.
type PatientAccess struct {
RelationshipID string
Active, IsOwner bool
}type PatientAccessReader
PatientAccessReader reads current relationship eligibility with ordinary membership precedence.
type PatientAccessReader interface {
GetPatientAccess(context.Context, string, string, string) (PatientAccess, error)
}type PatientAccessTransactions
PatientAccessTransactions locks Organization and rechecks the exact relationship in a caller-owned transaction.
type PatientAccessTransactions interface {
LockPatientAccess(context.Context, pgx.Tx, string, string, string) (PatientAccess, error)
}type PatientDoctorAffiliation
PatientDoctorAffiliation contains pure organization and doctor relationship eligibility.
type PatientDoctorAffiliation struct {
ID, OrganizationID, DoctorID string
Active bool
}type UpdateOrganizationInput
UpdateOrganizationInput contains replacement organization details and audit context.
type UpdateOrganizationInput struct {
Type *string
Audit audit.OperationContext `json:"-"`
OrganizationID string
Name, Description, Phone, Email, Address string
}Generated by gomarkdoc