Exemplo n.º 1
0
        /// <summary>
        /// Gets back a resource from a xml sample file.
        /// </summary>
        /// <param name="fileName">The XML filename, omit the extension</param>
        public static Resource GetXmlSample(string fileName)
        {
            var fhirSource = GetXml(fileName);
            var parser     = new Hl7.Fhir.Serialization.FhirXmlParser();

            return(parser.Parse <Resource>(fhirSource));
        }
Exemplo n.º 2
0
        public PatientFixture()
        {
            var parser = new Hl7.Fhir.Serialization.FhirXmlParser();
            var tpXml  = TestData.ReadTextFile("fp-test-patient.xml");

            var patient = parser.Parse <Patient>(tpXml);

            TestInput = new PocoNavigator(patient);

            tpXml = TestData.ReadTextFile("questionnaire-example.xml");
            var quest = parser.Parse <Questionnaire>(tpXml);

            Questionnaire = new PocoNavigator(quest);

            tpXml = TestData.ReadTextFile("uuid.profile.xml");
            var uuid = parser.Parse <StructureDefinition>(tpXml);

            UuidProfile = new PocoNavigator(uuid);

            Xdoc = new XDocument(new XElement("group", new XAttribute("name", "CSharpTests")));
        }
        protected void ParseResponseBody()
        {
            var     tpXml   = this.Body;
            Patient Patient = null;

            if (this.Format == FhirApi.FhirFormat.Xml)
            {
                var parser = new Hl7.Fhir.Serialization.FhirXmlParser();
                Patient = parser.Parse <Patient>(tpXml);
            }
            else
            {
                var parser = new Hl7.Fhir.Serialization.FhirJsonParser();
                Patient = parser.Parse <Patient>(tpXml);
            }

            IElementNavigator PocoPatient = new PocoNavigator(Patient);

            this.ApiPatient = new ApiPatient(PocoPatient);
        }
Exemplo n.º 4
0
        protected void ParseResponseBody()
        {
            var    tpXml  = this.Body;
            Bundle Bundle = null;

            if (this.Format == FhirApi.FhirFormat.Xml)
            {
                var parser = new Hl7.Fhir.Serialization.FhirXmlParser();
                Bundle = parser.Parse <Bundle>(tpXml);
            }
            else
            {
                var parser = new Hl7.Fhir.Serialization.FhirJsonParser();
                Bundle = parser.Parse <Bundle>(tpXml);
            }

            IElementNavigator PocoBundel = new PocoNavigator(Bundle);

            foreach (var RelatedPerson in PocoBundel.Select(@"Bundle.entry.select(resource as RelatedPerson)"))
            {
                ApiRelatedPerson ApiRelatedPerson = new ApiRelatedPerson(RelatedPerson);
                ApiRelatedPersonList.Add(ApiRelatedPerson);
            }
        }
Exemplo n.º 5
0
 private Resource DeSerializeFromXml(System.Xml.XmlReader XmlReader)
 {
     Hl7.Fhir.Serialization.FhirXmlParser FhirXmlParser = new Hl7.Fhir.Serialization.FhirXmlParser();
     return(FhirXmlParser.Parse <Resource>(XmlReader));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Process the specified excel file into a dataset file
        /// </summary>
        private static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("SanteDB Vocabulary Importer v{0} ({1})", Assembly.GetEntryAssembly().GetName().Version, Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion);
                Console.WriteLine("Copyright (C) 2015-2022 See NOTICE for contributors");
                var     parms  = new ParameterParser <ConsoleParameters>().Parse(args);
                Dataset retVal = new Dataset()
                {
                    Id     = parms.Name ?? "Imported Dataset",
                    Action = new List <DataInstallAction>()
                };

                // Process a FHIR
                if (parms.Fhir || parms.Csv)
                {
                    if (!File.Exists(parms.SourceFile))
                    {
                        throw new FileNotFoundException($"{parms.SourceFile} not found");
                    }
                    if (parms.Fhir)
                    {
                        using (var fhirFileStream = File.OpenRead(parms.SourceFile))
                        {
                            using (var xreader = XmlReader.Create(fhirFileStream))
                            {
                                var fsz = new Hl7.Fhir.Serialization.FhirXmlParser();
                                var cs  = fsz.Parse <Hl7.Fhir.Model.CodeSystem>(xreader);

                                retVal.Id = $"Import FHIR Code System {cs.Id}";
                                var csId = Guid.NewGuid();
                                retVal.Action.Add(new DataUpdate()
                                {
                                    InsertIfNotExists = true,
                                    Element           = new CodeSystem()
                                    {
                                        Key         = csId,
                                        Authority   = CamelCase(cs.Name),
                                        Url         = cs.Url,
                                        Oid         = cs.Identifier.First(i => i.System == "urn:ietf:rfc:3986").Value,
                                        VersionText = cs.Version,
                                        Name        = cs.Title
                                    }
                                });

                                if (parms.CreateConcept)
                                {
                                    var setId = Guid.NewGuid();
                                    retVal.Action.Add(new DataUpdate()
                                    {
                                        InsertIfNotExists = true,
                                        Element           = new ConceptSet()
                                        {
                                            Key      = setId,
                                            Name     = cs.Name,
                                            Mnemonic = CamelCase(cs.Name),
                                            Url      = cs.Url,
                                            Oid      = cs.Identifier.First(i => i.System == "urn:ietf:rfc:3986").Value
                                        }
                                    });
                                    retVal.Action.AddRange(cs.Concept.SelectMany(o => ConvertToReferenceTerm(o, csId, setId, cs.Name)));
                                }
                                else
                                {
                                    retVal.Action.AddRange(cs.Concept.SelectMany(o => ConvertToReferenceTerm(o, csId, null, null)));
                                }
                            }
                        }
                    }
                    else if (parms.Csv)
                    {
                        // Open excel file stream
                        using (var excelFileStream = File.OpenRead(parms.SourceFile))
                        {
                            using (var importWkb = new XLWorkbook(excelFileStream, new LoadOptions()
                            {
                                RecalculateAllFormulas = false
                            }))
                            {
                                retVal.Action = importWkb.Worksheets.SelectMany(o => o.Rows()).SelectMany(o => CreateReferenceTermInstruction(o, parms)).ToList();
                            }
                        }
                    }

                    if (parms.CreateConcept)
                    {
                        retVal.Action.Add(new DataUpdate()
                        {
                            InsertIfNotExists = true,
                            Element           = new ConceptSet()
                            {
                                ConceptsXml = retVal.Action.Where(o => o.Element is Concept).Select(o => o.Element.Key.Value).ToList(),
                                Mnemonic    = parms.Prefix,
                                Name        = "A new Code System",
                                Oid         = ""
                            }
                        });
                    }
                    if (parms.OutputFile == "-")
                    {
                        new XmlSerializer(typeof(Dataset)).Serialize(Console.Out, retVal);
                    }
                    else
                    {
                        using (var fs = File.Create(parms.OutputFile))
                        {
                            new XmlSerializer(typeof(Dataset)).Serialize(fs, retVal);
                        }
                    }
                }
                else
                {
                    new ParameterParser <ConsoleParameters>().WriteHelp(Console.Out);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error processing file: {0}", e);
            }
        }