Skip to content

Commit

Permalink
improving code for patient caller and bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
daviian committed May 17, 2019
1 parent 54943d7 commit a094d8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
10 changes: 5 additions & 5 deletions cmd/pagient-server/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,29 @@ func Web() *cli.Command {

{
// Setup Bridge Database Connection
bDB, err := bridgeDB.Open()
db, err := bridgeDB.Open()
if err != nil {
log.Fatal().
Err(err).
Msg("bridge database initialization failed")

return err
}
defer bDB.Close()
defer db.Close()

// Setup Software Bridge
softwareBridge := bridge.NewBridge(bDB)
b := bridge.NewBridge(db)

// Setup Caller
pagerCaller := caller.NewCaller(s, softwareBridge)
c := caller.NewCaller(s, b)
stop := make(chan struct{}, 1)

gr.Add(func() error {
log.Info().
Msg("starting caller")

every := time.Duration(config.Bridge.PollingInterval) * time.Second
return pagerCaller.Run(every, stop)
return c.Run(every, stop)
}, func(reason error) {
close(stop)

Expand Down
13 changes: 4 additions & 9 deletions internal/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func NewBridge(db DB) *DefaultBridge {

// GetToBeExaminedPatients returns all patients that are queued to be examined next
func (b *DefaultBridge) GetToBeExaminedPatients() ([]*model.Patient, error) {
assignments, err := b.getRoomAssignments()
assignments, err := b.db.GetRoomAssignments(config.Bridge.CallActionWZ, config.Bridge.CallActionQueuePosition)
if err != nil {
return nil, errors.WithStack(err)
return nil, errors.Wrap(err, "get patients by room assignment failed")
}

patients := mapAssignmentsToPatients(assignments)
Expand All @@ -40,9 +40,9 @@ func (b *DefaultBridge) GetToBeExaminedPatients() ([]*model.Patient, error) {

// GetExaminedPatients returns all patients that have been examined and are finished now since last call
func (b *DefaultBridge) GetExaminedPatients() ([]*model.Patient, error) {
assignments, err := b.getRoomAssignments()
assignments, err := b.db.GetRoomAssignments(config.Bridge.CallActionWZ, config.Bridge.CallActionQueuePosition)
if err != nil {
return nil, errors.WithStack(err)
return nil, errors.Wrap(err, "get patients by room assignment failed")
}

removedAssignments := subtractSet(b.lastAssignments, assignments)
Expand All @@ -56,11 +56,6 @@ func (b *DefaultBridge) GetExaminedPatients() ([]*model.Patient, error) {
return patients, nil
}

func (b *DefaultBridge) getRoomAssignments() ([]*bridgeModel.RoomAssignment, error) {
assignments, err := b.db.GetRoomAssignments(config.Bridge.CallActionWZ, config.Bridge.CallActionQueuePosition)
return assignments, errors.Wrap(err, "get patients by room assignment failed")
}

func subtractSet(assignmentsA, assignmentsB []*bridgeModel.RoomAssignment) []*bridgeModel.RoomAssignment {
sortAssignmentsByPID(assignmentsB)

Expand Down

0 comments on commit a094d8e

Please sign in to comment.