web stats
count fields in pipe delimited - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2017, 11:38 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Default count fields in pipe delimited

is there a way to count in the number of segments in a pipe delimited input message?
Ideally I would like a source filter that rejects the message if it doesn't have the correct number of fields.
Any help at all, of course, is greatly appreciated!
thank you.
Mirth.3.4.2.8129
Reply With Quote
  #2  
Old 03-15-2017, 03:01 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 280
AlexNeiva is on a distinguished road
Default

Dear stormcel,

you can do in the Source Transformer or in the Sour Filter a split for the pipes like this:

Code:
var spl = []; 
spl = msg.toString().split("|");

var count = spl.length;
and gives you the number of columns

Last edited by AlexNeiva; 03-15-2017 at 03:11 AM.
Reply With Quote
  #3  
Old 03-15-2017, 09:05 AM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Default

thank you SO MUCH!!!

This was very useful.
However, msg did not return the incoming message, but the xml version of it.
I changed it to the following to get it to work:

Code:
var spl = []; 
spl = connectorMessage.getRawData().toString().split("|");

var pipecount = spl.length;
Reply With Quote
  #4  
Old 03-15-2017, 10:10 AM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
 
Join Date: Sep 2014
Location: Michigan
Posts: 613
kirbykn2 is on a distinguished road
Default

Fields for a particular segment or fields in the whole message? What message type are we talking about?

Try msg.*.length()
__________________
Best,

Kirby

Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8
Reply With Quote
  #5  
Old 03-15-2017, 07:28 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Default

it is a pipe delimited input message.
I want there to be precisely 1107 pipes in the message or to filter it.
Unfortunately the numbers returned by the script mentioned in this thread are not a correct count of the pipes in the message.
I can't figure out what it's counting, but it is counting something.
Does anyone know how to accomplish the following:
see if incoming message has exactly 1107 pipe separated fields in order to accept the message?

thanks!

Last edited by stormcel; 03-15-2017 at 08:56 PM. Reason: p.s. the output from Try msg.*.length() for all messages was 1.0
Reply With Quote
  #6  
Old 03-16-2017, 04:31 AM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
 
Join Date: Sep 2014
Location: Michigan
Posts: 613
kirbykn2 is on a distinguished road
Default

Is this an HL7 message type? How many segments are there? Can you provide an example.

logger.info("length wildcard "+ msg.*.length()); // gets the number of segments in the message.

logger.info("length msg.PID " + msg.PID.*.length()); // gets the number of fields in the PID segment

iterate over the segments in msg, get a count of the fields in each segment, and add them all together.
__________________
Best,

Kirby

Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8

Last edited by kirbykn2; 03-16-2017 at 06:01 AM.
Reply With Quote
  #7  
Old 03-16-2017, 12:47 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Default

the incoming msg is JUST pipe delimited.
i.e.
84443|48883|Y|12.5|KYA.KK|14|20170112|19560210|7|n |........ up to 1017 fields.
I map each of these fields to a variable and produce an HL7 output message.

the code
Code:
msg.*.length()
Just gives me a 1 for all messages.

And, again, thanks for the help!!!
Reply With Quote
  #8  
Old 03-16-2017, 12:53 PM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
 
Join Date: Sep 2014
Location: Michigan
Posts: 613
kirbykn2 is on a distinguished road
Default

What is the data type set to?
__________________
Best,

Kirby

Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8
Reply With Quote
  #9  
Old 03-16-2017, 12:56 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Default

source connector inbound: delimited text
source connector outbound: hl7
Reply With Quote
  #10  
Old 03-16-2017, 12:58 PM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
 
Join Date: Sep 2014
Location: Michigan
Posts: 613
kirbykn2 is on a distinguished road
Default

can you post a screenshot of what the transformed message looks like in the source connector?
__________________
Best,

Kirby

Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8
Reply With Quote
Reply

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 11:28 AM.


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