output

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package output renders results as JSON (for pipes/agents) or aligned tables (for interactive terminals), and writes structured errors to stderr.

Index

Constants

This section is empty.

Variables

View Source
var Columns = map[string][]Column{
	"patient": {
		{"UUID", "uuid"}, {"NAME", "person.display"}, {"GENDER", "person.gender"},
		{"AGE", "person.age"}, {"BIRTHDATE", "person.birthdate"}, {"ID", "display"},
	},
	"concept": {
		{"UUID", "uuid"}, {"DISPLAY", "display"},
		{"DATATYPE", "datatype.display"}, {"CLASS", "conceptClass.display"},
	},
	"encounter": {
		{"UUID", "uuid"}, {"TYPE", "encounterType.display"},
		{"DATETIME", "encounterDatetime"}, {"LOCATION", "location.display"},
	},
	"obs": {
		{"UUID", "uuid"}, {"CONCEPT", "concept.display"},
		{"VALUE", "value.display|value"}, {"DATETIME", "obsDatetime"},
	},
	"visit": {
		{"UUID", "uuid"}, {"TYPE", "visitType.display"}, {"PATIENT", "patient.display"},
		{"START", "startDatetime"}, {"STOP", "stopDatetime"},
	},
	"location": {
		{"UUID", "uuid"}, {"NAME", "name|display"}, {"DESCRIPTION", "description"},
	},
	"user": {
		{"UUID", "uuid"}, {"DISPLAY", "display"}, {"USERNAME", "username"}, {"SYSTEMID", "systemId"},
	},
	"provider": {
		{"UUID", "uuid"}, {"DISPLAY", "display"},
	},
}

Columns maps a resource hint to its default table columns.

Functions

func Extract

func Extract(rec map[string]any, path string) string

Extract resolves a dot-path (e.g. "person.age") within a decoded JSON object. Alternate paths may be separated by "|": the first non-empty wins.

func Print

func Print(data map[string]any, mode Mode, resource string) error

Print renders data. Objects containing a "results" array render as a table in table mode; other objects render as key/value records.

func PrintError

func PrintError(err error, forceJSON bool) int

PrintError writes the error to stderr and returns the process exit code. Agents (stderr piped, or --json) get one-line structured JSON; humans at a terminal get plain readable text.

func Warn added in v0.2.1

func Warn(format string, args ...any)

Warn emits an advisory one-line JSON warning to stderr. Always marshaled — never hand-built — so embedded quotes can't produce invalid JSON on the wire agents parse.

Types

type Column

type Column struct {
	Label string
	Path  string
}

Column defines one table column: header label + dot-path into the record.

type Mode

type Mode int
const (
	ModeJSON Mode = iota
	ModeTable
)

func Detect

func Detect(jsonFlag, tableFlag bool) Mode

Detect picks the output mode: explicit flags win, otherwise JSON when stdout is not a terminal (piped/redirected — the agent case).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL