NIFI-11029 Added Standard XML parsing to ExtractCCDAAttributes

- Added DeprecationNotice to ExtractCCDAAttributes

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #6828
This commit is contained in:
exceptionfactory 2023-01-06 13:18:56 -06:00 committed by Matthew Burgess
parent 9252dcbc76
commit e966336e89
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
3 changed files with 33 additions and 14 deletions

View File

@ -35,6 +35,11 @@
<artifactId>nifi-utils</artifactId>
<version>1.20.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-xml-processing</artifactId>
<version>1.20.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>

View File

@ -41,6 +41,7 @@ import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
import org.apache.nifi.annotation.behavior.SideEffectFree;
import org.apache.nifi.annotation.behavior.SupportsBatching;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.DeprecationNotice;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.annotation.lifecycle.OnScheduled;
import org.apache.nifi.components.PropertyDescriptor;
@ -53,6 +54,7 @@ import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.util.StopWatch;
import org.apache.nifi.xml.processing.parsers.StandardDocumentProvider;
import org.eclipse.emf.common.util.Diagnostic;
import org.openhealthtools.mdht.uml.cda.CDAPackage;
import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
@ -62,7 +64,9 @@ import org.openhealthtools.mdht.uml.cda.hitsp.HITSPPackage;
import org.openhealthtools.mdht.uml.cda.ihe.IHEPackage;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil.ValidationHandler;
import org.w3c.dom.Document;
@DeprecationNotice(reason = "Parsing XML elements to FlowFile attributes is not recommend and should be replaced with record-oriented handling")
@SideEffectFree
@SupportsBatching
@InputRequirement(Requirement.INPUT_REQUIRED)
@ -284,7 +288,11 @@ public class ExtractCCDAAttributes extends AbstractProcessor {
ClinicalDocument cd = null;
try {
cd = CDAUtil.load(inputStream); // load CDA document
final StandardDocumentProvider documentProvider = new StandardDocumentProvider();
documentProvider.setNamespaceAware(true);
final Document document = documentProvider.parse(inputStream);
cd = CDAUtil.load(document); // load CDA document
if (!skipValidation && !CDAUtil.validate(cd, new CDAValidationHandler())) { //optional validation
getLogger().error("Failed to validate CDA document");
throw new ProcessException("Failed to validate CDA document");

View File

@ -19,7 +19,6 @@ package org.apache.nifi.processors.ccda;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhealthtools.mdht.uml.cda.consol.ConsolFactory;
@ -33,20 +32,17 @@ import org.openhealthtools.mdht.uml.cda.consol.VitalSignsOrganizer;
import org.openhealthtools.mdht.uml.cda.consol.VitalSignsSection;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class TestExtractCCDAAttributes {
private TestRunner runner;
private static final String INVALID_DOCTYPE = "<!DOCTYPE invalid [<!ENTITY entity SYSTEM 'file:///file-not-found'> %entity;]>";
@BeforeAll
public static void setup() {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "INFO");
}
private static final String INVALID_DOCUMENT = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>%s<ClinicalDocument xmlns=\"urn:hl7-org:v3\" />", INVALID_DOCTYPE);
private TestRunner runner;
@BeforeEach
public void init() {
@ -55,7 +51,7 @@ public class TestExtractCCDAAttributes {
@Test
public void testProcessor() throws Exception {
Map<String, String> expectedAttributes = new HashMap<String, String>();
Map<String, String> expectedAttributes = new LinkedHashMap<>();
expectedAttributes.put("code.code", "34133-9");
expectedAttributes.put("code.codeSystem", "2.16.840.1.113883.6.1");
expectedAttributes.put("code.codeSystemName", "LOINC");
@ -110,11 +106,21 @@ public class TestExtractCCDAAttributes {
StringWriter writer = new StringWriter();
CDAUtil.save(doc, writer);
runTests(writer.toString(), expectedAttributes, true, true);
runTests(writer.toString(), expectedAttributes);
}
private void runTests(final String content, Map<String, String> expectedAttributes, final boolean skipValidation, final boolean prettyPrinting) throws IOException{
runner.setProperty(ExtractCCDAAttributes.SKIP_VALIDATION, String.valueOf(skipValidation));
@Test
public void testRunInvalidDocument() {
runner.enqueue(INVALID_DOCUMENT);
runner.run();
runner.assertAllFlowFilesTransferred(ExtractCCDAAttributes.REL_FAILURE);
}
private void runTests(final String content, final Map<String, String> expectedAttributes) {
runner.setProperty(ExtractCCDAAttributes.SKIP_VALIDATION, Boolean.TRUE.toString());
runner.enqueue(content);