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
相关产品推荐
相关产品推荐

