微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 FHIR API 中获取元素?

如何解决如何在 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}");

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。