postgres
import "github.com/prescriptoo/prescriptoo-api/services/organization/internal/adapters/postgres"Package postgres provides PostgreSQL driven adapter implementations.
Index
- func NewMemberRepository() ports.MemberRepository
- func NewOrganizationRepository() ports.OrganizationRepository
- func NewPgMemberRepository(db *pgxpool.Pool) ports.MemberRepository
- func NewPgOrganizationRepository(db *pgxpool.Pool) ports.OrganizationRepository
- func NewPgTeamRepository(db *pgxpool.Pool) ports.TeamRepository
- func NewTeamRepository() ports.TeamRepository
- type BillingOrganizations
- type DoctorAffiliations
- func (r DoctorAffiliations) AssignDoctors(ctx context.Context, input p.AssignDoctorsInput) ([]p.DoctorAffiliation, error)
- func (r DoctorAffiliations) ChangeDoctorAffiliationStatus(ctx context.Context, in p.ChangeDoctorAffiliationStatusInput) (*p.DoctorAffiliation, error)
- func (r DoctorAffiliations) ListDoctorAffiliations(ctx context.Context, ids []string) ([]p.DoctorAffiliation, error)
- type DoctorInvitations
- type Insights
- type MutationRunner
- type OrganizationDiscovery
- type PatientAccess
- func (r PatientAccess) GetDoctorAffiliation(ctx context.Context, org, doctor string) (p.PatientDoctorAffiliation, error)
- func (r PatientAccess) GetPatientAccess(ctx context.Context, org, user, doctor string) (p.PatientAccess, error)
- func (r PatientAccess) LockPatientAccess(ctx context.Context, tx pgx.Tx, org, user, doctor string) (p.PatientAccess, error)
func NewMemberRepository
func NewMemberRepository() ports.MemberRepositoryNewMemberRepository returns an in-memory stub implementation.
func NewOrganizationRepository
func NewOrganizationRepository() ports.OrganizationRepositoryNewOrganizationRepository returns an in-memory stub implementation.
func NewPgMemberRepository
func NewPgMemberRepository(db *pgxpool.Pool) ports.MemberRepositoryNewPgMemberRepository creates a PostgreSQL membership repository.
func NewPgOrganizationRepository
func NewPgOrganizationRepository(db *pgxpool.Pool) ports.OrganizationRepositoryNewPgOrganizationRepository creates a PostgreSQL organization repository.
func NewPgTeamRepository
func NewPgTeamRepository(db *pgxpool.Pool) ports.TeamRepositoryNewPgTeamRepository creates a PostgreSQL team repository.
func NewTeamRepository
func NewTeamRepository() ports.TeamRepositoryNewTeamRepository returns an in-memory stub implementation.
type BillingOrganizations
BillingOrganizations exposes Organization-owned locking and relationship usage for billing.
type BillingOrganizations struct{}func (BillingOrganizations) LockForBilling
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.
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
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
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
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.
type DoctorInvitations struct {
CheckMutation func(context.Context, pgx.Tx, string, int, int, bool) error
}func (DoctorInvitations) RedeemDoctorInvitation
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.
type Insights struct{ DB *pgxpool.Pool }func (Insights) ListAffiliations
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
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.
type MutationRunner struct {
CheckMutation func(context.Context, pgx.Tx, string, int, int, bool) error
DB *pgxpool.Pool
Audit audit.TransactionalRecorderFactory
}func (MutationRunner) Run
func (w MutationRunner) Run(ctx context.Context, op audit.OperationContext, fn func(ports.MutationRepositories) error) errorRun runs a mutation with transaction-bound repositories and mandatory recording.
type OrganizationDiscovery
OrganizationDiscovery reads only active organization discovery fields.
type OrganizationDiscovery struct{ DB *pgxpool.Pool }func (OrganizationDiscovery) ListActive
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
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.
type PatientAccess struct{ DB *pgxpool.Pool }func (PatientAccess) GetDoctorAffiliation
func (r PatientAccess) GetDoctorAffiliation(ctx context.Context, org, doctor string) (p.PatientDoctorAffiliation, error)GetDoctorAffiliation reads pure affiliation and organization eligibility.
func (PatientAccess) GetPatientAccess
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
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