【问题标题】:How to get an element in FHIR API?如何在 FHIR API 中获取元素?
【发布时间】:2020-12-20 08:06:28
【问题描述】:

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

    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]

【问题讨论】:

  • 这意味着你有一个标识符列表,你必须通过列表来获取数据。列表包含什么?
  • 你有什么异常吗?你是否通过代码来确定你失败的地方?将 try 块放在创建 FhirClient 的行周围,以防构造函数失败。如果您没有收到任何异常,则可能患者不在数据库中。您可能使用了错误的数据库。

标签: c# hl7-fhir


【解决方案1】:

您的搜索是针对没有“状态”搜索参数或字段的患者。您使用的服务器消除了搜索参数,并在条目中发回包含患者的 Bundle - 这是根据 FHIR 规范。

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

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

【讨论】:

  • 感谢您的回复。还有一个,我用“2018-03-16&status=planned”替换了“status=planned”,但没有用,那么正确的语法是什么?谢谢
  • 患者没有状态,因此您无法搜索。您可以根据服务器支持的内容搜索姓名、生日、地址等。标准搜索参数列表见hl7.org/fhir/STU3/patient.html#search
  • 对不起,我的意思是 Encounter,将“status=planned”替换为“date=2018-03-16&status=planned”
  • 该语法是正确的,但是您在代码中提到的服务器没有该搜索的任何结果。在尝试对条目进行处理之前检查 Bundle.total。
猜你喜欢
  • 2019-06-18
  • 1970-01-01
  • 2016-04-20
  • 2011-12-11
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多