Tabnine Logo
GenericParser
Code IndexAdd Tabnine to your IDE (free)

How to use
GenericParser
in
ca.uhn.hl7v2.parser

Best Java code snippets using ca.uhn.hl7v2.parser.GenericParser (Showing top 20 results out of 315)

origin: pentaho/pentaho-kettle

Parser parser = new GenericParser();
ValidationContext validationContext = new NoValidation();
parser.setValidationContext( validationContext );
origin: openmrs/openmrs-core

/**
 * @see org.openmrs.hl7.HL7Service#parseHL7String(String)
 */
@Override
public Message parseHL7String(String hl7Message) throws HL7Exception {
  // Any pre-parsing for HL7 messages would go here
  // or a module can use AOP to pre-parse the message
  
  // First, try and parse the message
  Message message;
  try {
    message = parser.parse(hl7Message);
  }
  catch (EncodingNotSupportedException e) {
    throw new HL7Exception("HL7 encoding not supported", e);
  }
  catch (HL7Exception e) {
    throw new HL7Exception("Error parsing message", e);
  }
  
  return message;
}

origin: ca.uhn.hapi/hapi-osgi-base

/** 
 * Converts XML message to ER7, first checking integrity of parse and throwing 
 * an exception if parse not correct
 */
static String safeER7Conversion(String xmlMessage) throws HL7Exception {
  Message m = parser.parse(xmlMessage);
  String check = parser.encode(m, "XML");
  if (!equivalent(xmlMessage, check)) {
    throw new HL7Exception("Parsed and encoded message not equivalent to original (possibilities: invalid message, bug in parser)");
  }
  
  return parser.encode(m, "VB");        
}
origin: stackoverflow.com

 // the ANTLR grammar
File f = new File("src/test/ressources/Java.g4");
// plug the ANTLR grammar in 
GenericParser gp = new GenericParser(f, "Java");
// load the file that we'd like to parse into a String variable
String s = FileUtils.loadFileContent("src/test/ressources/HelloWorld.java");
// this listener will create an AST from the java file    
gp.setListener(new DefaultTreeListener());
// compile Parser/Lexer
gp.compile();
ParserRuleContext ctx = ctx = gp.parse(s);
// get access to AST
Ast ast = dlist.getAst();
// print AST in dot format
System.out.println(ast.toDot());
origin: ca.uhn.hapi/hapi-base

public static void main(String[] args) throws HL7Exception {
  String msgString = "MSH|^~\\&|RAMSOFT|SENDING FACILITY|RAMSOFT|RECEIVING FACILITY|20101223202939-0400||ADT^A08|101|P|2.3.1||||||||\r"
      + "EVN|A08|20101223202939-0400||||\r"
      + "PID||P12345^^^ISSUER|P12345^^^ISSUER||PATIENT^TEST^M^^^^||19741018|M|||10808 FOOTHILL BLVD^^RANCHO CUCAMONGA^CA^91730^US||(909)481-5872^^^sales@ramsoft.com|(909)481-5800x1||M||12345|286-50-9510|||\r"
      + "PV1||O||||||||||||||||||||||||||||||||||||||||||||||||||\r"
      + "AL1|1||^PORK^|\r"
      + "AL1|2||^PENICILLIN^|";
  GenericParser parser = new GenericParser();
  parser.setValidationContext(ValidationContextFactory.noValidation());
  Message msg = parser.parse(msgString);
  System.out.println(msg.getClass().getName());
}
origin: ca.uhn.hapi/hapi-base

/**
 * Parses a message string and returns the corresponding Message object.
 * 
 * @throws HL7Exception if the message is not correctly formatted.
 * @throws EncodingNotSupportedException if the message encoded is not supported by this parser.
 */
protected Message doParse(String message, String version) throws HL7Exception {
  return getAppropriateParser(message).doParse(message, version);
}
origin: ca.uhn.hapi/hapi-base

/**
 * Checks the encoding of the message using getEncoding(), and returns the corresponding parser
 * (either pipeParser or xmlParser). If the encoding is not recognized an HL7Exception is
 * thrown.
 */
private Parser getAppropriateParser(String message) throws HL7Exception {
  String encoding = getEncoding(message);
  if ("VB".equalsIgnoreCase(encoding)) return pipeParser;
  if ("XML".equalsIgnoreCase(encoding)) return xmlParser;
  throw new HL7Exception("Can't find appropriate parser - encoding not recognized");          
}
origin: ca.uhn.hapi/hapi-base

/**
 * @param context the HapiContext to be used
 */
public GenericParser(HapiContext context) {
  super(context);
  pipeParser = new PipeParser(context);
  xmlParser = new DefaultXMLParser(context);
  setPipeParserAsPrimary();
}
origin: ca.uhn.hapi/hapi-base

/**
 * Generates an empty response message. This class generates an
 * ACKnowledgement using the code returned by {@link #getSuccessAcknowledgementCode()}.
 * 
 * @param request request message, either a {@link String} or a
 *            {@link Message}
 * @return acknowledgment to the request
 * @throws HL7Exception
 */
protected Message generateResponseMessage(Object request) throws HL7Exception {
  try {
    Message in;
    if (request instanceof String) {
      Segment s = getHapiContext().getGenericParser().getCriticalResponseData(
          (String)request);
      in = s.getMessage();
      DeepCopy.copy(s, (Segment) in.get("MSH"));
    } else if (request instanceof Message) {
      in = (Message) request;
    } else {
      throw new HL7Exception("Validated message must be either Message or String");
    }
    return in.generateACK(getSuccessAcknowledgementCode(), null);
  } catch (IOException e) {
    throw new HL7Exception(e);
  }
}
origin: ca.uhn.hapi/hapi-osgi-base

public static void main(String[] args) throws HL7Exception {
  String msgString = "MSH|^~\\&|RAMSOFT|SENDING FACILITY|RAMSOFT|RECEIVING FACILITY|20101223202939-0400||ADT^A08|101|P|2.3.1||||||||\r"
      + "EVN|A08|20101223202939-0400||||\r"
      + "PID||P12345^^^ISSUER|P12345^^^ISSUER||PATIENT^TEST^M^^^^||19741018|M|||10808 FOOTHILL BLVD^^RANCHO CUCAMONGA^CA^91730^US||(909)481-5872^^^sales@ramsoft.com|(909)481-5800x1||M||12345|286-50-9510|||\r"
      + "PV1||O||||||||||||||||||||||||||||||||||||||||||||||||||\r"
      + "AL1|1||^PORK^|\r"
      + "AL1|2||^PENICILLIN^|";
  GenericParser parser = new GenericParser();
  parser.setValidationContext(ValidationContextFactory.noValidation());
  Message msg = parser.parse(msgString);
  System.out.println(msg.getClass().getName());
}
origin: ca.uhn.hapi/hapi-osgi-base

/**
 * Returns the version ID (MSH-12) from the given message, without fully parsing the message.
 * The version is needed prior to parsing in order to determine the message class into which the
 * text of the message should be parsed.
 * 
 * @throws HL7Exception if the version field can not be found.
 */
public String getVersion(String message) throws HL7Exception {
  return getAppropriateParser(message).getVersion(message);
}
origin: ca.uhn.hapi/hapi-osgi-base

/**
 * Checks the encoding of the message using getEncoding(), and returns the corresponding parser
 * (either pipeParser or xmlParser). If the encoding is not recognized an HL7Exception is
 * thrown.
 */
private Parser getAppropriateParser(String message) throws HL7Exception {
  String encoding = getEncoding(message);
  if ("VB".equalsIgnoreCase(encoding)) return pipeParser;
  if ("XML".equalsIgnoreCase(encoding)) return xmlParser;
  throw new HL7Exception("Can't find appropriate parser - encoding not recognized");          
}
origin: ca.uhn.hapi/hapi-base

/**
 * Creates a new instance of GenericParser
 * 
 * @param theFactory custom factory to use for model class lookup
 */
public GenericParser(ModelClassFactory theFactory) {
  super(theFactory);
  pipeParser = new PipeParser(theFactory);
  xmlParser = new DefaultXMLParser(theFactory);
  setPipeParserAsPrimary();
}
origin: ca.uhn.hapi/hapi-osgi-base

/**
 * Generates an empty response message. This class generates an
 * ACKnowledgement using the code returned by {@link #getSuccessAcknowledgementCode()}.
 * 
 * @param request request message, either a {@link String} or a
 *            {@link Message}
 * @return acknowledgment to the request
 * @throws HL7Exception
 */
protected Message generateResponseMessage(Object request) throws HL7Exception {
  try {
    Message in;
    if (request instanceof String) {
      Segment s = getHapiContext().getGenericParser().getCriticalResponseData(
          (String)request);
      in = s.getMessage();
      DeepCopy.copy(s, (Segment) in.get("MSH"));
    } else if (request instanceof Message) {
      in = (Message) request;
    } else {
      throw new HL7Exception("Validated message must be either Message or String");
    }
    return in.generateACK(getSuccessAcknowledgementCode(), null);
  } catch (IOException e) {
    throw new HL7Exception(e);
  }
}
origin: openmrs/openmrs-core

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test(expected = ApplicationException.class)
public void processMessage_shouldFailOnEmptyConceptAnswers() throws Exception {
  String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080630094800||ORU^R01|kgWdFt0SVwwClOfJm3pe|P|2.5|1||||||||15^AMRS.ELD.FORMID\r"
      + "PID|||3^^^^~d3811480^^^^||John3^Doe^||\r"
      + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20080208|||||||V\r"
      + "ORC|RE||||||||20080208000000|1^Super User\r"
      + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r"
      + "OBX|1|CWE|5497^CD4, BY FACS^99DCT||^^99DCT|||||||||20080208";
  Message hl7message = parser.parse(hl7string);
  router.processMessage(hl7message);
}

origin: pentaho/pentaho-kettle

meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );
data.parser = new GenericParser();
data.parser.setValidationContext( new NoValidation() );
origin: ca.uhn.hapi/hapi-base

/** 
 * Converts XML message to ER7, first checking integrity of parse and throwing 
 * an exception if parse not correct
 */
static String safeER7Conversion(String xmlMessage) throws HL7Exception {
  Message m = parser.parse(xmlMessage);
  String check = parser.encode(m, "XML");
  if (!equivalent(xmlMessage, check)) {
    throw new HL7Exception("Parsed and encoded message not equivalent to original (possibilities: invalid message, bug in parser)");
  }
  
  return parser.encode(m, "VB");        
}
origin: ca.uhn.hapi/hapi-osgi-base

/**
 * Parses a message string and returns the corresponding Message object.
 * 
 * @throws HL7Exception if the message is not correctly formatted.
 * @throws EncodingNotSupportedException if the message encoded is not supported by this parser.
 */
protected Message doParse(String message, String version) throws HL7Exception {
  return getAppropriateParser(message).doParse(message, version);
}
origin: ca.uhn.hapi/hapi-base

/**
 * Returns a "standardized" equivalent of the given message string.  For delimited
 * messages, the returned value is the shortest string that has an equivalent
 * meaning in HL7.  For XML-encoded messages, the returned value is equivalent XML output
 * using a standard pretty-print format.  An automatic determination is made about whether 
 * the given string is XML or ER7 (i.e. traditionally) encoded.
 * @param message an XML-encoded or ER7-encoded message string
 */
public static String standardize(String message) throws SAXException {
  String result = null;
  String encoding = parser.getEncoding(message);
  if (encoding.equals("XML")) {
    result = standardizeXML(message);
  } else {
    result = standardizeER7(message);
  }
  return result;
}

origin: ca.uhn.hapi/hapi-osgi-base

/**
 * @param context the HapiContext to be used
 */
public GenericParser(HapiContext context) {
  super(context);
  pipeParser = new PipeParser(context);
  xmlParser = new DefaultXMLParser(context);
  setPipeParserAsPrimary();
}
ca.uhn.hl7v2.parserGenericParser

Javadoc

A Parser that delegates parsing tasks to an underlying PipeParser and DefaultXMLParser as needed. Messages to be parsed are inspected in order to determine which Parser to use. If a message is to be encoded, the "primary" Parser will be used. The primary parser defaults to PipeParser, and can be configured using the set...AsPrimary() methods.

Most used methods

  • <init>
    Creates a new instance of GenericParser
  • parse
  • encode
  • getAppropriateParser
    Checks the encoding of the message using getEncoding(), and returns the corresponding parser (either
  • getCriticalResponseData
    Returns a minimal amount of data from a message string, including only the data needed to send a re
  • getEncoding
    Returns a String representing the encoding of the given message, if the encoding is recognized. For
  • setPipeParserAsPrimary
    Sets the underlying PipeParser as the primary parser, so that subsequent calls to encode() will retu
  • setValidationContext
  • compile
  • setListener

Popular in Java

  • Reading from database using SQL prepared statement
  • getSharedPreferences (Context)
  • getResourceAsStream (ClassLoader)
  • requestLocationUpdates (LocationManager)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JList (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now