You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DMN FEEL表达式过滤嵌套复杂对象列表的技术问询

DMN FEEL表达式实现components列表过滤需求

需求说明

从给定的components复杂对象列表中,过滤出满足components[].code.coding.code = "48005-3"的项,最终返回对应项的valueCodeableConcept.coding.code字段值。

输入数据示例

{
  "components": [
    {
      "code": {
        "coding": [
          {
            "system": "http://loinc.org",
            "code": "48005-3"
          }
        ]
      },
      "valueCodeableConcept": {
        "coding": [
          {
            "system": "http://varnomen.hgvs.org",
            "code": "p.Val455Met"
          }
        ],
        "text": "V455M"
      }
    },
    {
      "code": {
        "coding": [
          {
            "system": "http://loinc.org",
            "code": "53037-8"
          }
        ]
      },
      "valueCodeableConcept": {
        "coding": [
          {
            "system": "http://loinc.org",
            "code": "LA26333-7"
          }
        ],
        "text": "Variant of Uncertain Significance"
      }
    }
  ]
}

错误表达式分析

你之前编写的表达式存在多层不必要的嵌套循环,会遍历所有coding和code属性,每次判断后返回组件或null,最终得到包含所有遍历结果的列表,不符合预期:

(context)
for aComponent in components return
for aCoding in aComponent.code.coding return
for aCode in aCoding return if aCode.code="48005-3" = true then aComponent else null

正确FEEL表达式实现

方案1:使用filter函数筛选后提取字段

filter(components, c -> some coding in c.code.coding satisfies coding.code = "48005-3").valueCodeableConcept.coding.code

方案2:使用for...where循环提取

for c in components 
where some coding in c.code.coding satisfies coding.code = "48005-3"
return c.valueCodeableConcept.coding.code

说明

  • 两种方案均通过some ... satisfies判断组件的coding列表中是否存在指定code值的项,符合FEEL集合判断语法
  • 直接筛选出符合条件的组件后提取目标字段,避免了无效的嵌套循环
  • 针对示例输入,上述表达式会返回结果:["p.Val455Met"]

内容的提问来源于stack exchange,提问作者Mallesh Nagothi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 11:37:21