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

使用Mirth Connect及MDHT库获取CCDA文件就诊详情的技术求助

解决Mirth Connect中CCDA就诊详情(Encounter Details)的解析问题

嘿,我看你在Mirth Connect解析CCDA的就诊信息这块卡壳了,刚好我对这块有点经验,给你支几招~

首先得说,你当前代码里用get(4)来定位Section的方式很容易出问题——不同CCDA文档的Section顺序可能不一样,硬编码索引根本不可靠,这也是你可能找不到正确就诊信息的原因之一。

CCDA中就诊信息的标准结构

CCDA里的就诊信息一般在Encounters Section(对应的LOINC编码是46240-8),这个Section下会包含一个或多个<encounter>条目,每个条目里包含了就诊的核心细节:

  • 就诊唯一ID
  • 就诊类型(比如门诊、住院、急诊)
  • 就诊的开始/结束时间
  • 就诊机构/地点
  • 关联的诊断信息(部分文档会包含)

修正后的Mirth Connect代码示例

下面是更可靠的解析方式,通过LOINC码定位Encounters Section,再提取就诊详情:

// 加载CCDA文档
var doc = org.openhealthtools.mdht.uml.cda.util.CDAUtil.load(new java.io.ByteArrayInputStream(connectorMessage.getRawData().getBytes("UTF-8")));
var structuredBody = doc.getStructuredBody();
var encountersSection = null;

// 遍历所有Section,精准定位Encounters Section(通过LOINC码46240-8)
for (var i = 0; i < structuredBody.getComponents().size(); i++) {
    var sectionComponent = structuredBody.getComponents().get(i);
    var section = sectionComponent.getSection();
    
    if (section != null) {
        var sectionCode = section.getCode();
        // 匹配LOINC码,确保找到正确的就诊Section
        if (sectionCode != null && sectionCode.getCode().equals("46240-8")) {
            encountersSection = section;
            break;
        }
    }
}

if (encountersSection != null) {
    // 获取所有就诊条目
    var encounterList = encountersSection.getEncounters();
    for (var j = 0; j < encounterList.size(); j++) {
        var currentEncounter = encounterList.get(j);
        
        // 解析就诊核心字段(记得加空值判断,避免空指针异常)
        var encounterId = currentEncounter.getId() != null 
            ? currentEncounter.getId().getRoot() + "-" + currentEncounter.getId().getExtension() 
            : "无ID";
        
        var encounterType = currentEncounter.getCode() != null 
            ? currentEncounter.getCode().getDisplayName() 
            : "未指定类型";
        
        var startTime = currentEncounter.getEffectiveTime() != null && currentEncounter.getEffectiveTime().getLow() != null
            ? currentEncounter.getEffectiveTime().getLow().getValue()
            : "无开始时间";
        
        var endTime = currentEncounter.getEffectiveTime() != null && currentEncounter.getEffectiveTime().getHigh() != null
            ? currentEncounter.getEffectiveTime().getHigh().getValue()
            : "无结束时间";
        
        var facilityName = currentEncounter.getParticipant() != null && currentEncounter.getParticipant().size() > 0
            ? currentEncounter.getParticipant().get(0).getParticipantRole().getPlayingEntity().getName()
            : "未记录机构";
        
        // 这里可以把解析后的数据插入SQL数据库,示例:
        // var insertSql = "INSERT INTO encounters (encounter_id, type, start_time, end_time, facility) VALUES (?, ?, ?, ?, ?)";
        // db.executeInsert(insertSql, [encounterId, encounterType, startTime, endTime, facilityName]);
        
        logger.info("解析到就诊信息:ID=" + encounterId + ", 类型=" + encounterType + ", 时间=" + startTime + "至" + endTime);
    }
} else {
    logger.error("当前CCDA文档中未找到Encounters Section(LOINC:46240-8)");
}

关键注意事项

  • 不要依赖Section索引:不同机构生成的CCDA,Section的排列顺序可能差异很大,必须通过LOINC码或模板ID来定位,这是保证兼容性的核心。
  • 空值判断不能少:CCDA里很多字段是可选的,比如部分就诊可能没有结束时间,必须先判断对象是否为空再调用方法,避免Mirth抛出空指针错误。
  • 时间格式转换:MDHT返回的时间字符串可能需要进一步转换(比如从yyyyMMddHHmmss转成SQL支持的yyyy-MM-dd HH:mm:ss格式),可以用Mirth的日期工具类处理。
  • MDHT API扩展:如果需要解析更多字段(比如就诊诊断),可以探索Encounter对象的其他方法(比如getDiagnosis()),适配你的业务需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 17:28:14