web stats
HOw to implement Dispatch Pattern based on incoming Message contents (X12 source)? - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 02-03-2014, 03:47 PM
eduardoa eduardoa is offline
Mirth Employee
 
Join Date: Mar 2013
Location: Santa Fe Springs, California
Posts: 134
eduardoa is on a distinguished road
Default

Depending on whether you would like to just use the X12 as your message you could do this a couple of ways. If you just want to serialize the X12 and put it in the channel map, that works too.

You could do the following to serialize the X12 to XML and put it in the channel map:

var x12Message = SerializerFactory.getSerializer('EDI/X12').toXML(msg.*::Body.*::Process837.*::Input837. toString());
channelMap.put('x12Message', x12Message);

Then you could do this in another destination's filter:

if(new XML(channelMap.get('x12Message'))['ISA']['ISA.05']['ISA.05.1'] == "Abcd1234"){
logger.info('Containted value Abcd1234');
return true;
}

I'll attach a sample using your channel. Worked for this message:
ISA*00* *00* *Abcd1234*521301729 *20*0135WCH00 *100126
Attached Files
File Type: xml Test WS Dispatcher 1.1.xml (28.2 KB, 10 views)
Reply With Quote
  #12  
Old 02-03-2014, 10:27 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Smile

Here's the slightly improved version of my attempt to implement a dispatch pattern for your review, narupley.
I still can't figure out the logic of properly building filter expressions based on message fields' values (which need to be extracted form bulk X12 payload first - how) ... Could you please take a look and let me know what could be updated so in the first scenario the SOAP Web Servcies destination will be called and in the second - RESTull HTTP GET request with parameters passed in "query string"?

many thanks!
Dan Z
Attached Files
File Type: xml Test WS Dispatcher 2.xml (37.1 KB, 4 views)
Reply With Quote
  #13  
Old 02-04-2014, 10:26 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Cool X12 ==> XML transformer fails

Many thanks Eduardo - but I couldn't import your sample b/c it was created in the newer version of Mirth. Mine is Mirth Connect Server 3.0.0.6931. Any chance you could "back port" your sample to that version? I really like your idea of putting the whole X12 message object into the channel Map and then construct an XML form it and look for specific element's value, right:

Quote:
if(new XML(channelMap.get('x12Message'))['ISA']['ISA.05']['ISA.05.1'] == "Abcd1234"){
logger.info('Containted value Abcd1234');
return true;
}
I have followed your example and created a filter with pretty much same code (see attached) but it always fails with this exception:

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: Test WS Dispatcher 1
CONNECTOR: Destination 1
SCRIPT SOURCE:
SOURCE CODE:
21: }
22: }
23: function doScript() {
24: msg = new XML(connectorMessage.getTransformedData());
25: if (msg.namespace('') != undefined) { default xml namespace = msg.namespace(''); } else { default xml namespace = ''; }
26: tmp = new XML(template);
27: function doFilter() { phase[0] = 'filter'; return true; }function doTransform() { phase[0] = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase[0]);
28:
29:
30: //from the Mirth forum sample:
LINE NUMBER: 26
DETAILS: TypeError: The prefix "soap" for element "soap:Envelope" is not bound.
at 63307e0e-6d59-4d65-bd7d-64299ee801d7:26 (doScript)
at 63307e0e-6d59-4d65-bd7d-64299ee801d7:54
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.call(JavaScr iptFilterTransformer.java:134)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.call(JavaScr iptFilterTransformer.java:100)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
----------------------------------------------------
I am not sure where soap prefix comes form - maybe from the template?

Could you please review the attached channel, correct it for 3.0.0 and share?

many thanks,
Dan Z
Attached Files
File Type: xml Test WS Dispatcher DZ.xml (26.6 KB, 6 views)
Reply With Quote
  #14  
Old 02-05-2014, 12:24 PM
eduardoa eduardoa is offline
Mirth Employee
 
Join Date: Mar 2013
Location: Santa Fe Springs, California
Posts: 134
eduardoa is on a distinguished road
Default

You are seeing that error because you are stripping the namespaces. You can choose the option to not strip namespaces in the Summary tab-> Set Data Types.

I'll upload the way you can do it if you wanted to put the message in the channelmap. It is probably best if you just change the data type to be X12 after the source connector. That way you can just use the transformed message and check values in the x12 from msg. If you needed anymore values from the envelope then you could put those in the channel map.

I'll include an example of both.
Attached Files
File Type: xml Test WS Dispatcher 1a.xml (26.5 KB, 5 views)
File Type: xml Test WS Dispatcher 1 b.xml (30.0 KB, 6 views)

Last edited by eduardoa; 02-05-2014 at 03:16 PM.
Reply With Quote
  #15  
Old 02-05-2014, 02:10 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Default

Thanks a ton, Eduardo - will try these soon!
Could you comment when IT DOES MAKE SENSE to strip out XML namespaces?

Dan Z
Reply With Quote
  #16  
Old 02-05-2014, 02:12 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,097
narupley is on a distinguished road
Default

Quote:
Originally Posted by dzilberman View Post
Thanks a ton, Eduardo - will try these soon!
Could you comment when IT DOES MAKE SENSE to strip out XML namespaces?

Dan Z
When you don't want the namespaces present in the XML. However right now it can be a bit of a pain because it doesn't handle bound prefixes correctly: MIRTH-3129
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #17  
Old 02-06-2014, 10:46 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Talking I got this version to work - but w/o script based conversion XML ==> X12

Eduardo, I got my original example to work assuming input as XML and OOTB translation XML ==> X12 with stripped namespaces and inferred X12 delimeters in the source. Then I found the necessary element and placed on the Channel map in Transformer and then used it in Filters.
Your examples using JavaScript code are great as they show how to address variables in channelMap object etc. but unfortunately when I changed source to XML and tried to adjust transformer script to:

Code:
//XML == EDI X12
msg = SerializerFactory.getSerializer('EDI/X12').fromXML(msg.*::Body.*::Process837.*::Input837. toString());
I was getting parser exceptions like:

Code:
Caused by: org.xml.sax.SAXParseException; Premature end of file.
	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
I guess I have to learn how to properly use arguments in the fromXML(..) functions for the attached XML chunk. But thanks again for showing many useful examples!

Dan Z
Attached Files
File Type: xml Test WS Dispatcher Works.xml (27.0 KB, 2 views)
File Type: xml Tesia_837.xml (1.3 KB, 6 views)
Reply With Quote
  #18  
Old 02-07-2014, 10:00 AM
eduardoa eduardoa is offline
Mirth Employee
 
Join Date: Mar 2013
Location: Santa Fe Springs, California
Posts: 134
eduardoa is on a distinguished road
Default

That call will not work because it would be passing in an empty string. You also should be using toXML since what we are trying to do is go from the X12 String to a serialized XML version of the X12 message.

msg.*::Body.*::Process837.*::Input837. toString()

This line would work to access the value from the original xml. Where msg is the xml representation of your raw message. Then Body was the parent node for Process837 and that was the parent node for Input837.

So usually that call would be msg.Body.Process837.Input837.toString(). Since the envelope used namespaces then it you would need to include those. I just went ahead and used a wildcard though(*:: as opposed to soap:.


This was the original message that it was meant to work off of:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Process837 xmlns="https://www.realtimeclaims.com/">
<Input837>ISA*00* *00* *30*521301729 *20*0135WCH00 *100126*1731*U*00401*000000001*1*T*:~GS*HC*5213017 29*0135WCH00*20100126*0531*1001*X*004010X097A1~ST
</Input837>
<OutputEOB />
<Output997 />
<UserId>userid</UserId>
<UserPassword>xxxx</UserPassword>
</Process837>
</soap:Body>
</soap:Envelope>
Reply With Quote
  #19  
Old 02-07-2014, 01:35 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Default

You are right Eduardo - I forgot my own spec The Web Service listener would get the SOAP request with the data as the schema above and then your parsing code reflecting XML hierarchy would work.

Thanks a ton for being so responsive to my (silly) questions

Dan Z
Reply With Quote
  #20  
Old 02-10-2014, 02:24 PM
dzilberman dzilberman is offline
OBX.2 Kenobi
 
Join Date: Sep 2013
Location: San Francisco, CA
Posts: 71
dzilberman is on a distinguished road
Default

Hi Eduardo,

One more follow-up question, please. My actual SOAP request comes in with multiple name spaces in the message:
Quote:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:real="https://www.realtimeclaims.com/">
<soap:Header/>
<soap:Body>
<real:Process270>
<!--Optional:-->
<real:Input270>
ISA*00* *00* *12*ABCCOM *01*999999999 *120117*1719*U*00400*000006768*0*P*>
GS*HS*4405197800*999999999*20120117*1719*1421*X*00 4010VICS
ST*270*1234
BHT*0022*13*1*20010820*1330
HL*1**20*1
NM1*PR*2******PI*123456789
HL*2*1*21*1
NM1*1P*2******SV*987654321
HL*3*2*22*0
NM1*IL*1*DOE*JANE****MI*345678901
EQ*30**FAM
SE*10*1234
GE*1*1421
IEA*1*000006768
</real:Input270>
<!--Optional:-->
<real:Output271></real:Output271>
<!--Optional:-->
<real:OutputDisclaimer></real:OutputDisclaimer>
<!--Optional:-->
<real:UserId>test</real:UserId>
<!--Optional:-->
<real:UserPassword>test</real:UserPassword>
</real:Process270>
</soap:Body>
</soap:Envelope>
So if I want to extract the X12 message payload via JS fucntion call in this case, it should be something like this:

Quote:
//XML == EDI X12
msg = SerializerFactory.getSerializer('EDI/X12').fromXML(msg.*::Body.*::Process270.*::Input27 0. toString());
(Namespace is NOT stripped out and wild cards .*:: should match either soap: or real: namespaces? For some reason it fails for me so far with SAX errors.

thanks again,
Dan Z
Reply With Quote
Reply

Tags
dispatch pattern, x12

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 03:57 PM.


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