web stats
Is it possible to set source mappings? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2018, 09:43 AM
llong llong is offline
What's HL7?
 
Join Date: Jul 2018
Posts: 5
llong is on a distinguished road
Unhappy Is it possible to set source mappings?

I'm pulling a JSON message from a database and then routing it to a different channel based off of the channel name in a channel column.

My issue is that the channel it routes to is looking for the JSON in the following Source variable $s('content'), however it doesn't exist when entering the channel this way. I can't change the logic of the channel as it is being used to handle POST calls and works perfectly that way because the Source variables get assigned properly.

I'm trying to re-inject bad messages into this channel and they don't parse right. I tried using channelMap.put('content', request);, but it wouldn't read correctly as it's stored in the Channel scope

I want to manually set the Source variables but can't seem to find a way
Reply With Quote
  #2  
Old 07-13-2018, 11:48 AM
calvinouk calvinouk is offline
Mirth Employee
 
Join Date: Jan 2015
Posts: 2
calvinouk is on a distinguished road
Default

How are you routing the message from the first channel that reads from the database to the second one? If you're using a channel writer for channel #1, you can set a variable in the Message Metadata, and that variable should appear in the Source map when received by channel #2.
__________________
Integration Engineer, Connected Health Services
NextGen Healthcare

Last edited by calvinouk; 07-13-2018 at 11:52 AM.
Reply With Quote
  #3  
Old 07-14-2018, 10:39 AM
llong llong is offline
What's HL7?
 
Join Date: Jul 2018
Posts: 5
llong is on a distinguished road
Default

Here is the whole workflow:

1. ) HTTP Listener (Receives inbound POST requests from client) on the source, javascript writer on the destination to route based off of the method in the request
2. ) Receives from 1, and is set as a channel reader as the source, and javascript writer as the destination (this is the channel I'm re-injecting the message to), routes to two other channels within this
3. ) Continues onto vendors

The message comes into 1 in an XML body with a tag of "Content" that contains the JSON. When it is received in 1 it automatically is parsed into the Source variables based on what's in the XML tag. I'm not sure how it does it, but that's what I've noticed.

When it gets routed to 2 from 1 it transfers those source variables because the XML is still being sent. Still unsure of how this works.

When I'm re-injecting the message it is no longer contained in the XML structure and just the JSON itself so it doesn't get parsed to Source variables.

4. ) Channel injecting into 2. This channel is set as a database reader on the source, on the destination it is set as an empty JavaScript writer. In the transformer I'm setting two variables from the msg that was read in the database reader. One labeled "channel" and another labeled "messageBody". I then call a custom function called "callChannel" to route the message so I can get a response and then store that back into the database with an update query.

I don't have it as a channel writer as there are a number of possibilities it can route to (though I could set it up as various destinations with channel writers and write a filter to distinguish which one to go to). I did try briefly setting the "messageBody" variable in the Message Metadata but it didn't work, the message just had "messageBody" in Metadata but didn't contain a variable called 'content' when getting back to 2.

Edit 1: I went back and changed "messageBody" to content and did a test between two channels.

I set the variable "content" to "TEST" and then set up a channel writer with metadata of "content" and passed to another channel with a channel reader ad it didn't pass the variable to the source.

Edit 2: Figured it out, so I did what you mentioned of putting the "content" variable name in the Message Metadata on a channel writer, but figured out why it wasn't working because I was trying to pass "var content = 'TEST'" instead of doing "channelMap.put('content', 'TEST')" which I changed it to and worked. Is there a way to pass Message Metadata in a javascript writer? I'd rather it be done that way instead of having to create 50 different destinations with a filter based off the channel name.

Last edited by llong; 07-14-2018 at 11:14 AM. Reason: Solved
Reply With Quote
  #4  
Old 07-16-2018, 06:20 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 330
agermano is on a distinguished road
Default

http://javadocs.mirthcorp.com/connec.../VMRouter.html

You can pass routeMessage a RawMessage rather than a string. You can initialize the sourceMap when you create a RawMessage.
Reply With Quote
Reply

Tags
json source scope

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:54 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Mirth Corporation