runner

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: 17 Imported by: 0

Documentation

Overview

Package runner 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 APIConfig

type APIConfig struct {
	APIPort string
	APIKey  string
}

APIConfig contains base configuration for authenticated endpoints.

type APIEndpointAndHandler

type APIEndpointAndHandler struct {
	EndpointAndHandler
	HTTPMethod string
}

APIEndpointAndHandler defines a Simulated Hospital API endpoint and its handler.

type Config

type Config struct {
	// AdditionalDashboardEndpoints is a slice of endpoints and their handlers.
	// The root path for these endpoints will be the Simulated Hospital dashboard address.
	AdditionalDashboardEndpoints []EndpointAndHandler
	// AuthenticatedAPIConfig is the API config for authenticated endpoints.
	AuthenticatedAPIConfig APIConfig
	// AuthenticatedEndpoints is a slice of API endpoints and their handlers.
	// The root path for these endpoints will be the API root path.
	AuthenticatedEndpoints []APIEndpointAndHandler
	// PathwayStarter is a starter of pathways through an endpoint.
	PathwayStarter *starter.PathwayStarter
	// PathwaysPerHour indicates how often new pathways are generated.
	PathwaysPerHour float64
	// MaxPathways is the number of pathways to run before stopping.
	// If negative, Simulated Hospital will keep running pathways indefinitely.
	MaxPathways int
	// DashboardURI is the base URI path at which the simulated hospital dashboard and
	// endpoints are available, e.g., /simulated-hospital/. Note that this needs to match
	// the data-path on elements in index.html.
	DashboardURI string
	// DashboardAddress is the port on which the simulated hospital is accessible.
	// The value is expected to be in the form :int, e.g. :8000.
	DashboardAddress string
	// DashboardStaticDir is the directory for static assets for the dashboard.
	DashboardStaticDir string
	// MetricsAddress is the address for the /metrics endpoint.
	MetricsAddress string
	// SleepFor represents the interval at which the queues are checked.
	SleepFor time.Duration
	// Clock is the clock for the hospital.
	Clock clock.Clock
}

Config contains optional configuration options for Simulated Hospital Runner used to extend the main functionality.

type EndpointAndHandler

type EndpointAndHandler struct {
	Endpoint string
	Handler  func(http.ResponseWriter, *http.Request)
}

EndpointAndHandler defines a Simulated Hospital endpoint and its handler.

type Hospital

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

Hospital wraps the hospital.Hospital and implements the run functionality.

func New

func New(h *hospital.Hospital, config Config) (*Hospital, error)

New creates a new Runner.

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) ProcessMessages

func (h *Hospital) ProcessMessages(ctx context.Context) error

ProcessMessages processes (e.g. sends) the HL7 messages. Returns an error if the context is Done.

func (*Hospital) Run

func (h *Hospital) Run(ctx context.Context)

Run starts the Simulated Hospital. It starts multiple servers including the Simulated Hospital dashboard. The following happens in parallel and continuously while Simulated Hospital is running:

  1. Start pathways, which create events (e.g., patients are admitted in the hospital, test results, etc.).
  2. Run those events at the appropriate time, which generates HL7 messages.
  3. Process HL7 messages at the appropriate time.

The processing of pathways, events and messages can finish if Hospital.maxPathways is negative, otherwise Run() runs forever. When the creation of pathways finishes, we can stop processing events after all our current events are processed. When processing events finishes, we can stop processing messages after all our current messages are processed. If this happens, all servers are stopped and this method returns.

func (*Hospital) RunEvents

func (h *Hospital) RunEvents(ctx context.Context) error

RunEvents runs the events as they are due. Returns an error if the context is Done.

Directories

Path Synopsis
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