Medicine
Medicine owns the global manufacturer, generic, brand, and drug catalog. Brands reference a manufacturer and named generic; drugs add form and strength display text. Admin delegates catalog management through individually injected public capabilities and does not own medicine storage.
Implementation
All 32 reader and administration operations are implemented with use cases and a PostgreSQL adapter. Authentication, authorization, audit recording, and events are not enabled in this initial implementation. Ordinary readers expose active, non-deleted entries whose parents are also active and non-deleted.
Each HTTP operation has its request/response DTOs and mapper in a _query.go or _command.go file. Handlers invoke use cases only. Responses use the organization API envelope: message, data, status_code, and pagination for lists. DELETE returns 200 with the success envelope and data: {}.
Medicine workflows describes routes, filtering, pagination, PATCH semantics, soft deletion, and restoration. The public package contains capability inputs and results; transport DTOs belong to the route files.
PATCH distinguishes omission from explicit description clearing:
package public_test
import (
"encoding/json"
"fmt"
medicine "github.com/prescriptoo/prescriptoo-api/services/medicine/public"
)
// PATCH distinguishes an omitted field from explicit null. This example only
// decodes the public contract used by the catalog use cases.
func ExamplePatchManufacturerParams_UnmarshalJSON() {
var patch medicine.PatchManufacturerParams
if err := json.Unmarshal([]byte(`{"description":null}`), &patch); err != nil {
panic(err)
}
fmt.Println("description supplied:", patch.Supplied["description"])
fmt.Println("description cleared:", patch.Description == nil)
fmt.Println("name preserved:", !patch.Supplied["name"])
// Output:
// description supplied: true
// description cleared: true
// name preserved: true
}Persistence and verification
Run go run ./tools/cli database migrate --service medicine before using the routes. Medicine migrations are included in database migrate and tracked in goose_medicine_version. Load the bundled Bangladesh catalog with go run ./tools/cli database seed-medicine: it contains 600 drug variants, 310 brands, 62 generics, and 26 manufacturers. Repeated runs reuse matching live records and do not duplicate them. A module constructed without a database returns 503 for valid operations and still supports offline OpenAPI generation.
Unit and route tests cover validation, mapper/delegation behavior, lifecycle rules, and cursor binding. PostgreSQL integration tests cover all 32 routes, search, duplicate conflicts, rollback, restoration, persistence across module reconstruction, and concurrent parent deletion/child creation. Run them with:
MEDICINE_TEST_DATABASE_URL='postgres://.../prescriptoo_test' \
go test -race -count=1 ./services/api/cmd/server -run 'TestMedicine.*Integration'The integration tests require a local dedicated test database and create and remove their own isolated schemas. They also accept AUTH_TEST_DATABASE_URL from the repository test environment.
Code reference
See public catalog contracts, module capabilities, and use cases.