Documentation ¶
Overview ¶
Package state contains definitions of stateful objects in Simulated Hospital.
Index ¶
- Constants
- Variables
- type Event
- type EventUnmarshaller
- type HL7Message
- type MarshallableQueueItem
- type MessageUnmarshaller
- type Patient
- func (p *Patient) AddDocument(pathwayDocumentID string, document *ir.Document)
- func (p *Patient) AddOrder(orderID string, order *ir.Order)
- func (p *Patient) GetDocument(pathwayDocumentID string) *ir.Document
- func (p *Patient) GetOrder(orderID string) *ir.Order
- func (p Patient) ID() (string, error)
- func (p Patient) Marshal() ([]byte, error)
- func (p *Patient) PopPastVisit() (uint64, error)
- func (p *Patient) PushPastVisit(visit uint64)
- type PatientUnmarshaller
- type PatientsMap
- type WrappedQueue
- func (q *WrappedQueue) Empty() bool
- func (q *WrappedQueue) Get() (*MarshallableQueueItem, error)
- func (q *WrappedQueue) IsConsistent() bool
- func (q *WrappedQueue) Len() int
- func (q *WrappedQueue) LoadFromSyncer() error
- func (q *WrappedQueue) Peek() queue.Item
- func (q *WrappedQueue) Put(items ...MarshallableQueueItem) error
Constants ¶
const ( // EventItemType used for Event items. EventItemType = "event" // MessageItemType used for Message items. MessageItemType = "message" // PatientItemType used for Patient items. PatientItemType = "patient" )
Variables ¶
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 ¶
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) ResolveMRN ¶
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.
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) Marshal ¶
func (m HL7Message) Marshal() ([]byte, error)
Marshal marshals the HL7Message.
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 ¶
func (u MessageUnmarshaller) Unmarshal(b []byte) (persist.MarshallableItem, error)
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 ¶
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 ¶
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) GetDocument ¶
GetDocument retrieves an order by the pathway Document ID.
func (*Patient) PopPastVisit ¶
PopPastVisit gets and deletes the most recent past visit. PopPastVisit returns an error if there are no past visits.
func (*Patient) PushPastVisit ¶
PushPastVisit appends a visit number to the patients PastVisits slice.
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) 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 ¶
func (q *WrappedQueue) Get() (*MarshallableQueueItem, error)
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.