【发布时间】:2022-01-19 08:24:39
【问题描述】:
我有很多类似于下面的 json 资源。但是,我只需要获取满足两个条件的 json 资源: (1) component.code.text == 舒张压 (2) valueQuantity.value
这是 JSON 对象/资源
{
"fullUrl": "urn:uuid:edf9439b-0173-b4ab-6545 3b100165832e",
"resource": {
"resourceType": "Observation",
"id": "edf9439b-0173-b4ab-6545-3b100165832e",
"component": [ {
"code": {
"coding": [ {
"system": "http://loinc.org",
"code": "8462-4",
"display": "Diastolic Blood Pressure"
} ],
"text": "Diastolic Blood Pressure"
},
"valueQuantity": {
"value": 81,
"unit": "mm[Hg]",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
}, {
"code": {
"coding": [ {
"system": "http://loinc.org",
"code": "8480-6",
"display": "Systolic Blood Pressure"
} ],
"text": "Systolic Blood Pressure"
},
"valueQuantity": {
"value": 120,
"unit": "mm[Hg]",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
} ]
},
}
我需要编写一个条件来获取带有文本的资源:“舒张压” AND valueQuantity.value > 90
我写了以下代码:
def self.hypertension_observation(bundle)
entries = bundle.entry.select {|entry| entry.resource.is_a?(FHIR::Observation)}
observations = entries.map {|entry| entry.resource}
hypertension_observation_statuses = ((observations.select {|observation| observation&.component&.at(0)&.code&.text.to_s == 'Diastolic Blood Pressure'}) && (observations.select {|observation| observation&.component&.at(0)&.valueQuantity&.value.to_i >= 90}))
end
我得到的输出没有任何错误。但是,输出中不满足第二个条件。输出包含偶数
请任何人帮助纠正这个关于仅获取的红宝石代码,输出包含值
【问题讨论】:
-
请将 JSON 减少到最低限度;为 JSON 提供这么多不相关的条目是没有意义的;我看不到里面的组件
-
我已经编辑了兄弟。现在看清楚了吗?
标签: arrays json ruby dictionary select