private static BundleEntry loadEntry(JObject entry) { BundleEntry result; try { if (entry[JATOM_DELETED] != null) { result = new DeletedEntry(); result.Id = SerializationUtil.UriValueOrNull(entry[BundleXmlParser.XATOM_ID]); } else { var content = entry[BundleXmlParser.XATOM_CONTENT]; var id = SerializationUtil.UriValueOrNull(entry[BundleXmlParser.XATOM_ID]); if (content != null) { var parsed = getContents(content); if (parsed != null) { result = ResourceEntry.Create(parsed); } else { throw Error.Format("BundleEntry {0} has a content element without content", null, id); } } else { result = SerializationUtil.CreateResourceEntryFromId(id); } result.Id = id; } result.Links = getLinks(entry[BundleXmlParser.XATOM_LINK]); result.Tags = TagListParser.ParseTags(entry[BundleXmlParser.XATOM_CATEGORY]); if (result is DeletedEntry) { ((DeletedEntry)result).When = instantOrNull(entry[JATOM_DELETED]); } else { var re = (ResourceEntry)result; re.Title = entry.Value <string>(BundleXmlParser.XATOM_TITLE); re.LastUpdated = instantOrNull(entry[BundleXmlParser.XATOM_UPDATED]); re.Published = instantOrNull(entry[BundleXmlParser.XATOM_PUBLISHED]); re.AuthorName = entry[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? entry[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_NAME)) .FirstOrDefault() : null; re.AuthorUri = entry[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? entry[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_URI)) .FirstOrDefault() : null; } } catch (Exception exc) { throw Error.Format("Exception while reading entry: " + exc.Message, null); } return(result); }
internal static Bundle Load(JsonReader reader) { JObject feed; try { reader.DateParseHandling = DateParseHandling.None; reader.FloatParseHandling = FloatParseHandling.Decimal; feed = JObject.Load(reader); if (feed.Value <string>(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME) != "Bundle") { throw Error.Format("Input data is not an json FHIR bundle", null); } } catch (Exception exc) { throw Error.Format("Exception while parsing feed: " + exc.Message, null); } Bundle result; try { result = new Bundle() { Title = feed.Value <string>(BundleXmlParser.XATOM_TITLE), LastUpdated = instantOrNull(feed[BundleXmlParser.XATOM_UPDATED]), Id = SerializationUtil.UriValueOrNull(feed[BundleXmlParser.XATOM_ID]), Links = getLinks(feed[BundleXmlParser.XATOM_LINK]), Tags = TagListParser.ParseTags(feed[BundleXmlParser.XATOM_CATEGORY]), AuthorName = feed[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? feed[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_NAME)) .FirstOrDefault() : null, AuthorUri = feed[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? feed[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_URI)) .FirstOrDefault() : null, TotalResults = intValueOrNull(feed[BundleXmlParser.XATOM_TOTALRESULTS]) }; } catch (Exception exc) { throw Error.Format("Exception while parsing json feed attributes: " + exc.Message, null); } var entries = feed[BundleXmlParser.XATOM_ENTRY]; if (entries != null) { if (!(entries is JArray)) { throw Error.Format("The json feed contains a single entry, instead of an array", null); } result.Entries = loadEntries((JArray)entries, result); } return(result); }
private static BundleEntry loadEntry(XElement entry) { BundleEntry result; try { if (entry.Name == XTOMBSTONE + XATOM_DELETED_ENTRY) { result = new DeletedEntry(); result.Id = SerializationUtil.UriValueOrNull(entry.Attribute(XATOM_DELETED_REF)); } else { XElement content = entry.Element(XATOMNS + XATOM_CONTENT); var id = SerializationUtil.UriValueOrNull(entry.Element(XATOMNS + XATOM_ID)); if (content != null) { var parsed = getContents(content); if (parsed != null) { result = ResourceEntry.Create(parsed); } else { throw Error.Format("BundleEntry has a content element without content", XmlDomFhirReader.GetLineInfo(content)); } } else { result = SerializationUtil.CreateResourceEntryFromId(id); } result.Id = id; } result.Links = getLinks(entry.Elements(XATOMNS + XATOM_LINK)); result.Tags = TagListParser.ParseTags(entry.Elements(XATOMNS + XATOM_CATEGORY)); if (result is DeletedEntry) { ((DeletedEntry)result).When = SerializationUtil.InstantOrNull(entry.Attribute(XATOM_DELETED_WHEN)); } else { ResourceEntry re = (ResourceEntry)result; re.Title = SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_TITLE)); re.LastUpdated = SerializationUtil.InstantOrNull(entry.Element(XATOMNS + XATOM_UPDATED)); re.Published = SerializationUtil.InstantOrNull(entry.Element(XATOMNS + XATOM_PUBLISHED)); re.AuthorName = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null : SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR) .Element(XATOMNS + XATOM_AUTH_NAME)); re.AuthorUri = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null : SerializationUtil.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR) .Element(XATOMNS + XATOM_AUTH_URI)); } } catch (Exception exc) { throw Error.Format("Exception while reading entry: " + exc.Message, XmlDomFhirReader.GetLineInfo(entry)); } return(result); }