web stats
appendChile to XML repeating segment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2019, 12:13 PM
tdickerson tdickerson is offline
Mirth Newb
 
Join Date: Aug 2016
Posts: 6
tdickerson is on a distinguished road
Default appendChile to XML repeating segment

Hi - I am trying to create an XML message with a repeating segment that has many loops in it. I would like to keep the loops for those segments together in the XML output. When I am using the appendChild, it is creating it at the end of the message. I am pulling the data from a database to an XML message.

Here is my xml template:
<specimenInformation>
<tumorSpecimenInformation>
</tumorSpecimenInformation>
</specimenInformation>
<tests>
<testName></testName>
<testCode></testCode>
<platformTechnology></platformTechnology>
<testMethodology></testMethodology>
<testResults></testResults>
</tests>
<clinicalTrials>
<nctID></nctID>
<titleBrief></titleBrief>
</clinicalTrials>
<therapies>
<therapyName></therapyName>
</therapies>
</root>

Here is part of my code:
**I pull from a query***
if (resultTest.getString('Test_Id') == holdTestId)
{
// do nothing
}

else {

createSegment('tests', tmp, testCount);
//createSegmentAfter('tests', tmp['specimenInformation'], testCount);

testCountD = testCount + 1;

// test info
tmp['tests'][testCount]['testName'] = validate(resultTest.getString('Test'), '');
tmp['tests'][testCount]['testCode'] = validate(resultTest.getString('Compendium_Id'), '');
tmp['tests'][testCount]['platformTechnology'] = validate(resultTest.getString('Technology'), '');
tmp['tests'][testCount]['testMethodology'] = validate(resultTest.getString('Method'), '');

testCountResults = testCount;
testCount++;
resultIndex = 1;
resultCount = 0;

}

**based on test, I have a switch setup to send over different type of results**
switch(String(resultTest.getString('Technology'))) {

case 'NGS':
var resultStr = <testResults/>;

tmp['tests'][testCountResults].appendChild(resultStr);

break;

case 'CNA':
var resultStr = <testResults/>;

tmp['tests'][testCountResults].appendChild(resultStr);

break;

then I have a new query for the therapies and clinical trials:
var caseDrugs = executeCachedQuery(dbConn, caseDrugQuery);

caseDrugsCount = 0;

while (caseDrugs.next()) {
tmp['therapies']['therapyName'][caseDrugsCount] = caseDrugs.getString('Drugs');
caseDrugsCount++;
}

and
var caseCTCs = executeCachedQuery(dbConn, ctcQuery);

ctcCount = 0;

while (caseCTCs.next()){
tmp['clinicalTrials']['nctID'][ctcCount] = caseCTCs.getString('NCT_ID');
tmp['clinicalTrials']['titleBrief'][ctcCount] = caseCTCs.getString('BRIEF_TITLE');
ctcCount++;
}

The output of the xml looks like this:
<specimenInformation>
data here
</specimenInformation>
<tests>
<testName></testName>
<testCode></testCode>
<platformTechnology></platformTechnology>
<testMethodology></testMethodology>
<testResults>
1 test result here
</testResults>
</tests>
<clinicalTrials> then case clinical trials</clinicalTrials>
<therapies>
<therapyName/>case therapies <therapyName/>
</therapies>
<tests>
<testName></testName>
<testCode></testCode>
<platformTechnology></platformTechnology>
<testMethodology></testMethodology>
<testResults>
then the other tests and test results start
</testResults>
</tests>


I would like the other test results to appear before the clincial trials and therapies for the case.
Reply With Quote
  #2  
Old 05-24-2019, 01:44 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,303
cory_cole is on a distinguished road
Default

Use insertBefore or insertAfter
Reply With Quote
  #3  
Old 05-24-2019, 02:59 PM
tdickerson tdickerson is offline
Mirth Newb
 
Join Date: Aug 2016
Posts: 6
tdickerson is on a distinguished road
Default

I tried createSegmentAfter. This did put them before the clinical trials tag, but it left out the test information except for the last test. Then it added the test results to the last test.
</specimenInformation>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests/>
<tests>
<testName>test</testName>
<testCode>testcode</testCode>
<platformTechnology>testTech</platformTechnology>
<testMethodology>testMethod</testMethodology>
<testResults>



I tried to use insertAfter, but is said not defined.
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 12:49 AM.


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