func (dal *mongoDataAccessLayer) invokeInterceptorsOnError(op, resourceType string, err error, resource interface{}) {
	for _, interceptor := range dal.Interceptors[op] {
		if interceptor.ResourceType == resourceType || interceptor.ResourceType == "*" {
			interceptor.Handler.OnError(err, resource)
		}
	}
}
invokeInterceptorsOnError invokes the interceptor list for the given resource type after a database
operation occurs and fails.
package server
import (
	"errors"
	"fmt"
	"net/url"
	"reflect"
	"strconv"
	"time"
	"github.com/intervention-engine/fhir/models"
	"github.com/intervention-engine/fhir/search"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)
type MasterSession struct {
	session *mgo.Session
	dbname  string
}
type WorkerSession struct {
	session *mgo.Session
	dbname  string
}
func NewMasterSession(session *mgo.Session, dbname string) (master *MasterSession) {
	return &MasterSession{
		session: session,
		dbname:  dbname,
	}
}
func (ms *MasterSession) GetWorkerSession() (worker *WorkerSession) {
	if ms.session == nil {
		return nil
	}
	return &WorkerSession{
		session: ms.session.Copy(),
		dbname:  ms.dbname,
	}
}
func (ws *WorkerSession) SetTimeout(d time.Duration) {
	if ws.session != nil {
		ws.session.SetSocketTimeout(d)
	}
}
func (ws *WorkerSession) DB() (db *mgo.Database) {
	if ws.session != nil && ws.dbname != "" {
		db = ws.session.DB(ws.dbname)
	}
	return
}
func (ws *WorkerSession) Close() {
	if ws.session != nil {
		ws.session.Close()
	}
}
func NewMongoDataAccessLayer(ms *MasterSession, interceptors map[string]InterceptorList) DataAccessLayer {
	return &mongoDataAccessLayer{
		MasterSession: ms,
		Interceptors:  interceptors,
	}
}
type mongoDataAccessLayer struct {
	MasterSession *MasterSession
	Interceptors  map[string]InterceptorList
}
type InterceptorList []Interceptor
type Interceptor struct {
	ResourceType string
	Handler      InterceptorHandler
}
type InterceptorHandler interface {
	Before(resource interface{})
	After(resource interface{})
	OnError(err error, resource interface{})
}
func (dal *mongoDataAccessLayer) invokeInterceptorsBefore(op, resourceType string, resource interface{}) {
	for _, interceptor := range dal.Interceptors[op] {
		if interceptor.ResourceType == resourceType || interceptor.ResourceType == "*" {
			interceptor.Handler.Before(resource)
		}
	}
}
func (dal *mongoDataAccessLayer) invokeInterceptorsAfter(op, resourceType string, resource interface{}) {
	for _, interceptor := range dal.Interceptors[op] {
		if interceptor.ResourceType == resourceType || interceptor.ResourceType == "*" {
			interceptor.Handler.After(resource)
		}
	}
}