ports
import "github.com/prescriptoo/prescriptoo-api/pkg/types/ports"Package ports defines shared service, repository and transaction interfaces. Organization implements DoctorOrganizationService for authenticated doctor queries. Doctor consumes DoctorClinicalService, Admin consumes AdminClinicalSuggestionService, and Prescription implements both services. Repositories and transaction ports are implementation dependencies, not API capabilities for Doctor/Admin. Port signatures use shared domain models.
Index
- type AdminClinicalSuggestionService
- type ChiefComplaintRepository
- type DoctorClinicalPageService
- type DoctorClinicalService
- type DoctorOrganizationService
- type FinalPrescriptionDoctorVerifier
- type FinalPrescriptionPatientReader
- type FinalPrescriptionProductResolver
- type FinalPrescriptionService
- type HistoryRepository
- type Mutation
- type MutationStore
- type PatientService
type AdminClinicalSuggestionService
AdminClinicalSuggestionService manages both clinical suggestion catalogs. Admin enforces read/manage permissions before invoking each operation. Mutations carry verified actor attribution and commit their catalog changes with audit.
type AdminClinicalSuggestionService interface {
// ListChiefComplaints returns a page under the management filters/order.
ListChiefComplaints(ctx context.Context, query domain.CatalogQuery) (domain.Page[domain.ChiefComplaint], error)
// GetChiefComplaint returns one term, including a deleted term, or domain.ErrNotFound.
GetChiefComplaint(ctx context.Context, id string) (domain.ChiefComplaint, error)
// ListHistorySuggestions optionally filters category across a management page.
ListHistorySuggestions(ctx context.Context, query domain.HistoryCatalogQuery) (domain.Page[domain.HistorySuggestion], error)
// GetHistorySuggestion returns one term, including a deleted term, or domain.ErrNotFound.
GetHistorySuggestion(ctx context.Context, id string) (domain.HistorySuggestion, error)
// CreateChiefComplaint validates identity and commits the term with audit.
CreateChiefComplaint(ctx context.Context, input domain.CreateChiefComplaintInput) (domain.ChiefComplaint, error)
// PatchChiefComplaint merges supplied fields under lock and audits actual changes.
PatchChiefComplaint(ctx context.Context, input domain.PatchChiefComplaintInput) (domain.ChiefComplaint, error)
// DeleteChiefComplaint soft-deletes once; an already deleted ID is a no-op.
DeleteChiefComplaint(ctx context.Context, input domain.DeleteInput) error
// CreateHistorySuggestion validates category/attributes and commits with audit.
CreateHistorySuggestion(ctx context.Context, input domain.CreateHistoryInput) (domain.HistorySuggestion, error)
// PatchHistorySuggestion validates the merged category and classification values.
PatchHistorySuggestion(ctx context.Context, input domain.PatchHistoryInput) (domain.HistorySuggestion, error)
// DeleteHistorySuggestion soft-deletes once without changing prior clinical documents.
DeleteHistorySuggestion(ctx context.Context, input domain.DeleteInput) error
}type ChiefComplaintRepository
ChiefComplaintRepository provides catalog reads without transport concerns.
type ChiefComplaintRepository interface {
// Suggest performs matching/ranking and includes inline associations.
Suggest(ctx context.Context, query domain.SuggestionQuery) ([]domain.ChiefComplaint, error)
// List applies management filtering and cursor pagination.
List(ctx context.Context, query domain.CatalogQuery) (domain.Page[domain.ChiefComplaint], error)
// Get returns a term irrespective of its deletion state.
Get(ctx context.Context, id string) (domain.ChiefComplaint, error)
}type DoctorClinicalPageService
DoctorClinicalPageService extends real catalogue queries with scoped ranked pagination. Doctor validates the session and affiliation before providing the trusted scope.
type DoctorClinicalPageService interface {
SuggestChiefComplaintsPage(context.Context, domain.ScopedSuggestionQuery) (domain.Page[domain.ChiefComplaint], error)
SuggestHistoryPage(context.Context, domain.ScopedSuggestionQuery) (domain.Page[domain.HistorySuggestion], error)
}type DoctorClinicalService
DoctorClinicalService supplies active, non-deleted clinical input suggestions. Doctor authenticates the persistent session before invoking this query-only service.
type DoctorClinicalService interface {
// SuggestChiefComplaints searches title/aliases or returns curated defaults.
// Results include associations and contain at most query.Limit records.
SuggestChiefComplaints(ctx context.Context, query domain.SuggestionQuery) ([]domain.ChiefComplaint, error)
// SuggestHistory requires a valid category and includes classification attributes.
SuggestHistory(ctx context.Context, query domain.HistorySuggestionQuery) ([]domain.HistorySuggestion, error)
}type DoctorOrganizationService
DoctorOrganizationService lists active organizations without membership or billing data. The calling use case must authenticate an active doctor before invoking the service.
type DoctorOrganizationService interface {
ListOrganizations(context.Context, types.ListDoctorOrganizationsQuery) (*types.DoctorOrganizationPage, error)
// ListAssignedOrganizations returns every active assignment for a verified doctor profile.
// It never falls back to global discovery when no assignments exist.
ListAssignedOrganizations(context.Context, string) ([]types.DoctorOrganizationAssignment, error)
}type FinalPrescriptionDoctorVerifier
FinalPrescriptionDoctorVerifier freezes current professional selections under a transaction-held profile lock.
type FinalPrescriptionDoctorVerifier interface {
VerifyFinalDoctorSnapshot(context.Context, pgx.Tx, d.FinalDoctorSnapshot) error
}type FinalPrescriptionPatientReader
FinalPrescriptionPatientReader authorizes patient linkage within the caller's transaction and returns its MRN.
type FinalPrescriptionPatientReader interface {
FinalPrescriptionPatientMRN(context.Context, pgx.Tx, string, string) (string, error)
}type FinalPrescriptionProductResolver
FinalPrescriptionProductResolver validates real product references inside the finalization transaction.
type FinalPrescriptionProductResolver interface {
ResolveFinalPrescriptionProducts(context.Context, pgx.Tx, []d.FinalProductSnapshot) ([]d.FinalCanonicalProduct, error)
}type FinalPrescriptionService
FinalPrescriptionService owns the real immutable clinical-document workflow.
type FinalPrescriptionService interface {
SaveFinalPrescription(context.Context, d.SaveFinalPrescriptionInput) (*d.FinalPrescriptionMetadata, error)
GetFinalPrescription(context.Context, d.FinalPrescriptionReadInput) (*d.FinalPrescriptionRecord, error)
ListFinalPrescriptions(context.Context, d.FinalPrescriptionListInput) (*d.FinalPrescriptionPage, error)
}type HistoryRepository
HistoryRepository provides categorized catalog reads.
type HistoryRepository interface {
// Suggest enforces category and active/live eligibility before limiting.
Suggest(ctx context.Context, query domain.HistorySuggestionQuery) ([]domain.HistorySuggestion, error)
// List supports optional category and lifecycle filters for administrators.
List(ctx context.Context, query domain.HistoryCatalogQuery) (domain.Page[domain.HistorySuggestion], error)
// Get returns a history term irrespective of its deletion state.
Get(ctx context.Context, id string) (domain.HistorySuggestion, error)
}type Mutation
Mutation is valid only for the lifetime of a WithinMutation callback.
type Mutation interface {
// LockChiefComplaint reads current state under a write lock, including deleted rows.
LockChiefComplaint(ctx context.Context, id string) (domain.ChiefComplaint, error)
// InsertChiefComplaint enforces ID and live-title uniqueness.
InsertChiefComplaint(ctx context.Context, item domain.ChiefComplaint) error
// SaveChiefComplaint persists validated edits/deletion plus normalized search values.
SaveChiefComplaint(ctx context.Context, item domain.ChiefComplaint) error
// LockHistorySuggestion reads the latest history term under a write lock.
LockHistorySuggestion(ctx context.Context, id string) (domain.HistorySuggestion, error)
// InsertHistorySuggestion enforces category-scoped live-title uniqueness.
InsertHistorySuggestion(ctx context.Context, item domain.HistorySuggestion) error
// SaveHistorySuggestion persists merged content/lifecycle/search values.
SaveHistorySuggestion(ctx context.Context, item domain.HistorySuggestion) error
// AppendAudit appends a domain change through the transaction-bound audit adapter.
AppendAudit(ctx context.Context, change domain.CatalogChange) error
}type MutationStore
MutationStore commits catalog writes and audit in one storage transaction.
type MutationStore interface {
// WithinMutation rolls back on callback/audit/commit failure and honors cancellation.
// The callback receives domain interfaces, never a database-driver transaction.
WithinMutation(ctx context.Context, actor domain.MutationActor, fn func(Mutation) error) error
}type PatientService
PatientService provides doctor patient operations without role or permission checks. Callers authenticate with IIdentityService and supply the verified UserID. Implementations resolve the current doctor profile and organization affiliation.
type PatientService interface {
DoctorCreatePatient(context.Context, types.DoctorCreatePatientInput) (*types.Patient, error)
DoctorListPatients(context.Context, types.DoctorListPatientsInput) (*types.PatientPage, error)
DoctorGetPatient(context.Context, types.DoctorGetPatientInput) (*types.Patient, error)
DoctorPatchPatient(context.Context, types.DoctorPatchPatientInput) (*types.Patient, error)
}Generated by gomarkdoc