Jolt转换技术求助:OMH转FHIR时日期格式转换需求
解决方案:修改Jolt规则实现日期格式转换
输入数据
{ "heart_rate": { "value": 70, "unit": "beats/min" }, "effective_time_frame": { "time_interval": { "start_date_time": "11/01/22 22:14:21" } }, "descriptive-statistics": "minimum" }
预期输出
{ "effectiveDateTime": "2022-11-01", "valueQuantity": { "value": 70, "unit": "beats/minute", "code": "/min", "system": "http://unitsofmeasure.org" }, "descriptive-statistics": "minimum" }
修改后的Jolt转换规则
[ // 1. 映射核心字段,同时保留原始日期用于后续处理 { "operation": "shift", "spec": { "effective_time_frame": { "time_interval": { "start_date_time": ["tempStartDateTime", "effectiveDateTime"] } }, "heart_rate": { "value": "valueQuantity.value" }, "descriptive-statistics": "&" // 不需要保留此字段可删除此行 } }, // 2. 转换日期格式:MM/DD/YY HH:MM:SS → YYYY-MM-DD { "operation": "modify-default-beta", "spec": { "year": "=concat('20',=substring(@(tempStartDateTime),6,8))", "month": "=substring(@(tempStartDateTime),0,2)", "day": "=substring(@(tempStartDateTime),3,5)", "effectiveDateTime": "=concat(@(year),'-',@(month),'-',@(day))" } }, // 3. 清理临时字段 { "operation": "remove", "spec": { "tempStartDateTime": "", "year": "", "month": "", "day": "" } }, // 4. 补充valueQuantity默认属性 { "operation": "default", "spec": { "valueQuantity": { "code": "/min", "system": "http://unitsofmeasure.org", "unit": "beats/minute" } } } ]
关键修改说明
Shift操作优化:
- 新增
tempStartDateTime临时字段保存原始日期字符串,避免Shift后原始路径丢失导致后续无法引用 - 可选保留
descriptive-statistics字段,按需调整
- 新增
日期转换逻辑:
- 通过
substring精准截取原始日期的年、月、日部分:- 年份:截取第6-8位的后两位年份,拼接
20补全为4位年份 - 月份:截取第0-2位的MM部分
- 日期:截取第3-5位的DD部分
- 年份:截取第6-8位的后两位年份,拼接
- 用
concat按YYYY-MM-DD格式拼接新日期,覆盖原effectiveDateTime值
- 通过
临时字段清理:
- 通过Remove操作删除转换过程中生成的临时字段,保证输出结构整洁
内容的提问来源于stack exchange,提问作者mbGraz
相关产品推荐
相关产品推荐

