hospital

package
v0.0.0-...-e69eef7 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 31 Imported by: 20

Documentation

Overview

Package hospital implements the main functionality of Simulated Hospital.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalConfig

type AdditionalConfig struct {
	// ValidFn contains any additional validation for all parsed pathways.
	ValidFn func(*pathway.Pathway) error

	// Processors for events and messages.
	Processors Processors

	// ItemSyncers contains a map of item type to the ItemSyncer that will be used to sync those items
	// to more permanent storage. Currently, the following items are supported to be synced:
	//   - event
	//   - message
	//   - patient
	ItemSyncers map[string]persist.ItemSyncer

	// OrderAckDelay is the delay in sending Order Acknowledgement (ORR^O02) messages
	// after the corresponding Order message.
	OrderAckDelay *pathway.Delay

	// AddressGenerator generates random addresses.
	AddressGenerator person.AddressGenerator

	// MRNGenerator generates new MRNs.
	MRNGenerator id.Generator

	// PlacerGenerator generates Placer Order Numbers.
	PlacerGenerator id.Generator

	// FillerGenerator generates Filler Order Numbers.
	FillerGenerator id.Generator
}

AdditionalConfig contains optional configuration options for Simulated Hospital used to extend the main functionality. All fields are optional.

type Arguments

type Arguments struct {
	// LocationsFile to create the Config.LocationManager.
	// Also required to create Config.PathwayParser and Config.PathwayManager.
	LocationsFile *string

	// HardcodedMessagesDir to create Config.MessagesManager.
	HardcodedMessagesDir *string

	// Hl7ConfigFile to create Config.HL7Config.
	// Also required to create Config.OrderProfiles.
	Hl7ConfigFile *string

	// HeaderConfigFile to create Config.Header.
	HeaderConfigFile *string

	// DoctorsFile to create Config.Doctors.
	// Also required to create Config.PathwayParser and Config.PathwayManager.
	DoctorsFile *string

	// OrderProfilesFile to create Config.OrderProfiles.
	// Also required to create Config.PathwayParser and Config.PathwayManager.
	OrderProfilesFile *string

	// ResourceArguments to create ResourceWriter.
	ResourceArguments *ResourceArguments

	// DeletePatientsFromMemory to set as Config.DeletePatientsFromMemory.
	DeletePatientsFromMemory bool

	// PathwayArguments to create Config.PathwayManager.
	PathwayArguments *PathwayArguments

	// SenderArguments to create Config.Sender.
	SenderArguments *SenderArguments

	// DataFiles to set as Config.DataFiles.
	DataFiles *config.DataFiles

	// MessageControlGenerator for the hospital. If not set, a default generator is created.
	MessageControlGenerator *header.MessageControlGenerator

	// Clock for this hospital. If not set, a default clock is created.
	Clock clock.Clock
}

Arguments contains the arguments used to create a default Simulated Hospital Config.

type Config

type Config struct {
	// The location manager.
	// Required.
	LocationManager *location.Manager

	// The generator of message control IDs.
	// Required.
	MessageControlGenerator *header.MessageControlGenerator

	// The manager of hardcoded messages.
	// Required.
	MessagesManager *hardcoded.Manager

	// The configuration for HL7 messages.
	// Required.
	HL7Config *config.HL7Config

	// The configuration for the headers of the HL7 messages.
	// Required.
	Header *config.Header

	// The files to load the data from.
	DataFiles config.DataFiles

	// Doctors is the set of doctors to be used in pathways.
	Doctors *doctor.Doctors

	// OrderProfiles are the order profiles to be used in pathways.
	OrderProfiles *orderprofile.OrderProfiles

	// PathwayParser is used to parse pathways.
	PathwayParser *pathway.Parser

	// PathwayManager is the pathway manager to use for the hospital.
	PathwayManager pathway.Manager

	// Clock is the clock for the hospital.
	Clock clock.Clock

	// Sender contains the sender of HL7 messages.
	Sender hl7.Sender

	// Whether patients are deleted from the in-memory map after their pathways finish.
	// Deleting patients saves memory, but patients cannot be reused for other pathways.
	DeletePatientsFromMemory bool

	// ResourceWriter is used to write resources.
	ResourceWriter ResourceWriter

	// Additional configuration.
	// Optional.
	AdditionalConfig AdditionalConfig
}

Config contains the configuration for Simulated Hospital.

func DefaultConfig

func DefaultConfig(ctx context.Context, arguments Arguments) (Config, error)

DefaultConfig returns a default Config from Arguments. Config may be only partially populated if some Arguments are not specified. It is the responsibility of the caller to initialize missing components of the Config.

type EventProcessor

type EventProcessor interface {
	// Process processes the given event and returns any HL7 messages that must be sent as the result of the processing, if any.
	Process(*state.Event, *ir.PatientInfo, *processor.Config) ([]*message.HL7Message, error)
	// Matches returns whether the given event can be processed by the processor.
	Matches(*state.Event) bool
}

EventProcessor defines a processor of events that is run before, instead of or after the standard event processing logic.

type Hospital

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

Hospital contains the main functionality of Simulated Hospital.

func NewHospital

func NewHospital(ctx context.Context, c Config) (*Hospital, error)

NewHospital creates a new Hospital.

func (*Hospital) Close

func (h *Hospital) Close() error

Close closes resources held by the Hospital. Should be called if the Hospital is no longer needed or at the program exit.

func (*Hospital) EventsLen

func (h *Hospital) EventsLen() int

EventsLen returns the number of events waiting to be processed.

func (*Hospital) GetPathway

func (h *Hospital) GetPathway(pathwayName string) (*pathway.Pathway, error)

GetPathway gets the pathway with the given name configured in the hospital's pathway manager.

func (*Hospital) HasEvents

func (h *Hospital) HasEvents() bool

HasEvents returns whether there are events in the Event queue, independently of when they are due.

func (*Hospital) HasMessages

func (h *Hospital) HasMessages() bool

HasMessages returns whether there are messages in the Message queue, independently of when they are due.

func (*Hospital) MessagesLen

func (h *Hospital) MessagesLen() int

MessagesLen returns the number of messages waiting to be processed.

func (*Hospital) PatientExists

func (h *Hospital) PatientExists(id string) bool

PatientExists returns whether the patient with the given id is a known patient.

func (*Hospital) PatientsLen

func (h *Hospital) PatientsLen() int

PatientsLen returns the number of patients in the internal patients map.

func (*Hospital) ProcessNextMessageIfDue

func (h *Hospital) ProcessNextMessageIfDue() (bool, error)

ProcessNextMessageIfDue checks if there is a message available on the message queue and if it is due, and if so, it processes the next message. Returns true if there was a message for processing and the processing was successful, false otherwise.

func (*Hospital) RunNextEventIfDue

func (h *Hospital) RunNextEventIfDue(ctx context.Context) (bool, error)

RunNextEventIfDue checks if there is an event available on the event queue and if it is due, and if so, it runs the next event. Returns true it there was an event for processing and the event ran successfully, false otherwise.

func (*Hospital) StartNextPathway

func (h *Hospital) StartNextPathway() error

StartNextPathway starts the next pathway.

func (*Hospital) StartPathway

func (h *Hospital) StartPathway(p *pathway.Pathway) ([]*ir.Person, error)

StartPathway starts the given pathway. StartsPathway initialises the patient or patients this pathway refers to, and queues the first event for processing. StartPathway returns:

  • the list of persons that were generated as a result of running this pathway.
  • an error if something unexpected happened.

type MessageProcessor

type MessageProcessor interface {
	// Process processes the given message.
	Process(*state.HL7Message) error
	// Matches returns whether the given message can be processed by the processor.
	Matches(*state.HL7Message) bool
}

MessageProcessor defines a processor of messages that is run before, instead of or after the standard message processing logic.

type PathwayArguments

type PathwayArguments struct {
	// Dir contains all pathways to be used to create a Pathway Manager.
	Dir string

	// Names contains all pathway names to be included when creating a Pathway Manager.
	Names []string

	// ExcludeNames contains pathways names to be excluded when creating a Pathway Manager.
	ExcludeNames []string

	// Type is the way pathways are picked to be run - either "distribution" or "deterministic".
	Type string
}

PathwayArguments contains arguments to create a Pathway Manager.

type Processors

type Processors struct {
	// EventOverride is a slice of event processors that can be used to process an event
	// instead of the standard processing logic.
	EventOverride []EventProcessor

	// EventPre is a slice of event processors that can be used to process an event
	// before the standard event processing logic or its overrides have started.
	EventPre []EventProcessor

	// EventPost is a slice of event processors that can be used to process an event
	// after the standard event processing logic or its overrides have finished.
	EventPost []EventProcessor

	// MessageOverride is a slice of message processors that can be used to process a message
	// instead of the standard message processing logic.
	MessageOverride []MessageProcessor

	// MessagePre is a slice of message processors that can be used to process a message
	// before the standard message processing logic or its overrides have started.
	MessagePre []MessageProcessor

	// MessagePost is a slice of message processors that can be used to process a message
	// after the standard message processing logic or its overrides have finished.
	MessagePost []MessageProcessor
}

Processors for events and messages that enable configurable event/message processing logic to be run before, instead of or after the standard event/message processing logic.

type ResourceArguments

type ResourceArguments struct {
	Output    string
	OutputDir string
	Format    string

	// Arguments to connect to a Cloud FHIR store.
	// Only relevant if Output=cloud.
	CloudProjectID string
	CloudLocation  string
	CloudDataset   string
	CloudDatastore string
}

ResourceArguments contains arguments to create a ResourceWriter.

type ResourceWriter

type ResourceWriter interface {
	// Generate generates resources from the given info.
	Generate(*ir.PatientInfo) error
	Close() error
}

ResourceWriter defines an object which can produce resources.

type SenderArguments

type SenderArguments struct {
	// Output specified where the generated HL7 messages will be sent.
	Output string

	// OutputFile is a file path to write messages if Output=file.
	OutputFile string

	// MllpDestination is Host:Port to which MLLP messages will be sent if Output=mllp.
	MllpDestination string

	// MllpKeepAlive is whether to send keep-alive messages on the MLLP connection.
	// Only relevant if Output=mllp.
	MllpKeepAlive bool

	// MllpKeepAliveInterval is an interval between keep-alive messages.
	// Only relevant if Output=mllp and MllpKeepAlive=true.
	MllpKeepAliveInterval *time.Duration
}

SenderArguments contains arguments to create a Sender.

Directories

Path Synopsis
Package runner implements the main functionality of Simulated Hospital.
Package runner implements the main functionality of Simulated Hospital.
authentication
Package authentication provides functionality for authentication.
Package authentication provides functionality for authentication.

Jump to

Keyboard shortcuts

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