英文:
Iterate through a FHIR element binding
问题
我正在尝试迭代FHIR能力声明,以获取服务器支持的所有问题和值集的列表。
我已经下载了FHIR能力声明,以及随后的结构定义,然后在结构定义中迭代每个快照元素。
一些元素具有"binding",我可以从控制台和调试断点中看到它们已经正确填充,但我无法确定在代码中正确访问它们的方法。
例如,即时窗口提供了有关"element.Binding.ValueSet"的以下信息:
element.Binding.ValueSet
{url: http://hl7.org/fhir/ValueSet/adverse-event-category}
Children: {Hl7.Fhir.Model.ResourceReference.<get_Children>d__32}
Display: null
DisplayElement: null
ElementId: null
Extension: Count = 0
Identifier: null
IsContainedReference: false
NamedChildren: {Hl7.Fhir.Model.ResourceReference.<get_NamedChildren>d__34}
Reference: "http://hl7.org/fhir/ValueSet/adverse-event-category"
ReferenceElement: {Value="http://hl7.org/fhir/ValueSet/adverse-event-category"}
Type: null
TypeElement: null
TypeName: "Reference"
Url: {http://hl7.org/fhir/ValueSet/adverse-event-category}
Results View: Expanding the Results View will enumerate the IEnumerable
但我无法访问这些"属性",例如:
"element.Binding.ValueSet.Reference"返回
element.Binding.ValueSet.Reference
error CS1061: 'DataType' does not contain a definition for 'Reference' and no accessible extension method 'Reference' accepting a first argument of type 'DataType' could be found (are you missing a using directive or an assembly reference?)
当我查看类型或属性时,我得到以下内容:
element.Binding.ValueSet.GetType() (results abridged)
{Name = "ResourceReference" FullName = "Hl7.Fhir.Model.ResourceReference"}
Assembly: {Hl7.Fhir.Support.Poco, Version=4.3.0.0, Culture=neutral, PublicKeyToken=d706911480550fc3}
AssemblyQualifiedName: "Hl7.Fhir.Model.ResourceReference, Hl7.Fhir.Support.Poco, Version=4.3.0.0, Culture=neutral, PublicKeyToken=d706911480550fc3"
BaseType: {Name = "DataType" FullName = "Hl7.Fhir.Model.DataType"}
DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22}
DeclaredProperties: {System.Reflection.PropertyInfo[13]}
FullName: "Hl7.Fhir.Model.ResourceReference"
Module (System.Reflection.MemberInfo): {Hl7.Fhir.Support.Poco.dll}
Module: {Hl7.Fhir.Support.Poco.dll}
Name: "ResourceReference"
Namespace: "Hl7.Fhir.Model"
UnderlyingSystemType: {Name = "ResourceReference" FullName = "Hl7.Fhir.Model.ResourceReference"}
element.Binding.ValueSet.GetType().GetProperties()
{System.Reflection.PropertyInfo[14]}
[0]: {System.String TypeName}
[1]: {Hl7.Fhir.Model.FhirString ReferenceElement}
[2]: {System.String Reference}
[3]: {Hl7.Fhir.Model.FhirUri TypeElement}
[4]: {System.String Type}
[5]: {Hl7.Fhir.Model.Identifier Identifier}
[6]: {Hl7.Fhir.Model.FhirString DisplayElement}
[7]: {System.String Display}
[8]: {System.Collections.Generic.IEnumerable'1[Hl7.Fhir.Model.Base] Children}
[9]: {System.Collections.Generic.IEnumerable'1[Hl7.Fhir.Model.ElementValue] NamedChildren}
[10]: {System.Uri Url}
[11]: {Boolean IsContainedReference}
[12]: {System.String ElementId}
[13]: {System.Collections.Generic.List`1[Hl7.Fhir.Model.Extension] Extension}
我可以将这个对象转换成列表,它似乎是一些键值对的可枚举集合:
element.Binding.ValueSet.ToList()
Count = 1
[0]: {[reference, {Value=http://hl7.org/fhir/ValueSet/adverse-event-category}]}
但调用"element.Binding.ValueSet.Keys"或"element.Binding.ValueSet.Values"也不起作用。
使用这个对象的正确方法是什么?
英文:
I'm trying to iterate through a FHIR capability statement to pull down a list of all the questions and values sets that are supported by the server.
I have a downloaded FHIR capability statement, and subsequent structure definition and within the structure definition I am iterating through each snapshot element.
Some of the elements have a binding
, which I can see is correctly populated from the console and debug break points but I can't determine the correct way to access this in code.
For example, the immediate window is giving me the following information about the element.Binding.ValueSet
:
> element.Binding.ValueSet
{url: http://hl7.org/fhir/ValueSet/adverse-event-category}
Children: {Hl7.Fhir.Model.ResourceReference.<get_Children>d__32}
Display: null
DisplayElement: null
ElementId: null
Extension: Count = 0
Identifier: null
IsContainedReference: false
NamedChildren: {Hl7.Fhir.Model.ResourceReference.<get_NamedChildren>d__34}
Reference: "http://hl7.org/fhir/ValueSet/adverse-event-category"
ReferenceElement: {Value="http://hl7.org/fhir/ValueSet/adverse-event-category"}
Type: null
TypeElement: null
TypeName: "Reference"
Url: {http://hl7.org/fhir/ValueSet/adverse-event-category}
Results View: Expanding the Results View will enumerate the IEnumerable
But I can't access these "Properties", for example:
element.Binding.ValueSet.Reference
returns
> element.Binding.ValueSet.Reference
> error CS1061: 'DataType' does not contain a definition for 'Reference' and no accessible extension method 'Reference' accepting a first argument of type 'DataType' could be found (are you missing a using directive or an assembly reference?)
When I interrogate the type or properties I get the following:
> element.Binding.ValueSet.GetType() (results abridged)
> {Name = "ResourceReference" FullName = "Hl7.Fhir.Model.ResourceReference"}
> Assembly: {Hl7.Fhir.Support.Poco, Version=4.3.0.0, Culture=neutral, PublicKeyToken=d706911480550fc3}
> AssemblyQualifiedName: "Hl7.Fhir.Model.ResourceReference, Hl7.Fhir.Support.Poco, Version=4.3.0.0, Culture=neutral,
> PublicKeyToken=d706911480550fc3"
> BaseType: {Name = "DataType" FullName = "Hl7.Fhir.Model.DataType"}
> DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22}
> DeclaredProperties: {System.Reflection.PropertyInfo[13]}
> FullName: "Hl7.Fhir.Model.ResourceReference"
> Module (System.Reflection.MemberInfo): {Hl7.Fhir.Support.Poco.dll}
> Module: {Hl7.Fhir.Support.Poco.dll}
> Name: "ResourceReference"
> Namespace: "Hl7.Fhir.Model"
> UnderlyingSystemType: {Name = "ResourceReference" FullName = "Hl7.Fhir.Model.ResourceReference"}
> element.Binding.ValueSet.GetType().GetProperties()
> {System.Reflection.PropertyInfo[14]}
> [0]: {System.String TypeName}
> [1]: {Hl7.Fhir.Model.FhirString ReferenceElement}
> [2]: {System.String Reference}
> [3]: {Hl7.Fhir.Model.FhirUri TypeElement}
> [4]: {System.String Type}
> [5]: {Hl7.Fhir.Model.Identifier Identifier}
> [6]: {Hl7.Fhir.Model.FhirString DisplayElement}
> [7]: {System.String Display}
> [8]: {System.Collections.Generic.IEnumerable'1[Hl7.Fhir.Model.Base] Children}
> [9]: {System.Collections.Generic.IEnumerable'1[Hl7.Fhir.Model.ElementValue]
> NamedChildren}
> [10]: {System.Uri Url}
> [11]: {Boolean IsContainedReference}
> [12]: {System.String ElementId}
> [13]: {System.Collections.Generic.List`1[Hl7.Fhir.Model.Extension] Extension}
I can convert this object to a list, it appears to be some enumerable of KVPs:
> element.Binding.ValueSet.ToList()
> Count = 1
> [0]: {[reference, {Value=http://hl7.org/fhir/ValueSet/adverse-event-category}]}
But calling for the element.Binding.ValueSet.Keys
or element.Binding.ValueSet.Values
does not work either
What is the correct way to work with this object?
答案1
得分: 1
假设您正在使用FHIR STU3,element.Binding.ValueSet
将是通用数据类型,可以表示任何FHIR数据类型,因为此元素是选择属性,可以是Reference类型或Uri类型之一。访问内部数据的方法是将ValueSet属性转换为ResourceReference或使用as ResourceReference
,然后您将能够访问引用属性。
英文:
Assuming you are using FHIR STU3, element.Binding.ValueSet
will be of the generic DataType which can mean any of the FHIR datatypes, since this element is a choice property and could be either of type Reference or Uri.
The way to access the data inside is to cast the ValueSet property to ResourceReference or use as ResourceReference
, after which you'll be able to access the reference properties.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论