Skip to content

postgres ​

go
import "github.com/prescriptoo/prescriptoo-api/services/organization/internal/adapters/postgres"

Package postgres provides PostgreSQL driven adapter implementations.

Index ​

func NewMemberRepository ​

go
func NewMemberRepository() ports.MemberRepository

NewMemberRepository returns an in-memory stub implementation.

func NewOrganizationRepository ​

go
func NewOrganizationRepository() ports.OrganizationRepository

NewOrganizationRepository returns an in-memory stub implementation.

func NewPgMemberRepository ​

go
func NewPgMemberRepository(db *pgxpool.Pool) ports.MemberRepository

NewPgMemberRepository creates a PostgreSQL membership repository.

func NewPgOrganizationRepository ​

go
func NewPgOrganizationRepository(db *pgxpool.Pool) ports.OrganizationRepository

NewPgOrganizationRepository creates a PostgreSQL organization repository.

func NewPgTeamRepository ​

go
func NewPgTeamRepository(db *pgxpool.Pool) ports.TeamRepository

NewPgTeamRepository creates a PostgreSQL team repository.

func NewTeamRepository ​

go
func NewTeamRepository() ports.TeamRepository

NewTeamRepository returns an in-memory stub implementation.

type BillingOrganizations ​

BillingOrganizations exposes Organization-owned locking and relationship usage for billing.

go
type BillingOrganizations struct{}

func (BillingOrganizations) LockForBilling ​

go
func (BillingOrganizations) LockForBilling(ctx context.Context, tx pgx.Tx, id string) (p.BillingOrganization, error)

LockForBilling locks the organization and reads its authoritative relationship usage.

type DoctorAffiliations ​

DoctorAffiliations persists organization-owned affiliations independently from membership.

go
type DoctorAffiliations struct {
    CheckMutation func(context.Context, pgx.Tx, string, int, int, bool) error
    Accounts      identity.ActiveAccountLocker
    DB            *pgxpool.Pool
    Audit         audit.TransactionalRecorderFactory
}

func (DoctorAffiliations) AssignDoctors ​

go
func (r DoctorAffiliations) AssignDoctors(ctx context.Context, input p.AssignDoctorsInput) ([]p.DoctorAffiliation, error)

AssignDoctors creates or reactivates a validated batch under one transaction. Identity account locks and an organization row lock serialize eligibility with concurrent suspension/lifecycle changes. The caller supplies trusted audit context and the profile-to-account IDs it resolved through public provider capabilities.

Active assignments are idempotent and preserve assignment timestamps/actors. Reactivation records a new effective assignment without changing joined_at. Each actual change and its audit event commit together; any failure rolls back the complete batch. Subscription policy is evaluated by the application callback in this transaction.

func (DoctorAffiliations) ChangeDoctorAffiliationStatus ​

go
func (r DoctorAffiliations) ChangeDoctorAffiliationStatus(ctx context.Context, in p.ChangeDoctorAffiliationStatusInput) (*p.DoctorAffiliation, error)

ChangeDoctorAffiliationStatus updates an existing relationship and its audit event atomically. Activation takes Identity, organization, then affiliation locks in the same order as batch assignment. Deactivation requires no account eligibility.

func (DoctorAffiliations) ListDoctorAffiliations ​

go
func (r DoctorAffiliations) ListDoctorAffiliations(ctx context.Context, ids []string) ([]p.DoctorAffiliation, error)

ListDoctorAffiliations batches Organization-owned relationships for the supplied professional profile IDs. The organization join contributes current display and lifecycle information, while stored assignment metadata preserves who last activated each relationship. No doctor credentials or Identity accounts are read here; consumers enrich those fields through their owning services.

type DoctorInvitations ​

DoctorInvitations owns transactional invitation redemption.

go
type DoctorInvitations struct {
    CheckMutation func(context.Context, pgx.Tx, string, int, int, bool) error
}

func (DoctorInvitations) RedeemDoctorInvitation ​

go
func (r DoctorInvitations) RedeemDoctorInvitation(ctx context.Context, tx pgx.Tx, token, email, doctorID string) (*p.DoctorAffiliation, error)

RedeemDoctorInvitation locks the invitation and organization until signup commits.

type Insights ​

Insights reads organization-owned data without joining provider-owned tables.

go
type Insights struct{ DB *pgxpool.Pool }

func (Insights) ListAffiliations ​

go
func (r Insights) ListAffiliations(ctx context.Context, q p.AffiliationQuery) ([]p.DoctorAffiliation, error)

ListAffiliations reads relationships restricted to an organization, a doctor, or their intersection, rejecting an entirely unscoped read. It joins only Organization-owned tables and includes lifecycle/provenance data needed by both directions of the affiliation API. Search enrichment and keyset pagination are applied by the calling use case after reading this scoped relationship set.

func (Insights) OrganizationUsage ​

go
func (r Insights) OrganizationUsage(ctx context.Context, ids []string) (map[string]p.OrganizationUsage, error)

OrganizationUsage returns total and active relationship counts for each supplied organization ID. Ordinary memberships and doctor affiliations are aggregated separately and merged by ID so a many-to-many join cannot multiply either count. The caller validates organization existence; requested IDs with no relationships receive explicit zero values. Account and verification state do not affect usage.

type MutationRunner ​

MutationRunner commits owner-managed business writes and their audit records together.

go
type MutationRunner struct {
    CheckMutation func(context.Context, pgx.Tx, string, int, int, bool) error
    DB            *pgxpool.Pool
    Audit         audit.TransactionalRecorderFactory
}

func (MutationRunner) Run ​

go
func (w MutationRunner) Run(ctx context.Context, op audit.OperationContext, fn func(ports.MutationRepositories) error) error

Run runs a mutation with transaction-bound repositories and mandatory recording.

type OrganizationDiscovery ​

OrganizationDiscovery reads only active organization discovery fields.

go
type OrganizationDiscovery struct{ DB *pgxpool.Pool }

func (OrganizationDiscovery) ListActive ​

go
func (r OrganizationDiscovery) ListActive(ctx context.Context, query ports.ListActiveOrganizationsQuery) ([]types.DoctorOrganization, error)

ListActive reads a bounded page ordered by organization ID.

func (OrganizationDiscovery) ListAssigned ​

go
func (r OrganizationDiscovery) ListAssigned(ctx context.Context, doctorID string) ([]types.DoctorOrganizationAssignment, error)

ListAssigned reads the complete eligible affiliation list without a discovery fallback.

type PatientAccess ​

PatientAccess contains current organization relationship facts for patient authorization.

go
type PatientAccess struct{ DB *pgxpool.Pool }

func (PatientAccess) GetDoctorAffiliation ​

go
func (r PatientAccess) GetDoctorAffiliation(ctx context.Context, org, doctor string) (p.PatientDoctorAffiliation, error)

GetDoctorAffiliation reads pure affiliation and organization eligibility.

func (PatientAccess) GetPatientAccess ​

go
func (r PatientAccess) GetPatientAccess(ctx context.Context, org, user, doctor string) (p.PatientAccess, error)

GetPatientAccess resolves current eligibility and the selected relationship incarnation.

func (PatientAccess) LockPatientAccess ​

go
func (r PatientAccess) LockPatientAccess(ctx context.Context, tx pgx.Tx, org, user, doctor string) (p.PatientAccess, error)

LockPatientAccess serializes patient writes with organization and relationship changes.

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.