web stats
Strict Parser is removing leading empty spaces at the beginning of segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2012, 10:07 AM
jmendezzz jmendezzz is offline
OBX.2 Kenobi
 
Join Date: Nov 2009
Posts: 85
jmendezzz is on a distinguished road
Post Strict Parser is removing leading empty spaces at the beginning of segments

Hello,

I have a channel that i need to have data type set to: *Strict Parser*. I understand that by having the strict parser checked, it will inherently remove empty spaces at the beginning of any subfield. The reason i have Strict parser checked is because I have a transformer where i remove certain test, along with their grouped segments(ORC->OBR-> OBX->NTE). I do not want to remove the empty spaces. How can i go about having strict parser checked and leaving the empty spaces.
Reply With Quote
  #2  
Old 03-07-2012, 08:15 PM
jmendezzz jmendezzz is offline
OBX.2 Kenobi
 
Join Date: Nov 2009
Posts: 85
jmendezzz is on a distinguished road
Post

No suggestions...
Reply With Quote
  #3  
Old 03-08-2012, 06:07 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

HAPI has two basic forms of validation: DefaultValidation and NoValidation. Both types add the following primitive rule bindings:

Rule 1
  • HL7 Version: All
  • Scope: FT
  • Action: Trim Leading Whitespace
Rule 2
  • HL7 Version: All
  • Scope: ST
  • Action: Trim Leading Whitespace
Rule 3
  • HL7 Version: All
  • Scope: TX
  • Action: Trim Leading Whitespace

To get around this, you can just extend ValidationContextImpl and make your own custom validation context, and then manually do the parsing yourself. For example, to use a completely blank context with no rule bindings:

Code:
default xml namespace = new Namespace('urn:hl7-org:v2xml');
importPackage(Packages.ca.uhn.hl7v2.parser);
importPackage(Packages.ca.uhn.hl7v2.validation.impl);
var pipeParser = new PipeParser();
pipeParser.setValidationContext(new ValidationContextImpl());
var xmlParser = new DefaultXMLParser();
xmlParser.setKeepAsOriginalNodes(['NTE.3','OBX.5']);
var newMsg = new XML(xmlParser.encode(pipeParser.parse(messageObject.getRawData().trim())));
Then, given the following sample message:

Code:
MSH|^~\&|PATHNET|BEND_IN|OCF|HSI|20120302145504||ORU^R01|123456|P|2.2
PID|1|1234567|1234567||TEST^TEST||19800101|M|||123 FUBAR LANE|||||||987654|123456789
PV1|1||||||||||||||||111111^DOE MD^JOHN|I|222222|I|P|||||||||||||||||||||||20120301053800
ORC|RE|001670001|01429868230001100002912722504857222504857200000000^101LA||CM||||20120302145400||||  H2A|||^RESULT PERFORMED|||H3871
OBR|1|001670001|01429868230001100002912722504857222504857200000000^101LA|0029127^K-^POTASSIUM-SERUM|||20120302142500|||101||||20120302143200||111111^DOE MD^JOHN|||00131130||0001206205436|20120302145400||LA|F||^^^20120302142700^^ST~^^^^^ST
OBX|1|NM|0029027^K^POTASSIUM-SERUM||4.1|mEq/L|3.6-5.2||||F|||20120302145400|IIM^^^00131130^SVHCI Dxc600i sn 3055|H3871
NTE|1|C|Generic Lab CLIA # 111111
ORC.13.1 has some white space (this happens often with some clients). So to test that it worked:

Code:
logger.info('|'+newMsg['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['ORC']['ORC.13']['CM_PARENT_RESULT.1']['CE.1'].toString()+'|');
The server log output:

Code:
[2012-03-08 09:52:06,295]  INFO  (transformer:?): |  H2A|
Reply With Quote
  #4  
Old 03-09-2012, 04:11 AM
jmendezzz jmendezzz is offline
OBX.2 Kenobi
 
Join Date: Nov 2009
Posts: 85
jmendezzz is on a distinguished road
Post

neat idea...let me try that. Thanks for the help.
Reply With Quote
  #5  
Old 02-12-2013, 01:16 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Quote:
Originally Posted by rav View Post
Where would the above lines of code go..Will that be in the preprocessor script?? Thanks in advance
That code would go in a transformer, since that's where the HL7 v2.x -> XML serialization occurs.
__________________
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
  #6  
Old 02-13-2013, 08:04 AM
rav rav is offline
Mirth Guru
 
Join Date: Oct 2012
Posts: 258
rav is on a distinguished road
Default

How to make the code more generalized way...meaning..I don't want to remove spaces for all the fields.....Somehow this code doesn't work for my mappings.....The spaces get stripped of...Do I need to check or uncheck options from my channel...
Reply With Quote
  #7  
Old 02-13-2013, 10:40 AM
rav rav is offline
Mirth Guru
 
Join Date: Oct 2012
Posts: 258
rav is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
HAPI has two basic forms of validation: DefaultValidation and NoValidation. Both types add the following primitive rule bindings:

Rule 1
  • HL7 Version: All
  • Scope: FT
  • Action: Trim Leading Whitespace
Rule 2
  • HL7 Version: All
  • Scope: ST
  • Action: Trim Leading Whitespace
Rule 3
  • HL7 Version: All
  • Scope: TX
  • Action: Trim Leading Whitespace

To get around this, you can just extend ValidationContextImpl and make your own custom validation context, and then manually do the parsing yourself. For example, to use a completely blank context with no rule bindings:

Code:
default xml namespace = new Namespace('urn:hl7-org:v2xml');
importPackage(Packages.ca.uhn.hl7v2.parser);
importPackage(Packages.ca.uhn.hl7v2.validation.impl);
var pipeParser = new PipeParser();
pipeParser.setValidationContext(new ValidationContextImpl());
var xmlParser = new DefaultXMLParser();
xmlParser.setKeepAsOriginalNodes(['NTE.3','OBX.5']);
var newMsg = new XML(xmlParser.encode(pipeParser.parse(messageObject.getRawData().trim())));
Then, given the following sample message:

Code:
MSH|^~\&|PATHNET|BEND_IN|OCF|HSI|20120302145504||ORU^R01|123456|P|2.2
PID|1|1234567|1234567||TEST^TEST||19800101|M|||123 FUBAR LANE|||||||987654|123456789
PV1|1||||||||||||||||111111^DOE MD^JOHN|I|222222|I|P|||||||||||||||||||||||20120301053800
ORC|RE|001670001|01429868230001100002912722504857222504857200000000^101LA||CM||||20120302145400||||  H2A|||^RESULT PERFORMED|||H3871
OBR|1|001670001|01429868230001100002912722504857222504857200000000^101LA|0029127^K-^POTASSIUM-SERUM|||20120302142500|||101||||20120302143200||111111^DOE MD^JOHN|||00131130||0001206205436|20120302145400||LA|F||^^^20120302142700^^ST~^^^^^ST
OBX|1|NM|0029027^K^POTASSIUM-SERUM||4.1|mEq/L|3.6-5.2||||F|||20120302145400|IIM^^^00131130^SVHCI Dxc600i sn 3055|H3871
NTE|1|C|Generic Lab CLIA # 111111
ORC.13.1 has some white space (this happens often with some clients). So to test that it worked:

Code:
logger.info('|'+newMsg['ORU_R01.PATIENT_RESULT']['ORU_R01.ORDER_OBSERVATION']['ORC']['ORC.13']['CM_PARENT_RESULT.1']['CE.1'].toString()+'|');
The server log output:

Code:
[2012-03-08 09:52:06,295]  INFO  (transformer:?): |  H2A|

This code works if I don't check non strict parser..if I check strict parser this code is not working..Am I missing anything...
Reply With Quote
  #8  
Old 02-13-2013, 10:42 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Quote:
Originally Posted by rav View Post
This code works if I don't check non strict parser..if I check strict parser this code is not working..Am I missing anything...
The code is not designed to work with the "Use Strict Parser" option in the HL7 v2.x properties, because that uses the default HAPI validation context. That's the whole point; instead you turn off that option and use the "strict parser" directly in the transformer.
__________________
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
  #9  
Old 02-13-2013, 10:45 AM
rav rav is offline
Mirth Guru
 
Join Date: Oct 2012
Posts: 258
rav is on a distinguished road
Default

Aa got you.. Sorry missed this point..The other thing is I have mapping based on strict parser as

msg['ORU_R01.RESPONSE']['ORU_R01.ORDER_OBSERVATION']

Will unchecking strict parser option effect this code? Thanks a lot ..
Reply With Quote
  #10  
Old 02-13-2013, 10:48 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Quote:
Originally Posted by rav View Post
Aa got you.. Sorry missed this point..The other thing is I have mapping based on strict parser as

msg['ORU_R01.RESPONSE']['ORU_R01.ORDER_OBSERVATION']

Will unchecking strict parser option effect this code? Thanks a lot ..
It will, unless you override msg in your transformer with your manually serialized message.
__________________
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

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 06:26 AM.


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