C# 如何在FHIR API中获取元素?

C# 如何在FHIR API中获取元素?,c#,hl7-fhir,C#,Hl7 Fhir,我尝试获取标识符、位置、周期等元素。。。但不起作用。我怎样才能得到它? 我的代码如下: static void Main(string[] args) { //The fhir server end point address string ServiceRootUrl = "http://stu3.test.pyrohealth.net/fhir"; //Create a client to sen

我尝试获取标识符、位置、周期等元素。。。但不起作用。我怎样才能得到它? 我的代码如下:

    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();
    }
static void Main(字符串[]args)
{
//fhir服务器端点地址
字符串ServiceRootUrl=”http://stu3.test.pyrohealth.net/fhir";
//创建客户端以发送到给定端点处的服务器。
var FhirClient=new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl);
//增加超时,因为服务器可能已关机
FhirClient.Timeout=(60*1000);
Console.WriteLine(“按任意键发送到服务器:“+ServiceRootUrl”);
Console.WriteLine();
Console.ReadKey();
尝试
{
//尝试将资源发送到服务器终结点
Hl7.Fhir.Model.Bundle返回的searchbundle=FhirClient.Search(新字符串[]{“status=planned”});
WriteLine(string.Format(“Found:{0}Fhirman patients.”,ReturnedSearchBundle.Total.ToString());
WriteLine(“它们的逻辑ID是:”);
foreach(ReturnedSearchBundle.Entry中的var条目)
{
Console.WriteLine(“ID:+Entry.Resource.ID”);
Console.WriteLine(“ID2:+Entry.Identifier”);
}
Console.WriteLine();
}
捕获(Hl7.Fhir.Rest.Fhir操作异常FhirOpExec)
{
//处理作为OperationOutcome资源返回的任何Fhir错误
Console.WriteLine();
Console.WriteLine(“错误消息:+FhirOpExec.message”);
Console.WriteLine();
字符串xml=Hl7.Fhir.Serialization.fhirsializer.SerializeResourceToXml(FhirOpExec.output);
XDocument xDoc=XDocument.Parse(xml);
Console.WriteLine(xDoc.ToString());
}
catch(异常GeneralException)
{
Console.WriteLine();
Console.WriteLine(“错误消息:“+GeneralException.message”);
Console.WriteLine();
}
Console.WriteLine(“按任意键结束”);
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[0].System}{Patient.identifier[0].Value}”);

这意味着您有一个标识符列表,您必须浏览该列表才能获得数据。这个列表包含什么?你有例外吗?您是否逐级检查代码以确定失败的地方?在创建FhirClient的行周围放置try块,以防构造函数失败。如果您没有得到任何异常,那么患者可能不在数据库中。您可能使用了错误的数据库。感谢您的回复。还有一点,我用“2018-03-16&status=planned”替换了“status=planned”,但不起作用,那么正确的语法是什么呢?ThanksA患者没有状态,因此您无法搜索该状态。您可以根据服务器支持的内容搜索姓名、出生日期、地址等。有关标准搜索参数的列表,请参阅。对不起,我的意思是使用Conference,将“status=planned”替换为“date=2018-03-16&status=planned”,语法正确,但是您在代码中提到的服务器没有任何搜索结果。在尝试处理条目之前,请检查Bundle.total。