如何获取 FHIR API 中的元素?
How to get an element in 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]
您搜索的是患者,该患者没有 'status' 搜索参数或字段。您使用的服务器消除了搜索参数,并在条目中发回一个包含患者的捆绑包 - 这是根据 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}");
我尝试获取标识符、位置、句点等元素,但没有成功。我怎么才能得到它? 我的代码如下:
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]
您搜索的是患者,该患者没有 'status' 搜索参数或字段。您使用的服务器消除了搜索参数,并在条目中发回一个包含患者的捆绑包 - 这是根据 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}");