Sql server 如何使用Mirth从xml文件在sqlserver数据库中插入数据
我想使用Mirth从XML文件(CCD)中获取数据,并将其放入sqlserver数据库中 所以我已经在我的pc上安装了Mirth connect administrator,然后我刚刚用源XML文件创建了一个新的通道,并将其连接到我的SQL server数据库的目标。我还选择了数据库的表,并自动创建了以下查询:Sql server 如何使用Mirth从xml文件在sqlserver数据库中插入数据,sql-server,xml,mirth,ccd,hl7-v3,Sql Server,Xml,Mirth,Ccd,Hl7 V3,我想使用Mirth从XML文件(CCD)中获取数据,并将其放入sqlserver数据库中 所以我已经在我的pc上安装了Mirth connect administrator,然后我刚刚用源XML文件创建了一个新的通道,并将其连接到我的SQL server数据库的目标。我还选择了数据库的表,并自动创建了以下查询: INSERT INTO CLINICAL_DOC_Problems (Id, IdRoot, IdExtension, IdObservationRoot, IdObservationE
INSERT INTO CLINICAL_DOC_Problems (Id, IdRoot, IdExtension, IdObservationRoot, IdObservationExtension, EffectiveTime, EffectiveTimeMin, EffectivTimeMax, CodeSystem, Code, CodeSystemStatus, CodeStatus, IdSection)
VALUES (, , , , , , , , , , , , )
现在的问题是,我的CCD文档(file.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>
正如你所看到的,有两个标签
条目类型代码=“DRIV”
我想在我的数据库中插入和条目标记一样多的记录。
在本例中,我需要在数据库中插入2条记录。您可以在JavaScript编写器中执行以下操作。我更喜欢JavaScript编写器而不是数据库编写器,因为您具有更大的灵活性,可以从JavaScript调用所有相同的原生mirthjava 如果您将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...
}
var-dbConn;
试一试{
dbConn=DatabaseConnectionFactory.createConnection(驱动程序、地址、用户名、密码);
var xml=new-xml(connectorMessage.getEncodedData());
for(var i=0;i
通过XML的迭代是使用E4X完成的:如果您愿意,这里有两个问题或疾病,都是指同一个患者。因此,基本上您必须迭代并使用下面答案中的代码分别插入每个疾病。离题:我想知道为什么问题状态模板的“值”数据类型是CE。我以前见过它,但它没有意义,因为没有或将提供替代编码。在这种情况下,CD数据类型应该可以工作。