web stats
Not able to use E4X filtering without losing 3x message - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2018, 01:51 PM
Geekn Geekn is offline
Mirth Newb
 
Join Date: May 2018
Posts: 25
Geekn is on a distinguished road
Default Not able to use E4X filtering without losing 3x message

I'm trying create a set of objects that populate base patient properties depending on whether it's a 2x or 3x message. I've removed much of the code to isolate the issue I'm seeing. When I run this code through a channel that accepts 2x messages all lines are logged regardless of E4X filtering code from below (var mrnNode = …). When I run it through a 3x message channel the code that does E4X filtering causes the second logging line to not write out any data. If I comment out the filtering line on the 3x patient, it WILL SUCCUSSFULLY log all the data in that node for the 3x channel.


I also don't understand why a line below a logging method would affect the state of scoped variables above it.


Code:
// Called from source transform 
CreatePatient()

// Following code Located in code template (compiled)
function CreatePatient() 
{	
	var patient = null;
	// Grab version information and message data
	var majorVersion = String($('mirth_version') == null ? null : $('mirth_version').substring(0,1));

	// Create version specific patient
	switch(majorVersion)
	{
		case "2":
			patient = new HL72xPatient(msg);
			break;
		case "3":
			patient = new HL73xPatient(msg);
			break;
		default:
			// Adding default here because the version does not come across when submitting 3x messages via the SendMessage Mirth command
			patient = new HL73xPatient(msg);
	}

	// Initialize the patient to populate the properties
	if(patient)
		patient.Initialize();	
		
	return patient;
}

function Patient(msgData) 
{
	this.MessageData = msgData;
	// Setup abstract method that must be overridden in derived instances of Patient to populate patient properties
	this.constructor.prototype.Initialize = function()  { logger.error('Initialize() has not been implemented'); }
}

function HL73xPatient(msgData)
{
	Patient.call(this, msgData);
	HL73xPatient.prototype.Initialize = function() 
	{	
		logger.info("document " + this.MessageData); // Always logs regardless of filtering line
		// The following line will log out the recordTarget node ONLY if the filtering is not done on the line below it (var mrnNode...)
		// If you take off the filtering, it works as expected such as only assigning mrnNode to "this.MessageData['recordTarget']['patientRole']['id']"
		logger.info("document/recordTarget:"  + this.MessageData["recordTarget"]);
		
		var mrnNode = this.MessageData['recordTarget']['patientRole']['id'].(function() { return new XML(this)['@Code'] == "MR"; }());	
	}	
}

function HL72xPatient(msgData)
{
	Patient.call(this, msgData);
	HL72xPatient.prototype.Initialize = function() 
	{	
		logger.info("document " + this.MessageData); // Always logs regardless of filtering line
		logger.info("document/PID:"  + this.MessageData["PID"]); // Always logs regardless of filtering line
		
		var mrnNode = this.MessageData['PID']['PID.3'].(function() { return new XML(this)['PID.3.5'] == "MR"; }());
		
	}	
}

Last edited by Geekn; 06-30-2018 at 02:54 PM.
Reply With Quote
  #2  
Old 07-02-2018, 01:35 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

I would suggest to not use the $('mirth_version') to check whether it is a v2 message or v3 message.

Better than that is to use a boolean flag like isV3Message set to false when it is a v2 message. You can set this variable from the channel and pass it to your function call.

You can call the method from channel like so
Code:
parseMessage(msg,true)
And function definition
Code:
function parseMessage(msg, isV3Message) {
//add your code here.
}
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #3  
Old 07-02-2018, 03:37 AM
Geekn Geekn is offline
Mirth Newb
 
Join Date: May 2018
Posts: 25
Geekn is on a distinguished road
Default

That is certainly an option. I would have thought there would be a way to access the instance specific configuration properties of an executing channel (like maybe the data types) which could be used to detect the version of the message. I can certainly use your suggestion if nothing exist.

But this post is more about the completely strange behavior related to the entire message content not being logged or available when the code that tries to filter rows using E4X filtering is executed for a 3.x message in a 3.x channel. Very strange stuff.
Reply With Quote
  #4  
Old 07-04-2018, 10:12 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 841
agermano is on a distinguished road
Default

Your issue has me baffled. I don't know why a line of code would produce different output depending on whether a line after it was commented out or not.

You can simplify your HL73xPatient filter, though. You only need to use the self-executing anonymous function when the element/attribute you are trying to access can't be referenced with dot notation.

You should be able to do
Code:
var mrnNode = this.MessageData['recordTarget']['patientRole']['id'].(@Code == "MR");
// or even
var mrnNode = this.MessageData.recordTarget.patientRole.id.(@Code == "MR");
Reply With Quote
  #5  
Old 07-05-2018, 09:17 AM
Geekn Geekn is offline
Mirth Newb
 
Join Date: May 2018
Posts: 25
Geekn is on a distinguished road
Default

I agree that it should be simpler filter syntax @agermano...I actually mentioned that to ya in a different post, but I believed you mentioned that it was the only way to make it work ; ) I'm going to try and recreate the issue related to this post, however, to isolate it. It is very strange and I'll try to come up with some code that makes it simpler to recreate if you are not seeing. Once again though, thanks for helping me through it.

http://www.mirthcorp.com/community/f...d.php?p=264081
Reply With Quote
  #6  
Old 07-05-2018, 02:18 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 841
agermano is on a distinguished road
Default

The reason it's required for v2 is because child element 'PID.3.5' has dots in it. It will throw an error if you try to access that without placing it in a string.

The v3 element names in your example don't contain any javascript operators, so you can use the shorter form there.
Reply With Quote
  #7  
Old 07-06-2018, 03:58 AM
Geekn Geekn is offline
Mirth Newb
 
Join Date: May 2018
Posts: 25
Geekn is on a distinguished road
Default

OK...I have isolated this issue down to three steps. If you follow them, you will see the problem.

1. Create a channel with data types that use HL7 3x and copy the following code into a source transform JavaScript step. Submit any valid HL3x message and validate that both logging statements successfully write out the nodes.

Code:
logFromMessage(msg);

function logFromMessage(msgData)
{
	// Test that we can log the message
	logger.info("document " + msgData);
	// Test that we can log a child of the message
	logger.info("document/recordTarget:"  + msgData["recordTarget"]);
	// Try a random query using E4X
	var mrnNode = msgData['recordTarget']['patientRole']['id'].(@Code == "MR");
}
2. Now move the function logFromMessage() into a compiled code block and ensure the test channel can see it.

3. Submit the same 3x message and confirm that the second line to log the record target will be empty.


If you want to successfully log both lines from the code block, simply comment out the E4X filtering line from the function. If you follow the same steps above for an HL7 2x message channel (even with filtering line), everything works as expected.

Last edited by Geekn; 07-06-2018 at 04:19 AM.
Reply With Quote
  #8  
Old 07-06-2018, 11:59 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 841
agermano is on a distinguished road
Default

Do you have a sample message I can try? When I grabbed a random one off the internet (https://github.com/HL7/C-CDA-Example...C-CDAR2.1).xml) I couldn't reproduce your error.
Reply With Quote
  #9  
Old 07-06-2018, 01:14 PM
Geekn Geekn is offline
Mirth Newb
 
Join Date: May 2018
Posts: 25
Geekn is on a distinguished road
Default

I was just going to post a sample from the same place, but I tried yours and can recreate the issue. Umm...I've attached my channel XML but it's pretty basic setup I think. I thought it might be the Java version I was using so I upgraded to version 10, but no dice.
Attached Files
File Type: xml Test E4X.xml (11.4 KB, 2 views)
File Type: xml HL7_v3_example1.xml (45.5 KB, 4 views)

Last edited by Geekn; 07-06-2018 at 05:27 PM.
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 03:52 AM.


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