c# - 无法访问 FHIR 模型中的 Procedure.reason

标签 c# json asp.net-mvc hl7-fhir dstu2-fhir

我将 Fhir-net-api 与 DSTU2 结合使用,将 JSON 对象解析为 C# 模型。一切正常,只是我无法访问资源类型 ProcedureReason 元素。例如,我使用 FhirParser 将以下 JSON 对象解析为 Procedure 模型:

{
"resourceType": "Procedure",
"identifier": [
    {
        "system": "https://mrd2.melanoma.org.au/fhir",
        "value": "100200199664802"
    }
],
"subject": { "reference": "Patient/10101000001733" },
"status": "completed",
"category": {
    "coding": [
        {
            "system": "https://mrd2.melanoma.org.au/fhir/RootType",
            "code": "3004"
        }
    ],
    "text": "Primary Surgery"
},
"bodySite": [
    {
        "coding": [
            {
                "system": "http://snomed.info/sct",
                "code": "7771000"
            }
        ],
        "text": "Left Forearm, Anterior"
    }
],
"reasonReference": { "reference": "/Condition/10106000001807" },
"performedDateTime": "1968-03-11",
"report": [ { "reference": "/DiagnosticReport/100200199664828" } ]
}

并且生成的对象具有以下条目(摘录): Procedure

我可以很好地访问 Report[0].Reference,但它不能与 Reason.Reference 一起使用。我的 JSON 对象中的数据是否有误? 我看到 ReasonHl7.Fhir.Model.Element 类型,ReportHl7.Fhir.Model 类型。资源引用。有没有办法将 Reason 更改为 Hl7.Fhir.Model.ResourceReference 然后访问 Reference 元素?

如有任何提示,我们将不胜感激。谢谢。

问候,

拉米

最佳答案

如您所见,reasonReference 的类型是 Model.Element,而 report 的类型是 ResourceReference。这种差异源于 FHIR specification for Procedure 中这些元素的定义。 ,其中 report 固定为 Reference 类型,但 reason(或者更确切地说 reason[x])可以是CodeableConceptReference

当元素可以是多种类型时(我们称之为“选择元素”,您可以识别它们,因为它们的名称在规范中以 [x] 结尾),我们创建了一个 C# Model.Element 类型的成员(Reference 和 CodeableConcept 的基类)。

现在,根据您刚刚解析或接收的实例,reason 成员的内容可以是这两种类型之一。因此,您必须检查您的代码:

if(Reports[0].reason is ResourceReference)
{
    var reference = (ResourceReference)Reports[0].reason;
    //handle the case where this is a reference
    //doing reference.Reference will now work as expected
}
else if(Reports[0].reason is CodeableConcept)
{
    var concept = (CodeableConcept)Reports[0].reason;
    //handle the case where this is a codeable concept
}
else
{
    // Oops! Should not happen unless the standard has changed
}

当然,如果你确定你只能接收reason是ResourceReference的实例,你可以直接做一个cast:

var myReference = (ResourceReference)Reports[0].Reference;
// myReference.Reference and myReference.Display will now work

关于c# - 无法访问 FHIR 模型中的 Procedure.reason,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302188/

相关文章:

c# - 在 ASP.NET 中上传文件时,超出最大请求长度

c# - 用于制作 linq anyFlags(MyFlag) 的标志和枚举

C# - StreamReader/StreamWriter - 另一个进程使用的文件

javascript - 从 JSON 字符串元素中提取 JSON 表

javascript - Amazon S3 客户端加密 Javascript

c# - Controller 参数 MVC ASP.NET

c# - 在 C# 中确定类的 default() 值

javascript - 如何解决 javascript 中 JSON 中的意外标记 { 语法错误

asp.net-mvc - 如何在 MVC 5 中创建 Multi-Tenancy View 结构

c# - MVC 单选按钮选择一个