web stats
Replacing a sequence of hex characters in preprocessor - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2012, 06:28 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default Replacing a sequence of hex characters in preprocessor

Hi All;

I'm working with a kludgy delimited file and am having fits getting it parsed out properly.

Here's a snippet

Code:
{
"unitNumber": "H153734",
"accountNumber": "MA000715/11",
"name": "O'DWARF,ONE 00/100",
"filed by": "NUCAMC",
"filed by name": "CAMERON,CHRISTINE",
"OCANC.|8|": "20121001",
"OCANC11|20|": "Sandra James",
"OCANC25|15|": "8422182918",
"OCANC17|2|": "ON",
"OCANC127|1|": "Y",
"OCANC163|1|": "Y",
}
Looks like json doesn't it?

When I receive the file the actual delimiting sequence between fields is \x2C\x0D\x0A or ,\r\n

My issue is that Mirth will break on commas, even in a string that's wrapped with quotes.

My thinking is that this is because its in a second set of quotes on each line.

Has anyone encountered this issue before or have any suggestions as to how to solve it?

Thanks
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #2  
Old 12-06-2012, 06:41 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Funny how immediately after I post I stumble across the solution.

I put this in my pre-processor

Code:
var pattern = RegExp(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)","g");



message = message.replace(pattern,'~');
Then I use ~ as a column delimiter.

Seems to work great!
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #3  
Old 12-06-2012, 09:01 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Just as an aside for anyone else who comes across this, here's another example of how to use Delimited Text to parse JSON: http://www.mirthcorp.com/community/f...23&postcount=6

Also, there's an open issue for adding JSON as a data type as well, so hopefully we'll be able to add that in the near future: MIRTH-2276
__________________
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
Reply

Tags
comma, delimited, parse

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:39 PM.


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