testhospital

package
v0.0.0-...-0da26dc Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testhospital contains functionality to test hospitals. It allows to create hospitals easily and run the events and messages.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Arguments contains default arguments for testing.
	Arguments = hospital.Arguments{
		DoctorsFile:          &test.DoctorsConfigTest,
		OrderProfilesFile:    &test.OrderProfilesConfigTest,
		PathwayArguments:     &hospital.PathwayArguments{Dir: test.PathwaysDirTest, Type: "distribution"},
		Hl7ConfigFile:        &test.MessageConfigTest,
		HeaderConfigFile:     &test.HeaderConfigTest,
		HardcodedMessagesDir: &test.HardcodedMessagesDirTest,
		LocationsFile:        &test.LocationsConfigTest,
		DataFiles:            &dataFilesTest,
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	hospital.Config
	hospital.Arguments
}

Config is the configuration of a test hospital. Fields common to both Config and Arguments are taken from hospital.Config.

type Hospital

type Hospital struct {
	*hospital.Hospital

	Sender          *testhl7.Sender
	Parser          *pathway.Parser
	PathwayManager  pathway.Manager
	LocationManager *location.Manager
	MessageConfig   *config.HL7Config
	// contains filtered or unexported fields
}

Hospital represents a hospital that can be used for testing. Some of the fields this hospital is created with are exposed so that they can be accessed in the tests.

func New

func New(ctx context.Context, t *testing.T, cfg Config) *Hospital

New creates a new Hospital for test.

func WithTime

func WithTime(ctx context.Context, t *testing.T, cfg Config, now time.Time) *Hospital

WithTime creates a new Hospital for test initialised with the given time.

func (*Hospital) ConsumeQueues

func (h *Hospital) ConsumeQueues(ctx context.Context, t *testing.T) (events int, messages []string)

ConsumeQueues consumes all events and messages and returns the number of events that were run and the messages that were sent. ConsumeQueues fails if processing a message or an event fails. See ConsumeQueuesWithLimit for the order in which events and messages are processed.

func (*Hospital) ConsumeQueuesWithLimit

func (h *Hospital) ConsumeQueuesWithLimit(ctx context.Context, t *testing.T, limit int, failIfError bool) (events int, messages []string)

ConsumeQueuesWithLimit consumes limit events and their corresponding messages, and returns the number of events that were run and the messages that were sent. Parameters:

  • limit is the maximum number of events to run. All messages relevant to those events will be sent. If there are less than limit events in the queue, this method consumes the events in the queue and returns. Set <1 for no limit.
  • 'failIfError' specifies whether errors running events or sending messages should make the method fail.

The order in which events and messages are processed is the following:

  1. Run all events that are due at the current time.
  2. Send all messages that are due at the current time.
  3. If there were no events due, advance the clock, and process any messages for that time so that we give priority to the existing messages before running new events.
  4. If there are still events in the queue, go back to step 1.
  5. After all events are consumed, process all of the remaining messages advancing the clock if needed.

Jump to

Keyboard shortcuts

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