gpt4 book ai didi

javascript - 使用 JavaScript 从 SOAP 响应中提取特定值

转载 作者:行者123 更新时间:2023-11-28 04:15:24 29 4
gpt4 key购买 nike

我需要使用 JavaScript 从以下 SOAP 响应中提取患者 ID (PATAA000000040) 并将其插入到 Mirth 目标中。该值位于 LivingSubjectId 标签下。该标签可能会重复,但我们需要获取第一个 LivingSubjectId 迭代值。

如何编写 JavaScript?

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope
xmlns:S="http://www.w3.org/2003/05/soap-envelope">
<S:Body>
<ns3:RespondingGateway_PRPA_IN201306UV02Response
xmlns="urn:gov:hhs:fha:NwHINc:common:NwHINccommon"
xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:ns3="urn:hl7-org:v3"
xmlns:ns4="urn:gov:hhs:fha:NwHINc:common:patientcorrelationfacade">
<ns3:communityResponse>
<ns3:PRPA_IN201306UV02 ITSVersion="XML_1.0" nullFlavor="">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002" extension="245c45ce:137cd5bcb6d:-7f4d"/>
<ns3:creationTime value="201268183250"/>
<ns3:interactionId root="2.16.840.1.113883.1.6" extension="PRPA_IN201306UV02"/>
<ns3:processingCode code="P"/>
<ns3:processingModeCode code="T"/>
<ns3:acceptAckCode code="NE"/>
<ns3:receiver typeCode="RCV">
<ns3:device classCode="DEV" determinerCode="INSTANCE">
<ns3:id/>
<ns3:asAgent classCode="AGNT">
<ns3:representedOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.3.609.10.330.000"/>
</ns3:representedOrganization>
</ns3:asAgent>
</ns3:device>
</ns3:receiver>
<ns3:sender typeCode="SND">
<ns3:device classCode="DEV" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.3.609.10.330.002"/>
<ns3:asAgent classCode="AGNT">
<ns3:representedOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.3.609.10.330.002"/>
</ns3:representedOrganization>
</ns3:asAgent>
</ns3:device>
</ns3:sender>
<ns3:acknowledgement>
<ns3:typeId root="2.16.840.1.113883.1.6" extension="PRPA_IN201305UV02"/>
<ns3:typeCode code="AA"/>
<ns3:targetMessage xsi:nil="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns3:acknowledgement>
<ns3:controlActProcess nullFlavor="" classCode="CACT" moodCode="EVN">
<ns3:code code="PRPA_TE201306UV" codeSystem="2.16.840.1.113883.1.6"/>
<ns3:authorOrPerformer nullFlavor="" typeCode="AUT">
<ns3:assignedDevice classCode="ASSIGNED">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.1"/>
</ns3:assignedDevice>
</ns3:authorOrPerformer>
<ns3:subject typeCode="SUBJ">
<ns3:registrationEvent classCode="REG" moodCode="EVN">
<ns3:id nullFlavor="NA"/>
<ns3:statusCode code="active"/>
<ns3:subject1 typeCode="SBJ">
<ns3:patient classCode="PAT">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.1" extension="PATAA002000040"/>
<ns3:statusCode code="SD"/>
<ns3:patientPerson classCode="PSN" determinerCode="INSTANCE">
<ns3:name>
<ns3:family partType="FAM">LastName40</ns3:family>
<ns3:given partType="GIV">FirstName40</ns3:given>
<ns3:given partType="GIV">MN40</ns3:given>
</ns3:name>
<ns3:telecom value="tel:+1-417-831-1475"/>
<ns3:administrativeGenderCode code="M"/>
<ns3:birthTime value="19350213"/>
<ns3:addr>
<ns3:streetAddressLine>225 E Commercial St</ns3:streetAddressLine>
<ns3:city>Springfield</ns3:city>
<ns3:state>MO</ns3:state>
<ns3:postalCode>65803</ns3:postalCode>
</ns3:addr>
<ns3:asOtherIDs classCode="SD">
<ns3:id root="2.16.840.1.113883.4.1" extension="990000040"/>
<ns3:scopingOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.4.1"/>
</ns3:scopingOrganization>
</ns3:asOtherIDs>
</ns3:patientPerson>
<ns3:providerOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.1"/>
<ns3:contactParty xsi:nil="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns3:providerOrganization>
<ns3:subjectOf1>
<ns3:queryMatchObservation classCode="CASE" moodCode="EVN">
<ns3:code code="IHE_PDQ"/>
<ns3:value xsi:type="ns3:INT" value="100"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns3:queryMatchObservation>
</ns3:subjectOf1>
</ns3:patient>
</ns3:subject1>
<ns3:custodian typeCode="CST">
<ns3:assignedEntity classCode="ASSIGNED">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.1"/>
<ns3:code code="NotHealthDataLocator" codeSystem="1.3.6.1.4.1.19376.1.2.27.2"/>
</ns3:assignedEntity>
</ns3:custodian>
</ns3:registrationEvent>
</ns3:subject>
<ns3:subject typeCode="SUBJ">
<ns3:registrationEvent classCode="REG" moodCode="EVN">
<ns3:id nullFlavor="NA"/>
<ns3:statusCode code="active"/>
<ns3:subject1 typeCode="SBJ">
<ns3:patient classCode="PAT">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.2" extension="PATAA002000040"/>
<ns3:statusCode code="SD"/>
<ns3:patientPerson classCode="PSN" determinerCode="INSTANCE">
<ns3:name>
<ns3:family partType="FAM">LastName40</ns3:family>
<ns3:given partType="GIV">FirstName40</ns3:given>
<ns3:given partType="GIV">MN40</ns3:given>
</ns3:name>
<ns3:telecom value="tel:+1-417-831-1475"/>
<ns3:administrativeGenderCode code="M"/>
<ns3:birthTime value="19350213"/>
<ns3:addr>
<ns3:streetAddressLine>225 E Commercial St</ns3:streetAddressLine>
<ns3:city>Springfield</ns3:city>
<ns3:state>MO</ns3:state>
<ns3:postalCode>65803</ns3:postalCode>
</ns3:addr>
<ns3:asOtherIDs classCode="SD">
<ns3:id root="2.16.840.1.113883.4.1" extension="990000040"/>
<ns3:scopingOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.4.1"/>
</ns3:scopingOrganization>
</ns3:asOtherIDs>
</ns3:patientPerson>
<ns3:providerOrganization classCode="ORG" determinerCode="INSTANCE">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.2"/>
<ns3:contactParty xsi:nil="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns3:providerOrganization>
<ns3:subjectOf1>
<ns3:queryMatchObservation classCode="CASE" moodCode="EVN">
<ns3:code code="IHE_PDQ"/>
<ns3:value xsi:type="ns3:INT" value="100"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns3:queryMatchObservation>
</ns3:subjectOf1>
</ns3:patient>
</ns3:subject1>
<ns3:custodian typeCode="CST">
<ns3:assignedEntity classCode="ASSIGNED">
<ns3:id root="2.16.840.1.113883.3.609.20.330.002.2"/>
<ns3:code code="NotHealthDataLocator" codeSystem="1.3.6.1.4.1.19376.1.2.27.2"/>
</ns3:assignedEntity>
</ns3:custodian>
</ns3:registrationEvent>
</ns3:subject>
<ns3:queryAck>
<ns3:queryId root="2.16.840.1.113883.3.609.10.330.000" extension="-abd3453dcd24wkkks545"/>
<ns3:queryResponseCode code="OK"/>
</ns3:queryAck>
<ns3:queryByParameter>
<ns3:queryId root="2.16.840.1.113883.3.609.10.330.000" extension="-abd3453dcd24wkkks545"/>
<ns3:statusCode code="new"/>
<ns3:responseModalityCode code="R"/>
<ns3:responsePriorityCode code="I"/>
<ns3:parameterList>
<ns3:livingSubjectAdministrativeGender>
<ns3:value code="M"/>
<ns3:semanticsText representation="TXT"/>
</ns3:livingSubjectAdministrativeGender>
<ns3:livingSubjectBirthTime>
<ns3:value value="19350213"/>
<ns3:semanticsText representation="TXT"/>
</ns3:livingSubjectBirthTime>
<ns3:livingSubjectId>
<ns3:value root="2.16.840.1.113883.3.609.20.330.000" extension="PATAA000000040"/>
<ns3:semanticsText representation="TXT"/>
</ns3:livingSubjectId>
<ns3:livingSubjectId>
<ns3:value root="2.16.840.1.113883.4.1" extension=""/>
<ns3:semanticsText representation="TXT"/>
</ns3:livingSubjectId>
<ns3:livingSubjectName>
<ns3:value>
<ns3:prefix partType="PFX"/>
<ns3:given partType="GIV">FirstName40</ns3:given>
<ns3:given partType="GIV"/>
<ns3:family partType="FAM">LastName40</ns3:family>
<ns3:suffix partType="PFX"/>
</ns3:value>
<ns3:semanticsText representation="TXT"/>
</ns3:livingSubjectName>
<ns3:patientAddress>
<ns3:value/>
</ns3:patientAddress>
<ns3:patientTelecom>
<ns3:value value=""/>
<ns3:semanticsText representation="TXT"/>
</ns3:patientTelecom>
</ns3:parameterList>
</ns3:queryByParameter>
</ns3:controlActProcess>
</ns3:PRPA_IN201306UV02>
<ns3:NwHINTargetCommunity>
<homeCommunity>
<homeCommunityId>2.16.840.1.113883.3.609.10.330.002</homeCommunityId>
</homeCommunity>
</ns3:NwHINTargetCommunity>
</ns3:communityResponse>
</ns3:RespondingGateway_PRPA_IN201306UV02Response>
</S:Body>
</S:Envelope>

这是我尝试过的:

msg = new XML(msg);
logger.info(msg);
var soap = new Namespace('http://www.w3.org/2003/05/soap-envelope');
var edeia = new Namespace('http://schemas.xmlsoap.org/ws/2004/08/addressing');
var PatientID = msg.soap::Body.edeia::controlActProcess.edeia::queryByParameter.edeia::livingSubjectId.toString();
logger.info(PatientID);
channelMap.put('PatientID',PatientID);

但是在 Mirth 中出现以下错误:

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException:
CHANNEL: Test SOAP Response
CONNECTOR: sourceConnector
SCRIPT SOURCE:
SOURCE CODE:
39: }
40: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPackage().getName() + ')');
41: }
42: }
43: function doScript() {
44: msg = new XML(connectorMessage.getTransformedData());
45: if (msg.namespace('') != undefined) { default xml namespace = msg.namespace(''); } else { default xml namespace = ''; }
46: function doFilter() { phase[0] = 'filter'; return true; }function doTransform() { phase[0] = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase[0]);
47:
48:
LINE NUMBER: 44
DETAILS: TypeError: The content of elements must consist of well-formed character data or markup.
at a2b07c33-e451-4e76-9a96-81c0fdf80552:44 (doScript)
at a2b07c33-e451-4e76-9a96-81c0fdf80552:79
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

最佳答案

我认为您没有正确解析 XML 标记,这就是错误的内容。我收到了这样的 SOAP 响应。

<S:Envelope xmlns:S="http://test.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://test.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns1:addInformation xmlns:ns2="http://Getdatawebservice/">;
<send>
<MrnNumber>MRN5023150</MrnNumber>
<isError>True</isError>
<ErrorReason>Patient deceased</ErrorReason>
</send>
</ns1:addInformation>
</S:Body>
</S:Envelope>

下面是我用来从响应消息中获取 ErrorReason 标记详细信息的代码。我在目标的编辑响应选项卡中编写了此代码。

//Replace : completely, mirth somehow not takes it
var updateMsg= new XML (msg).toString().replace(/:/g,”)
//Create a new XML using it
var newMsg= new XML (updateMsg);
//Get the specific Error Reason XML tag value
var checkError = newmsg[‘SBody’][‘ns1addInformation ‘][‘send’][‘isError’].toString();
// Not required in your scenario
if(checkError==”false”)
{
var errorMessage = “Message Sent Successfully”;
channelMap.put(“errorMessage”,errorMessage);
}

您也可以使用上面相同的代码来解析您的必填字段。它应该有效。对于您所说的情况下的迭代,它可能会出现多次,您必须执行循环逻辑。

关于javascript - 使用 JavaScript 从 SOAP 响应中提取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45914572/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com