如何使用Mirth从XML文件向SQL Server数据库插入数据

3
我希望使用Mirth从XML文件(CCD)中获取数据并将其放入我的SQL Server数据库中。
因此,我已在我的电脑上安装了Mirth Connect管理器,然后创建了一个新通道,源XML文件,目标为我的SQL服务器数据库。我还选择了我的数据库表,自动地Mirth创建了这个查询:
INSERT INTO CLINICAL_DOC_Problems (Id, IdRoot, IdExtension, IdObservationRoot, IdObservationExtension, EffectiveTime, EffectiveTimeMin, EffectivTimeMax, CodeSystem, Code, CodeSystemStatus, CodeStatus, IdSection)
VALUES (, , , , , , , , , , , , )

现在问题是,我想要插入到数据库中的CCD文档(文件.xml)中的部分具有以下结构:
<component>
<section>
    <templateId root='2.16.840.1.113883.10.20.1.11'/> <!-- Problem section template -->
    <code code="11450-4" codeSystem="2.16.840.1.113883.6.1"/> 
    <entry typeCode="DRIV">
        <act classCode="ACT" moodCode="EVN">
            <templateId root='2.16.840.1.113883.10.20.1.27'/> <!-- Problem act template -->
            <id root="6a2fa88d-4174-4909-aece-db44b60a3abb"/>
            <entryRelationship typeCode="SUBJ">
                <observation classCode="OBS" moodCode="EVN">
                    <templateId root='2.16.840.1.113883.10.20.1.28'/> <!-- Problem observation template -->
                    <id root="d11275e7-67ae-11db-bd13-0800200c9a66"/>
                    <code code="ASSERTION" codeSystem="2.16.840.1.113883.5.4"/>                 
                    <effectiveTime><low value="1950"/></effectiveTime>
                    <value xsi:type="CD" code="195967001" codeSystem="2.16.840.1.113883.6.96" displayName="Asthma"/>
                    <entryRelationship typeCode="REFR">
                        <observation classCode="OBS" moodCode="EVN">
                            <templateId root='2.16.840.1.113883.10.20.1.50'/> <!-- Problem status observation template -->
                            <code code="33999-4" codeSystem="2.16.840.1.113883.6.1" displayName="Status"/>
                            <value xsi:type="CE" code="55561003" codeSystem="2.16.840.1.113883.6.96" displayName="Active"/>
                        </observation>
                    </entryRelationship>
                </observation>
            </entryRelationship>
        </act>  
    </entry>
    <entry typeCode="DRIV">
        <act classCode="ACT" moodCode="EVN">
            <templateId root='2.16.840.1.113883.10.20.1.27'/> <!-- Problem act template -->
            <id root="ec8a6ff8-ed4b-4f7e-82c3-e98e58b45de7"/>
            <entryRelationship typeCode="SUBJ">
                <observation classCode="OBS" moodCode="EVN">
                    <templateId root='2.16.840.1.113883.10.20.1.28'/> <!-- Problem observation template -->
                    <id root="ab1791b0-5c71-11db-b0de-0800200c9a66"/>
                    <code code="ASSERTION" codeSystem="2.16.840.1.113883.5.4"/>
                    <value xsi:type="CD" code="233604007" codeSystem="2.16.840.1.113883.6.96" displayName="Pneumonia"/>
                    <entryRelationship typeCode="REFR">
                        <observation classCode="OBS" moodCode="EVN">
                            <templateId root='2.16.840.1.113883.10.20.1.50'/> <!-- Problem status observation template -->
                            <code code="33999-4" codeSystem="2.16.840.1.113883.6.1" displayName="Status"/>
                            <value xsi:type="CE" code="413322009" codeSystem="2.16.840.1.113883.6.96" displayName="Resolved"/>
                        </observation>
                    </entryRelationship>
                </observation>
            </entryRelationship>
        </act>
    </entry>
</section>
</component>

如您所见,有两个标签

entry typeCode="DRIV"

我想在我的数据库中插入与entry标签相同数量的记录。 在这个例子中,我应该在我的数据库中插入2条记录。


如果你在这里指的是同一个患者,那么你就有两个问题或疾病。因此,基本上你需要迭代并使用下面答案中的代码来分别插入每个疾病。 - Shamil
2
离题:我想知道为什么问题状态模板的“value”数据类型是CE。我以前见过它,但是这没有意义,因为没有提供或将提供任何替代编码。在这种情况下,CD数据类型应该可以工作。 - Shamil
1个回答

3
您可以在JavaScript编写器中执行以下操作。我更喜欢JavaScript编写器,因为您拥有更大的灵活性,并且可以从JavaScript调用所有相同的本地Mirth Java。
如果您将XML(如果我理解正确,来自文件阅读器)从源传递到目标,请将目标类型设置为JavaScript编写器,然后按如下方式遍历对象:
var dbConn;
try {
    dbConn = DatabaseConnectionFactory.createConnection(driver, address, username, password);
    var xml = new XML(connectorMessage.getEncodedData());
    for(var i = 0; i < xml.section.entry.length(); i++) {
        if(xml.section.entry[i].@typeCode == 'DRIV') {
            var myData = xml.section.entry[i].act;
            var myQuery = '';
            //do something with myVar to get a query...
            dbConn.executeCachedQuery(myQuery);
        }
    }
} catch (ex) {
    //handle any exceptions...
}

使用E4X迭代XML: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X_tutorial


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接