Skip to content

public ​

go
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 ​

Assignment sources identify the workflow that most recently activated a relationship.

go
const (
    AssignmentSourceLegacy       = "legacy"
    AssignmentSourceAdmin        = "super_admin_portal"
    AssignmentSourceRegistration = "doctor_registration"
)

Organization types are the supported classification values.

go
const (
    OrganizationTypeHospital        = "Hospital"
    OrganizationTypePharmaceuticals = "Pharmaceuticals"
    OrganizationTypePartner         = "Partner"
)

Variables ​

go
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")
)

go
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.

go
var ErrInvalidDoctorInvitation = errors.New("invalid doctor invitation")

ErrUnavailable indicates that an organization capability is unavailable.

go
var ErrUnavailable = errors.New("organization service unavailable")

func AssignmentEligibility ​

go
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 ​

go
func ValidOrganizationType(value string) bool

ValidOrganizationType 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.

go
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.

go
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.

go
type AffiliationQuery struct{ OrganizationID, DoctorID string }

type AssignDoctorsInput ​

AssignDoctorsInput creates or reactivates separate professional affiliations.

go
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.

go
type AuthorizationMembership struct {
    ID      string
    Active  bool
    IsOwner bool
}

type AuthorizationMembershipReader ​

AuthorizationMembershipReader exposes pure membership lookups without permission callbacks.

go
type AuthorizationMembershipReader interface {
    GetOrganizationAuthorizationMembership(context.Context, string, string) (AuthorizationMembership, error)
}

type BillingOrganization ​

BillingOrganization is read only after acquiring the shared organization row lock.

go
type BillingOrganization struct {
    TotalMembers                 int
    Status                       string
    ActiveMembers, ActiveDoctors int
}

type BillingOrganizations ​

BillingOrganizations preserves Organization's ownership of relationship counts.

go
type BillingOrganizations interface {
    LockForBilling(context.Context, pgx.Tx, string) (BillingOrganization, error)
}

type ChangeDoctorAffiliationStatusInput ​

ChangeDoctorAffiliationStatusInput changes an existing professional relationship.

go
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.

go
type ChangeOrganizationStatusInput struct {
    Audit          audit.OperationContext `json:"-"`
    OrganizationID string
    Status         OrganizationStatus
}

type CreateMemberInput ​

CreateMemberInput selects a user, organization, and role with audit context.

go
type CreateMemberInput struct {
    Audit          audit.OperationContext `json:"-"`
    OrganizationID string
    UserID         string
    Role           MemberRole
}

type CreateOrganizationInput ​

CreateOrganizationInput contains new organization details and audit context.

go
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.

go
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.

go
type DoctorAffiliationReader interface {
    GetDoctorAffiliation(context.Context, string, string) (PatientDoctorAffiliation, error)
}

type DoctorAffiliationStatusWriter ​

DoctorAffiliationStatusWriter owns transactional relationship status changes.

go
type DoctorAffiliationStatusWriter interface {
    ChangeDoctorAffiliationStatus(context.Context, ChangeDoctorAffiliationStatusInput) (*DoctorAffiliation, error)
}

type DoctorInvitation ​

DoctorInvitation describes an organization-owned registration invitation without exposing its secret token.

go
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.

go
type DoctorInvitationRedeemer interface {
    RedeemDoctorInvitation(context.Context, pgx.Tx, string, string, string) (*DoctorAffiliation, error)
}

type DoctorJoinRequest ​

DoctorJoinRequest describes an organization-owned doctor affiliation request.

go
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.

go
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.

go
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.

go
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.

go
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.

go
type MemberRole string

MemberRoleAdmin identifies an organization administrator.

go
const MemberRoleAdmin MemberRole = "admin"

type Organization ​

Organization exposes organization details shared with other services.

go
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.

go
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.

go
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.

go
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.

go
type OrganizationDoctorsPage struct {
    Items      []OrganizationDoctorItem
    Pagination types.Pagination
}

type OrganizationDoctorsQuery ​

OrganizationDoctorsQuery always scopes the list to one organization.

go
type OrganizationDoctorsQuery struct {
    OrganizationID, Search, Status, Cursor string
    Limit                                  int
}

type OrganizationPage ​

OrganizationPage contains organization results and pagination metadata.

go
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.

go
type OrganizationStatus string

go
const (
    // 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.

go
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.

go
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.

go
type PatientAccess struct {
    RelationshipID  string
    Active, IsOwner bool
}

type PatientAccessReader ​

PatientAccessReader reads current relationship eligibility with ordinary membership precedence.

go
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.

go
type PatientAccessTransactions interface {
    LockPatientAccess(context.Context, pgx.Tx, string, string, string) (PatientAccess, error)
}

type PatientDoctorAffiliation ​

PatientDoctorAffiliation contains pure organization and doctor relationship eligibility.

go
type PatientDoctorAffiliation struct {
    ID, OrganizationID, DoctorID string
    Active                       bool
}

type UpdateOrganizationInput ​

UpdateOrganizationInput contains replacement organization details and audit context.

go
type UpdateOrganizationInput struct {
    Type                                     *string
    Audit                                    audit.OperationContext `json:"-"`
    OrganizationID                           string
    Name, Description, Phone, Email, Address string
}

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.