Example #1
0
        public IdentifiedData GetConceptSet()
        {
            var conceptRepositoryService = ApplicationContext.Current.GetService <IConceptRepositoryService>();

            var search = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            if (search.ContainsKey("_id"))
            {
                // Force load from DB
                ApplicationContext.Current.GetService <IDataCachingService>().Remove(Guid.Parse(search["_id"].FirstOrDefault()));
                var concept = conceptRepositoryService.GetConceptSet(Guid.Parse(search["_id"].FirstOrDefault()));
                return(concept);
            }
            else
            {
                int totalResults = 0,
                    offset       = search.ContainsKey("_offset") ? Int32.Parse(search["_offset"][0]) : 0,
                    count        = search.ContainsKey("_count") ? Int32.Parse(search["_count"][0]) : 100;

                var results = conceptRepositoryService.FindConceptSets(QueryExpressionParser.BuildLinqExpression <ConceptSet>(search, null, false), offset, count, out totalResults);

                //
                return(new Bundle
                {
                    Count = results.Count(),
                    Item = results.OfType <IdentifiedData>().ToList(),
                    Offset = 0,
                    TotalResults = totalResults
                });
            }
        }
Example #2
0
        /// <summary>
        /// Perform the actual query
        /// </summary>
        public virtual IEnumerable <IdentifiedData> Query(NameValueCollection queryParameters, int offset, int count, out int totalCount)
        {
            var           queryExpression = QueryExpressionParser.BuildLinqExpression <TResource>(queryParameters, null, false);
            List <String> query           = null;

            if (queryParameters.TryGetValue("_queryId", out query) && this.m_repository is IPersistableQueryRepositoryService)
            {
                Guid          queryId = Guid.Parse(query[0]);
                List <String> lean    = null;
                if (queryParameters.TryGetValue("_lean", out lean) && lean[0] == "true" && this.m_repository is IFastQueryRepositoryService)
                {
                    return((this.m_repository as IFastQueryRepositoryService).FindFast <TResource>(queryExpression, offset, count, out totalCount, queryId));
                }
                else
                {
                    return((this.m_repository as IPersistableQueryRepositoryService).Find <TResource>(queryExpression, offset, count, out totalCount, queryId));
                }
            }
            else
            {
                List <String> lean = null;
                if (queryParameters.TryGetValue("_lean", out lean) && lean[0] == "true" && this.m_repository is IFastQueryRepositoryService)
                {
                    return((this.m_repository as IFastQueryRepositoryService).FindFast <TResource>(queryExpression, offset, count, out totalCount, Guid.Empty));
                }
                else
                {
                    return(this.m_repository.Find(queryExpression, offset, count, out totalCount));
                }
            }
        }
Example #3
0
        public AmiCollection <AuditInfo> GetAudits()
        {
            var auditRepository = ApplicationContext.Current.GetService <IAuditRepositoryService>();

            var search = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            if (search.ContainsKey("_id"))
            {
                // Force load from DB
                var retVal = auditRepository.Get(search["_id"][0]);
                return(new AmiCollection <AuditInfo>(new AuditInfo[] { new AuditInfo(retVal) }));
            }
            else
            {
                int totalResults = 0,
                    offset       = search.ContainsKey("_offset") ? Int32.Parse(search["_offset"][0]) : 0,
                    count        = search.ContainsKey("_count") ? Int32.Parse(search["_count"][0]) : 100;

                var results = auditRepository.Find(QueryExpressionParser.BuildLinqExpression <AuditData>(search), offset, count, out totalResults);
                return(new AmiCollection <AuditInfo>(results.Select(o => new AuditInfo(o)))
                {
                    Size = totalResults,
                    Offset = offset
                });
            }
        }
        /// <summary>
        /// Searches for alerts.
        /// </summary>
        /// <param name="predicate">The predicate to use to search for alerts.</param>
        /// <param name="offset">The offset of the search.</param>
        /// <param name="count">The count of the search results.</param>
        /// <param name="totalCount">The total count of the alerts.</param>
        /// <returns>Returns a list of alerts.</returns>
        public IEnumerable <MailMessage> Find(Expression <Func <MailMessage, bool> > predicate, int offset, int?count, out int totalCount, params ModelSort <MailMessage>[] orderBy)
        {
            var persistenceService = ApplicationServiceContext.Current.GetService <IDataPersistenceService <MailMessage> >();

            if (persistenceService == null)
            {
                this.traceSource.TraceError($"{nameof(IDataPersistenceService<MailMessage>)} not found");
                throw new InvalidOperationException(this.m_localizationService.FormatString("error.server.core.persistenceService", new
                {
                    param = nameof(IDataPersistenceService <MailMessage>)
                }));
            }

            // Non archived messages
            var qry = new NameValueCollection(QueryExpressionBuilder.BuildQuery(predicate).ToArray());

            if (!qry.ContainsKey("flags"))
            {
                qry.Add("flags", $"!{(int)MailMessageFlags.Archived}");
            }
            var retVal = persistenceService.Query(QueryExpressionParser.BuildLinqExpression <MailMessage>(qry), offset, count, out totalCount, AuthenticationContext.Current.Principal, orderBy);

            this.Queried?.Invoke(this, new RepositoryEventArgs <IEnumerable <MailMessage> >(retVal));
            return(retVal);
        }
Example #5
0
        /// <summary>
        /// Get specified service
        /// </summary>
        private IdentifiedData GetAct <TAct>() where TAct : IdentifiedData
        {
            var actRepositoryService = ApplicationContext.Current.GetService <IRepositoryService <TAct> >();
            var search = NameValueCollection.ParseQueryString(MiniHdsiServer.CurrentContext.Request.Url.Query);

            if (search.ContainsKey("_id"))
            {
                // Force load from DB
                ApplicationContext.Current.GetService <IDataCachingService>().Remove(Guid.Parse(search["_id"].FirstOrDefault()));
                var act = actRepositoryService.Get(Guid.Parse(search["_id"].FirstOrDefault()), Guid.Empty);
                return(act);
            }
            else
            {
                var queryId = search.ContainsKey("_state") ? Guid.Parse(search["_state"][0]) : Guid.NewGuid();

                int totalResults = 0,
                    offset       = search.ContainsKey("_offset") ? Int32.Parse(search["_offset"][0]) : 0,
                    count        = search.ContainsKey("_count") ? Int32.Parse(search["_count"][0]) : 100;

                IEnumerable <TAct> results = null;
                if (search.ContainsKey("_onlineOnly") && search["_onlineOnly"][0] == "true")
                {
                    var integrationService = ApplicationContext.Current.GetService <IClinicalIntegrationService>();
                    var bundle             = integrationService.Find <Act>(QueryExpressionParser.BuildLinqExpression <Act>(search, null, false), offset, count);
                    totalResults = bundle.TotalResults;
                    bundle.Reconstitute();
                    bundle.Item.OfType <Act>().ToList().ForEach(o => o.Tags.Add(new ActTag("onlineResult", "true")));
                    results = bundle.Item.OfType <TAct>();
                }
                else if (actRepositoryService is IPersistableQueryRepositoryService)
                {
                    if (actRepositoryService is IFastQueryRepositoryService)
                    {
                        results = (actRepositoryService as IFastQueryRepositoryService).Find <TAct>(QueryExpressionParser.BuildLinqExpression <TAct>(search, null, false), offset, count, out totalResults, queryId);
                    }
                    else
                    {
                        results = (actRepositoryService as IPersistableQueryRepositoryService).Find <TAct>(QueryExpressionParser.BuildLinqExpression <TAct>(search, null, false), offset, count, out totalResults, queryId);
                    }
                }
                else
                {
                    results = actRepositoryService.Find(QueryExpressionParser.BuildLinqExpression <TAct>(search, null, false), offset, count, out totalResults);
                }

                //results.ToList().ForEach(a => a.Relationships.OrderBy(r => r.TargetAct.CreationTime));

                this.m_tracer.TraceVerbose("Returning ACT bundle {0}..{1} / {2}", offset, offset + count, totalResults);
                //
                return(new Bundle
                {
                    Key = queryId,
                    Count = results.Count(),
                    Item = results.OfType <IdentifiedData>().ToList(),
                    Offset = offset,
                    TotalResults = totalResults
                });
            }
        }
Example #6
0
        /// <summary>
        /// Gets a list of alert for a specific query.
        /// </summary>
        /// <returns>Returns a list of alert which match the specific query.</returns>
        public AmiCollection <AlertMessageInfo> GetAlerts()
        {
            var parameters = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;

            if (parameters.Count == 0)
            {
                throw new ArgumentException($"{nameof(parameters)} cannot be empty");
            }

            var expression = QueryExpressionParser.BuildLinqExpression <AlertMessage>(this.CreateQuery(parameters));

            var alertRepository = ApplicationContext.Current.GetService <IAlertRepositoryService>();

            if (alertRepository == null)
            {
                throw new InvalidOperationException($"{nameof(IAlertRepositoryService)} not found");
            }

            var alerts = new AmiCollection <AlertMessageInfo>();

            int totalCount = 0;

            alerts.CollectionItem = alertRepository.Find(expression, 0, null, out totalCount).Select(a => new AlertMessageInfo(a)).ToList();
            alerts.Size           = totalCount;

            return(alerts);
        }
Example #7
0
        /// <summary>
        /// Gets the code systems.
        /// </summary>
        /// <returns>Returns a list of code systems.</returns>
        /// <exception cref="System.ArgumentException">parameters</exception>
        /// <exception cref="System.InvalidOperationException">IMetadataRepositoryService</exception>
        public AmiCollection <CodeSystem> GetCodeSystems()
        {
            var parameters = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;

            if (parameters.Count == 0)
            {
                throw new ArgumentException($"{nameof(parameters)} cannot be empty");
            }

            var expression = QueryExpressionParser.BuildLinqExpression <CodeSystem>(this.CreateQuery(parameters));

            var metadataService = ApplicationContext.Current.GetService <IMetadataRepositoryService>();

            if (metadataService == null)
            {
                throw new InvalidOperationException($"Unable to locate service: {nameof(IMetadataRepositoryService)}");
            }

            var codeSystems = new AmiCollection <CodeSystem>();

            int totalCount;

            codeSystems.CollectionItem = metadataService.FindCodeSystem(expression, 0, null, out totalCount).ToList();
            codeSystems.Size           = totalCount;

            return(codeSystems);
        }
Example #8
0
        /// <summary>
        /// Queries for a specified resource.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns>Returns the FHIR query result containing the results of the query.</returns>
        /// <exception cref="System.ArgumentNullException">parameters</exception>
        public virtual FhirQueryResult Query(System.Collections.Specialized.NameValueCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Core.Model.Query.NameValueCollection imsiQuery = null;
            FhirQuery query = QueryRewriter.RewriteFhirQuery <TFhirResource, TModel>(parameters, out imsiQuery);

            // Do the query
            int totalResults            = 0;
            List <IResultDetail> issues = new List <IResultDetail>();
            var predicate           = QueryExpressionParser.BuildLinqExpression <TModel>(imsiQuery);
            var imsiResults         = this.Query(predicate, issues, query.QueryId, query.Start, query.Quantity, out totalResults);
            var webOperationContext = WebOperationContext.Current;

            // Return FHIR query result
            return(new FhirQueryResult()
            {
                Details = issues,
                Outcome = ResultCode.Accepted,
                Results = imsiResults.AsParallel().Select(o => this.MapToFhir(o, webOperationContext)).OfType <DomainResourceBase>().ToList(),
                Query = query,
                TotalResults = totalResults
            });
        }
Example #9
0
        public IdentifiedData GetPlace()
        {
            var search = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            var placeService = ApplicationContext.Current.GetService <IPlaceRepositoryService>();

            if (search.ContainsKey("_id"))
            {
                return(placeService.Get(Guid.Parse(search["_id"].FirstOrDefault()), Guid.Empty));
            }
            else
            {
                var predicate = QueryExpressionParser.BuildLinqExpression <Place>(search);
                this.m_tracer.TraceVerbose("Searching Places : {0} / {1}", MiniImsServer.CurrentContext.Request.Url.Query, predicate);

                int totalResults = 0,
                    offset       = search.ContainsKey("_offset") ? Int32.Parse(search["_offset"][0]) : 0,
                    count        = search.ContainsKey("_count") ? Int32.Parse(search["_count"][0]) : 100;
                var retVal       = placeService.Find(predicate, offset, count, out totalResults);

                return(new Bundle()
                {
                    Item = retVal.OfType <IdentifiedData>().ToList(),
                    Offset = offset,
                    Count = count,
                    TotalResults = totalResults
                });
            }
        }
Example #10
0
        public void ForceRequeue()
        {
            // What does this do... oh my ... it is complex
            //
            // 1. We scan the entire database for all Patients that were created in the specified date ranges
            // 2. We scan the entire database for all Acts that were created in the specified date ranges
            // 3. We take all of those and we put them in the outbox in bundles to be shipped to the server at a later time
            var search = NameValueCollection.ParseQueryString(MiniImsServer.CurrentContext.Request.Url.Query);

            // Hit the act repository
            var patientDataRepository = ApplicationContext.Current.GetService <IRepositoryService <Patient> >() as IPersistableQueryRepositoryService;
            var actDataRepository     = ApplicationContext.Current.GetService <IRepositoryService <Act> >() as IPersistableQueryRepositoryService;
            var imsiIntegration       = ApplicationContext.Current.GetService <ImsiIntegrationService>();

            // Get all patients matching
            int  ofs = 0, tr = 1;
            Guid qid    = Guid.NewGuid();
            var  filter = QueryExpressionParser.BuildLinqExpression <Patient>(search);

            while (ofs < tr)
            {
                var res = patientDataRepository.Find <Patient>(filter, ofs, 25, out tr, qid);
                ApplicationContext.Current.SetProgress(Strings.locale_preparingPush, (float)ofs / (float)tr * 0.5f);
                ofs += 25;

                var serverSearch = new NameValueCollection();
                serverSearch.Add("id", res.Select(o => o.Key.ToString()).ToList());

                var serverKeys = imsiIntegration.Find <Patient>(serverSearch, 0, 25, new IntegrationQueryOptions()
                {
                    Lean = true,
                    InfrastructureOptions = NameValueCollection.ParseQueryString("_exclude=participation&_exclude=relationship&_exclude=tag&_exclude=identifier&_exclude=address&_exclude=name")
                }).Item.Select(o => o.Key);

                SynchronizationQueue.Outbound.Enqueue(Bundle.CreateBundle(res.Where(o => !serverKeys.Contains(o.Key)), tr, ofs), DataOperationType.Update);
            }

            // Get all acts matching
            qid = Guid.NewGuid();
            var actFilter = QueryExpressionParser.BuildLinqExpression <Act>(search);

            ofs = 0; tr = 1;
            while (ofs < tr)
            {
                var res = actDataRepository.Find <Act>(actFilter, ofs, 25, out tr, qid);
                ApplicationContext.Current.SetProgress(Strings.locale_preparingPush, (float)ofs / (float)tr * 0.5f + 0.5f);
                ofs += 25;

                var serverSearch = new NameValueCollection();
                serverSearch.Add("id", res.Select(o => o.Key.ToString()).ToList());

                var serverKeys = imsiIntegration.Find <Act>(serverSearch, 0, 25, new IntegrationQueryOptions()
                {
                    Lean = true,
                    InfrastructureOptions = NameValueCollection.ParseQueryString("_exclude=participation&_exclude=relationship&_exclude=tag&_exclude=identifier")
                }).Item.Select(o => o.Key);

                SynchronizationQueue.Outbound.Enqueue(Bundle.CreateBundle(res.Where(o => !serverKeys.Contains(o.Key)), tr, ofs), DataOperationType.Update);
            }
        }
        public void TestChainedParse()
        {
            Guid id   = Guid.Empty;
            var  qstr = "classConcept.mnemonic=GenderCode&statusConcept.mnemonic=ACTIVE";

            var query = QueryExpressionParser.BuildLinqExpression <Place>(NameValueCollection.ParseQueryString(qstr));
        }
Example #12
0
        public void TestAgeFilter()
        {
            QueryFilterExtensions.AddExtendedFilter(new AgeQueryFilterExtension());
            var filterQuery = NameValueCollection.ParseQueryString("dateOfBirth=:(age)<P3Y");
            var expr        = QueryExpressionParser.BuildLinqExpression <Patient>(filterQuery);

            Assert.IsTrue(expr.ToString().Contains("Age"));
        }
        /// <summary>
        /// Query for applet
        /// </summary>
        public IEnumerable <object> Query(Type scopingType, object scopingKey, NameValueCollection filter, int offset, int count, out int totalCount)
        {
            var query   = QueryExpressionParser.BuildLinqExpression <AppletManifest>(filter);
            var applets = this.m_solutionManager.GetApplets(scopingKey.ToString()).Where(query.Compile()).Select(o => new AppletManifestInfo(o.Info, null));

            totalCount = applets.Count();
            return(applets.Skip(offset).Take(count).OfType <Object>());
        }
Example #14
0
        /// <summary>
        /// Find a package
        /// </summary>
        public List <AppletInfo> Find()
        {
            var    filter = QueryExpressionParser.BuildLinqExpression <AppletInfo>(NameValueCollection.ParseQueryString(RestOperationContext.Current.IncomingRequest.Url.Query));
            string offset = RestOperationContext.Current.IncomingRequest.QueryString["_offset"] ?? "0",
                   count  = RestOperationContext.Current.IncomingRequest.QueryString["_count"] ?? "10";

            return(this.m_configuration.Repository.GetRepository().Find(filter, Int32.Parse(offset), Int32.Parse(count), out int _).ToList());
        }
        public IEnumerable <object> Query(NameValueCollection queryParameters, int offset, int count, out int totalCount)
        {
            var query   = QueryExpressionParser.BuildLinqExpression <AppletManifest>(queryParameters);
            var applets = ApplicationServiceContext.Current.GetService <IAppletManagerService>().Applets.Where(query.Compile()).Select(o => new AppletManifestInfo(o.Info, null));

            totalCount = applets.Count();
            return(applets.Skip(offset).Take(count).OfType <Object>());
        }
Example #16
0
        /// <summary>
        /// Query the specified sub-object
        /// </summary>
        public IEnumerable <object> Query(Type scopingType, object scopingKey, NameValueCollection filter, int offset, int count, out int totalCount)
        {
            filter.Add("roles.id", scopingKey.ToString());
            var expr = QueryExpressionParser.BuildLinqExpression <SecurityUser>(filter);

            // Could redirect but faster just to query and return
            return(this.m_userRepository.Find(expr, offset, count, out totalCount));
        }
        /// <summary>
        /// Gets a list of security roles.
        /// </summary>
        /// <returns>Returns a list of security roles.</returns>
        public AmiCollection <SecurityRoleInfo> GetRoles()
        {
            var expression     = QueryExpressionParser.BuildLinqExpression <SecurityRole>(this.CreateQuery(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters));
            var userRepository = ApplicationContext.Current.GetService <ISecurityRepositoryService>();

            return(new AmiCollection <SecurityRoleInfo> {
                CollectionItem = userRepository.FindRoles(expression).Select(o => new SecurityRoleInfo(o)).ToList()
            });
        }
Example #18
0
        /// <summary>
        /// Execute the configured guards
        /// </summary>
        protected bool ExecuteGuard <TModel>(TModel data) where TModel : IdentifiedData
        {
            var retVal = true;

            foreach (var guard in this.Configuration.Guards)
            {
                retVal &= QueryExpressionParser.BuildLinqExpression <TModel>(NameValueCollection.ParseQueryString(guard)).Compile().Invoke(data);
            }
            return(retVal);
        }
Example #19
0
        public void TestOrGuardCondition()
        {
            String expected = "o => o.Names.Where(guard => (((guard.NameUse ?? new Concept()).Mnemonic == \"Legal\") Or ((guard.NameUse ?? new Concept()).Mnemonic == \"OfficialRecord\"))).Any(name => name.Component.Where(guard => (((guard.ComponentType ?? new Concept()).Mnemonic == \"Given\") Or ((guard.ComponentType ?? new Concept()).Mnemonic == \"Family\"))).Any(component => (component.Value == \"John\")))";
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("name[Legal|OfficialRecord].component[Given|Family].value", "John");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
Example #20
0
        public void TestNonSerializedParse()
        {
            String expected = "o => o.Extensions.Any(extension => extension.ExtensionDisplay == \"1\")";
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("extension.display", "1");
            var expr  = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);
            var pexpr = new NameValueCollection(QueryExpressionBuilder.BuildQuery <Patient>(expr, true).ToArray());

            Assert.AreEqual(httpQueryParameters.ToString(), pexpr.ToString());
        }
Example #21
0
        public void TestBuildFuzzyDate()
        {
            String expected = $"o => ((o.DateOfBirth != null) AndAlso (((o.DateOfBirth.Value >= {new DateTime(2015,01,01)}) AndAlso (o.DateOfBirth.Value <= {new DateTime(2015, 12, 31, 23, 59, 59)})) == True))";

            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", "~2015");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected.ToString(), expr.ToString());
        }
Example #22
0
        public void TestBuildGuardUuid()
        {
            String expected = "o => o.Names.Where(guard => (guard.NameUseKey == Convert(effe122d-8d30-491d-805d-addcb4466c35))).Any(name => name.Component.Any(component => (component.Value == \"SMITH\")))";

            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add($"name[{NameUseKeys.Legal}].component.value", "SMITH");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected.ToString(), expr.ToString());
        }
        /// <summary>
        /// Perform actual invokation on all objects
        /// </summary>
        public TBinding Invoke <TBinding>(string triggerName, TBinding data) where TBinding : IdentifiedData
        {
            lock (this.m_lock)
            {
                using (AuthenticationContext.EnterSystemContext())
                {
                    if (data == default(TBinding))
                    {
                        return(data);
                    }

                    var callList = this.GetCallList(data.GetType(), triggerName);
                    callList = callList.Union(this.GetCallList <TBinding>(triggerName), this.m_javascriptComparer).ToList();
                    var retVal = data;

                    if (callList.Count() > 0)
                    {
                        dynamic viewModel = JavascriptUtils.ToViewModel(retVal);
                        foreach (var c in callList)
                        {
                            try
                            {
                                // There is a guard so let's execute it
                                if (c.Guard == null || QueryExpressionParser.BuildLinqExpression <TBinding>(c.Guard).Compile()(data))
                                {
                                    viewModel = c.Callback.DynamicInvoke(viewModel);
                                }
                            }
                            catch (JavaScriptException e)
                            {
                                this.m_tracer.TraceError("JS ERROR: Error running {0} for {1} @ {2}:{3} \r\n Javascript Stack: {4} \r\n C# Stack: {5}",
                                                         triggerName, data, e.Location.Source, e.LineNumber, e.CallStack, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", e);
                            }
                            catch (TargetInvocationException e) when(e.InnerException is JavaScriptException je)
                            {
                                this.m_tracer.TraceError("JS ERROR: Error running {0} for {1} @ {2}:{3} \r\n Javascript Stack: {4} \r\n C# Stack: {5}",
                                                         triggerName, data, je.Location.Source, je.LineNumber, je.CallStack, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", je);
                            }
                            catch (Exception e)
                            {
                                this.m_tracer.TraceError("Error running {0} for {1} : {2}", triggerName, data, e);
                                throw new JsBusinessRuleException($"Error running business rule {c.Id} - {triggerName} for {data}", e);
                            }
                        }

                        retVal = (TBinding)JavascriptUtils.ToModel(viewModel).CopyAnnotations(retVal);
                    }

                    return(retVal);
                }
            }
        }
Example #24
0
        public void TestBuildSimpleLinqMethod()
        {
            Expression <Func <Concept, bool> > expected = (o => o.Mnemonic == "ENT");

            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("mnemonic", "ENT");
            var expr = QueryExpressionParser.BuildLinqExpression <Concept>(httpQueryParameters);

            Assert.AreEqual(expected.ToString(), expr.ToString());
        }
Example #25
0
        public void TestNullGuardCondition()
        {
            var    dtString = DateTime.Now;
            String expected = "o => o.Names.Where(guard => ((guard.NameUse ?? new Concept()).Mnemonic == \"L\")).Any(name => name.Component.Where(guard => (guard.ComponentType == null)).Any(component => (component.Value == \"John\")))";
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("name[L].component[null].value", "John");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
        public void TestNullableCondition()
        {
            var    dtString = new DateTime(1999, 01, 01);
            String expected = "o => ((o.StartTime != null) AndAlso (o.StartTime.Value > 1/1/1999 12:00:00 AM -05:00))";
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("startTime", ">" + dtString);
            var expr = QueryExpressionParser.BuildLinqExpression <Act>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
Example #27
0
        public void TestBuildFuzzyDate()
        {
            String expected = "o => ((o.DateOfBirth != null) AndAlso (((o.DateOfBirth.Value >= Convert(2015-01-01 12:00:00 AM)) AndAlso (o.DateOfBirth.Value <= Convert(2015-12-31 11:59:59 PM))) == True))";

            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", "~2015");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected.ToString(), expr.ToString());
        }
Example #28
0
        public void TestOrGuardParse()
        {
            String expected = "o => o.Names.Where(guard => (guard.NameUse.Mnemonic == \"L\")).Any(name => name.Component.Where(guard => (guard.ComponentType == null)).Any(component => (component.Value == \"John\")))";
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("name[Legal|OfficialRecord].component[Given|Family].value", "John");
            var expr  = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);
            var pexpr = new NameValueCollection(QueryExpressionBuilder.BuildQuery <Patient>(expr, true).ToArray());

            Assert.AreEqual(httpQueryParameters.ToString(), pexpr.ToString());
        }
Example #29
0
        public IEnumerable <object> Query(NameValueCollection queryParameters, int offset, int count, out int totalCount)
        {
            var filter = QueryExpressionParser.BuildLinqExpression <AuditData>(queryParameters);

            ModelSort <AuditData>[] sortParameters = null;
            if (queryParameters.TryGetValue("_orderBy", out var orderBy))
            {
                sortParameters = QueryExpressionParser.BuildSort <AuditData>(orderBy);
            }
            return(this.GetRepository().Find(filter, offset, count, out totalCount, sortParameters));
        }
Example #30
0
        public void TestBuildSimpleAndLinqMethod()
        {
            Expression <Func <SecurityUser, bool> > expected = (o => o.UserName == "Charles" && o.Password == "20329132");

            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("userName", "Charles");
            httpQueryParameters.Add("password", "20329132");
            var expr = QueryExpressionParser.BuildLinqExpression <SecurityUser>(httpQueryParameters);

            Assert.AreEqual(expected.ToString(), expr.ToString());
        }