web stats
If EXISTS then process segment, otherwise ignore - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2013, 09:46 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default If EXISTS then process segment, otherwise ignore

I have 5 fields in a table, which I can process 5 OBR's, however, we can receive 2, 3 or 4, as opposed to the full 5. There will always be 1.

I am getting errors as I have direct mapped the fields to each field looking for 5 in the transformer, however when one of 2, 3 comes along, as there isnt 5 OBR's I am getting errors.

I was thinking easy enough, add if's around each;

Code:
//Loop Exam, Max 5
Exam2 = 'NULL';
Exam3 = 'NULL';
Exam4 = 'NULL';
Exam5 = 'NULL';
Exam = msg['OBR'][0]['OBR.4']['OBR.4.1'].toString();
//if more then one then check?
if (msg['OBR'][1]['OBR.1']['OBR.1.1'].toString()== "2") {
Exam2 = msg['OBR'][1]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][2]['OBR.1']['OBR.1.1'].toString() == "3") {
Exam3 = msg['OBR'][2]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][3]['OBR.1']['OBR.1.1'].toString() == "4") {
Exam4 = msg['OBR'][3]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][4]['OBR.1']['OBR.1.1'].toString() == "5") {
Exam5 = msg['OBR'][4]['OBR.4']['OBR.4.1'].toString();
};
Using the ID, as I will alwasy process 5, I will only get 5 OBR's.

I also tried

doing checkes on Length > 0 but the value I am receiving are letters, and was getting an error around numbers?

None the less, there must be a easier way, I am thinking? As I feel I am complicating the rules here?

Any help appreciated.
Reply With Quote
  #2  
Old 08-27-2013, 09:49 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default

Other code I tried without joy;

Code:
SOURCE CODE:	
33: Exam = msg['OBR'][0]['OBR.4']['OBR.4.1'].toString();
34: //if more then one then check?
35: if (msg['OBR'][1]['OBR.4']['OBR.4.1'].length() > 0) {
36: Exam2 = msg['OBR'][1]['OBR.4']['OBR.4.1'].toString();
37: };
38: if (msg['OBR'][2]['OBR.4']['OBR.4.1'].length() > 0) {
39: Exam3 = msg['OBR'][2]['OBR.4']['OBR.4.1'].toString();
40: };
41: if (msg['OBR'][3]['OBR.4']['OBR.4.1'].length() > 0) {
42: Exam4 = msg['OBR'][3]['OBR.4']['OBR.4.1'].toString();
LINE NUMBER:	38
DETAILS:	TypeError: Cannot read property "OBR.4" from undefined
Reply With Quote
  #3  
Old 08-27-2013, 09:58 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,675
narupley is on a distinguished road
Default

You would want to check if the length is greater than 1, then greater than 2, then 3, etc. You can also just iterate through the segments in the message and only pay attention to the first five, or something like that.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR

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
  #4  
Old 09-09-2013, 04:50 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
You would want to check if the length is greater than 1, then greater than 2, then 3, etc. You can also just iterate through the segments in the message and only pay attention to the first five, or something like that.
Many Thanks, How would I go about iterate, and only paying attention to the first 5, that sounds perfect for what I want I guess.
Reply With Quote
  #5  
Old 09-10-2013, 08:48 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default

Code:
ERROR-300: Transformer error
ERROR MESSAGE:	Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransformerException: 
CHANNEL:	OCS_ICE_HL7_IN
CONNECTOR:	RESP_ICE_ORDERS_OCS_OUT
SCRIPT SOURCE:	
SOURCE CODE:	
30: Exam3 = 'NULL';
31: Exam4 = 'NULL';
32: Exam5 = 'NULL';
33: Exam = msg['OBR'][0]['OBR.4']['OBR.4.1'].toString();
34: //if more then one then check?
35: if (msg['OBR'][1]['OBR.4']['OBR.4.1'].length() > 0) {
36: Exam2 = msg['OBR'][1]['OBR.4']['OBR.4.1'].toString();
37: };
38: if (msg['OBR'][2]['OBR.4']['OBR.4.1'].length() > 0) {
39: Exam3 = msg['OBR'][2]['OBR.4']['OBR.4.1'].toString();
LINE NUMBER:	35
DETAILS:	TypeError: Cannot read property "OBR.4" from undefined
	at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.evaluateScript(JavaScriptTransformer.java:398)
	at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:296)
	at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
	at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
	at com.mirth.connect.server.controllers.DefaultMessageObjectController.getMessageObjectFromEvent(DefaultMessageObjectController.java:790)
	at com.mirth.connect.connectors.jdbc.JdbcMessageDispatcher.doDispatch(JdbcMessageDispatcher.java:74)
	at com.mirth.connect.connectors.jdbc.JdbcMessageDispatcher.doSend(JdbcMessageDispatcher.java:162)
	at org.mule.providers.AbstractMessageDispatcher.send(AbstractMessageDispatcher.java:164)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:191)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:130)
	at org.mule.routing.outbound.AbstractOutboundRouter.send(AbstractOutboundRouter.java:85)
	at org.mule.routing.outbound.FilteringMulticastingRouter.route(FilteringMulticastingRouter.java:61)
	at org.mule.routing.outbound.OutboundMessageRouter$1.doInTransaction(OutboundMessageRouter.java:78)
	at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:48)
	at org.mule.routing.outbound.OutboundMessageRouter.route(OutboundMessageRouter.java:82)
	at org.mule.impl.model.DefaultMuleProxy.onCall(DefaultMuleProxy.java:247)
	at org.mule.impl.model.seda.SedaComponent.doSend(SedaComponent.java:209)
	at org.mule.impl.model.AbstractComponent.sendEvent(AbstractComponent.java:277)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:201)
	at org.mule.routing.inbound.InboundMessageRouter.send(InboundMessageRouter.java:176)
	at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:143)
	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:238)
	at com.mirth.connect.connectors.mllp.MllpMessageReceiver$TcpWorker.processHL7Data(MllpMessageReceiver.java:484)
	at com.mirth.connect.connectors.mllp.MllpMessageReceiver$TcpWorker.processData(MllpMessageReceiver.java:444)
	at com.mirth.connect.connectors.mllp.MllpMessageReceiver$TcpWorker.run(MllpMessageReceiver.java:361)
	at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
	at java.lang.Thread.run(Unknown Source)
The error I am seeing, I don't understand why with the 'if', mirth is still looking for the 4th iteration, hence me seeing this error.
Reply With Quote
  #6  
Old 09-10-2013, 09:25 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default

Code:
//Loop Exam, Max 5
var Exam2 = 'NULL';
var Exam3 = 'NULL';
var Exam4 = 'NULL';
var Exam5 = 'NULL';
Exam = msg['OBR'][0]['OBR.4']['OBR.4.1'].toString();
//if more then one then check?
if (msg['OBR'][1]['OBR.1']['OBR.1.1'].toString() == "2") {
Exam2 = msg['OBR'][1]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][2]['OBR.1']['OBR.1.1'].toString() == "3") {
Exam3 = msg['OBR'][2]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][3]['OBR.1']['OBR.1.1'].toString() == "4") {
Exam4 = msg['OBR'][3]['OBR.4']['OBR.4.1'].toString();
};
if (msg['OBR'][4]['OBR.1']['OBR.1.1'].toString() == "5") {
Exam5 = msg['OBR'][4]['OBR.4']['OBR.4.1'].toString();
};
added 'var' thinking this might have been the issue. No joy. Seems when I get one exam, it always fails.
Reply With Quote
  #7  
Old 09-10-2013, 10:03 AM
R A R A is offline
OBX.3 Kenobi
 
Join Date: Jan 2012
Location: London, UK
Posts: 173
R A is on a distinguished road
Default

Bingo,

Changed my approach a little, and when for a for each with:

Code:
var Exam = "";
var Exam2 = "";
var Exam3 = "";
var Exam4 = "";
var Exam5 = "";
for each (OBR4 in msg..OBR)  //Iterates only with NK1 segments so no need to check the segment name again
 {
	id = OBR4['OBR.1']['OBR.1.1'].toString();
if (id == "1"){
	Exam = OBR4['OBR.4']['OBR.4.1'].toString();
 };
if (id == "2"){
	Exam2 = OBR4['OBR.4']['OBR.4.1'].toString();
 };
if (id == "3"){
	Exam3 = OBR4['OBR.4']['OBR.4.1'].toString();
 };
if (id == "4"){
	Exam4 = OBR4['OBR.4']['OBR.4.1'].toString();
 };
if (id == "5"){
	Exam5 = OBR4['OBR.4']['OBR.4.1'].toString();
 };
};
Seems to work,

Many Thanks
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 -7. The time now is 09:51 PM.


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