This is an automated email from the ASF dual-hosted git repository.

turcsanyi pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
     new 6a3301dfbf NIFI-12520: ExtractHL7Attributes processor ignores 
repeatable field values
6a3301dfbf is described below

commit 6a3301dfbf4456c3ab1c6bca4ab797f302c8621d
Author: Mark Bathori <[email protected]>
AuthorDate: Fri Dec 15 22:41:17 2023 +0100

    NIFI-12520: ExtractHL7Attributes processor ignores repeatable field values
    
    This closes #8167.
    
    Signed-off-by: Peter Turcsanyi <[email protected]>
    
    (cherry picked from commit 16d170fdfdbc12723746ae1f7ae8568246227ab2)
---
 .../nifi/processors/hl7/ExtractHL7Attributes.java  |  20 ++--
 .../processors/hl7/TestExtractHL7Attributes.java   | 129 ++++++++++++++-------
 2 files changed, 101 insertions(+), 48 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java
 
b/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java
index aa7a867d9c..063d8e9b3b 100644
--- 
a/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java
+++ 
b/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java
@@ -281,8 +281,8 @@ public class ExtractHL7Attributes extends AbstractProcessor 
{
         final Map<String, Type> fields = new TreeMap<>();
         final String[] segmentNames = segment.getNames();
         for (int i = 1; i <= segment.numFields(); i++) {
-            final Type field = segment.getField(i, 0);
-            if (!isEmpty(field)) {
+            final Type[] fieldValues = segment.getField(i);
+            if (fieldValues != null && fieldValues.length != 0) {
                 final String fieldName;
                 //Some user defined segments (e.g. Z segments) will not have 
corresponding names returned
                 //from segment.getNames() above. If we encounter one of these, 
do the next best thing
@@ -294,13 +294,17 @@ public class ExtractHL7Attributes extends 
AbstractProcessor {
                     fieldName = String.valueOf(i);
                 }
 
-                final String fieldKey = new StringBuilder()
-                    .append(segmentKey)
-                    .append(".")
-                    .append(fieldName)
-                    .toString();
+                final String fieldKey = String.format("%s.%s", segmentKey, 
fieldName);
 
-                fields.put(fieldKey, field);
+                //Checks if the field is repeatable, if the max cardinality 
value is 0 or more than 1 then the field is repeatable
+                if (segment.getMaxCardinality(i) == 1) {
+                    fields.put(fieldKey, fieldValues[0]);
+                } else {
+                    for (int j = 0; j < fieldValues.length; j++) {
+                        final String repeatableFieldKey = 
String.format("%s_%s", fieldKey, j + 1);
+                        fields.put(repeatableFieldKey, fieldValues[j]);
+                    }
+                }
             }
         }
         return fields;
diff --git 
a/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/test/java/org/apache/nifi/processors/hl7/TestExtractHL7Attributes.java
 
b/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/test/java/org/apache/nifi/processors/hl7/TestExtractHL7Attributes.java
index e1b5fdc51d..8f02e3b05f 100644
--- 
a/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/test/java/org/apache/nifi/processors/hl7/TestExtractHL7Attributes.java
+++ 
b/nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/test/java/org/apache/nifi/processors/hl7/TestExtractHL7Attributes.java
@@ -22,7 +22,6 @@ import org.apache.nifi.util.TestRunners;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
-import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.SortedMap;
@@ -105,17 +104,17 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("MSH.12", "2.3");
 
         expectedAttributes.put("ORC_1.1", "NW");
-        expectedAttributes.put("ORC_1.2", "987654321^EPC");
+        expectedAttributes.put("ORC_1.2_1", "987654321^EPC");
         expectedAttributes.put("ORC_1.3", "123456789^EPC");
         expectedAttributes.put("ORC_1.9", "20161003000000");
-        expectedAttributes.put("ORC_1.12", "SMITH");
+        expectedAttributes.put("ORC_1.12_1", "SMITH");
 
         expectedAttributes.put("OBR_1.1", "1");
-        expectedAttributes.put("OBR_1.2", "341856649^HNAM_ORDERID");
+        expectedAttributes.put("OBR_1.2_1", "341856649^HNAM_ORDERID");
         expectedAttributes.put("OBR_1.3", "000000000000000000");
         expectedAttributes.put("OBR_1.4", "648088^Basic Metabolic Panel");
         expectedAttributes.put("OBR_1.7", "20150101000000");
-        expectedAttributes.put("OBR_1.16", "1620^Johnson^Corey^A");
+        expectedAttributes.put("OBR_1.16_1", "1620^Johnson^Corey^A");
         expectedAttributes.put("OBR_1.22", "20150101000000");
         expectedAttributes.put("OBR_1.25", "F");
         expectedAttributes.put("OBR_1.36", "20150101000000");
@@ -124,16 +123,16 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("OBX_1.2", "NM");
         expectedAttributes.put("OBX_1.3", "GLU^Glucose Lvl");
         expectedAttributes.put("OBX_1.4", "59");
-        expectedAttributes.put("OBX_1.5", "mg/dL");
+        expectedAttributes.put("OBX_1.5_1", "mg/dL");
         expectedAttributes.put("OBX_1.6", "65-99^65^99");
         expectedAttributes.put("OBX_1.7", "L");
         expectedAttributes.put("OBX_1.10", "F");
         expectedAttributes.put("OBX_1.13", "20150102000000");
 
-        expectedAttributes.put("PD1.4", "1234567890^LAST^FIRST^M^^^^^NPI");
+        expectedAttributes.put("PD1.4_1", "1234567890^LAST^FIRST^M^^^^^NPI");
 
-        expectedAttributes.put("PID.3", "12345^^^XYZ^MR");
-        expectedAttributes.put("PID.5", "SMITH^JOHN");
+        expectedAttributes.put("PID.3_1", "12345^^^XYZ^MR");
+        expectedAttributes.put("PID.5_1", "SMITH^JOHN");
         expectedAttributes.put("PID.7", "19700100");
         expectedAttributes.put("PID.8", "M");
         expectedAttributes.put("PID.18", "111111111111");
@@ -143,7 +142,7 @@ public class TestExtractHL7Attributes {
     }
 
     @Test
-    public void testExtractWithSegmentNames() throws IOException {
+    public void testExtractWithSegmentNames() {
         final String message = 
"MSH|^~\\&|XXXXXXXX||HealthProvider||||ORU^R01|Q1111111111111111111|P|2.3|\r\n" 
+
             
"PID|||12345^^^XYZ^MR||SMITH^JOHN||19700100|M||||||||||111111111111|123456789|\r\n"
 +
             "PD1||||1234567890^LAST^FIRST^M^^^^^NPI|\r\n" +
@@ -163,17 +162,17 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("MSH.VersionID", "2.3");
 
         expectedAttributes.put("ORC_1.OrderControl", "NW");
-        expectedAttributes.put("ORC_1.PlacerOrderNumber", "987654321^EPC");
+        expectedAttributes.put("ORC_1.PlacerOrderNumber_1", "987654321^EPC");
         expectedAttributes.put("ORC_1.FillerOrderNumber", "123456789^EPC");
         expectedAttributes.put("ORC_1.DateTimeOfTransaction", 
"20161003000000");
-        expectedAttributes.put("ORC_1.OrderingProvider", "SMITH");
+        expectedAttributes.put("ORC_1.OrderingProvider_1", "SMITH");
 
         expectedAttributes.put("OBR_1.SetIDObservationRequest", "1");
-        expectedAttributes.put("OBR_1.PlacerOrderNumber", 
"341856649^HNAM_ORDERID");
+        expectedAttributes.put("OBR_1.PlacerOrderNumber_1", 
"341856649^HNAM_ORDERID");
         expectedAttributes.put("OBR_1.FillerOrderNumber", 
"000000000000000000");
         expectedAttributes.put("OBR_1.UniversalServiceIdentifier", 
"648088^Basic Metabolic Panel");
         expectedAttributes.put("OBR_1.ObservationDateTime", "20150101000000");
-        expectedAttributes.put("OBR_1.OrderingProvider", 
"1620^Johnson^Corey^A");
+        expectedAttributes.put("OBR_1.OrderingProvider_1", 
"1620^Johnson^Corey^A");
         expectedAttributes.put("OBR_1.ResultsRptStatusChngDateTime", 
"20150101000000");
         expectedAttributes.put("OBR_1.ResultStatus", "F");
         expectedAttributes.put("OBR_1.ScheduledDateTime", "20150101000000");
@@ -182,16 +181,16 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("OBX_1.ValueType", "NM");
         expectedAttributes.put("OBX_1.ObservationIdentifier", "GLU^Glucose 
Lvl");
         expectedAttributes.put("OBX_1.ObservationSubID", "59");
-        expectedAttributes.put("OBX_1.ObservationValue", "mg/dL");
+        expectedAttributes.put("OBX_1.ObservationValue_1", "mg/dL");
         expectedAttributes.put("OBX_1.Units", "65-99^65^99");
         expectedAttributes.put("OBX_1.ReferencesRange", "L");
         expectedAttributes.put("OBX_1.NatureOfAbnormalTest", "F");
         expectedAttributes.put("OBX_1.UserDefinedAccessChecks", 
"20150102000000");
 
-        expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo", 
"1234567890^LAST^FIRST^M^^^^^NPI");
+        expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1", 
"1234567890^LAST^FIRST^M^^^^^NPI");
 
-        expectedAttributes.put("PID.PatientIDInternalID", "12345^^^XYZ^MR");
-        expectedAttributes.put("PID.PatientName", "SMITH^JOHN");
+        expectedAttributes.put("PID.PatientIDInternalID_1", "12345^^^XYZ^MR");
+        expectedAttributes.put("PID.PatientName_1", "SMITH^JOHN");
         expectedAttributes.put("PID.DateOfBirth", "19700100");
         expectedAttributes.put("PID.Sex", "M");
         expectedAttributes.put("PID.PatientAccountNumber", "111111111111");
@@ -201,7 +200,7 @@ public class TestExtractHL7Attributes {
     }
 
     @Test
-    public void testExtractWithSegmentNamesAndFields() throws IOException {
+    public void testExtractWithSegmentNamesAndFields() {
         final String message = 
"MSH|^~\\&|XXXXXXXX||HealthProvider||||ORU^R01|Q1111111111111111111|P|2.3|\r\n" 
+
             
"PID|||12345^^^XYZ^MR||SMITH^JOHN||19700100|M||||||||||111111111111|123456789|\r\n"
 +
             "PD1||||1234567890^LAST^FIRST^M^^^^^NPI|\r\n" +
@@ -222,24 +221,24 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("MSH.VersionID", "2.3");
 
         expectedAttributes.put("ORC_1.OrderControl", "NW");
-        expectedAttributes.put("ORC_1.PlacerOrderNumber.EntityIdentifier", 
"987654321");
-        expectedAttributes.put("ORC_1.PlacerOrderNumber.NamespaceID", "EPC");
+        expectedAttributes.put("ORC_1.PlacerOrderNumber_1.EntityIdentifier", 
"987654321");
+        expectedAttributes.put("ORC_1.PlacerOrderNumber_1.NamespaceID", "EPC");
         expectedAttributes.put("ORC_1.FillerOrderNumber.EntityIdentifier", 
"123456789");
         expectedAttributes.put("ORC_1.FillerOrderNumber.NamespaceID", "EPC");
         expectedAttributes.put("ORC_1.DateTimeOfTransaction", 
"20161003000000");
-        expectedAttributes.put("ORC_1.OrderingProvider.IDNumber", "SMITH");
+        expectedAttributes.put("ORC_1.OrderingProvider_1.IDNumber", "SMITH");
 
         expectedAttributes.put("OBR_1.SetIDObservationRequest", "1");
-        expectedAttributes.put("OBR_1.PlacerOrderNumber.EntityIdentifier", 
"341856649");
-        expectedAttributes.put("OBR_1.PlacerOrderNumber.NamespaceID", 
"HNAM_ORDERID");
+        expectedAttributes.put("OBR_1.PlacerOrderNumber_1.EntityIdentifier", 
"341856649");
+        expectedAttributes.put("OBR_1.PlacerOrderNumber_1.NamespaceID", 
"HNAM_ORDERID");
         expectedAttributes.put("OBR_1.FillerOrderNumber.EntityIdentifier", 
"000000000000000000");
         expectedAttributes.put("OBR_1.UniversalServiceIdentifier.Identifier", 
"648088");
         expectedAttributes.put("OBR_1.UniversalServiceIdentifier.Text", "Basic 
Metabolic Panel");
         expectedAttributes.put("OBR_1.ObservationDateTime", "20150101000000");
-        expectedAttributes.put("OBR_1.OrderingProvider.IDNumber", "1620");
-        expectedAttributes.put("OBR_1.OrderingProvider.FamilyName", "Johnson");
-        expectedAttributes.put("OBR_1.OrderingProvider.GivenName", "Corey");
-        expectedAttributes.put("OBR_1.OrderingProvider.MiddleInitialOrName", 
"A");
+        expectedAttributes.put("OBR_1.OrderingProvider_1.IDNumber", "1620");
+        expectedAttributes.put("OBR_1.OrderingProvider_1.FamilyName", 
"Johnson");
+        expectedAttributes.put("OBR_1.OrderingProvider_1.GivenName", "Corey");
+        expectedAttributes.put("OBR_1.OrderingProvider_1.MiddleInitialOrName", 
"A");
         expectedAttributes.put("OBR_1.ResultsRptStatusChngDateTime", 
"20150101000000");
         expectedAttributes.put("OBR_1.ResultStatus", "F");
         expectedAttributes.put("OBR_1.ScheduledDateTime", "20150101000000");
@@ -249,7 +248,7 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("OBX_1.ObservationIdentifier.Identifier", 
"GLU");
         expectedAttributes.put("OBX_1.ObservationIdentifier.Text", "Glucose 
Lvl");
         expectedAttributes.put("OBX_1.ObservationSubID", "59");
-        expectedAttributes.put("OBX_1.ObservationValue", "mg/dL");
+        expectedAttributes.put("OBX_1.ObservationValue_1", "mg/dL");
         expectedAttributes.put("OBX_1.Units.Identifier", "65-99");
         expectedAttributes.put("OBX_1.Units.Text", "65");
         expectedAttributes.put("OBX_1.Units.NameOfCodingSystem", "99");
@@ -257,17 +256,17 @@ public class TestExtractHL7Attributes {
         expectedAttributes.put("OBX_1.NatureOfAbnormalTest", "F");
         expectedAttributes.put("OBX_1.UserDefinedAccessChecks", 
"20150102000000");
 
-        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.IDNumber", 
"1234567890");
-        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.FamilyName", 
"LAST");
-        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.GivenName", 
"FIRST");
-        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.MiddleInitialOrName",
 "M");
-        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.AssigningAuthority",
 "NPI");
-
-        expectedAttributes.put("PID.PatientIDInternalID.ID", "12345");
-        expectedAttributes.put("PID.PatientIDInternalID.AssigningAuthority", 
"XYZ");
-        expectedAttributes.put("PID.PatientIDInternalID.IdentifierTypeCode", 
"MR");
-        expectedAttributes.put("PID.PatientName.FamilyName", "SMITH");
-        expectedAttributes.put("PID.PatientName.GivenName", "JOHN");
+        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1.IDNumber", 
"1234567890");
+        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1.FamilyName", 
"LAST");
+        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1.GivenName", 
"FIRST");
+        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1.MiddleInitialOrName",
 "M");
+        
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo_1.AssigningAuthority",
 "NPI");
+
+        expectedAttributes.put("PID.PatientIDInternalID_1.ID", "12345");
+        expectedAttributes.put("PID.PatientIDInternalID_1.AssigningAuthority", 
"XYZ");
+        expectedAttributes.put("PID.PatientIDInternalID_1.IdentifierTypeCode", 
"MR");
+        expectedAttributes.put("PID.PatientName_1.FamilyName", "SMITH");
+        expectedAttributes.put("PID.PatientName_1.GivenName", "JOHN");
         expectedAttributes.put("PID.DateOfBirth", "19700100");
         expectedAttributes.put("PID.Sex", "M");
         expectedAttributes.put("PID.PatientAccountNumber.ID", "111111111111");
@@ -276,4 +275,54 @@ public class TestExtractHL7Attributes {
         runTests(message, expectedAttributes, true, true);
     }
 
+    @Test
+    public void testExtractWithRepeatableField() {
+        final String message = 
"MSH|^~\\&|XXXXXXXX||HealthProvider||||SIU^S12|Q1111111111111111111|P|2.5.1|\r\n"
 +
+                
"AIP|1||123456^SMITH^JOHN^A^^^^^NPI^^^^NPI~123457^SMITH^JOHN^A^^^^^OD^^^^OD~123458^SMITH^JOHN^A^^^^^MD^^^^MD|100^M.D.||20231010133000|0|MIN|45|MIN\r\n";
+
+        final SortedMap<String, String> expectedAttributes = new TreeMap<>();
+
+        expectedAttributes.put("MSH.FieldSeparator", "|");
+        expectedAttributes.put("MSH.EncodingCharacters", "^~\\&");
+        expectedAttributes.put("MSH.SendingApplication.NamespaceID", 
"XXXXXXXX");
+        expectedAttributes.put("MSH.ReceivingApplication.NamespaceID", 
"HealthProvider");
+        expectedAttributes.put("MSH.MessageType.MessageCode", "SIU");
+        expectedAttributes.put("MSH.MessageType.TriggerEvent", "S12");
+        expectedAttributes.put("MSH.MessageControlID", "Q1111111111111111111");
+        expectedAttributes.put("MSH.ProcessingID.ProcessingID", "P");
+        expectedAttributes.put("MSH.VersionID.VersionID", "2.5.1");
+
+        expectedAttributes.put("AIP.Duration", "45");
+        expectedAttributes.put("AIP.DurationUnits.Identifier", "MIN");
+        expectedAttributes.put("AIP.ResourceType.Identifier", "100");
+        expectedAttributes.put("AIP.ResourceType.Text", "M.D.");
+        expectedAttributes.put("AIP.SetIDAIP", "1");
+        expectedAttributes.put("AIP.StartDateTime", "20231010133000");
+        expectedAttributes.put("AIP.StartDateTimeOffset", "0");
+        expectedAttributes.put("AIP.StartDateTimeOffsetUnits.Identifier", 
"MIN");
+
+        expectedAttributes.put("AIP.PersonnelResourceID_1.AssigningAuthority", 
"NPI");
+        expectedAttributes.put("AIP.PersonnelResourceID_1.FamilyName", 
"SMITH");
+        expectedAttributes.put("AIP.PersonnelResourceID_1.GivenName", "JOHN");
+        expectedAttributes.put("AIP.PersonnelResourceID_1.IDNumber", "123456");
+        expectedAttributes.put("AIP.PersonnelResourceID_1.IdentifierTypeCode", 
"NPI");
+        
expectedAttributes.put("AIP.PersonnelResourceID_1.SecondAndFurtherGivenNamesOrInitialsThereof",
 "A");
+
+        expectedAttributes.put("AIP.PersonnelResourceID_2.AssigningAuthority", 
"OD");
+        expectedAttributes.put("AIP.PersonnelResourceID_2.FamilyName", 
"SMITH");
+        expectedAttributes.put("AIP.PersonnelResourceID_2.GivenName", "JOHN");
+        expectedAttributes.put("AIP.PersonnelResourceID_2.IDNumber", "123457");
+        expectedAttributes.put("AIP.PersonnelResourceID_2.IdentifierTypeCode", 
"OD");
+        
expectedAttributes.put("AIP.PersonnelResourceID_2.SecondAndFurtherGivenNamesOrInitialsThereof",
 "A");
+
+        expectedAttributes.put("AIP.PersonnelResourceID_3.AssigningAuthority", 
"MD");
+        expectedAttributes.put("AIP.PersonnelResourceID_3.FamilyName", 
"SMITH");
+        expectedAttributes.put("AIP.PersonnelResourceID_3.GivenName", "JOHN");
+        expectedAttributes.put("AIP.PersonnelResourceID_3.IDNumber", "123458");
+        expectedAttributes.put("AIP.PersonnelResourceID_3.IdentifierTypeCode", 
"MD");
+        
expectedAttributes.put("AIP.PersonnelResourceID_3.SecondAndFurtherGivenNamesOrInitialsThereof",
 "A");
+
+        runTests(message, expectedAttributes, true, true);
+    }
+
 }

Reply via email to