private async Task <Resource> ProcessSingleResource(Resource p, string resourceType, string matchversionid = null) { //Version conflict detection if (!String.IsNullOrEmpty(matchversionid)) { var cv = await storage.LoadFHIRResource(p.Id, resourceType); if (cv == null || !matchversionid.Equals(cv.Meta.VersionId)) { OperationOutcome oo = new OperationOutcome(); oo.Issue = new System.Collections.Generic.List <OperationOutcome.IssueComponent>(); OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent(); ic.Severity = OperationOutcome.IssueSeverity.Error; ic.Code = OperationOutcome.IssueType.Exception; ic.Diagnostics = "Version conflict current resource version of " + resourceType + "/" + p.Id + " is " + cv.Meta.VersionId; oo.Issue.Add(ic); return(oo); } } //Prepare for Insert/update and Version if (String.IsNullOrEmpty(p.Id)) { p.Id = Guid.NewGuid().ToString(); } p.Meta = new Meta(); p.Meta.VersionId = Guid.NewGuid().ToString(); p.Meta.LastUpdated = DateTimeOffset.UtcNow; var rslt = await storage.UpsertFHIRResource(p); return(p); }
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); }