internal void AuditPatientAccess(object entity, AbstractEvent @event, string patientAccessEventType, Func<string> getAuditNote)
        {
            var patientAccessAuditable = entity as IPatientAccessAuditable;

            var aggregateNode = entity as IAggregateNode;
            var aggregateRoot = entity as IAggregateRoot;

            if (aggregateNode != null)
            {
                aggregateRoot = aggregateNode.AggregateRoot;
                patientAccessAuditable = aggregateRoot as IPatientAccessAuditable;
            }

            if (patientAccessAuditable == null)
            {
                return;
            }

            string noteResult = getAuditNote();

            if ( string.IsNullOrWhiteSpace ( noteResult ) )
            {
                return;
            }

            Patient patient = patientAccessAuditable.AuditedPatient;

            ISession session = @event.Session.GetSession(EntityMode.Poco);

            PatientAccessEventType eventType = PatientAccessEventTypeHelper.GetPatientAccessEventTypeByWellKnownName(
                session, patientAccessEventType);

            var eventAccessEntry = new PatientAccessEvent(patient, eventType, patientAccessAuditable.AuditedContextDescription, noteResult)
                {
                    AggregateRootTypeName = aggregateRoot.GetType().FullName,
                    AggregateRootKey = aggregateRoot.Key,
                    AggregateNodeTypeName = aggregateNode == null ? null : aggregateNode.GetType().FullName
                };

            if (aggregateNode != null)
            {
                if ((aggregateNode as IEntity) != null)
                {
                    eventAccessEntry.AggregateNodeKey = (aggregateNode as IEntity).Key;
                }
            }

            session.Save(eventAccessEntry);

            session.Flush();
        }
 /// <summary>
 /// Does the work, after checking that the entity type is indeed indexed.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="id"></param>
 /// <param name="workType"></param>
 /// <param name="e"></param>
 protected void ProcessWork(Object entity, object id, WorkType workType, AbstractEvent e)
 {
     if (EntityIsIndexed(entity))
     {
         Work work = new Work(entity, id, workType);
         searchFactory.Worker.PerformWork(work, e.Session);
     }
 }