web stats
Transforming RXA segment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2019, 12:07 PM
msmusic2 msmusic2 is offline
What's HL7?
 
Join Date: May 2019
Location: Tennessee
Posts: 4
msmusic2 is on a distinguished road
Default Transforming RXA segment

if I have an RXA.5.3 segment that contains "NDC" how can I transform to delete RXA.5.1 5.2 and 5.3

I want this
RXA|0|1|20190426|20190426|49281-0400-88^ADACEL^NDC^115^Tdap^CVX

TO LOOK LIKE

this...
RXA|0|1|20190426|20190426|115^Tdap^CVX


if I transform like this...
delete msg['RXA']['RXA.5']['RXA.5.1'];
delete msg['RXA']['RXA.5']['RXA.5.2'];
delete msg['RXA']['RXA.5']['RXA.5.3'];

then the carats are left

RXA|0|1|20190426|20190426|^^^115^Tdap^CVX

So if I can base it on NDC in RXA.5.3 and remove everything before in in RXA.5 that would be great!

Thanks in advance
Reply With Quote
  #2  
Old 05-09-2019, 10:53 AM
bhesler bhesler is offline
Mirth Newb
 
Join Date: Jul 2015
Posts: 10
bhesler is on a distinguished road
Default

Try the code below

var rxa5_4 = msg['RXA']['RXA.5']['RXA.5.4'].toString();
var rxa5_5 = msg['RXA']['RXA.5']['RXA.5.5'].toString();
var rxa5_6 = msg['RXA']['RXA.5']['RXA.5.6'].toString();


msg['RXA']['RXA.5'] = ""

msg['RXA']['RXA.5']['RXA.5.1'] = rxa5_4;
msg['RXA']['RXA.5']['RXA.5.2'] = rxa5_5;
msg['RXA']['RXA.5']['RXA.5.3'] = rxa5_6;
Reply With Quote
  #3  
Old 05-09-2019, 12:18 PM
msmusic2 msmusic2 is offline
What's HL7?
 
Join Date: May 2019
Location: Tennessee
Posts: 4
msmusic2 is on a distinguished road
Default

Thanks! Now.. how would you code this if there are multiple RXA segments? could I just prepend with
for each (seg in msg..RXA)?
Reply With Quote
  #4  
Old 05-09-2019, 12:19 PM
msmusic2 msmusic2 is offline
What's HL7?
 
Join Date: May 2019
Location: Tennessee
Posts: 4
msmusic2 is on a distinguished road
Default

Here was my error for one with multiple RXA

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: Test code
CONNECTOR: testing MSH4 copy
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
3826: var rxa5_4 = msg['RXA']['RXA.5']['RXA.5.4'].toString();
3827: var rxa5_5 = msg['RXA']['RXA.5']['RXA.5.5'].toString();
3828: var rxa5_6 = msg['RXA']['RXA.5']['RXA.5.6'].toString();
3829:
3830:
3831: msg['RXA']['RXA.5'] = ""
3832:
3833: msg['RXA']['RXA.5']['RXA.5.1'] = rxa5_4;
3834: msg['RXA']['RXA.5']['RXA.5.2'] = rxa5_5;
3835: msg['RXA']['RXA.5']['RXA.5.3'] = rxa5_6;
LINE NUMBER: 3831
DETAILS: TypeError: Assignment to lists with more than one item is not supported
at c623cc0b-8fa9-40cd-a911-32ab8de39bd5:3831 (doTransform)
at c623cc0b-8fa9-40cd-a911-32ab8de39bd5:3857 (doScript)
at c623cc0b-8fa9-40cd-a911-32ab8de39bd5:3859
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Reply With Quote
  #5  
Old 05-09-2019, 04:32 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 718
agermano is on a distinguished road
Default

This should get all of them

Code:
for each (var rxa5 in msg['RXA']['RXA.5']) {
    if (rxa5['RXA.5.3'].toString() === 'NDC') {
        rxa5.setChildren(<>
            <RXA.5.1>{rxa5['RXA.5.4'].toString()}</RXA.5.1>
            <RXA.5.2>{rxa5['RXA.5.5'].toString()}</RXA.5.2>
            <RXA.5.3>{rxa5['RXA.5.6'].toString()}</RXA.5.3>
        </>);
    }
}
Reply With Quote
  #6  
Old 05-10-2019, 04:40 AM
msmusic2 msmusic2 is offline
What's HL7?
 
Join Date: May 2019
Location: Tennessee
Posts: 4
msmusic2 is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post
This should get all of them

Code:
for each (var rxa5 in msg['RXA']['RXA.5']) {
    if (rxa5['RXA.5.3'].toString() === 'NDC') {
        rxa5.setChildren(<>
            <RXA.5.1>{rxa5['RXA.5.4'].toString()}</RXA.5.1>
            <RXA.5.2>{rxa5['RXA.5.5'].toString()}</RXA.5.2>
            <RXA.5.3>{rxa5['RXA.5.6'].toString()}</RXA.5.3>
        </>);
    }
}
Thank you agermano! That did the trick!
Reply With Quote
Reply

Tags
transformer template

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:13 AM.


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