Exemplo n.º 1
0
        public string GenerateQuery(IFHIRStore store, string resourceType, NameValueCollection parms)
        {
            StringBuilder where = new StringBuilder();
            //Select statement for Resource
            StringBuilder select = new StringBuilder();

            select.Append(store.SelectAllQuery);
            foreach (string key in parms)
            {
                string value   = parms[key];
                string parmdef = null;
                _pmap.TryGetValue((resourceType + "." + key), out parmdef);
                if (parmdef != null)
                {
                    //TODO Handle Setting up Parm Type and process value for prefix and modifiers
                    //Add JOINS to select
                    string join = null;
                    _pmap.TryGetValue(resourceType + "." + key + ".join", out join);
                    if (join != null)
                    {
                        if (!select.ToString().Contains(join))
                        {
                            select.Append(" " + join);
                        }
                    }
                    //Add Where clauses/bind values
                    string querypiece = null;
                    _pmap.TryGetValue(resourceType + "." + key + ".default", out querypiece);
                    if (querypiece != null)
                    {
                        if (where.Length == 0)
                        {
                            where.Append(" WHERE (");
                        }
                        else
                        {
                            where.Append(" and (");
                        }
                        //Handle bind values single or multiple
                        string[] vals = value.Split(',');
                        foreach (string s in vals)
                        {
                            string   currentpiece = querypiece;
                            string[] t            = s.Split('|');
                            int      x            = 0;
                            foreach (string u in t)
                            {
                                currentpiece = currentpiece.Replace(("~v" + x++ + "~"), u);
                            }
                            where.Append("(" + currentpiece + ") OR ");
                        }
                        where.Remove(where.Length - 3, 3);
                        where.Append(")");
                    }
                }
            }
            return(select.ToString() + where.ToString());
        }
Exemplo n.º 2
0
        //TODO: Inject Storage Implementation
        public ResourceController(IFHIRStore store)
        {
            string s = CloudConfigurationManager.GetSetting("FHIRParserMode");

            _strict        = (s == null || s.Equals("strict", StringComparison.CurrentCultureIgnoreCase) ? true : false);
            this.storage   = store;
            parsersettings = new ParserSettings();
            parsersettings.AcceptUnknownMembers   = !_strict;
            parsersettings.AllowUnrecognizedEnums = !_strict;
            jsonparser = new FhirJsonParser(parsersettings);
            xmlparser  = new FhirXmlParser(parsersettings);
        }
Exemplo n.º 3
0
 //TODO: Inject Storage Implementation
 public ResourceController(IFHIRStore store)
 {
     _secresolve    = new SecretResolver();
     parsemode      = _secresolve.GetConfiguration("FHIRParserMode", "open");
     _strict        = (parsemode == null || parsemode.Equals("strict", StringComparison.CurrentCultureIgnoreCase) ? true : false);
     this.storage   = store;
     parsersettings = new ParserSettings();
     parsersettings.AcceptUnknownMembers   = !_strict;
     parsersettings.AllowUnrecognizedEnums = !_strict;
     jsonparser = new FhirJsonParser(parsersettings);
     xmlparser  = new FhirXmlParser(parsersettings);
 }
Exemplo n.º 4
0
        public static async Task <List <Resource> > ProcessIncludes(Resource source, NameValueCollection parms, IFHIRStore store)
        {
            var    retVal      = new List <Resource>();
            string includeparm = parms["_include"];

            if (!string.IsNullOrEmpty(includeparm))
            {
                JObject  j    = JObject.Parse(FhirSerializer.SerializeToJson(source));
                string[] incs = includeparm.Split(',');
                foreach (string t in incs)
                {
                    bool     isinstance = false;
                    string[] s          = t.Split(':');
                    if (s.Length > 1)
                    {
                        var    prop = s[1];
                        JToken x    = null;
                        try
                        {
                            if (prop.Equals("substance"))
                            {
                                x          = j["suspectEntity"];
                                isinstance = true;
                            }
                            else
                            {
                                x = j[prop];
                            }
                        }
                        catch (Exception)
                        {
                        }
                        if (x != null)
                        {
                            for (int i = 0; i < x.Count(); i++)
                            {
                                var      x1    = (x.Type == JTokenType.Array ? x[i] : x);
                                string   z     = (isinstance ? x1["instance"]["reference"].ToString() : x1["reference"].ToString());
                                string[] split = z.Split('/');
                                if (split.Length > 1)
                                {
                                    var a1 = await store.LoadFHIRResource(split[1], split[0]);

                                    if (a1 != null)
                                    {
                                        retVal.Add(a1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(retVal);
        }