Skip to content

domain ​

go
import "github.com/prescriptoo/prescriptoo-api/pkg/types/domain"

Package domain contains shared clinical catalog models, value objects, inputs, errors and validation. It has no service/repository interfaces or transport, storage-driver, or service-package dependencies; those interfaces live in ports. Existing unrelated types remain in the root types package.

Index ​

Constants ​

Supported history categories match the doctor editor's category identifiers.

go
const (
    Medical            HistoryCategory = "medical"
    Surgical           HistoryCategory = "surgical"
    Medication         HistoryCategory = "medication"
    Allergy            HistoryCategory = "allergy"
    Family             HistoryCategory = "family"
    Social             HistoryCategory = "social"
    PresentIllness     HistoryCategory = "present-illness"
    Obstetric          HistoryCategory = "obstetric"
    Pediatric          HistoryCategory = "pediatric"
    Immunization       HistoryCategory = "immunization"
    AdverseReaction    HistoryCategory = "adverse-reaction"
    Other              HistoryCategory = "other"
    Active             Status          = "active"
    Inactive           Status          = "inactive"
    Live               DeletionFilter  = "live"
    Deleted            DeletionFilter  = "deleted"
    All                DeletionFilter  = "all"
    AllergyDrug                        = "Drug"
    AllergyFood                        = "Food"
    AllergyOther                       = "Other"
    AllergyUnspecified                 = "Unspecified"
    // MutationLock serializes catalog writes and seed identity reservations.
    MutationLock int64 = 726583947201
)

Variables ​

Stable catalog errors are mapped to transport errors by Doctor and Admin.

go
var (
    ErrInvalidInput = errors.New("invalid clinical suggestion input")
    ErrNotFound     = errors.New("clinical suggestion not found")
    ErrConflict     = errors.New("clinical suggestion identity or state conflicts")
    ErrUnavailable  = errors.New("clinical suggestion capability unavailable")
)

go
var (
    // ErrFinalPrescriptionInvalid rejects malformed commands and cursor/filter combinations.
    ErrFinalPrescriptionInvalid = errors.New("invalid final prescription")
    // ErrFinalPrescriptionNotFound hides inaccessible organizations, patients and records.
    ErrFinalPrescriptionNotFound = errors.New("prescription resource not found")
    // ErrFinalPrescriptionConflict requires explicit review of a changed identity or save request.
    ErrFinalPrescriptionConflict = errors.New("prescription snapshot or idempotency conflict")
    // ErrFinalPrescriptionProductConflict rejects unknown, inactive or mismatched canonical products.
    ErrFinalPrescriptionProductConflict = errors.New("prescription product conflict")
    // ErrFinalPrescriptionUnavailable indicates an unavailable real persistence or eligibility capability.
    ErrFinalPrescriptionUnavailable = errors.New("prescription unavailable")
)

func Display ​

go
func Display(s string) string

Display normalizes Unicode and whitespace while retaining original letter case.

func Normalize ​

go
func Normalize(s string) string

Normalize is the common seed, identity and search normalization, preserving Bengali marks.

func ValidActor ​

go
func ValidActor(a MutationActor) bool

ValidActor checks trusted attribution before any mutation, including a no-op.

func ValidCategory ​

go
func ValidCategory(c HistoryCategory) bool

ValidCategory reports whether a required category is supported.

func ValidID ​

go
func ValidID(s string) bool

ValidID requires the canonical UUID spelling used in paths and stored IDs.

type CatalogChange ​

CatalogChange records create/update/delete before-and-after domain snapshots. Actor attribution belongs to WithinMutation; request metadata comes from context.

go
type CatalogChange struct {
    Entity        string // chief-complaint | history-suggestion
    Action        string // create | update | delete
    ID            string
    Before, After CatalogSnapshot
}

type CatalogQuery ​

CatalogQuery selects a filter-bound management page.

go
type CatalogQuery struct {
    // Search matches titles/aliases; Cursor binds continuation to the normalized filters.
    Search, Cursor string
    // Limit defaults to 20 and must be between 1 and 100.
    Limit int
    // Status controls Doctor eligibility independently of soft deletion.
    Status Status
    // Deletion selects live, deleted, or all terms for management reads.
    Deletion DeletionFilter
}

func PrepareCatalogQuery ​

go
func PrepareCatalogQuery(q CatalogQuery) (CatalogQuery, error)

PrepareCatalogQuery applies management defaults and validates filter bounds.

type CatalogSnapshot ​

CatalogSnapshot contains exactly one resource type for a nonempty snapshot.

go
type CatalogSnapshot struct {
    ChiefComplaint    *ChiefComplaint
    HistorySuggestion *HistorySuggestion
}

type ChiefComplaint ​

ChiefComplaint is a catalog term with optional associated complaint choices.

go
type ChiefComplaint struct {
    Metadata
    // Title is the English display label, normalized for whitespace and Unicode.
    Title string
    // Aliases are searchable synonyms; Associated are optional related choices in display order.
    Aliases, Associated []string
}

func PrepareChiefComplaint ​

go
func PrepareChiefComplaint(v ChiefComplaint) (ChiefComplaint, error)

PrepareChiefComplaint validates and normalizes content, initializing empty lists.

type ChiefComplaintPatch ​

ChiefComplaintPatch represents exactly the fields supplied by an editor.

go
type ChiefComplaintPatch struct {
    // Title is the English display label, normalized for whitespace and Unicode.
    Title Field[string]
    // Aliases are searchable synonyms; Associated are optional related choices in display order.
    Aliases, Associated Field[[]string]
    // Status controls Doctor eligibility independently of soft deletion.
    Status Field[Status]
    // SortOrder ranks default suggestions in ascending order.
    SortOrder Field[int]
}

type ChiefComplaintValues ​

ChiefComplaintValues supplies validated create values after defaults.

go
type ChiefComplaintValues struct {
    // Title is the English display label, normalized for whitespace and Unicode.
    Title string
    // Aliases are searchable synonyms; Associated are optional related choices in display order.
    Aliases, Associated []string
    // Status controls Doctor eligibility independently of soft deletion.
    Status Status
    // SortOrder ranks default suggestions in ascending order.
    SortOrder int
}

type CreateChiefComplaintInput ​

CreateChiefComplaintInput combines authorized attribution and new values.

go
type CreateChiefComplaintInput struct {
    // Actor comes from the verified Admin principal, never an HTTP body.
    Actor MutationActor
    // Values contains editable creation fields after defaults.
    Values ChiefComplaintValues
}

type CreateHistoryInput ​

CreateHistoryInput combines authorized attribution and new history values.

go
type CreateHistoryInput struct {
    // Actor comes from the verified Admin principal, never an HTTP body.
    Actor MutationActor
    // Values contains editable creation fields after defaults.
    Values HistoryValues
}

type DeleteInput ​

DeleteInput soft-deletes one term while retaining actor attribution.

go
type DeleteInput struct {
    // Actor comes from the verified Admin principal, never an HTTP body.
    Actor MutationActor
    // ID is a stable server-assigned UUID; edits preserve it.
    ID  string
}

type DeletionFilter ​

DeletionFilter controls visibility in administrator list queries.

go
type DeletionFilter string // live | deleted | all

type Field ​

Field retains PATCH presence independently of a value's zero value. HTTP mappers reject explicit null before constructing this domain value.

go
type Field[T any] struct {
    // Present distinguishes an omitted patch field from an explicit zero or empty value.
    Present bool
    // Value replaces the stored field only when Present is true.
    Value T
}

type FinalCanonicalProduct ​

FinalCanonicalProduct archives resolved catalogue identity and update provenance.

go
type FinalCanonicalProduct struct {
    ID, GenericID, BrandID, GenericName, BrandName, Strength, Form, Route, TherapeuticClassID, CatalogueVersion string
    IngredientIDs                                                                                               []string
    UpdatedAt                                                                                                   time.Time
}

type FinalDoctorChamber ​

FinalDoctorChamber preserves a submitted professional practice location.

go
type FinalDoctorChamber struct{ Name, Address, Hours string }

type FinalDoctorEntry ​

FinalDoctorEntry is the identity and display snapshot of a professional catalogue selection.

go
type FinalDoctorEntry struct{ ID, Name string }

type FinalDoctorSnapshot ​

FinalDoctorSnapshot is verified against current professional data before finalization.

go
type FinalDoctorSnapshot struct {
    ID, UserID, Name, LicenseNumber string
    Speciality                      FinalDoctorEntry
    Qualifications                  []FinalDoctorEntry
    Chambers                        []FinalDoctorChamber
}

type FinalPrescriptionActor ​

FinalPrescriptionActor is constructed from the verified account/profile, never client identity.

go
type FinalPrescriptionActor struct{ UserID, DoctorID, Name string }

type FinalPrescriptionListInput ​

FinalPrescriptionListInput selects authorized summaries with stable keyset pagination.

go
type FinalPrescriptionListInput struct {
    Actor                                                       FinalPrescriptionActor
    OrganizationID, PatientID, Search, DateFrom, DateTo, Cursor string
    Limit                                                       int
}

type FinalPrescriptionMetadata ​

FinalPrescriptionMetadata is immutable server-generated save metadata.

go
type FinalPrescriptionMetadata struct {
    ID, OrganizationID, DoctorID string
    PatientID                    *string
    PrescriptionNumber           string
    Version                      int64
    CreatedAt, FinalizedAt       time.Time
}

type FinalPrescriptionPage ​

FinalPrescriptionPage carries initialized summary rows and an opaque continuation.

go
type FinalPrescriptionPage struct {
    Items      []FinalPrescriptionSummary
    NextCursor string
}

type FinalPrescriptionReadInput ​

FinalPrescriptionReadInput selects a record in a captured organization and verified actor scope.

go
type FinalPrescriptionReadInput struct {
    Actor              FinalPrescriptionActor
    OrganizationID, ID string
}

type FinalPrescriptionRecord ​

FinalPrescriptionRecord retains the complete sanitized clinical and letterhead payload.

go
type FinalPrescriptionRecord struct {
    FinalPrescriptionMetadata
    Payload []byte
}

type FinalPrescriptionSummary ​

FinalPrescriptionSummary omits the clinical payload when browsing saved records.

go
type FinalPrescriptionSummary struct {
    FinalPrescriptionMetadata
    PatientName, ConsultationDate string
}

type FinalProductSnapshot ​

FinalProductSnapshot is an existing canonical product reference plus its submitted display snapshot.

go
type FinalProductSnapshot struct{ ID, GenericName, BrandName, Strength, Form, Route string }

type HistoryAttributes ​

HistoryAttributes contains catalog classifications, not patient findings.

go
type HistoryAttributes struct {
    // AllergyKind classifies allergy terms; an empty value carries no classification.
    AllergyKind string // empty, Drug, Food, Other, or Unspecified
}

type HistoryCatalogQuery ​

HistoryCatalogQuery optionally limits management results to one category.

go
type HistoryCatalogQuery struct {
    CatalogQuery
    // Category selects a history editor section; management queries may omit it.
    Category HistoryCategory // empty means all categories
}

type HistoryCategory ​

HistoryCategory identifies one of the twelve supported history sections.

go
type HistoryCategory string

func Categories ​

go
func Categories() []HistoryCategory

Categories returns an independent ordered list of supported categories.

type HistoryPatch ​

HistoryPatch is validated together with the current stored record.

go
type HistoryPatch struct {
    // Category selects a history editor section; management queries may omit it.
    Category Field[HistoryCategory]
    // Title is the English display label, normalized for whitespace and Unicode.
    Title Field[string]
    // Aliases includes English/Bengali search terms and is initialized when empty.
    Aliases Field[[]string]
    // Attributes contains only catalog classifications, never patient observations.
    Attributes Field[HistoryAttributes]
    // Status controls Doctor eligibility independently of soft deletion.
    Status Field[Status]
    // SortOrder ranks default suggestions in ascending order.
    SortOrder Field[int]
}

type HistorySuggestion ​

HistorySuggestion is a history term scoped to one category.

go
type HistorySuggestion struct {
    Metadata
    // Category selects a history editor section; management queries may omit it.
    Category HistoryCategory
    // Title is the English display label, normalized for whitespace and Unicode.
    Title string
    // Aliases includes English/Bengali search terms and is initialized when empty.
    Aliases []string
    // Attributes contains only catalog classifications, never patient observations.
    Attributes HistoryAttributes
}

func PrepareHistory ​

go
func PrepareHistory(v HistorySuggestion) (HistorySuggestion, error)

PrepareHistory validates a category and its catalog classifications together.

type HistorySuggestionQuery ​

HistorySuggestionQuery adds the required category filter.

go
type HistorySuggestionQuery struct {
    SuggestionQuery
    // Category selects a history editor section; management queries may omit it.
    Category HistoryCategory
}

type HistoryValues ​

HistoryValues supplies a category and compatible classifications.

go
type HistoryValues struct {
    // Category selects a history editor section; management queries may omit it.
    Category HistoryCategory
    // Title is the English display label, normalized for whitespace and Unicode.
    Title string
    // Aliases includes English/Bengali search terms and is initialized when empty.
    Aliases []string
    // Attributes contains only catalog classifications, never patient observations.
    Attributes HistoryAttributes
    // Status controls Doctor eligibility independently of soft deletion.
    Status Status
    // SortOrder ranks default suggestions in ascending order.
    SortOrder int
}

type Metadata ​

Metadata contains catalog identity, lifecycle, and display priority.

go
type Metadata struct {
    // ID is a stable server-assigned UUID; edits preserve it.
    ID  string
    // Status controls Doctor eligibility independently of soft deletion.
    Status Status
    // SortOrder ranks default suggestions in ascending order.
    SortOrder int
    // CreatedAt and UpdatedAt record creation and the latest actual change in UTC.
    CreatedAt, UpdatedAt time.Time
    // DeletedAt is nil for a live term; deleted terms remain recoverable.
    DeletedAt *time.Time
}

type MutationActor ​

MutationActor identifies the authorized administrator for atomic audit. Admin derives it from verified identity/membership, never a request body.

go
type MutationActor struct {
    // UserID identifies the authenticated active identity account.
    UserID string
    // MembershipID identifies its verified active platform-admin membership.
    MembershipID string
    // Name preserves the administrator display name for audit attribution.
    Name string
}

type Page ​

Page contains a bounded management page and an opaque continuation.

go
type Page[T any] struct {
    // Items is initialized for an empty management page.
    Items []T
    // NextCursor is opaque and empty at the end of management results.
    NextCursor string
}

type PatchChiefComplaintInput ​

PatchChiefComplaintInput identifies the record and supplied edits.

go
type PatchChiefComplaintInput struct {
    // Actor comes from the verified Admin principal, never an HTTP body.
    Actor MutationActor
    // ID is a stable server-assigned UUID; edits preserve it.
    ID  string
    // Patch contains exactly the fields supplied by the editor.
    Patch ChiefComplaintPatch
}

type PatchHistoryInput ​

PatchHistoryInput identifies the history term and supplied edits.

go
type PatchHistoryInput struct {
    // Actor comes from the verified Admin principal, never an HTTP body.
    Actor MutationActor
    // ID is a stable server-assigned UUID; edits preserve it.
    ID  string
    // Patch contains exactly the fields supplied by the editor.
    Patch HistoryPatch
}

type SaveFinalPrescriptionInput ​

SaveFinalPrescriptionInput contains a validated detached document and the logical save identity.

go
type SaveFinalPrescriptionInput struct {
    Actor                                       FinalPrescriptionActor
    OrganizationID, IdempotencyKey, RequestHash string
    Doctor                                      FinalDoctorSnapshot
    PatientID                                   *string
    PatientName, ConsultationDate               string
    Payload                                     []byte
    Products                                    []FinalProductSnapshot
}

type ScopedSuggestionQuery ​

ScopedSuggestionQuery pages a Doctor catalogue using an actor/organization-bound scope.

go
type ScopedSuggestionQuery struct {
    SuggestionQuery
    Cursor   string
    Scope    string
    Category HistoryCategory
}

type Status ​

Status controls eligibility for Doctor autocomplete results.

go
type Status string // active | inactive

type SuggestionQuery ​

SuggestionQuery selects a bounded autocomplete result without a cursor.

go
type SuggestionQuery struct {
    // Search matches titles/aliases literally after shared normalization.
    Search string
    // Limit defaults to 20 and must be between 1 and 100.
    Limit int
}

func PrepareSuggestionQuery ​

go
func PrepareSuggestionQuery(q SuggestionQuery) (SuggestionQuery, error)

PrepareSuggestionQuery validates bounds and normalizes a query before storage access.

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.