如何在 FHIR API 中获取元素?

问题描述

我试图获取诸如标识符、位置、句点等元素,但不起作用。我怎么才能得到它? 我的代码如下:

    static void Main(string[] args)
    {
        //The fhir server end point address      
        string ServiceRootUrl = "http://stu3.test.pyrohealth.net/fhir";
        //Create a client to send to the server at a given endpoint.
        var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl);
        // increase timeouts since the server might be powered down
        FhirClient.Timeout = (60 * 1000);

        Console.WriteLine("Press any key to send to server: " + ServiceRootUrl);
        Console.WriteLine();
        Console.ReadKey();
        try
        {
            //Attempt to send the resource to the server endpoint
            Hl7.Fhir.Model.Bundle ReturnedSearchBundle = FhirClient.Search<Hl7.Fhir.Model.Patient>(new string[] { "status=planned" });
            Console.WriteLine(string.Format("Found: {0} Fhirman patients.",ReturnedSearchBundle.Total.ToString()));
            Console.WriteLine("Their logical IDs are:");
            foreach (var Entry in ReturnedSearchBundle.Entry)
            {
                Console.WriteLine("ID: " + Entry.Resource.Id);
                Console.WriteLine("ID2: " + Entry.Identifier);
            }
            Console.WriteLine();
        }
        catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec)
        {
            //Process any Fhir Errors returned as OperationOutcome resource
            Console.WriteLine();
            Console.WriteLine("An error message: " + FhirOpExec.Message);
            Console.WriteLine();
            string xml = Hl7.Fhir.Serialization.Fhirserializer.SerializeResourcetoXml(FhirOpExec.Outcome);
            XDocument xDoc = XDocument.Parse(xml);
            Console.WriteLine(xDoc.ToString());
        }
        catch (Exception GeneralException)
        {
            Console.WriteLine();
            Console.WriteLine("An error message: " + GeneralException.Message);
            Console.WriteLine();
        }
        Console.WriteLine("Press any key to end.");
        Console.ReadKey();
    }

结果是 System.Collections.Generic.List`1[Hl7.Fhir.Model.Identifier]

解决方法

您搜索的是没有“状态”搜索参数和字段的患者。您使用的服务器消除了搜索参数,并在条目中发回了一个包含患者的捆绑包 - 这符合 FHIR 规范。

foreach 中的第一行 (Console.WriteLine("ID: " + Entry.Resource.Id);) 将输出资源的技术 ID。由于条目上没有标识符字段,我假设您的第二个字段实际上读取的是 Entry.Resource.Identifier。 Patient.identifier 字段是一个 0..* 标识符列表,因此您必须选择其中之一。标识符数据类型又是一种复杂的数据类型,通常会填充系统和值字段。因此,您可以执行以下操作 - 假设标识符列表包含一个项目:

var patient = (Patient)Entry.Resource;
Console.WriteLine($"Patient identifier: {patient.Identifier[0].System} {patient.Identifier[0].Value}");

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...