state

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

Documentation

Overview

Package state contains definitions of stateful objects in Simulated Hospital.

Index

Constants

View Source
const (
	// EventItemType used for Event items.
	EventItemType = "event"

	// MessageItemType used for Message items.
	MessageItemType = "message"

	// PatientItemType used for Patient items.
	PatientItemType = "patient"
)

Variables

View Source
var ErrSyncerNotSet = errors.New("ItemSyncer not set; cannot load from the syncer")

ErrSyncerNotSet is returned if no ItemSyncer is set, but the load operation was called.

Functions

This section is empty.

Types

type Event

type Event struct {
	EventTime      time.Time
	MessageTime    time.Time
	PathwayName    string
	PatientMRN     string
	Step           pathway.Step
	History        []pathway.Step
	Pathway        []pathway.Step
	PathwayStarted time.Time
	IsHistorical   bool
	Index          int
	// PatientIDs is a map from PatientID to MRN; only set if the pathway this event belongs to had a Persons section.
	PatientIDs map[pathway.PatientID]string
}

Event is a stateful object representing Simulated Hospital events currently in progress.

func (Event) Compare

func (e Event) Compare(other queue.Item) int

Compare compares the current event with the given one. This method is part of the queue.Item interface and allows the events to be added to the priority queue. The items on the priority queue need to be sorted by their eventTime date. If two items have exactly the same eventTime date, they will be ordered by insertion time, ie: the item inserted earlier will be first.

func (Event) End

func (e Event) End() time.Time

func (Event) ID

func (e Event) ID() (string, error)

ID returns this event's identifier.

func (Event) Marshal

func (e Event) Marshal() ([]byte, error)

Marshal marshals the event for persistence.

func (Event) ResolveMRN

func (e Event) ResolveMRN(patientID pathway.PatientID) string

ResolveMRN transforms the given PatientID into an MRN. If the given PatientID is not in this event's patient map, it is assumed that it is an MRN already.

func (Event) Start

func (e Event) Start() time.Time

func (Event) String

func (e Event) String() string

type EventUnmarshaller

type EventUnmarshaller struct{}

EventUnmarshaller can be used to unmarshal events.

func (EventUnmarshaller) Unmarshal

func (u EventUnmarshaller) Unmarshal(b []byte) (persist.MarshallableItem, error)

Unmarshal unmarshals events.

type HL7Message

type HL7Message struct {
	// Name is the message's title for logging purposes.
	Name         string
	Message      *message.HL7Message
	MessageTime  time.Time
	PathwayName  string
	IsHistorical bool
	Event        *Event
}

HL7Message is a stateful object representing HL7 messages being generated by Simulated Hospital.

func (HL7Message) Compare

func (m HL7Message) Compare(other queue.Item) int

Compare compares the current HL7Message with the given Item. This method is part of the queue.Item interface and allows the events to be added to the priority queue. The items on the priority queue get sorted by their messageTime date. If two items have exactly the same messageTime date, they will be ordered by insertion time.

func (HL7Message) End

func (m HL7Message) End() time.Time

func (HL7Message) ID

func (m HL7Message) ID() (string, error)

ID returns this message's ID.

func (HL7Message) Marshal

func (m HL7Message) Marshal() ([]byte, error)

Marshal marshals the HL7Message.

func (HL7Message) Start

func (m HL7Message) Start() time.Time

func (HL7Message) String

func (m HL7Message) String() string

type MarshallableQueueItem

type MarshallableQueueItem interface {
	persist.MarshallableItem
	Compare(queue.Item) int
}

MarshallableQueueItem is the interface for items that can be stored in a MarshallableQueue.

type MessageUnmarshaller

type MessageUnmarshaller struct{}

MessageUnmarshaller can be used to unmarshal persisted HL7 messages.

func (MessageUnmarshaller) Unmarshal

Unmarshal unmarshals the given HL7 message.

type Patient

type Patient struct {
	PatientInfo *ir.PatientInfo
	// Orders maps from orderIDs to Orders. This is used to provide an index to all of a Patient's
	// orders so they can be looked up later on. In particular, this is used to link Results events
	// to their corresponding Order events.
	Orders     map[string]*ir.Order
	PastVisits []uint64
	Documents  map[string]*ir.Document
}

Patient represents a patient in Simulated Hospital.

func (*Patient) AddDocument

func (p *Patient) AddDocument(pathwayDocumentID string, document *ir.Document)

AddDocument adds a document to the map against the specified pathway Document ID, so that it can be looked up and updated. If the pathwayDocumentID is not specified, a unique ID is generated.

func (*Patient) AddOrder

func (p *Patient) AddOrder(orderID string, order *ir.Order)

AddOrder adds an order to the map against the specified order ID if it does not exist, and adds it to the current Encounter. If the orderID is not specified (ie is an empty string), a unique ID is generated.

func (Patient) End

func (p Patient) End() time.Time

func (*Patient) GetDocument

func (p *Patient) GetDocument(pathwayDocumentID string) *ir.Document

GetDocument retrieves an order by the pathway Document ID.

func (*Patient) GetOrder

func (p *Patient) GetOrder(orderID string) *ir.Order

GetOrder retrieves an order by its identifier.

func (Patient) ID

func (p Patient) ID() (string, error)

ID returns the patient's ID.

func (Patient) Marshal

func (p Patient) Marshal() ([]byte, error)

Marshal marshals a Patient into JSON.

func (*Patient) PopPastVisit

func (p *Patient) PopPastVisit() (uint64, error)

PopPastVisit gets and deletes the most recent past visit. PopPastVisit returns an error if there are no past visits.

func (*Patient) PushPastVisit

func (p *Patient) PushPastVisit(visit uint64)

PushPastVisit appends a visit number to the patients PastVisits slice.

func (Patient) Start

func (p Patient) Start() time.Time

type PatientUnmarshaller

type PatientUnmarshaller struct{}

PatientUnmarshaller is an unmarshaller of patients.

func (*PatientUnmarshaller) Unmarshal

func (u *PatientUnmarshaller) Unmarshal(b []byte) (persist.MarshallableItem, error)

Unmarshal unmarshals JSON input into a Patient.

type PatientsMap

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

PatientsMap contains the map of patients, indexed by their ID.

func NewPatientsMap

func NewPatientsMap(syncer persist.ItemSyncer, deleteFromMap bool) *PatientsMap

NewPatientsMap returns a map-based store for tracking patients inside Simulated Hospital. NewPatientsMap takes an optional ItemSyncer which can be used to persist items into other storage (e.g., a database) so that if the execution stops for any reason, the items can be loaded from such storage. If the syncer is set, all operations (Put, Get, Delete, etc.) performed on PatientsMap are performed on the syncer too. Pass in a nil ItemSyncer if you only wish to use the in-memory map for storing state. deleteFromMap indicates whether patients are deleted from the internal map to save memory.

func (*PatientsMap) Delete

func (m *PatientsMap) Delete(id string)

Delete deletes a patient from the internal patients map and the syncer, by its identifier.

func (*PatientsMap) Get

func (m *PatientsMap) Get(id string) *Patient

Get returns a patient if its identifier is present within the internal patients map or the syncer, in this order.

func (*PatientsMap) GetAll

func (m *PatientsMap) GetAll() []*Patient

Get returns a patient if its identifier is present within the internal patients map or the syncer, in this order.

func (*PatientsMap) Len

func (m *PatientsMap) Len() int

Len returns the length of the patients map.

func (*PatientsMap) Put

func (m *PatientsMap) Put(p *Patient)

Put adds a patient to the internal patients map and the syncer.

type WrappedQueue

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

WrappedQueue is a queue that contains both a PriorityQueue and an internal struct with objects that are marshallable (for persisting).

func NewWrappedQueue

func NewWrappedQueue(itemType string, syncer persist.ItemSyncer) (*WrappedQueue, error)

NewWrappedQueue returns a priority-queue based store for tracking the state of various objects inside Simulated Hospital. It accepts an itemType specifying what type of stateful object will be stored in the queue and an ItemSyncer for persisting state. Pass in a nil ItemSyncer if you only wish to use the in-memory priority queue for storing state. If ItemSyncer is specified, it also loads all items from the syncer. If loading all items from syncer fails, it returns an error, but also returns a valid WrappedQueue. The user can decide whether loading the items on the initialization is critical for their use case.

func (*WrappedQueue) Empty

func (q *WrappedQueue) Empty() bool

Empty returns whether the queue is empty.

func (*WrappedQueue) Get

Get retrieves the next item from the queue, removing it from all internal data structures and the syncer.

func (*WrappedQueue) IsConsistent

func (q *WrappedQueue) IsConsistent() bool

IsConsistent returns whether the queue and mapping of MarshallableQueueItems have ever fallen out of sync.

func (*WrappedQueue) Len

func (q *WrappedQueue) Len() int

Len returns the number of items in the queue.

func (*WrappedQueue) LoadFromSyncer

func (q *WrappedQueue) LoadFromSyncer() error

LoadFromSyncer loads all items from the syncer into the queue.

func (*WrappedQueue) Peek

func (q *WrappedQueue) Peek() queue.Item

Peek returns the next item in the queue without removing it from the queue.

func (*WrappedQueue) Put

func (q *WrappedQueue) Put(items ...MarshallableQueueItem) error

Put inserts all arguments into the queue.

Directories

Path Synopsis
Package persist contains persist-specific interfaces.
Package persist contains persist-specific interfaces.

Jump to

Keyboard shortcuts

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