import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.conf.ProfileException; import ca.uhn.hl7v2.conf.check.DefaultValidator; import ca.uhn.hl7v2.conf.parser.ProfileParser; import ca.uhn.hl7v2.conf.spec.RuntimeProfile; import ca.uhn.hl7v2.model.Message; //import ca.uhn.hl7v2.model.v231.message.*; //import ca.uhn.hl7v2.model.v24.message.*; //import ca.uhn.hl7v2.model.v251.message.*; //import ca.uhn.hl7v2.model.v25.message.*; //import ca.uhn.hl7v2.model.v26.message.*; //import ca.uhn.hl7v2.model.v25.*; import ca.uhn.hl7v2.parser.EncodingNotSupportedException; import ca.uhn.hl7v2.parser.FastParser; import ca.uhn.hl7v2.parser.PipeParser; import ca.uhn.hl7v2.util.Terser; import ca.uhn.hl7v2.validation.impl.NoValidation; //import ca.uhn.hl7v2.model.v25.message.RSP_K21; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.conf.ProfileException; import ca.uhn.hl7v2.conf.parser.ProfileParser; import ca.uhn.hl7v2.conf.spec.RuntimeProfile; import ca.uhn.hl7v2.conf.store.CodeStore; import ca.uhn.hl7v2.conf.store.ProfileCodeStore; import ca.uhn.hl7v2.conf.store.ProfileStoreFactory; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.parser.PipeParser; import ca.uhn.hl7v2.validation.impl.NoValidation; // those imports are required even if not explicitly used in this class!!! do not remove it import ca.uhn.hl7v2.model.v231.message.*; import ca.uhn.hl7v2.model.v24.message.*; import ca.uhn.hl7v2.model.v251.message.*; import ca.uhn.hl7v2.model.v25.message.*; import ca.uhn.hl7v2.model.v26.message.*; //import net.ihe.gazelle.iti.hl7v2.model.v25.message.QBP_Q21; //import net.ihe.gazelle.iti.hl7v2.model.v25.message.RSP_K22; import org.dom4j.io.SAXReader; import org.dom4j.*; public class Guess { public static String messageType(String message) { try { Message sutMessage; PipeParser pipeParser = new PipeParser() ; pipeParser.setValidationContext(new NoValidation()); sutMessage = pipeParser.parse(message); Terser t = new Terser(sutMessage); String messageType = ""; messageType = t.get("/.MSH-9-1") + "^"; messageType = messageType + t.get("/.MSH-9-2") + "^"; messageType = messageType + t.get("/.MSH-9-3"); if (messageType.isEmpty() || messageType.length() < 11 || messageType.length() > 15) { return null; } return messageType; } catch (HL7Exception e) { e.printStackTrace(); return null; } } public static String lastChangeToGetTheMessageType(String message) { if (message.startsWith("MSH")) { int a = 0; int b = 0; a = message.indexOf("|"); for (int i=0; i<7 ; i++) { a = message.indexOf("|", a+1); if (a == -1) return null; } message = message.substring(a+1, message.indexOf("|", a+1)); return message; } else return null; } }