public static ITypedElement GetResourceNavigatorSTU3(string text, out string parseErrors) { f3.Resource resource = null; try { if (text.StartsWith("{")) { resource = new stu3.Hl7.Fhir.Serialization.FhirJsonParser(new stu3.Hl7.Fhir.Serialization.ParserSettings() { PermissiveParsing = true }).Parse <f3.Resource>(text); } else { resource = new stu3.Hl7.Fhir.Serialization.FhirXmlParser(new stu3.Hl7.Fhir.Serialization.ParserSettings() { PermissiveParsing = true }).Parse <f3.Resource>(text); } } catch (Exception ex) { parseErrors = "STU3 Resource read error:\r\n" + ex.Message; return(null); } parseErrors = null; var inputNav = stu3.Hl7.Fhir.ElementModel.PocoNavigatorExtensions.ToTypedElement(resource); return(inputNav); }
private IElementNavigator GetResourceNavigatorSTU3(out string parseErrors) { f3.Resource resource = null; try { if (textboxInputXML.Text.StartsWith("{")) { resource = new s3.FhirJsonParser().Parse <f3.Resource>(textboxInputXML.Text); } else { resource = new s3.FhirXmlParser().Parse <f3.Resource>(textboxInputXML.Text); } } catch (Exception ex) { parseErrors = "STU3 Resource read error:\r\n" + ex.Message; return(null); } parseErrors = null; var inputNav = new stu3.Hl7.Fhir.ElementModel.PocoNavigator(resource); return(inputNav); }
public static void PretifyJson(string text, Action <string> setText) { // prettify the Json (and convert to Json if it wasn't already) f3.Resource resource = null; string contentAsJson; try { if (text.StartsWith("{")) { contentAsJson = text; } else { resource = new stu3.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f3.Resource>(text); contentAsJson = new stu3.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource); } var sr = new System.IO.StringReader(contentAsJson); var reader = new JsonTextReader(sr); var doc = JObject.Load(reader); setText(doc.ToString(Formatting.Indented)); } catch (Exception) { f2.Resource resource2 = null; try { if (text.StartsWith("{")) { contentAsJson = text; } else { resource2 = new dstu2.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f2.Resource>(text); contentAsJson = new dstu2.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource2); } var sr = new System.IO.StringReader(contentAsJson); var reader = new JsonTextReader(sr); var doc = JObject.Load(reader); setText(doc.ToString(Formatting.Indented)); } catch (Exception) { f4.Resource resource4 = null; try { if (text.StartsWith("{")) { contentAsJson = text; } else { resource4 = new r4.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f4.Resource>(text); contentAsJson = new r4.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource4); } var sr = new System.IO.StringReader(contentAsJson); var reader = new JsonTextReader(sr); var doc = JObject.Load(reader); setText(doc.ToString(Formatting.Indented)); } catch (Exception) { } } } }
public static void PretifyXML(string text, Action <string> setText) { // prettify the XML (and convert to XML if it wasn't already) f3.Resource resource = null; string contentAsXML; try { if (text.StartsWith("{")) { resource = new stu3.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f3.Resource>(text); contentAsXML = new stu3.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource); } else { contentAsXML = text; } var doc = System.Xml.Linq.XDocument.Parse(contentAsXML); setText(doc.ToString(System.Xml.Linq.SaveOptions.None)); } catch (Exception ex3) { f2.Resource resource2 = null; try { if (text.StartsWith("{")) { resource2 = new dstu2.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f2.Resource>(text); contentAsXML = new dstu2.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource2); } else { contentAsXML = text; } var doc = System.Xml.Linq.XDocument.Parse(contentAsXML); setText(doc.ToString(System.Xml.Linq.SaveOptions.None)); } catch (Exception ex2) { f4.Resource resource4 = null; try { if (text.StartsWith("{")) { resource4 = new r4.Hl7.Fhir.Serialization.FhirJsonParser().Parse <f4.Resource>(text); contentAsXML = new r4.Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(resource4); } else { contentAsXML = text; } var doc = System.Xml.Linq.XDocument.Parse(contentAsXML); setText(doc.ToString(System.Xml.Linq.SaveOptions.None)); } catch (Exception ex4) { System.Diagnostics.Debug.WriteLine(ex4.Message); System.Diagnostics.Debug.WriteLine(ex3.Message); System.Diagnostics.Debug.WriteLine(ex2.Message); } } } }
public void ScanResourceInstance(fm3.Resource resource, string source) { SourceDetails sourceDetail; if (!Sources.ContainsKey(source)) { sourceDetail = new SourceDetails() { Source = source, ResourceName = resource.TypeName, InstanceCount = 1 }; Sources.Add(source, sourceDetail); } else { sourceDetail = Sources[source]; sourceDetail.InstanceCount++; } this.ResourceName = resource.TypeName; // Prepare the property list from the Structure Definition if (!_properties.ContainsKey(ResourceName)) { var sourceSD = new Hl7.Fhir.Specification.Source.ZipSource(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "specification.zip")); var instSD = sourceSD.ResolveByUri("http://hl7.org/fhir/StructureDefinition/" + resource.TypeName) as fm3.StructureDefinition; if (instSD == null) { Console.WriteLine($"Unable to load the StructureDefinition for {resource.TypeName}"); return; } foreach (var ed in instSD.Differential.Element) { if (!_properties.ContainsKey(ed.Path)) { _properties.Add(ed.Path, new ResultItem() { PropertyName = ed.Path, UsageCount = 0, FromStructureDef = true }); } } } if (_properties.ContainsKey(ResourceName)) { _properties[ResourceName].UsageCount++; } // Now process this actual instance var results = stu3.Hl7.Fhir.FhirPath.ElementNavFhirExtensions.Select(resource, "descendants().element_def_path()"); foreach (var item in results) { if (item is fm3.FhirString str) { string pname = $"{str.Value}"; if (_properties.ContainsKey(pname)) { _properties[pname].UsageCount++; } else { // don't count props not in the differential // _properties.Add(pname, new ResultItem() { PropertyName = pname, UsageCount = 1 }); } } } }