Here is the code to remove inactive allergies from a cda.
var allergiesSection = qie.parseXMLString(message.getNode('/ClinicalDocument/component/structuredBody/component/section[code/@code=\'48765-2\']'));
var allergies = allergiesSection.getAllNodes('//entry');
for (var i = 0; i < allergies.length; i++) {
var allergy = qie.parseXMLString(allergies[i]);
if (allergy.getNode('/entry/act/entryRelationship[observation/code/@codeSystem=\'2.16.840.1.113883.5.4\']/observation/entryRelationship[observation/code/@codeSystem=\'2.16.840.1.113883.6.1\']/observation/value/@code') != '55561003') {
//Get the allergy id for removal
var allergyId = allergy.getNode('/entry/act/text/reference/@value');
//Remove Coded Section
message.removeFirstNode('/ClinicalDocument/component/structuredBody/component/section[code/@code=\'48765-2\']/entry[act/text/reference/@value=\'' + allergyId + '\']');
//Remove HTML section
message.removeFirstNode('/ClinicalDocument/component/structuredBody/component/section[code/@code=\'48765-2\']/text/table/tbody/tr[td/@ID=\'' + StringUtils.substringAfter(allergyId, '#') + '\']');
}
}