Commit 43cc5a6f authored by Thomas Huster's avatar Thomas Huster

[17300] fix ORC segment in OUL_R22 message in HL7ReaderFactory

parent d4531247
Pipeline #12667 passed with stages
in 5 minutes and 2 seconds
......@@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
......@@ -82,7 +84,7 @@ public enum HL7ReaderFactory {
while (stringIterator.hasNext()) {
String next = stringIterator.next();
next = assureSaveMSH9Access(next);
next = assureSaveMessage(next);
Message hl7Message = p.parse(next);
messageList.add(hl7Message);
ret.add(getReaderForMessage(hl7Message));
......@@ -123,14 +125,58 @@ public enum HL7ReaderFactory {
return new ByteArrayInputStream(bytes);
}
private String assureSaveMSH9Access(String hl7Message){
private String assureSaveMessage(String hl7Message){
String ret = assureSaveMSH9Access(hl7Message);
ret = assureSaveORC(ret);
return ret;
}
private String[] getLines(String hl7Message){
String separator = "\r";
String[] splitted = hl7Message.split(separator);
if (splitted.length < 2) {
separator = "\n";
splitted = hl7Message.split(separator);
}
// make sure no new lines at beginning of string
for (int i = 0; i < splitted.length; i++) {
splitted[i] = splitted[i].replaceAll("\n", "");
}
return splitted;
}
private int getIndexOfSegment(String[] splittedMessage, String segmentStart){
int index = 0;
boolean found = false;
for (; index < splittedMessage.length; index++) {
if (splittedMessage[index].startsWith(segmentStart)) {
found = true;
break;
}
}
return found ? index : -1;
}
private String assureSaveORC(String hl7Message){
String[] splitted = getLines(hl7Message);
if (splitted.length < 2) {
throw new IllegalArgumentException("Could not split message");
}
List<String> splittedList = new ArrayList<>(Arrays.asList(splitted));
String[] mshPart = splitted[0].split("\\|", -1);
if (mshPart[8].contains("OUL^R22")) {
int orcIndex = getIndexOfSegment(splitted, "ORC|");
int obrIndex = getIndexOfSegment(splitted, "OBR|");
if (orcIndex > 0 && obrIndex > 0 && orcIndex < obrIndex) {
Collections.swap(splittedList, orcIndex, obrIndex);
}
}
return joinStrings(splittedList.toArray(new String[splittedList.size()]), "\r\n");
}
private String assureSaveMSH9Access(String hl7Message){
String[] splitted = getLines(hl7Message);
if (splitted.length < 2) {
throw new IllegalArgumentException("Could not split message");
}
......@@ -168,7 +214,7 @@ public enum HL7ReaderFactory {
splitted[0] = joinStrings(mshPart, "|");
}
return joinStrings(splitted, separator);
return joinStrings(splitted, "\r\n");
}
private String joinStrings(String[] array, String separator){
......
......@@ -34,8 +34,103 @@
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="ch.elexis.core.application.product"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
<stringAttribute key="selected_target_plugins" value="ca.uhn.hapi.osgi-base@default:default,ch.qos.logback.classic@default:default,ch.qos.logback.core@default:default,ch.qos.logback.slf4j@default:false,com.eclipsesource.jaxrs.jersey-all-nojavax@default:default,com.google.gson@default:default,com.google.guava@default:default,com.ibm.icu@default:default,com.mysql.cj@default:default,com.sun.activation.javax.activation@default:default,jakarta.persistence@default:default,javax.el@default:default,javax.enterprise.cdi-api@default:default,javax.inject@default:default,javax.interceptor-api@default:default,javax.servlet@default:default,javax.transaction-api@default:default,javax.transaction.jta@default:default,javax.xml.stream.stax-api@default:default,javax.xml@default:default,jaxb-api@default:default,org.apache.commons.beanutils@default:default,org.apache.commons.codec@default:default,org.apache.commons.collections4@default:default,org.apache.commons.collections@default:default,org.apache.commons.dbcp@default:default,org.apache.commons.io*2.5.0@default:default,org.apache.commons.lang3@default:default,org.apache.commons.logging@default:default,org.apache.commons.pool@default:default,org.apache.felix.scr@1:true,org.beanshell.bsh@default:default,org.bouncycastle.bcprov@default:default,org.eclipse.ant.core@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.linux.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.core.variables@default:default,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.event@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.gemini.jpa@3:true,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi.services@default:default,org.eclipse.osgi.util@default:default,org.eclipse.osgi@-1:true,org.eclipse.persistence.antlr@default:default,org.eclipse.persistence.asm@default:default,org.eclipse.persistence.core@default:default,org.eclipse.persistence.extension@default:false,org.eclipse.persistence.jpa.jpql@default:default,org.eclipse.persistence.jpa@default:default,org.h2@default:default,org.hamcrest.core@default:default,org.jdom@default:default,org.json@default:default,org.junit@default:default,org.postgresql.jdbc42@default:default,org.slf4j.api@default:default,org.slf4j.nop@default:false,osgi.enterprise@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="ch.elexis.core.hl7.v2x.tests@default:false,ch.elexis.core.hl7.v2x@default:default,ch.elexis.core.jcifs.test@default:false,ch.elexis.core.jcifs@default:default,ch.elexis.core.jpa.datasource@default:default,ch.elexis.core.jpa.entities.test@default:false,ch.elexis.core.jpa.entities@3:true,ch.elexis.core.jpa.logging.slf4j@default:false,ch.elexis.core.jpa.test@default:false,ch.elexis.core.jpa@default:true,ch.elexis.core.l10n@default:default,ch.elexis.core.logback.rocketchat@default:default,ch.elexis.core.logging.default_configuration@default:false,ch.elexis.core.model.test@default:false,ch.elexis.core.model@default:default,ch.elexis.core.services.test@default:false,ch.elexis.core.services@default:default,ch.elexis.core.test.context@default:false,ch.elexis.core.test@default:default,ch.elexis.core@default:default,ch.rgw.utility.tests@default:false,ch.rgw.utility@default:default,jaxb-api-impl-import-java9@default:default"/>
<setAttribute key="selected_target_bundles">
<setEntry value="ca.uhn.hapi.osgi-base@default:default"/>
<setEntry value="ch.qos.logback.classic@default:default"/>
<setEntry value="ch.qos.logback.core@default:default"/>
<setEntry value="ch.qos.logback.slf4j@default:false"/>
<setEntry value="com.eclipsesource.jaxrs.jersey-all-nojavax@default:default"/>
<setEntry value="com.google.gson@default:default"/>
<setEntry value="com.google.guava@default:default"/>
<setEntry value="com.ibm.icu@default:default"/>
<setEntry value="com.mysql.cj@default:default"/>
<setEntry value="com.sun.activation.javax.activation@default:default"/>
<setEntry value="jakarta.persistence@default:default"/>
<setEntry value="javax.el@default:default"/>
<setEntry value="javax.enterprise.cdi-api@default:default"/>
<setEntry value="javax.inject@default:default"/>
<setEntry value="javax.interceptor-api@default:default"/>
<setEntry value="javax.servlet@default:default"/>
<setEntry value="javax.transaction-api@default:default"/>
<setEntry value="javax.transaction.jta@default:default"/>
<setEntry value="javax.xml.stream.stax-api@default:default"/>
<setEntry value="javax.xml@default:default"/>
<setEntry value="jaxb-api@default:default"/>
<setEntry value="org.apache.commons.beanutils@default:default"/>
<setEntry value="org.apache.commons.codec@default:default"/>
<setEntry value="org.apache.commons.collections4@default:default"/>
<setEntry value="org.apache.commons.collections@default:default"/>
<setEntry value="org.apache.commons.dbcp@default:default"/>
<setEntry value="org.apache.commons.io*2.5.0@default:default"/>
<setEntry value="org.apache.commons.lang3@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.commons.pool@default:default"/>
<setEntry value="org.apache.felix.scr@1:true"/>
<setEntry value="org.beanshell.bsh@default:default"/>
<setEntry value="org.bouncycastle.bcprov@default:default"/>
<setEntry value="org.eclipse.ant.core@default:default"/>
<setEntry value="org.eclipse.core.contenttype@default:default"/>
<setEntry value="org.eclipse.core.expressions@default:default"/>
<setEntry value="org.eclipse.core.filesystem.linux.x86_64@default:false"/>
<setEntry value="org.eclipse.core.filesystem@default:default"/>
<setEntry value="org.eclipse.core.jobs@default:default"/>
<setEntry value="org.eclipse.core.resources@default:default"/>
<setEntry value="org.eclipse.core.runtime@default:true"/>
<setEntry value="org.eclipse.core.variables@default:default"/>
<setEntry value="org.eclipse.emf.common@default:default"/>
<setEntry value="org.eclipse.emf.ecore@default:default"/>
<setEntry value="org.eclipse.equinox.app@default:default"/>
<setEntry value="org.eclipse.equinox.common@2:true"/>
<setEntry value="org.eclipse.equinox.ds@1:true"/>
<setEntry value="org.eclipse.equinox.event@default:default"/>
<setEntry value="org.eclipse.equinox.preferences@default:default"/>
<setEntry value="org.eclipse.equinox.registry@default:default"/>
<setEntry value="org.eclipse.gemini.jpa@3:true"/>
<setEntry value="org.eclipse.osgi.compatibility.state@default:false"/>
<setEntry value="org.eclipse.osgi.services@default:default"/>
<setEntry value="org.eclipse.osgi.util@default:default"/>
<setEntry value="org.eclipse.osgi@-1:true"/>
<setEntry value="org.eclipse.persistence.antlr@default:default"/>
<setEntry value="org.eclipse.persistence.asm@default:default"/>
<setEntry value="org.eclipse.persistence.core@default:default"/>
<setEntry value="org.eclipse.persistence.extension@default:false"/>
<setEntry value="org.eclipse.persistence.jpa.jpql@default:default"/>
<setEntry value="org.eclipse.persistence.jpa@default:default"/>
<setEntry value="org.h2@default:default"/>
<setEntry value="org.hamcrest.core@default:default"/>
<setEntry value="org.jdom@default:default"/>
<setEntry value="org.json@default:default"/>
<setEntry value="org.junit@default:default"/>
<setEntry value="org.postgresql.jdbc42@default:default"/>
<setEntry value="org.slf4j.api@default:default"/>
<setEntry value="org.slf4j.nop@default:false"/>
<setEntry value="osgi.enterprise@default:default"/>
</setAttribute>
<setAttribute key="selected_workspace_bundles">
<setEntry value="ch.elexis.core.hl7.v2x.tests@default:false"/>
<setEntry value="ch.elexis.core.hl7.v2x@default:default"/>
<setEntry value="ch.elexis.core.jcifs.test@default:false"/>
<setEntry value="ch.elexis.core.jcifs@default:default"/>
<setEntry value="ch.elexis.core.jpa.datasource@default:default"/>
<setEntry value="ch.elexis.core.jpa.entities.test@default:false"/>
<setEntry value="ch.elexis.core.jpa.entities@3:true"/>
<setEntry value="ch.elexis.core.jpa.logging.slf4j@default:false"/>
<setEntry value="ch.elexis.core.jpa.test@default:false"/>
<setEntry value="ch.elexis.core.jpa@default:true"/>
<setEntry value="ch.elexis.core.l10n@default:default"/>
<setEntry value="ch.elexis.core.logback.rocketchat@default:default"/>
<setEntry value="ch.elexis.core.logging.default_configuration@default:false"/>
<setEntry value="ch.elexis.core.model.test@default:false"/>
<setEntry value="ch.elexis.core.model@default:default"/>
<setEntry value="ch.elexis.core.services.test@default:false"/>
<setEntry value="ch.elexis.core.services@default:default"/>
<setEntry value="ch.elexis.core.test.context@default:false"/>
<setEntry value="ch.elexis.core.test@default:default"/>
<setEntry value="ch.elexis.core@default:default"/>
<setEntry value="ch.rgw.utility.tests@default:false"/>
<setEntry value="ch.rgw.utility@default:default"/>
<setEntry value="jaxb-api-impl-import-java9@default:default"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
......
MSH|^~\&|LabCube|CelltacMEK6500|||20191128093117||OUL^R22^OUL_R22|20191128093117034358|P|2.5.1||||NE||8859/1|en|| PID|1|9885|9885|||||U||||||||U|||||||||||||||||||||| SPM|1||||||||||P|||||||||||||||||| SAC||||||||U|||||||||||||||||||||||||||||||||||| INV||OK|||||||||||||||||| ORC|RE||||||||20191127093117|||||||||||||||||||||| OBR|1||||||20191127093117|||||||||||||||20191128093117|||||||||||||||||||||||||||| OBX|1|NM|WBC^Leukozyten||10|G/l|3-9.6|HH|||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|2|NM|LY%^Lymphozyten||37.4|%|19-48||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|3|NM|MO%^Monozyten||2.2|%|3.4-17.5|LL|||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|4|NM|GR%^Granulozyten||60.4|%|40-74||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|5|NM|LY^Lymphozyten||3.7|G/l|1.5-4||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|6|NM|MO^Monozyten||0.2|G/l|0.1-1.8||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|7|NM|GR^Granulozyten||6.1|G/l|1.4-8||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|8|NM|RBC^Erythrozyten||4.82|T/l|3.9-5.7||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|9|NM|HGB^Hmoglobin||15.3|g/l|11.7-17||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|10|NM|HCT^Hmatokrit||43.3|%|35-50||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|11|NM|MCV^MCV||89.8|fl|80-100||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|12|NM|MCH^MCH||31.7|pg|26-34||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|13|NM|MCHC^MCHC||35.3|g/l|31-36||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|14|NM|RDW-CV^RDW-CV||11.5|%|0-16||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|15|NM|PLT^Thrombozyten||325|G/l|143-400||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|16|NM|PCT^Thrombokrit||0.25|%|0.1-0.5||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|17|NM|MPV^Mittleres Thrombozytenvolumen||7.6|fl|6-13||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117|||||| OBX|18|NM|PDW^Thrombozyten-Verteilungsbreite||16|%|6-18||||F|||20191127093117||||MEK6500^Celltac^^|20191127093117||||||
\ No newline at end of file
......@@ -71,6 +71,35 @@ public class Test_SpecificImportFiles {
assertEquals(LabResultStatus.FINAL, lrd.getResultStatus());
}
@Test
public void test_V251_OUL_R22_17300() throws IOException, ElexisException{
File importFile = new File(PlatformHelper.getBasePath("ch.elexis.core.hl7.v2x.tests"),
"rsc/LabCube/9885_LabCube_CelltacMEK6500_20191128093117_034358.hl7");
List<HL7Reader> hl7Readers = HL7ReaderFactory.INSTANCE.getReader(importFile);
assertNotNull(hl7Readers);
assertEquals(1, hl7Readers.size());
HL7Reader reader = hl7Readers.get(0);
assertEquals(HL7ReaderV251.class, reader.getClass());
ObservationMessage observationMsg = reader.readObservation(resolver, false);
List<IValueType> observations = observationMsg.getObservations();
System.out.println("Observations [" + observations.size() + "]");
assertEquals(18, observations.size());
LabResultData lrd = (LabResultData) observations.get(3);
assertEquals("Granulozyten", lrd.getName());
assertEquals("GR%", lrd.getCode());
assertEquals("60.4", lrd.getValue());
assertEquals("40-74", lrd.getRange());
assertTrue(lrd.isNumeric());
assertFalse(lrd.isPlainText());
assertEquals("%", lrd.getUnit());
assertEquals("", lrd.getComment());
assertEquals("", lrd.getGroup());
assertEquals(LabResultStatus.FINAL, lrd.getResultStatus());
}
/**
* @throws IOException
* @throws ElexisException
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment