JavaScript can be used to extract a specific value from a SOAP response

In order to extract the Patient ID (PATAA000000040) from the SOAP response below using JavaScript and insert it into a Mirth destination, we need to target the value under the livingSubjectId tag. It's important to note that this tag may repeat, but we should only consider the first iteration of livingSubjectId.

How would you implement this in 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">
           [SOAP Response Continued...]

This is an attempted solution:

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);

However, the following error occurred in Mirth:

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException: 
CHANNEL:    Test SOAP Response
CONNECTOR:  sourceConnector
SCRIPT SOURCE:  
SOURCE CODE:    
[Detailed error message continues...]

Answer №1

It seems like the XML tag is not being parsed correctly, which is causing the error message to appear. When I received a SOAP response, it looked like this.

<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>

The code snippet below demonstrates how I extracted details from the ErrorReason tag within the response message. This code was written in the Edit Response section of the destination.

//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);
    }

You can utilize the above code to parse other fields as well. It should be effective. If you encounter multiple occurrences of the field, you'll need to implement looping logic.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Flot seems to be having difficulty uploading JSON files

I am relatively new to working with json and flot, but have been tasked with creating a chart. Can someone please help me troubleshoot why my code is not functioning as expected? $.getJSON('chart.json', function(graphData){ alert(graphData); ...

JavaScript and PHP are successfully displaying a success message despite the data not being saved to the database

I recently added a new feature to my website where users can submit a form using Javascript without having to reload or refresh the page. This allows for a seamless experience and displays success messages instantly. However, being a newcomer to Javascript ...

How do I redirect with a GET method after calling the *delete* method in Node / Express server?

As someone new to AJAX and Node, I encountered a dilemma that I hope to get some guidance on. Here's the issue: I have a DELETE ajax call that removes a row from the database and I want to redirect back to the same route with a GET method afterwards. ...

Angular: A guide to binding to the required/ngRequired attribute

There is a directive that may or may not be required, and it can be used in two different ways. <my-foo required></my-foo> or <my-foo ng-required="data.value > 10"></my-foo> Even though require and ngRequire are essentially t ...

Uncovering components generated by React JS with BeautifulSoup

My goal is to extract anchor links with the class "_1UoZlX" from the search results on a specific page - After analyzing the page, I realized that the search results are dynamically generated by React JS and not readily available in the page source or HTM ...

Understanding Multiple Type Scenarios in React with Typescript

Code Demonstration: type PropsType = {top: number} | {bottom: number} // The function that moves something in one direction by a specific distance. function move(props: PropsType) { ... } Expected Usage: move({top: 100}) or move({bottom: 100}) Avoid us ...

How to efficiently monitor and calculate changes in an array of objects using Vue?

I have a collection named people that holds data in the form of objects: Previous Data [ {id: 0, name: 'Bob', age: 27}, {id: 1, name: 'Frank', age: 32}, {id: 2, name: 'Joe', age: 38} ] This data can be modified: New ...

Timepicker.js - Incorrect Placement of Time Picker in Certain Scenarios

Utilizing the timepicker.js library to select a time, I am encountering an issue. When clicking on the input field, the timepicker should appear next to it. This function works as expected when the input is within the main view of the document. However, if ...

What could possibly be causing my app to exhaust CPU resources on Mozilla Firefox?

I have created a unique game application for Facebook. Currently, the app is not optimized with AJAX technology, resulting in multiple server requests causing high CPU usage (specifically in Firefox) which slows down the overall performance of the app. Alt ...

Evaluating QUnit Test Cases

How do you write a test method in QUnit for validating functions developed for a form? For example, let's consider a form where the name field should not be left blank. If the validation function looks like this: function validNameCheck(form) { if ...

I encountered an issue where the error "data.map is not a function" occurs whenever I try to execute a React component

I have implemented the HorizontalScrollbar component and passed data as a prop. When I try to run the HorizontalScrollbar component, I encounter the following error in the console tab of Chrome: Error: Uncaught TypeError: data.map is not a function Horiz ...

What is the best way to retrieve the post JSON data in the event of a 404 error?

When my service call returns a 404 error, I want to display the server's message indicating the status. The response includes a status code and message in JSON format for success or failure. This is an example of my current service call: this._trans ...

Experiencing difficulties with JavaScript/jQuery when encountering the 'use strict' error

I have been working on a small function to change the background of an HTML file, but I keep getting the 'Missing 'use strict' statement' error message from JSLint despite trying multiple solutions. Can anyone suggest how to resolve th ...

Reset input field when checkbox is deselected in React

How can I bind value={this.state.grade} to clear the input text when the checkbox is unchecked? The issue is that I am unable to modify the input field. If I were to use defaultValue, how would I go about clearing the input box? http://jsbin.com/lukewahud ...

Error TS2403: All variable declarations following the initial declaration must be of the same type in a React project

While developing my application using Reactjs, I encountered an error upon running it. The error message states: Subsequent variable declarations must have the same type. Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2 ...

Guide to transforming an embed/nested FormGroup into FormData

Presenting my Form Group: this.storeGroup = this.fb.group({ _user: [''], name: ['', Validators.compose([Validators.required, Validators.maxLength(60)])], url_name: [''], desc: ['', Validators.compose([Valida ...

Utilizing AngularJS and RequireJS to incorporate a controller into the view

I am facing an issue while trying to add an Angular controller to my HTML view. Typically, in Angular, this can be done using: ng-controller="<controller>". However, due to my use of RequireJS, I have had to implement it differently. I need to includ ...

Guide on transferring Javascript array to PHP script via AJAX?

I need to send a JavaScript array to a PHP file using an AJAX call. Here is the JavaScript array I am working with: var myArray = new Array("Saab","Volvo","BMW"); This JavaScript code will pass the array to the PHP file through an AJAX request and displ ...

A guide to integrating Material-UI with your Meteor/React application

I encountered an issue while trying to implement the LeftNav Menu from the Material-UI example. The error message I received is as follows: While building for web.browser: imports/ui/App.jsx:14:2: /imports/ui/App.jsx: Missing class properties transf ...

Focus on selecting each label within a table using JavaScript

In my current setup, I am attempting to customize radio buttons and checkboxes. Array.from(document.querySelectorAll("tr")).forEach((tr,index)=>{ var mark=document.createElement("span"); Array.from(tr.querySelectorAll("input")).forEach((inp,index ...