mirror of https://github.com/apache/nifi.git
NIFI-2564 This closes #854. Add support for HL7 composite component names
Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
parent
c9097e7db3
commit
c1e47f9b44
|
@ -55,14 +55,17 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-hl7-query-language</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi</groupId>
|
||||
<artifactId>hapi-base</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi</groupId>
|
||||
<artifactId>hapi-structures-v21</artifactId>
|
||||
|
@ -103,7 +106,7 @@
|
|||
<artifactId>hapi-structures-v26</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-mock</artifactId>
|
||||
|
|
|
@ -27,7 +27,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
|
@ -218,7 +221,7 @@ public class ExtractHL7Attributes extends AbstractProcessor {
|
|||
// These maybe should used the escaped values, but that would
|
||||
// change the existing non-broken behavior of the processor
|
||||
if (parseFields && (field instanceof Composite) && !isTimestamp(field)) {
|
||||
for (final Map.Entry<String, Type> componentEntry : getAllComponents(fieldKey, field).entrySet()) {
|
||||
for (final Map.Entry<String, Type> componentEntry : getAllComponents(fieldKey, field, useNames).entrySet()) {
|
||||
final String componentKey = componentEntry.getKey();
|
||||
final Type component = componentEntry.getValue();
|
||||
final String componentValue = HL7_ESCAPING.unescape(component.encode(), HL7_ENCODING);
|
||||
|
@ -298,25 +301,50 @@ public class ExtractHL7Attributes extends AbstractProcessor {
|
|||
return fields;
|
||||
}
|
||||
|
||||
private static Map<String, Type> getAllComponents(final String fieldKey, final Type field) throws HL7Exception {
|
||||
private static Map<String, Type> getAllComponents(final String fieldKey, final Type field, final boolean useNames) throws HL7Exception {
|
||||
final Map<String, Type> components = new TreeMap<>();
|
||||
if (!isEmpty(field) && (field instanceof Composite)) {
|
||||
final Type[] types = ((Composite) field).getComponents();
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
final Type type = types[i];
|
||||
if (!isEmpty(type)) {
|
||||
String fieldName = field.getName();
|
||||
if (fieldName.equals("CM_MSG")) {
|
||||
fieldName = "CM";
|
||||
if (useNames) {
|
||||
final Pattern p = Pattern.compile("^(cm_msg|[a-z][a-z][a-z]?)([0-9]+)_(\\w+)$");
|
||||
try {
|
||||
final java.beans.PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(field);
|
||||
for (final java.beans.PropertyDescriptor property : properties) {
|
||||
final String propertyName = property.getName();
|
||||
final Matcher matcher = p.matcher(propertyName);
|
||||
if (matcher.find()) {
|
||||
final Type type = (Type) PropertyUtils.getProperty(field, propertyName);
|
||||
if (!isEmpty(type)) {
|
||||
final String componentName = matcher.group(3);
|
||||
final String typeKey = new StringBuilder()
|
||||
.append(fieldKey)
|
||||
.append(".")
|
||||
.append(componentName)
|
||||
.toString();
|
||||
components.put(typeKey, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
final Type[] types = ((Composite) field).getComponents();
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
final Type type = types[i];
|
||||
if (!isEmpty(type)) {
|
||||
String fieldName = field.getName();
|
||||
if (fieldName.equals("CM_MSG")) {
|
||||
fieldName = "CM";
|
||||
}
|
||||
final String typeKey = new StringBuilder()
|
||||
.append(fieldKey)
|
||||
.append(".")
|
||||
.append(fieldName)
|
||||
.append(".")
|
||||
.append(i+1)
|
||||
.toString();
|
||||
components.put(typeKey, type);
|
||||
}
|
||||
final String typeKey = new StringBuilder()
|
||||
.append(fieldKey)
|
||||
.append(".")
|
||||
.append(fieldName)
|
||||
.append(".")
|
||||
.append(i+1)
|
||||
.toString();
|
||||
components.put(typeKey, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,64 +213,64 @@ public class TestExtractHL7Attributes {
|
|||
|
||||
expectedAttributes.put("MSH.FieldSeparator", "|");
|
||||
expectedAttributes.put("MSH.EncodingCharacters", "^~\\&");
|
||||
expectedAttributes.put("MSH.SendingApplication.HD.1", "XXXXXXXX");
|
||||
expectedAttributes.put("MSH.ReceivingApplication.HD.1", "HealthProvider");
|
||||
expectedAttributes.put("MSH.MessageType.CM.1", "ORU");
|
||||
expectedAttributes.put("MSH.MessageType.CM.2", "R01");
|
||||
expectedAttributes.put("MSH.SendingApplication.NamespaceID", "XXXXXXXX");
|
||||
expectedAttributes.put("MSH.ReceivingApplication.NamespaceID", "HealthProvider");
|
||||
expectedAttributes.put("MSH.MessageType.MessageType", "ORU");
|
||||
expectedAttributes.put("MSH.MessageType.TriggerEvent", "R01");
|
||||
expectedAttributes.put("MSH.MessageControlID", "Q1111111111111111111");
|
||||
expectedAttributes.put("MSH.ProcessingID.PT.1", "P");
|
||||
expectedAttributes.put("MSH.ProcessingID.ProcessingID", "P");
|
||||
expectedAttributes.put("MSH.VersionID", "2.3");
|
||||
|
||||
expectedAttributes.put("ORC_1.OrderControl", "NW");
|
||||
expectedAttributes.put("ORC_1.PlacerOrderNumber.EI.1", "987654321");
|
||||
expectedAttributes.put("ORC_1.PlacerOrderNumber.EI.2", "EPC");
|
||||
expectedAttributes.put("ORC_1.FillerOrderNumber.EI.1", "123456789");
|
||||
expectedAttributes.put("ORC_1.FillerOrderNumber.EI.2", "EPC");
|
||||
expectedAttributes.put("ORC_1.PlacerOrderNumber.EntityIdentifier", "987654321");
|
||||
expectedAttributes.put("ORC_1.PlacerOrderNumber.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.XCN.1", "SMITH");
|
||||
expectedAttributes.put("ORC_1.OrderingProvider.IDNumber", "SMITH");
|
||||
|
||||
expectedAttributes.put("OBR_1.SetIDObservationRequest", "1");
|
||||
expectedAttributes.put("OBR_1.PlacerOrderNumber.EI.1", "341856649");
|
||||
expectedAttributes.put("OBR_1.PlacerOrderNumber.EI.2", "HNAM_ORDERID");
|
||||
expectedAttributes.put("OBR_1.FillerOrderNumber.EI.1", "000000000000000000");
|
||||
expectedAttributes.put("OBR_1.UniversalServiceIdentifier.CE.1", "648088");
|
||||
expectedAttributes.put("OBR_1.UniversalServiceIdentifier.CE.2", "Basic Metabolic Panel");
|
||||
expectedAttributes.put("OBR_1.PlacerOrderNumber.EntityIdentifier", "341856649");
|
||||
expectedAttributes.put("OBR_1.PlacerOrderNumber.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.XCN.1", "1620");
|
||||
expectedAttributes.put("OBR_1.OrderingProvider.XCN.2", "Johnson");
|
||||
expectedAttributes.put("OBR_1.OrderingProvider.XCN.3", "Corey");
|
||||
expectedAttributes.put("OBR_1.OrderingProvider.XCN.4", "A");
|
||||
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.ResultsRptStatusChngDateTime", "20150101000000");
|
||||
expectedAttributes.put("OBR_1.ResultStatus", "F");
|
||||
expectedAttributes.put("OBR_1.ScheduledDateTime", "20150101000000");
|
||||
|
||||
expectedAttributes.put("OBX_1.SetIDOBX", "1");
|
||||
expectedAttributes.put("OBX_1.ValueType", "NM");
|
||||
expectedAttributes.put("OBX_1.ObservationIdentifier.CE.1", "GLU");
|
||||
expectedAttributes.put("OBX_1.ObservationIdentifier.CE.2", "Glucose Lvl");
|
||||
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.Units.CE.1", "65-99");
|
||||
expectedAttributes.put("OBX_1.Units.CE.2", "65");
|
||||
expectedAttributes.put("OBX_1.Units.CE.3", "99");
|
||||
expectedAttributes.put("OBX_1.Units.Identifier", "65-99");
|
||||
expectedAttributes.put("OBX_1.Units.Text", "65");
|
||||
expectedAttributes.put("OBX_1.Units.NameOfCodingSystem", "99");
|
||||
expectedAttributes.put("OBX_1.ReferencesRange", "L");
|
||||
expectedAttributes.put("OBX_1.NatureOfAbnormalTest", "F");
|
||||
expectedAttributes.put("OBX_1.UserDefinedAccessChecks", "20150102000000");
|
||||
|
||||
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.XCN.1", "1234567890");
|
||||
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.XCN.2", "LAST");
|
||||
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.XCN.3", "FIRST");
|
||||
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.XCN.4", "M");
|
||||
expectedAttributes.put("PD1.PatientPrimaryCareProviderNameIDNo.XCN.9", "NPI");
|
||||
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.CX.1", "12345");
|
||||
expectedAttributes.put("PID.PatientIDInternalID.CX.4", "XYZ");
|
||||
expectedAttributes.put("PID.PatientIDInternalID.CX.5", "MR");
|
||||
expectedAttributes.put("PID.PatientName.XPN.1", "SMITH");
|
||||
expectedAttributes.put("PID.PatientName.XPN.2", "JOHN");
|
||||
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("PID.DateOfBirth", "19700100");
|
||||
expectedAttributes.put("PID.Sex", "M");
|
||||
expectedAttributes.put("PID.PatientAccountNumber.CX.1", "111111111111");
|
||||
expectedAttributes.put("PID.PatientAccountNumber.ID", "111111111111");
|
||||
expectedAttributes.put("PID.SSNNumberPatient", "123456789");
|
||||
|
||||
runTests(message, expectedAttributes, true, true);
|
||||
|
|
|
@ -30,4 +30,19 @@
|
|||
<module>nifi-hl7-nar</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-hl7-processors</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-hl7-query-language</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue