【问题标题】:Can't access Procedure.reason in FHIR model无法访问 FHIR 模型中的 Procedure.reason
【发布时间】:2016-03-22 00:12:47
【问题描述】:

我正在使用带有 DSTU2 的 Fhir-net-api 将 JSON 对象解析为 C# 模型。一切正常,除了我无法访问资源类型 ProcedureReason 元素。例如,我使用 FhirParser 将以下 JSON 对象解析为过程模型:

{
"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 对象中的数据是否错误? 我已经看到 Reason 属于 Hl7.Fhir.Model.Element 类型,而 Report 属于 Hl7.Fhir.Model 类型。资源参考。有没有办法将 Reason 更改为 Hl7.Fhir.Model.ResourceReference 然后访问 Reference 元素?

将不胜感激任何提示。谢谢。

问候,

电车

【问题讨论】:

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


    【解决方案1】:

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

    当元素可以是多种类型时(我们称之为“选择元素”,您可以识别它们,因为它们的名称在规范中以 [x] 结尾),我们创建了一个类型为 @987654333 的 C# 成员@(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
    }
    

    当然,如果您确定只能接收原因为 ResourceReference 的实例,则可以直接进行强制转换:

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

    【讨论】:

    • 太棒了。这对我来说应该足够可行。我没有想过简单地将对象转换为所需的类型。谢谢
    猜你喜欢
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多