Replies: 16 comments 23 replies
-
The typical place you would do that is in a response transformer. That does mean making a databae call with javacript in the response transformer itself. |
Beta Was this translation helpful? Give feedback.
-
Thanks Pacman, I have the JS built just not sure on how to reference the message sent and on how to trigger the event. ... |
Beta Was this translation helpful? Give feedback.
-
In Mirth, the response received from any destination is stored in a response object named with the letter d and the destination's number. You also have access to response information by adding a response transformer to the destination. So you can add a destination to your channel in which you do the work up updating a database based on the response you received from the prior destination. Every one of your destinations will also have access to the message as it emerged from your source connector. Make sure your new destination waits for the prior destination before firing (this is the default behavior.) (This is an exercise in the fundamentals course, btw.) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion about the training. I've asked my manager about Mirth Training, we will see. I have my database inserts working correctly referencing the data fields in the sent channel. I am having a problem referencing the statuscode of the first destination channel.
My error is apparently on line 297, but 297 is not part of my code.
|
Beta Was this translation helpful? Give feedback.
-
Before Mirth Connect calls your transformer code it executes about 100 lines of setup in JavaScript, which is why your line number is surprising. But the complaint of an unexpected token "<" is saying Mirth is trying to parse the data which came back in your connector's response. By changing your anticipated response type to Raw on inbound and outbound for the destination in which the error is occurring, you'll turn off the connector's attempt to parse the response. Or, probably, setting the data type to XML will allow the response transformer to treat the entire response as XML, from which you can extract anything embedded in the response.
You can change anticipated response types by clicking Set Data Types on your summary screen.
The error is being generated on your "Insert audit row..." destination so that is the one where you'd want to set your data type to XML (or raw). On line 297 of the Javascript, "msg = JSON.parse(connectorMessage.getTransformedData());" is what triggers the error, and unless you have written such a line, that is Mirth Connect attempting to treat your response data as JSON, when it is coming back to you as XML. You can also change how your HTTP Sender handles the response, but this may cause you additional problems. There is a choice of "Plain Body" or "XML Body" for response content on the HTTP Sender.
Most likely, you are getting back an XML response body, which has JSON embedded inside an XML node, but are passing the root node of your XML into JSON.parse().
…On Thu, May 25, 2023, 6:21 AM LanciaH ***@***.***> wrote:
Hi Jon,
Another suggestion was to set the data type of the response in the SEND
Medication Channel. I tried a couple of different scenarios but they all
end with the same response.
All I want is the response from the previous destination channel, "Send
Medication"
The error from their server ooks like
*HTTP Sender error ERROR MESSAGE:
{"data":false,"totalRecords":0,"statusCode":400,"error":"2000624446079710:
VALIDATION_FAILURE: Only DcDate, DcReason and OnHold are allowed to be
updated.;"}*
I have limited my transformer code to
var resp = $('d1').getMessage();
logger.info(resp);
and I still get the same error.
Transformer error ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL:
Fusion_PatientMeds- New Orders-Audit 4 CONNECTOR: Insert audit row to
emar_patient_flags2 SCRIPT SOURCE: SOURCE CODE: 292: } 293:
eval('importPackage(' +
Packages.java.lang.Class.forName(className).getPackage().getName() + ')');
294: } 295: } 296: function doScript() { 297: msg =
JSON.parse(connectorMessage.getTransformedData()); 298: function doFilter()
{ phase[0] = 'filter'; return true; }function doTransform() { phase[0] =
'transformer'; logger =
Packages.org.apache.log4j.Logger.getLogger(phase[0]); 299: 300: 301: var
resp = $('d1').getMessage(); LINE NUMBER: 297 DETAILS: SyntaxError:
Unexpected token: <
—
Reply to this email directly, view it on GitHub
<#5774 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVPNVAG3MIOGQWXT6F6GUDXH5MD5ANCNFSM6AAAAAAX2GS2HE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Perhaps try this or similar, and tell us what gets logged: var destination1Response = responseMap.get('d1'); |
Beta Was this translation helpful? Give feedback.
-
I think but am not sure that you don't want to use the connector's name in the responseMap.get call. You want to look up the destination number of your connector Entity_Medications on the Destinations tab of your channel. If it is destination 4, use responseMap.get('d4'). |
Beta Was this translation helpful? Give feedback.
-
I made the following change.
|
Beta Was this translation helpful? Give feedback.
-
FWIW, there are going to be different sets of issues potentially involved here. You have multiple destinations on your channel. Let's say you have two destinations which operate sequentially; there's a checkbox that is normally checked that says a destination will wait for the previous destination to complete. If that is checked, so that destination 2 runs after destination 1 completes, you should not have a null return value when calling responseMap.get('d1') from your second destination. So maybe your second destination doesn't have that box checked? In addition to or instead of trying to retrieve destination 1's response object from within destination 2, you can also retrieve destination 1 response information in a response transformer placed on destination 1. What Mirth will do is look at the inbound response data type for the response, and, based on that type, convert it as necessary. If you get back XML, it will still be XML; if it were a pipe-hat style HL7 message, it will be converted to XML. If JSON, it may stay JSON, I'm not certain. But if it tries to parse XML as JSON, or vice versa you'll get an error when it attempts to do the parsing. What pacmano1 is showing above is a response, probably to a Mirth API call, which has come back as JSON. The JSON is just one part of the response object, the "message." |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if you're saying your problem is solved.
I'm not sure why you feel you must create an XML object out of
$('Entity_Medications').
But if you can log out rsp or extract error information from it, the only
other thing to do to make it available to any subsequent destination is to
put it into the channelMap with channelMap.put('rsp',rsp);
If you put rsp into the channelMap, you are placing an XML object into the
channel map. If you put rsp.toString() into the channel map you are
putting a string representation of rsp into the channel map.
If you're not sure about what type $('Entity_Medications') is returning,
you can write:
logger.info(typeof $('Entity_Medications'))
…On Thu, May 25, 2023 at 11:41 AM LanciaH ***@***.***> wrote:
" second destination doesn't have that box checked?" It does
"a response transformer placed on destination 1" That is exactly where it
is, in Destination one "Edit Response"
In my first destination channel I have the following code in the edit
response and the logger works and displays what I am sending to the vendor.
All I want is the response and to be able to reference it.
`$('Entity_Medications')
if($('Entity_Medications')!=""){
var rsp = new XML($('Entity_Medications'));
var success = false;
var errorString = false;
try{
errorString = rsp.toString().split("<a:Errors>")[1].split("</a:Errors>")[0];
error = true
}
catch(Exception){
error =false;
errorString = false;
}
logger.info(rsp)`
—
Reply to this email directly, view it on GitHub
<#5774 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVPNVBEZNZ2KKWVW2D7U43XH6RT3ANCNFSM6AAAAAAX2GS2HE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hi Mitch the type returned is object. Let me start over. I send the vendor medications and the vendor sends back a statusCode, 200 good, 400 bad. I need to capture this statusCode. If 200 do the Audit table Insert. If 400 do nothing. See the screen hsots |
Beta Was this translation helpful? Give feedback.
-
That's very helpful, thanks.
So you are getting back JSON. You want to set the Data Type of your Send
Medication Response to JSON inbound and could also set it to JSON
outbound. You do that off the dialog screen which appears when, on your
channel's Summary tab, you press "Set Data Types" just under the channel's
name in the "Channel Properties" frame.
Then, when you add a response transformer to your Send Medication
destination, the statusCode from the JSON will be available in the response
transformer as msg['statusCode'].
In the response transformer, to put the value into the channel map for use
by later destinations:
channelMap.put('statusCode', msg['statusCode']); // or
msg['statusCode']*.toString()
*if needed
In any later destination to get the statusCode back,
channelMap.get('statusCode');
…On Thu, May 25, 2023 at 4:11 PM LanciaH ***@***.***> wrote:
Hi Mitch the type returned is *object.*
Let me start over. I send the vendor medications and the vendor sends back
a statusCode, 200 good, 400 bad.
I need to capture this statusCode. If 200 do the Audit table Insert. If
400 do nothing.
See the screen hsots
[image: statusCode200]
<https://user-images.githubusercontent.com/104143486/241079599-a9915dd9-c116-4aeb-bd0a-fb5d6ab08904.jpg>
[image: statusCode400]
<https://user-images.githubusercontent.com/104143486/241079605-baf32fea-e006-4d94-b0bd-1ccb9bd5aeff.jpg>
—
Reply to this email directly, view it on GitHub
<#5774 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVPNVHQZCXR6F3HQN3UPNTXH7RI7ANCNFSM6AAAAAAX2GS2HE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
(You add your response transformer to the Send Medications destination by first highlighting that destination in the destinations tab, then selecting Edit Response from the Channel Tasks menu to the left, then clicking Add New Step in the Transformer Tasks menu and either putting msg['statusCode'] in as your mapping and statusCode as your variable name, or changing the step from Mapper (what you get when you click Add New Step) to JavaScript and entering JS as in the comment above.) |
Beta Was this translation helpful? Give feedback.
-
Mitch, This is perfect, This is all I needed in the first place. Thanks so much for our help.
In the next Channel, Insert audit row to emar_patient_flags2, I reference vStatusCode
|
Beta Was this translation helpful? Give feedback.
-
Now getting back to pacmano1's suggestion. Can I put my database insert under the first Channel's edit response? And get rid of the second channel? |
Beta Was this translation helpful? Give feedback.
-
Having the additional destination would, among other things, give you an
easy way to check counts, spot failures, etc.... But you can put JavaScript
in the Response transformer if you wish, and have it do whatever you want.
Think of Mirth as a framework where you can use services it provides while
rolling your own custom needs in JavaScript.
…On Fri, May 26, 2023, 5:49 AM LanciaH ***@***.***> wrote:
Now getting back to pacmano1's suggestion. Can I put my database insert
under the first Channel's edit response? And get rid of the second channel?
—
Reply to this email directly, view it on GitHub
<#5774 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVPNVGBN7UHEIZUQNFOFALXICRGZANCNFSM6AAAAAAX2GS2HE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hi All,
Very much a newbie here. I have a channel that sends data, everything is working as expected.
The vendor has asked me to insert the data sent into an oracle database after successful sending of the data, statuscode = 200.
{
"data" : true,
"totalRecords" : 1,
"statusCode" : 200,
"error" : ""
}
Not Sure where to start. In the channel, under the destination tab, I created another Destination to handle the database insert. I only want this destination to fire when there is a statuscode of 200. Pretty sure I have to create a "filter" that return a true? Also in the insert how do I reference the values sent? Is there an example I can download?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions