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

如何创建按指定键优先级/插入顺序排序的metadata对象?

生成指定结构的Metadata对象(按生命体征采集时间排序键优先级)

需求说明

需要创建一个固定结构的metadata对象,核心要求是对象的键优先级必须遵循allVitals数组按taken_on日期降序排序后的项的vital_type.name顺序。即便存在同类型的多条生命体征记录,每个类型在metadata中仅保留一个条目,排序优先级由该类型最新记录的位置决定。

基础Metadata结构

{
  glucose: {
    name: '血糖',
    units: 'mg/dL',
  },
  height: {
    name: '身高',
    units: '"',
    longUnit: '英寸',
  },
  weight: {
    name: '体重',
    units: 'lbs',
    longUnit: '磅',
  },
  bmi: {
    name: 'BMI',
  },
  pulse: {
    name: '脉搏',
  },
  temperature: {
    name: '体温',
    units: '℉',
    longUnit: '华氏度',
  },
  respiration_rate: {
    name: '呼吸频率',
  },
  o2_saturation: {
    name: '血氧饱和度',
    units: '%',
  },
}

排序规则示例

给定以下allVitals数组:

const allVitals = [{
  patient_id: 79,
  vital_type_id: 6,
  value: "9.76",
  taken_on: "2022-11-17T11:07:00.000-06:00",
  vital_type: {
    id: 6,
    name: "glucose",
    units: "mg/dL",
    created_at: "2022-11-17T13:52:00.360-06:00",
    updated_at: "2022-11-17T13:52:00.360-06:00",
  },
  notes: null,
  source: "patient_device",
  id: 1366,
  time_recorded: true,
  severity: "critical_low",
  formatted_severity: "Critical - Low",
  vital_attributes: {},
  vital_status: "valid",
}, {
  patient_id: 79,
  vital_type_id: 4,
  value: "171",
  taken_on: "2022-11-17T13:19:00.000-06:00",
  vital_type: {
    id: 4,
    name: "weight",
    units: "pounds",
    created_at: "2022-11-17T13:52:00.375-06:00",
    updated_at: "2022-11-17T13:52:00.375-06:00",
  },
  notes: null,
  source: "patient_device",
  id: 1399,
  time_recorded: true,
  severity: null,
  formatted_severity: "-",
  vital_attributes: {},
  vital_status: "valid",
}];

由于weight的采集时间晚于glucose,排序后weight键需排在glucose之前,最终生成的metadata结构如下:

{
  weight: {
    name: '体重',
    units: 'lbs',
    longUnit: '磅',
  },
  glucose: {
    name: '血糖',
    units: 'mg/dL',
  },
  height: {
    name: '身高',
    units: '"',
    longUnit: '英寸',
  },
  bmi: {
    name: 'BMI',
  },
  pulse: {
    name: '脉搏',
  },
  temperature: {
    name: '体温',
    units: '℉',
    longUnit: '华氏度',
  },
  respiration_rate: {
    name: '呼吸频率',
  },
  o2_saturation: {
    name: '血氧饱和度',
    units: '%',
  },
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 11:01:29