generate

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package generate makes synthetic HL7 v2 messages.

Two uses. Somebody trying Perfuse needs traffic to look at, and a channel test needs a fixture that is realistic enough to exercise the thing being tested. A generator is a paid extension in Mirth, which tells you people want one.

Everything here is invented. The names come from a fixed list of obviously fictional ones, the identifiers are sequential within a run, and the addresses are made up. That is not a disclaimer, it is the design: a generator that produced plausible-looking real names would eventually put one into a test fixture, a bug report and then a repository.

Realism is spent where it matters for testing and nowhere else. Timestamps carry offsets, repeating fields actually repeat, a name sometimes has a middle initial and sometimes does not, and roughly one message in twelve is deliberately awkward: a missing optional field, an unusual but legal separator, an empty component. Feeding a channel nothing but perfectly formed messages tells you very little.

Index

Constants

View Source
const (
	DefaultVersion  = "2.5.1"
	DefaultAwkward  = 1.0 / 12.0
	DefaultPatients = 8
	DefaultSpread   = 7 * time.Second
)

Defaults.

Variables

This section is empty.

Functions

func SyntheticSurnames added in v0.1.1

func SyntheticSurnames() []string

SyntheticSurnames returns the family names this generator invents.

Exported so the fixture check in internal/compliance can read them rather than keeping its own copy. Two lists of the same names drift, and the way that drift presents is a guard rejecting output produced by this repository's own generator - which is what happened: seven of the eight names here were absent from that check, so writing a fixture from generate output, the obvious thing to do, failed the build with a warning about real patient data.

Sorted, because a caller printing them should not see a different order each run.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator produces messages.

func New

func New(opts Options) *Generator

New builds a generator.

func (*Generator) All

func (g *Generator) All() []Message

All produces the whole batch.

func (*Generator) Next

func (g *Generator) Next() Message

Next produces one message.

type Kind

type Kind string

Kind is what to produce.

const (
	// ADT is admissions, discharges and transfers: the commonest feed.
	ADT Kind = "ADT"
	// ORU is observation results, which is where repeating OBX segments and
	// abnormal flags live.
	ORU Kind = "ORU"
	// ORM is orders.
	ORM Kind = "ORM"
	// MDM carries a clinical document.
	MDM Kind = "MDM"
)

type Message

type Message struct {
	// Raw is the ER7 bytes, segments separated by carriage returns.
	Raw []byte

	// ControlID is MSH-10.
	ControlID string
	// Type and Event are MSH-9.1 and MSH-9.2.
	Type  string
	Event string
	// Patient is the identifier used, so a caller can assert on it.
	Patient string
	// At is the message timestamp.
	At time.Time
	// Awkward records that this one was deliberately given an inconvenient shape,
	// and what shape, so a test that fails on it can tell why.
	Awkward string
}

Message is one generated message and what it is meant to be.

func Corpus

func Corpus(opts Options) []Message

Corpus writes a mixed batch, which is what a demo or a soak test wants: a real site's traffic is mostly ADT with results and orders alongside, not one type.

type Options

type Options struct {
	Kind Kind

	// Count is how many to produce.
	Count int

	// Seed makes a run reproducible. Zero picks one, which is right for a demo and
	// wrong for a test fixture, so callers writing tests should set it.
	Seed uint64

	// Facility and Application identify the pretend sender.
	Facility    string
	Application string

	// Receiver identifies the pretend receiver.
	ReceivingApplication string
	ReceivingFacility    string

	// Version is the HL7 version to claim. Defaults to 2.5.1.
	Version string

	// Since anchors the timestamps. Zero means recent.
	Since time.Time

	// Spread is how far apart the messages are in time. Zero means a few seconds
	// apart, which looks like a real feed rather than a burst with identical
	// timestamps that no sorting can distinguish.
	Spread time.Duration

	// Awkward is the proportion of messages given a legal but inconvenient shape,
	// between 0 and 1. Zero uses the default; set Perfect to turn it off.
	Awkward float64

	// Perfect turns off awkward messages, for a demo where every message should
	// sail through.
	Perfect bool

	// Patients is how many distinct patients to cycle through. A feed about one
	// patient does not exercise anything; a feed where every message is a
	// different patient does not either, because real feeds revisit people.
	Patients int
}

Options controls generation.

Jump to

Keyboard shortcuts

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