コード例 #1
0
        private async Task <ResourceResponse> ProcessSingleResource(Resource p, string resourceType,
                                                                    string matchversionid = null)
        {
            //Version conflict detection
            if (!string.IsNullOrEmpty(matchversionid))
            {
                var cv = await storage.LoadFhirResourceAsync(p.Id, resourceType).ConfigureAwait(false);

                if (cv == null || !matchversionid.Equals(cv.Meta.VersionId))
                {
                    var oo = new OperationOutcome {
                        Issue = new List <OperationOutcome.IssueComponent>()
                    };
                    var ic = new OperationOutcome.IssueComponent
                    {
                        Severity    = OperationOutcome.IssueSeverity.Error,
                        Code        = OperationOutcome.IssueType.Exception,
                        Diagnostics = "Version conflict current resource version of " + resourceType + "/" + p.Id + " is " +
                                      cv.Meta.VersionId
                    };
                    oo.Issue.Add(ic);
                    return(new ResourceResponse(oo, -1));
                }
            }

            //Prepare for Insert/update and Version
            if (string.IsNullOrEmpty(p.Id))
            {
                p.Id = Guid.NewGuid().ToString();
            }
            p.Meta = new Meta
            {
                VersionId   = Guid.NewGuid().ToString(),
                LastUpdated = DateTimeOffset.UtcNow
            };
            var rslt = await storage.UpsertFhirResourceAsync(p).ConfigureAwait(false);

            return(new ResourceResponse(p, rslt));
        }
コード例 #2
0
        public static async Task <List <Resource> > ProcessIncludesAsync(Resource source, NameValueCollection parms, IFhirStore store)
        {
            var retVal      = new List <Resource>();
            var includeparm = parms["_include"];

            if (!string.IsNullOrEmpty(includeparm))
            {
                var serialize = new FhirJsonSerializer();


                var j    = serialize.SerializeToString(source);
                var incs = includeparm.Split(',');
                foreach (var t in incs)
                {
                    var isinstance = false;
                    var s          = t.Split(':');
                    if (s.Length <= 1)
                    {
                        continue;
                    }
                    var    prop = s[1];
                    JToken x    = null;
                    try
                    {
                        if (prop.Equals("substance"))
                        {
                            x          = j[Convert.ToInt32("suspectEntity")];
                            isinstance = true;
                        }
                        else
                        {
                            x = j[Convert.ToInt32(prop)];
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    if (x == null)
                    {
                        continue;
                    }
                    for (var i = 0; i < x.Count(); i++)
                    {
                        var x1    = x.Type == JTokenType.Array ? x[i] : x;
                        var z     = isinstance ? x1["instance"]["reference"].ToString() : x1["reference"].ToString();
                        var split = z.Split('/');
                        if (split.Length <= 1)
                        {
                            continue;
                        }
                        var a1 = await store.LoadFhirResourceAsync(split[1], split[0]).ConfigureAwait(false);

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

            return(retVal);
        }