/// <summary>
 /// Create a device entity
 /// </summary>
 public AmiCollection GetDeviceEntities(Expression <Func <DeviceEntity, bool> > expression)
 {
     return(this.Client.Get <AmiCollection>("DeviceEntity", QueryExpressionBuilder.BuildQuery(expression).ToArray()));
 }
 /// <summary>
 /// Retrieves a specified user.
 /// </summary>
 /// <param name="query">The query expression to use to find the user.</param>
 /// <returns>Returns a collection of users which match the specified query parameters.</returns>
 public AmiCollection GetUsers(Expression <Func <SecurityUser, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("SecurityUser", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
 /// <summary>
 /// Retrieves an audit
 /// </summary>
 /// <param name="expression">The query to filter audits on</param>
 public AuditData GetAudits(Expression <Func <AuditData, bool> > expression)
 {
     return(this.Client.Get <AuditData>($"Audit", QueryExpressionBuilder.BuildQuery(expression).ToArray()));
 }
 /// <summary>
 /// Gets the code systems.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns>Returns a list of code systems.</returns>
 public AmiCollection GetCodeSystems(Expression <Func <CodeSystem, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("CodeSystem", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
 /// <summary>
 /// Gets the extension types.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <returns>Returns a list of extension types.</returns>
 public AmiCollection GetExtensionTypes(Expression <Func <ExtensionType, bool> > expression)
 {
     return(this.Client.Get <AmiCollection>("ExtensionType", QueryExpressionBuilder.BuildQuery(expression).ToArray()));
 }
Example #6
0
        /// <summary>
        /// Create a query
        /// </summary>
        public SqlStatement CreateQuery <TModel>(Expression <Func <TModel, bool> > predicate)
        {
            var nvc = QueryExpressionBuilder.BuildQuery(predicate, true);

            return(CreateQuery <TModel>(nvc));
        }
Example #7
0
 /// <summary>
 /// Gets a list of alerts.
 /// </summary>
 /// <param name="query">The query expression to use to find the alerts.</param>
 /// <returns>Returns a collection of alerts which match the specified criteria.</returns>
 public AmiCollection <AlertMessageInfo> GetAlerts(Expression <Func <AlertMessage, bool> > query)
 {
     return(this.Client.Get <AmiCollection <AlertMessageInfo> >("alert", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
 /// <summary>
 /// Retrieves the specified role from the AMI
 /// </summary>
 public AmiCollection FindRole(Expression <Func <SecurityRole, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("SecurityRole", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
 /// <summary>
 /// Gets a list of alerts.
 /// </summary>
 /// <param name="query">The query expression to use to find the alerts.</param>
 /// <returns>Returns a collection of alerts which match the specified criteria.</returns>
 public AmiCollection GetMailMessages(Expression <Func <MailMessage, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("MailMessage", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
Example #10
0
        /// <summary>
        /// Find the specified audits with the specified query
        /// </summary>
        public IEnumerable <AuditData> Find(Expression <Func <AuditData, bool> > query, int offset, int?count, out int totalResults, params ModelSort <AuditData>[] orderBy)
        {
            // Convert query to easier format and map common parameters
            var inQuery  = QueryExpressionBuilder.BuildQuery(query);
            var outQuery = new NameValueCollection();

            var termService = ApplicationServiceContext.Current.GetService <IAuditTermLookupService>();

            // Map query
            foreach (var kv in inQuery)
            {
                object valueList = kv.Value;
                if (!(valueList is IList))
                {
                    valueList = new List <Object>()
                    {
                        valueList
                    }
                }
                ;

                // Iterate and add values
                foreach (var val in (valueList as IList).OfType <String>())
                {
                    switch (kv.Key)
                    {
                    case "action":
                    {
                        var code = new CodeValue <AtnaApi.Model.ActionType>(
                            (AtnaApi.Model.ActionType)Enum.Parse(typeof(AtnaApi.Model.ActionType), val)
                            );
                        outQuery.Add("action", termService.GetKey(code.Code, code.CodeSystem, "ActionType").ToString());
                    }
                    break;

                    case "correlationId":
                        outQuery.Add("correlationToken", val);
                        break;

                    case "event":
                    {
                        var code = new CodeValue <AtnaApi.Model.EventIdentifierType>(
                            (AtnaApi.Model.EventIdentifierType)Enum.Parse(typeof(AtnaApi.Model.EventIdentifierType), val)
                            );
                        outQuery.Add("eventId", termService.GetKey(code.Code, code.CodeSystem, "EventIdentifierType").ToString());
                        break;
                    }

                    case "type.code":
                        outQuery.Add("eventType.mnemonic", val);
                        break;

                    case "type.codeSystem":
                        outQuery.Add("eventType.domain", val);
                        break;

                    case "outcome":
                    {
                        var code = new CodeValue <AtnaApi.Model.OutcomeIndicator>(
                            (AtnaApi.Model.OutcomeIndicator)Enum.Parse(typeof(AtnaApi.Model.OutcomeIndicator), val)
                            );
                        outQuery.Add("outcome", termService.GetKey(code.Code, code.CodeSystem, "OutcomeIndicator").ToString());
                        break;
                    }

                    case "timestamp":
                        outQuery.Add("eventTime", val);
                        break;

                    default:
                        throw new InvalidOperationException($"Cannot map {kv.Key} as this property is unkown in SanteGuard");
                    }
                }
            }

            var newQuery = QueryExpressionParser.BuildLinqExpression <Audit>(outQuery);

            return(ApplicationServiceContext.Current.GetService <IRepositoryService <Audit> >().Find(newQuery, offset, count, out totalResults)
                   .Select(o => o.ToAuditData()));
        }
Example #11
0
        /// <summary>
        /// Subscription is executing
        /// </summary>
        private void AdtPatientPassthroughInterceptor_Executing(object sender, QueryRequestEventArgs <IdentifiedData> e)
        {
            e.Cancel = true;

            // Now we want to load the subscription
            var subscriptionDefinitionQuery = QueryExpressionParser.BuildLinqExpression <SubscriptionDefinition>(new NameValueCollection(QueryExpressionBuilder.BuildQuery(e.Query).ToArray()));
            var subscriptionDefinition      = ApplicationServiceContext.Current.GetService <IRepositoryService <SubscriptionDefinition> >().Find(subscriptionDefinitionQuery, 0, 1, out int tr, null).FirstOrDefault();
            // Get the HL7 definition
            var hl7Def = subscriptionDefinition.ServerDefinitions.FirstOrDefault(o => o.InvariantName == "hl7");

            if (hl7Def == null)
            {
                throw new InvalidOperationException("Subscription does not contian a definition for 'hl7' query");
            }

            // Get the parameters from the rest operation context
            NameValueCollection filter = e.QueryTag, subscription = NameValueCollection.ParseQueryString(hl7Def.Definition), queryFilter = new NameValueCollection();

            foreach (var itm in subscription)
            {
                queryFilter.Add(itm.Key, itm.Value.Select(o =>
                {
                    if (o.StartsWith("$") && o.EndsWith("$"))
                    {
                        return(filter["_" + o.Substring(1, o.Length - 2)][0]);
                    }
                    else
                    {
                        return(o);
                    }
                }).ToList());
            }

            // Original has modified on?
            if (filter.ContainsKey("modifiedOn"))
            {
                queryFilter.Add("modifiedOn", filter["modifiedOn"]);
            }
            e.Results      = this.SendQuery(queryFilter, e.Count ?? 25, out tr);
            e.TotalResults = tr;
        }
Example #12
0
 /// <summary>
 /// Retrieves a specified role.
 /// </summary>
 /// <param name="query">The query expression to use to find the role.</param>
 /// <returns>Returns a collection of roles which match the specified query parameters.</returns>
 public AmiCollection <SecurityRoleInfo> GetRoles(Expression <Func <SecurityRole, bool> > query)
 {
     return(this.Client.Get <AmiCollection <SecurityRoleInfo> >("role", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
Example #13
0
 /// <summary>
 /// Retrieves a specified policy.
 /// </summary>
 /// <param name="query">The query expression to use to find the policy.</param>
 /// <returns>Returns a collection of policies which match the specified query parameters.</returns>
 public AmiCollection <SecurityPolicyInfo> GetPolicies(Expression <Func <SecurityPolicy, bool> > query)
 {
     return(this.Client.Get <AmiCollection <SecurityPolicyInfo> >("policy", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
Example #14
0
 /// <summary>
 /// Gets a list applications for a specific query.
 /// </summary>
 /// <returns>Returns a list of application which match the specific query.</returns>
 public AmiCollection <SecurityApplicationInfo> GetApplications(Expression <Func <SecurityApplicationInfo, bool> > query)
 {
     return(this.Client.Get <AmiCollection <SecurityApplicationInfo> >("application", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
        /// <summary>
        /// Register subscription
        /// </summary>
        public PubSubSubscriptionDefinition RegisterSubscription <TModel>(string name, string description, PubSubEventType events, Expression <Func <TModel, bool> > filter, Guid channelId, string supportAddress = null, DateTimeOffset?notBefore = null, DateTimeOffset?notAfter = null)
        {
            var filterHdsi = QueryExpressionBuilder.BuildQuery(filter);

            return(this.RegisterSubscription(typeof(TModel), name, description, events, new NameValueCollection(filterHdsi.ToArray()).ToString(), channelId, supportAddress, notBefore, notAfter));
        }
 /// <summary>
 /// Gets a list of assigning authorities.
 /// </summary>
 /// <param name="query">The query expression to use to find the assigning authorities.</param>
 /// <returns>Returns a collection of assigning authorities which match the specified criteria.</returns>
 public AmiCollection GetAssigningAuthorities(Expression <Func <AssigningAuthority, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("AssigningAuthority", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
        /// <summary>
        /// Query function returning results and count control
        /// </summary>
        private IEnumerable <TData> Query(System.Linq.Expressions.Expression <Func <TData, bool> > query, int offset, int?count, out int totalResults, Guid queryId, bool countResults, bool fastQuery, IEnumerable <String> expandProperties = null)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            DataQueryPreEventArgs <TData> preArgs = new DataQueryPreEventArgs <TData>(query, offset, count);

            this.Querying?.Invoke(this, preArgs);
            if (preArgs.Cancel)
            {
                this.m_tracer.TraceWarning("Pre-Event handler indicates abort query {0}", query);
                totalResults = preArgs.TotalResults;
                return(preArgs.Results);
            }

#if PERFMON
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            // Query object
            using (var context = this.CreateReadonlyConnection())
                try
                {
                    IEnumerable <TData> results = null;
                    using (context.LockConnection())
                    {
                        this.m_tracer.TraceVerbose("QUERY {0}", query);

                        if (fastQuery)
                        {
                            context.DelayLoadMode = LoadState.PartialLoad;
                        }
                        else
                        {
                            context.DelayLoadMode = LoadState.FullLoad;
                        }

                        if (expandProperties != null)
                        {
                            context.LoadAssociations = expandProperties.ToArray();
                        }

                        results = this.Query(context, query, offset, count ?? -1, out totalResults, queryId, countResults);
                    }

                    var postData = new DataQueryResultEventArgs <TData>(query, results, offset, count, totalResults);
                    this.Queried?.Invoke(this, postData);

                    totalResults = postData.TotalResults;

                    // Remove from the cache
                    foreach (var itm in context.CacheOnCommit.AsParallel())
                    {
                        ApplicationContext.Current.GetService <IDataCachingService>()?.Add(itm);
                    }

                    return(postData.Results);
                }
                catch (NotSupportedException e)
                {
                    this.m_tracer.TraceVerbose("Cannot perform LINQ query, switching to stored query sqp_{0}", typeof(TData).Name, e);

                    // Build dictionary
                    var httpValues = QueryExpressionBuilder.BuildQuery <TData>(query, true);
                    var filter     = new Dictionary <String, Object>();

                    foreach (var f in httpValues)
                    {
                        object existing = null;
                        if (filter.TryGetValue(f.Key, out existing))
                        {
                            if (!(existing is IList))
                            {
                                existing = new List <Object>()
                                {
                                    existing
                                };
                                filter[f.Key] = existing;
                            }
                            (existing as IList).Add(f.Value);
                        }
                        else
                        {
                            filter.Add(f.Key, f.Value);
                        }
                    }
                    // Query
                    return(this.Query(String.Format("sqp_{0}", typeof(TData).Name), filter, offset, count, out totalResults, queryId));
                }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error : {0}", e);
                throw;
            }
#if PERFMON
            finally
            {
                sw.Stop();
                ApplicationContext.Current.PerformanceLog(typeof(TData).Name, nameof(Query), query.ToString(), sw.Elapsed);
            }
#endif
        }
 /// <summary>
 /// Gets a list of certificate signing requests.
 /// </summary>
 /// <param name="query">The query expression to use to find the certificate signing requests.</param>
 /// <returns>Returns a collection of certificate signing requests which match the specified query.</returns>
 public AmiCollection GetCertificateSigningRequests(Expression <Func <SubmissionInfo, bool> > query)
 {
     return(this.Client.Get <AmiCollection>("Csr", QueryExpressionBuilder.BuildQuery(query).ToArray()));
 }
Example #19
0
        /// <summary>
        /// Create a query
        /// </summary>
        public SqlStatement CreateQuery <TModel>(Expression <Func <TModel, bool> > predicate, params ColumnMapping[] selector)
        {
            var nvc = QueryExpressionBuilder.BuildQuery(predicate, true);

            return(CreateQuery <TModel>(nvc, selector));
        }
 /// <summary>
 /// Query the server endpoint for BIS metadata
 /// </summary>
 public IEnumerable <TBisDefinition> Query <TBisDefinition>(Expression <Func <TBisDefinition, bool> > filter, int offset, int?count) where TBisDefinition : BiDefinition
 {
     try
     {
         var rootAtt = typeof(TBisDefinition).GetTypeInfo().GetCustomAttribute <XmlRootAttribute>();
         using (var client = this.GetRestClient())
             return(client.Get <BiDefinitionCollection>($"{rootAtt.ElementName}", QueryExpressionBuilder.BuildQuery(filter).ToArray())?.Items.OfType <TBisDefinition>().ToList());
     }
     catch (Exception e)
     {
         this.m_tracer.TraceError("Error querying BIS definition with query {0}: {1}", filter, e);
         throw new Exception($"Error executing BIS query {filter}", e);
     }
 }