-1

I would like to use mirth in the following scenario: 1. Receive a xml file 2. Change value of a tag if this tag has a specific value 3. Outbound the resulting xml

So i've in mirth a filereader inbound connector and a filewriter outbound connector. How can i transform this xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<R>
  <NDOSM />
  <NADM>20060552</NADM>
  <DATECONS>20200205</DATECONS>
  <PRODNR />
  <PRODUCTID>1602235</PRODUCTID>
  <PRODUCTDESC>relaxine compr. pellic. 500 mg</PRODUCTDESC>
  <QTY>1.0</QTY>
  <PARSTOCKID>ethilog</PARSTOCKID>
  <PRIX />
  <STUPNR />
  <MEDNR>16822372</MEDNR>
  <CODEIDENTIFICATION />
  <SERIALNO />
  <NOMARGE />
  <PATIENTNAME>CLINT</PATIENTNAME>
  <PATIENTLASTNAME>EASTWOOD</PATIENTLASTNAME>
  <DATEOFBIRTH>19420910</DATEOFBIRTH>
  <LOTNR />
  <SERVICE />
  <SERVICEDIST>160</SERVICEDIST>
  <KEYFROMPM>20200205163309_05604132</KEYFROMPM>
  <TYPEMOUVEMENT>PREDISPOSITION</TYPEMOUVEMENT>
  <ANNULATION>N</ANNULATION>
  <PARSTOCKID-DOTATION />
  <COMMENTAIREMVT />
</R>

in this one

<?xml version="1.0" encoding="ISO-8859-1" ?>
<R>
  <NDOSM />
  <NADM>20060552</NADM>
  <DATECONS>20200205</DATECONS>
  <PRODNR />
  <PRODUCTID>1602235</PRODUCTID>
  <PRODUCTDESC>relaxine compr. pellic. 500 mg</PRODUCTDESC>
  <QTY>1.0</QTY>
  <PARSTOCKID>51</PARSTOCKID>
  <PRIX />
  <STUPNR />
  <MEDNR>16822372</MEDNR>
  <CODEIDENTIFICATION />
  <SERIALNO />
  <NOMARGE />
  <PATIENTNAME>CLINT</PATIENTNAME>
  <PATIENTLASTNAME>EASTWOOD</PATIENTLASTNAME>
  <DATEOFBIRTH>19420910</DATEOFBIRTH>
  <LOTNR />
  <SERVICE />
  <SERVICEDIST>160</SERVICEDIST>
  <KEYFROMPM>20200205163309_05604132</KEYFROMPM>
  <TYPEMOUVEMENT>PREDISPOSITION</TYPEMOUVEMENT>
  <ANNULATION>N</ANNULATION>
  <PARSTOCKID-DOTATION />
  <COMMENTAIREMVT />
</R>

I must change inbound xml only if value of tag PARSTOCKID is ethilog. In this case, i've to replace ethilog by 51. I've tried a couple of thing without success :(

Thanks

Yvkevitch
  • 65
  • 8

2 Answers2

1

Apologies for posting something that is more a comment than an answer, but it's too long for a comment and it may help you get to where you want.

Depending on the the method Mirth uses to change the text value of a node, this xpath expression

 /R//PARSTOCKID[text()='ethilog'] 

should select the child node of R with the name /PARSTOCKID which has a text value of ethilog; you then apply the text changing method directly to this child node.

If you need to start with the parent node, this xpath expression

/R[//PARSTOCKID[text()='ethilog']]

should select any R node that has a child with the name /PARSTOCKID, which itself has a text value of ethilog. At that point (and this is just a wild guess...) you assign some variable name to the selected R node and you do something along the lines of

my_var['PARSTOCKID']=51 (or maybe == "51"?)

Again, sorry I can't be more specific, not being familiar with Mirth, but if it gets you half way there, it's probably worth it.

Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
1

This is pretty straightforward to do with a javascript step in mirth.

if (msg.PARSTOCKID.toString() == 'ethilog') {
    msg.PARSTOCKID = '51';
}
agermano
  • 1,679
  • 6
  • 16
  • 1
    Thanks @agermano. So obvious when you know it. I still have a little problem. In the xml outpout file, the xml declaration tag is missing (). Why? – Yvkevitch Feb 18 '20 at 06:22
  • 1
    Found. I just had to add it to the template of the destination... – Yvkevitch Feb 18 '20 at 06:53
  • To answer your "Why?" xml declarations cause errors when present, so mirth strips them off. Your solution to add it back in the destination template is probably the easiest way to add it back. – agermano Feb 26 '20 at 20:49