试图将子类添加到Fhir.Net资源并使其序列化



由于我们尝试设置FHIR通信的合作伙伴使用的是FHIR架构的中间版本,因此他们发送并期望使用具有organization元素的Practicer/PracticerRoleComponent,而不是FHIR.NET API所期望的managingOrganization

我已经将Practicer和PracticerRoleComponent进行了子类化,并使对象创建良好,因此Practicer现在在我们的案例中有了一个自定义的"THXPractionerRole"。没有遇到任何错误,我已经在子类中放置了所有属性(见下文)。

然而,当我序列化到XML时,结果根本没有PracticerRole——似乎序列化程序完全忽略了它。我猜FHIR.Net序列化程序有某种检查,以确保它们只序列化有效的FHIR类型?或者我在子类中遗漏了什么,可能会阻止它工作吗?

我所说的API在这里:https://github.com/ewoutkramer/fhir-net-api/tree/develop

目标是能够在生成的XML/Json中具有Practice/practicationerRole/organization元素。

[FhirType("Practitioner", IsResource = true)]
[DataContract]
public partial class THXPractitioner : Hl7.Fhir.Model.Practitioner, System.ComponentModel.INotifyPropertyChanged
{
[FhirElement("practitionerRole", Order = 170)]
[Cardinality(Min = 0, Max = -1)]
[DataMember]
public List<THXPractitionerRoleComponent> THXPractitionerRole
{
get { if (_PractitionerRole == null) _PractitionerRole = new List<THXPractitionerRoleComponent>(); return _PractitionerRole; }
set { _PractitionerRole = value; OnPropertyChanged("PractitionerRole"); }
}
private List<THXPractitionerRoleComponent> _PractitionerRole;

[FhirType("PractitionerRoleComponent")]
[DataContract]
public partial class THXPractitionerRoleComponent : Hl7.Fhir.Model.Practitioner.PractitionerRoleComponent, System.ComponentModel.INotifyPropertyChanged, IBackboneElement
{
[NotMapped]
public override string TypeName { get { return "PractitionerRoleComponent"; } }
/// <summary>
/// Organization where the roles are performed
/// </summary>
[FhirElement("organization", Order = 40)]
[References("Organization")]
[DataMember]
public ResourceReference organization
{
get { return _organization; }
set { _organization = value; OnPropertyChanged("organization");}
}
private ResourceReference _organization;
}

以下是它的名称:

fhirpractitioner.THXPractitionerRole = new List<Model.THXPractitioner.THXPractitionerRoleComponent>()
{
new Model.THXPractitioner.THXPractitionerRoleComponent()
{
Extension = new List<Extension>()
{
new Extension()
{
Url = "[My Url]",
}
},
organization = new ResourceReference()
{
Reference = "asdfasfd"
,Display = "organization"
,DisplayElement= new FhirString("organization")
}
}
};

谢谢。

我的一位同事最终在GitHub上发现了这个项目的"问题":

https://github.com/ewoutkramer/fhir-net-api/issues/337

因此,我最终获得了该库的副本,并遵循问题线程中提出的想法进行了重新编译。我们现在有了一个自定义库。

来自问题:

当前处理自定义资源的唯一方法是为其创建StructureDefinition,将其添加到Model/Source目录中的profiles-resources.xml文件中,然后重新运行T4模板-您将获得自己版本的.NET库,并为自己的资源提供POCO。。。。

我做到了这一点,在通过Visual Studio中的Run Custom Tool上下文菜单选项运行Template-Model.tt之前,必须删除Generated/p执业者.cs文件。完成后,使用我们的新/自定义资源生成了Practice.cs文件,库能够将其序列化为我们需要的XML。

由于没有正式的FHIR版本可以满足您的需求,因此也没有可以使用的库版本,我们认为您最好的选择是派生库的源代码(请参阅https://github.com/ewoutkramer/fhir-net-api)。然后,您可以查找其他资源以查看其组件的代码,并更改Practicer以包含PracticerRoleComponent。构建解决方案,您将能够将其用作您的库,而不是官方库。

最新更新