ca.uhn.hl7v2.model.Message Java Examples

The following examples show how to use ca.uhn.hl7v2.model.Message. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HapiMessage.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public HapiMessage(final Message message) throws HL7Exception {
    this.message = message;

    allSegments = new ArrayList<>();
    populateSegments(message, allSegments);

    segmentMap = new HashMap<>();
    for (final HL7Segment segment : allSegments) {
        final String segmentName = segment.getName();
        List<HL7Segment> segmentList = segmentMap.get(segmentName);
        if (segmentList == null) {
            segmentList = new ArrayList<>();
            segmentMap.put(segmentName, segmentList);
        }

        segmentList.add(segment);
    }
}
 
Example #2
Source File: BaseIheActor.java    From openxds with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates a <code>MessageStore</code> instance, and log the 
 * initial message, either in-bound message or out-bound message.
 * 
 * @param message the initial message to log
 * @param isInbound whether the message is an in-bound message or out-bound message 
 * @return a <code>MessageStore</code>
 * @throws HL7Exception
 */
public MessageStore initMessageStore(Message message, boolean isInbound) 
throws HL7Exception {
	if (storeLogger == null)
		return null;
	
	MessageStore ret = new MessageStore(); 
	if (message != null) {
		String encodedMessage = HL7Util.encodeMessage(message);
	    if (isInbound)
	    	ret.setInMessage( encodedMessage );
	    else 
	    	ret.setOutMessage( encodedMessage );
	}
    return ret;
}
 
Example #3
Source File: BaseIheActor.java    From openxds with Apache License 2.0 6 votes vote down vote up
/**
 * Persists the <code>MessageStore</code> log, and save the return message
 * which could be either in-bound or out-bound.
 * 
 * @param message the last message to save and log
 * @param isInbound whether the message is an in-bound message or out-bound message 
 * @param msgStore the <code>MessageStore</code> instance to hold the log data
 * @throws HL7Exception if the message could not be encoded 
 */
public void saveMessageStore(Message message, boolean isInbound, MessageStore msgStore) 
throws HL7Exception {
	if (msgStore == null || storeLogger == null )
		return;
	
    if (message != null) {
	    String encodedMessage = HL7Util.encodeMessage(message);
	    if (isInbound) 
		    msgStore.setInMessage( encodedMessage );
	    else
	    	msgStore.setOutMessage( encodedMessage );
    }		
    storeLogger.saveLog( msgStore );

}
 
Example #4
Source File: SampleApp.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

    String encodedMessage = new PipeParser().encode(theIn);
    System.out.println("Received message:\n" + encodedMessage + "\n\n");

    // Now we need to generate a message to return. This will generally be an ACK message.
    Segment msh = (Segment) theIn.get("MSH");
    Message retVal;
    try {
        // This method takes in the MSH segment of an incoming message, and generates an
        // appropriate ACK
        retVal = DefaultApplication.makeACK(msh);
    } catch (IOException e) {
        throw new HL7Exception(e);
    }

    return retVal;
}
 
Example #5
Source File: XdsTest.java    From openxds with Apache License 2.0 6 votes vote down vote up
protected void createPatient(String patientId) throws Exception {
	if (!validatePatient)
		return ;
	
	patientId = patientId.replace("&amp;", "&");
	//If it is a valid patient, then no need to re-create.
	if (isValidPatient(patientId))
		return; 
	
	String msg = "MSH|^~\\&|OTHER_KIOSK|HIMSSSANDIEGO|PAT_IDENTITY_X_REF_MGR_MISYS|ALLSCRIPTS|20090512132906-0300||ADT^A04^ADT_A01|7723510070655179915|P|2.3.1\r" + 
      "EVN||20090512132906-0300\r" +
      "PID|||"+ patientId +"||FARNSWORTH^STEVE||19781208|M|||820 JORIE BLVD^^CHICAGO^IL^60523\r" +
      "PV1||O|";
	PipeParser pipeParser = new PipeParser();
	Message adt = pipeParser.parse(msg);
	ConnectionHub connectionHub = ConnectionHub.getInstance();
	Connection connection = connectionHub.attach(hostName, pixRegistryPort, new PipeParser(), MinLowerLayerProtocol.class);
	Initiator initiator = connection.getInitiator();
	Message response = initiator.sendAndReceive(adt);
	String responseString = pipeParser.encode(response);	        
	System.out.println("Received response:\n" + responseString);
		MSA msa = (MSA)response.get("MSA");
	assertEquals("AA", msa.getAcknowledgementCode().getValue());
}
 
Example #6
Source File: HapiMessage.java    From nifi with Apache License 2.0 6 votes vote down vote up
public HapiMessage(final Message message) throws HL7Exception {
    this.message = message;

    allSegments = new ArrayList<>();
    populateSegments(message, allSegments);

    segmentMap = new HashMap<>();
    for (final HL7Segment segment : allSegments) {
        final String segmentName = segment.getName();
        List<HL7Segment> segmentList = segmentMap.get(segmentName);
        if (segmentList == null) {
            segmentList = new ArrayList<>();
            segmentMap.put(segmentName, segmentList);
        }

        segmentList.add(segment);
    }
}
 
Example #7
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static Message createDefaultNackMessage(String errorMsg) throws DataTypeException {
    ACK ack = new ACK();
    ack.getMSH().getFieldSeparator().setValue(Axis2HL7Constants.HL7_DEFAULT_FIELD_SEPARATOR);
    ack.getMSH().getEncodingCharacters().setValue(Axis2HL7Constants.HL7_DEFAULT_ENCODING_CHARS);
    ack.getMSH().getReceivingApplication().setValue(Axis2HL7Constants.HL7_DEFAULT_RECEIVING_APPLICATION);
    ack.getMSH().getReceivingFacility().setValue(Axis2HL7Constants.HL7_DEFAULT_RECEIVING_FACILITY);
    ack.getMSH().getProcessingID().setValue(Axis2HL7Constants.HL7_DEFAULT_PROCESSING_ID);
    ack.getMSA().getAcknowledgementCode().setValue(Axis2HL7Constants.HL7_DEFAULT_ACK_CODE_AR);
    ack.getMSA().getMessageControlID().setValue(Axis2HL7Constants.HL7_DEFAULT_MESSAGE_CONTROL_ID);
    ack.getERR().getErrorCodeAndLocation(0).getCodeIdentifyingError().
            getIdentifier().setValue(errorMsg);
    return ack;
}
 
Example #8
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static MessageContext createSynapseMessageContext(Message message, InboundProcessorParams params)
        throws HL7Exception, AxisFault {

    MessageContext synCtx = createSynapseMessageContext(
            params.getProperties().getProperty(MLLPConstants.HL7_INBOUND_TENANT_DOMAIN));

    if (params.getProperties().getProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED) != null) {
        synCtx.setProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED,
                           params.getProperties().getProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED));
    }

    try {
        synCtx.setEnvelope(createEnvelope(synCtx, message, params));
    } catch (Exception e) {
        throw new HL7Exception(e);
    }

    return synCtx;
}
 
Example #9
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Reads an ORU_R01 HL7 file
 * 
 * @param text
 *            ISO-8559-1 String
 * @param readWithValidation
 *            True for parsing with validation, False for parsing without validation
 * @return The ORU_R01 message
 * @throws HL7Exception
 */
public ORU_R01 read(String text, boolean readWithValidation) throws HL7Exception{
	Parser p = new PipeParser();
	if (readWithValidation) {
		p.setValidationContext(new ElexisValidation());
	} else {
		p.setValidationContext(new NoValidation());
	}
	Message hl7Msg = p.parse(text);
	if (hl7Msg instanceof ORU_R01) {
		return (ORU_R01) hl7Msg;
	} else {
		addError(
			MessageFormat.format(Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName()));
	}
	return null;
}
 
Example #10
Source File: HL7KettleParser.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static List<HL7Value> extractValues( Message message ) throws Exception {
  Terser terser = new Terser( message );
  SegmentFinder finder = terser.getFinder();

  List<HL7Value> values = new ArrayList<HL7Value>();

  int childNr = 1;

  while ( finder.hasNextChild() ) {

    // next group in the message (MSH, PID, EVN and so on)
    //
    finder.nextChild();
    Structure[] structures = finder.getCurrentChildReps();
    for ( int i = 0; i < structures.length; i++ ) {
      Structure structure = structures[i];
      parseStructure( values, message, terser, structure, Integer.toString( childNr ) );
    }

    childNr++;
  }

  return values;
}
 
Example #11
Source File: TestHL7Query.java    From nifi with Apache License 2.0 5 votes vote down vote up
private HL7Message createMessage(final String msgText) throws HL7Exception, IOException {
    final HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(ValidationContextFactory.noValidation());

    final PipeParser parser = hapiContext.getPipeParser();
    final Message message = parser.parse(msgText);
    return new HapiMessage(message);
}
 
Example #12
Source File: HL7IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void testMarshalUnmarshal() throws Exception {

    final String msg = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";
    final HL7DataFormat format = new HL7DataFormat();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(format)
            .unmarshal(format)
            .to("mock:result");
        }
    });

    camelctx.start();
    try {
        HapiContext context = new DefaultHapiContext();
        Parser p = context.getGenericParser();
        Message hapimsg = p.parse(msg);

        ProducerTemplate producer = camelctx.createProducerTemplate();
        Message result = (Message) producer.requestBody("direct:start", hapimsg);
        Assert.assertEquals(hapimsg.toString(), result.toString());
    } finally {
        camelctx.close();
    }
}
 
Example #13
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
	 * Converts a PIX Feed Patient message to a {@link Patient} object.
	 * 
	 * @param msgIn the incoming PIX Feed message
	 * @return a {@link Patient} object
	 * @throws ApplicationException if something is wrong with the application
	 */
	private Patient getPatient(Message msgIn) throws ApplicationException,HL7Exception {
		HL7v231ToBaseConvertor convertor = null;
		if (msgIn.getVersion().equals("2.3.1")) {
			convertor = new HL7v231ToBaseConvertor(msgIn, connection);
		} else {
			throw new ApplicationException("Unexpected HL7 version");
		}
		Patient patientDesc = new Patient();
		patientDesc.setPatientIds(convertor.getPatientIds());
		patientDesc.setPatientName(convertor.getPatientName());
		patientDesc.setMonthersMaidenName(convertor.getMotherMaidenName());
		patientDesc.setBirthDateTime(convertor.getBirthDate());
		patientDesc.setAdministrativeSex(convertor.getSexType());
		patientDesc.setPatientAlias(convertor.getPatientAliasName());
		patientDesc.setRace(convertor.getRace());
		patientDesc.setPrimaryLanguage(convertor.getPrimaryLanguage());
		patientDesc.setMaritalStatus(convertor.getMartialStatus());
		patientDesc.setReligion(convertor.getReligion());
		patientDesc.setPatientAccountNumber(convertor.getpatientAccountNumber());
		patientDesc.setSsn(convertor.getSsn());
		patientDesc.setDriversLicense(convertor.getDriversLicense());
		patientDesc.setMonthersId(convertor.getMonthersId());
		patientDesc.setEthnicGroup(convertor.getEthnicGroup());
		patientDesc.setBirthPlace(convertor.getBirthPlace());
		patientDesc.setBirthOrder(convertor.getBirthOrder());
		patientDesc.setCitizenship(convertor.getCitizenShip());
		patientDesc.setDeathDate(convertor.getDeathDate());		
//TODO: patientDesc.setDeathIndicator(convertor.getDeathIndicator());
		patientDesc.setPhoneNumbers(convertor.getPhoneList());
		patientDesc.setAddresses(convertor.getAddressList());
		patientDesc.setVisits(convertor.getVisitList());
		return patientDesc;
	}
 
Example #14
Source File: HL7IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private Message createADT01Message() throws Exception {
    ADT_A01 adt = new ADT_A01();
    adt.initQuickstart("ADT", "A01", "P");

    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(PATIENT_ID);

    return adt;
}
 
Example #15
Source File: MergePatientTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
private void SendPIX(String msg) throws Exception {
PipeParser pipeParser = new PipeParser();
Message adt = pipeParser.parse(msg);
ConnectionHub connectionHub = ConnectionHub.getInstance();
Connection connection = connectionHub.attach(hostName, pixRegistryPort, new PipeParser(), MinLowerLayerProtocol.class);
Initiator initiator = connection.getInitiator();
Message response = initiator.sendAndReceive(adt);
String responseString = pipeParser.encode(response);	        
System.out.println("Received response:\n" + responseString);
MSA msa = (MSA)response.get("MSA");
assertEquals("AA", msa.getAcknowledgementCode().getValue());    	
  }
 
Example #16
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the merge patient out of a PIX Merge Patient message.
 * 
 * @param msgIn the incoming PIX Merge message
 * @return a {@link Patient} object that represents the merge patient
 * @throws ApplicationException if something is wrong with the application
 */
private Patient getMrgPatient(Message msgIn) throws ApplicationException, HL7Exception {
	HL7v231ToBaseConvertor convertor = null;		
	convertor = new HL7v231ToBaseConvertor(msgIn, connection);
	Patient patientDesc = new Patient();
	patientDesc.setPatientIds(convertor.getMrgPatientIds());
	patientDesc.setPatientName(convertor.getMrgPatientName());
	patientDesc.setPatientAccountNumber(convertor
			.getMrgpatientAccountNumber());
	patientDesc.setVisits(convertor.getMrgVisitList());
	return patientDesc;
}
 
Example #17
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
 * Processes PIX Feed Update Patient message.
 * 
 * @param msgIn the PIX Feed request message
 * @return a response message for PIX Feed
 * @throws ApplicationException If Application has trouble
 * @throws HL7Exception if something is wrong with HL7 message 
 */
private Message processUpdate(Message msgIn) throws ApplicationException,
		HL7Exception {
	assert msgIn instanceof ADT_A01 ||
		   msgIn instanceof ADT_A08 ;
	
	HL7Header hl7Header = new HL7Header(msgIn);
	
	//Create Acknowledgment and its Header
	ACK reply = initAcknowledgment(hl7Header);

	//Validate incoming message first
	PID pid = (PID)msgIn.get("PID");
	PatientIdentifier patientId = getPatientIdentifiers(pid);				
	boolean isValidMessage = validateMessage(reply, hl7Header, patientId, null, false);
	if (!isValidMessage) return reply;
	
	//Invoke eMPI function
	MessageHeader header = hl7Header.toMessageHeader();
	RegistryPatientContext context = new RegistryPatientContext(header);
	Patient patient = getPatient(msgIn);
	try {
		//Update Patient
		patientManager.updatePatient(patient, context);			
	} catch (RegistryPatientException e) {
		throw new ApplicationException(e);
	}
   	
	HL7v231.populateMSA(reply.getMSA(), "AA", hl7Header.getMessageControlId());
   	
	//TODO: revisit Audit
	//Finally, Audit Log PIX Feed Success 
    //auditLog(hl7Header, patient, AuditCodeMappings.EventActionCode.Update);

   	return reply;
}
 
Example #18
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
    * Whether an incoming message can be processed by this handler.
    * 
    * @return <code>true</code> if the incoming message can be processed;
    * otherwise <code>false</code>.
    */
public boolean canProcess(Message theIn) {
	if (theIn instanceof ADT_A01 || theIn instanceof ADT_A04 ||
	    theIn instanceof ADT_A05 || theIn instanceof ADT_A08 ||
	    theIn instanceof ADT_A39 )
		return true;
	else
		return false;
}
 
Example #19
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reads an ORU_R01 HL7 file
 * 
 * @param text
 *            ISO-8559-1 String
 * @return
 * @throws HL7Exception
 */
public ORU_R01 read(String text) throws HL7Exception{
	Parser p = new PipeParser();
	p.setValidationContext(new ElexisValidation());
	Message hl7Msg = p.parse(text);
	if (hl7Msg instanceof ORU_R01) {
		return (ORU_R01) hl7Msg;
	} else {
		addError(MessageFormat.format(
			Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName())); //$NON-NLS-1$
	}
	return null;
}
 
Example #20
Source File: HL7InboundTestSender.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public String send(String host, int port, Message message) throws HL7Exception, IOException, LLPException {
    HapiContext context = new DefaultHapiContext();
    Connection c = context.newClient(host, port, false);
    Initiator initiator = c.getInitiator();

    Message resp = initiator.sendAndReceive(message);
    return resp.encode();
}
 
Example #21
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static SOAPEnvelope createEnvelope(MessageContext synCtx, Message message, InboundProcessorParams params)
        throws HL7Exception, XMLStreamException, MLLProtocolException {
    SOAPEnvelope envelope = fac.getDefaultEnvelope();
    boolean rawMessage = false;
    String xmlDoc = "";
    try {
        xmlDoc = xmlParser.encode(message);
        synCtx.setProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED, new Boolean(true));
    } catch (HL7Exception e) {
        synCtx.setProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED, new Boolean(false));
        if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE) != null && params
                .getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equals("true")) {
            xmlDoc = message.encode();
            rawMessage = true;
        } else {
            log.error("Could not encode HL7 message into XML. " + "Set " + MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE
                              + " to build invalid HL7 messages containing raw HL7 message.", e);
            throw new HL7Exception("Could not encode HL7 message into XML", e);
        }
    }

    OMElement messageEl;
    if (!rawMessage) {
        messageEl = generateHL7MessageElement(xmlDoc);
    } else {
        messageEl = generateHL7RawMessaegElement(xmlDoc);
    }
    envelope.getBody().addChild(messageEl);
    return envelope;
}
 
Example #22
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static Message createNack(Message hl7Msg, String errorMsg) throws HL7Exception {
    if (errorMsg == null) {
        errorMsg = "";
    }
    if (hl7Msg == null) {
        return createDefaultNackMessage(errorMsg);
    } else {
        try {
            return hl7Msg.generateACK(AcknowledgmentCode.AE, new HL7Exception(errorMsg));
        } catch (IOException e) {
            throw new HL7Exception(e);
        }
    }
}
 
Example #23
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static Message createDefaultNack(String errorMsg) {
    try {
        return createDefaultNackMessage(errorMsg);
    } catch (DataTypeException e) {
        log.error("Error while creating default NACK message.", e);
    }

    return null;
}
 
Example #24
Source File: TestHL7Query.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private HL7Message createMessage(final File file) throws HL7Exception, IOException {
    final byte[] bytes = Files.readAllBytes(file.toPath());
    final String msgText = new String(bytes, "UTF-8");

    final HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(ValidationContextFactory.noValidation());

    final PipeParser parser = hapiContext.getPipeParser();
    final Message message = parser.parse(msgText);
    return new HapiMessage(message);
}
 
Example #25
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static Message parse(String msg, boolean validate) throws HL7Exception {
    if (validate) {
        return pipeParser.parse(msg);
    } else {
        return noValidationPipeParser.parse(msg);
    }
}
 
Example #26
Source File: HL7InboundTestSender.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public String send(String host, int port) throws HL7Exception, IOException, LLPException {
       HapiContext context = new DefaultHapiContext();
       Connection c = context.newClient(host, port, false);
       Initiator initiator = c.getInitiator();

       ADT_A01 msg = new ADT_A01();
       msg.initQuickstart("ADT", "A01", "T");
       Message resp = initiator.sendAndReceive(msg);
       return resp.encode();
}
 
Example #27
Source File: HL7MLLPInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) {
  Result result = previousResult;

  try {

    String serverName = environmentSubstitute( server );
    int portNumber = Integer.parseInt( environmentSubstitute( port ) );
    String messageVariable = environmentSubstitute( messageVariableName );
    String messageTypeVariable = environmentSubstitute( messageTypeVariableName );
    String versionVariable = environmentSubstitute( versionVariableName );

    MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource( serverName, portNumber );
    if ( entry.getJobListener() != null ) {
      parentJob.addJobListener( entry.getJobListener() );
    }
    MLLPTransport transport = entry.getTransport();

    // Get the next value...
    //
    synchronized ( transport ) {
      Transportable transportable = transport.doReceive();
      String message = transportable.getMessage();

      logDetailed( "Received message: " + message );

      parentJob.setVariable( messageVariable, message );

      // Parse the message and extract the control ID.
      //
      Parser parser = new GenericParser();
      ValidationContext validationContext = new NoValidation();
      parser.setValidationContext( validationContext );
      Message msg = parser.parse( message );
      Structure structure = msg.get( "MSH" );
      String messageType = null;
      String version = msg.getVersion();

      if ( structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v21.segment.MSH) structure ).getMESSAGETYPE().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v22.segment.MSH) structure ).getMessageType().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v23.segment.MSH) structure ).getMessageType().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v231.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v24.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v25.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v251.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v26.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else {
        logError( "This job entry does not support the HL7 dialect used. Found MSH class: "
            + structure.getClass().getName() );
      }

      if ( !Utils.isEmpty( messageTypeVariable ) ) {
        parentJob.setVariable( messageTypeVariable, messageType );
      }
      if ( !Utils.isEmpty( versionVariable ) ) {
        parentJob.setVariable( versionVariable, version );
      }
    }

    // All went well..
    //
    result.setNrErrors( 0 );
    result.setResult( true );

  } catch ( Exception e ) {
    log.logError( BaseMessages.getString( PKG, "HL7MLLPInput.Exception.UnexpectedError" ), e );
    result.setNrErrors( 1 );
    result.setResult( false );
  }

  return result;
}
 
Example #28
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public static Message parse(String msg, final Parser preProcessor) throws HL7Exception {
    return preProcessor.parse(msg);
}
 
Example #29
Source File: HL7Reader.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public Message getACK() throws HL7Exception, IOException{
	return message.generateACK();
}
 
Example #30
Source File: HL7Input.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (HL7InputMeta) smi;
  data = (HL7InputData) sdi;

  Object[] r = getRow(); // get row, set busy!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }

  if ( first ) {
    data.messageFieldIndex = getInputRowMeta().indexOfValue( meta.getMessageField() );
    if ( data.messageFieldIndex < 0 ) {
      throw new KettleException( "Unable to find field [" + meta.getMessageField() + "] in the input fields." );
    }

    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.parser = new GenericParser();
    data.parser.setValidationContext( new NoValidation() );
  }

  String messageString = getInputRowMeta().getString( r, data.messageFieldIndex );

  try {
    Message message = data.parser.parse( messageString );
    List<HL7Value> values = HL7KettleParser.extractValues( message );

    for ( HL7Value value : values ) {
      Object[] output = RowDataUtil.createResizedCopy( r, data.outputRowMeta.size() );
      int outputIndex = getInputRowMeta().size();

      output[outputIndex++] = value.getParentGroup();
      output[outputIndex++] = value.getGroupName();
      output[outputIndex++] = value.getVersion();
      output[outputIndex++] = value.getStructureName();
      output[outputIndex++] = value.getStructureNumber();
      output[outputIndex++] = value.getFieldName();
      output[outputIndex++] = value.getCoordinate();
      output[outputIndex++] = value.getDataType();
      output[outputIndex++] = value.getDescription();
      output[outputIndex++] = value.getValue();

      putRow( data.outputRowMeta, output );
    }
  } catch ( Exception e ) {
    throw new KettleException( "Error parsing message", e );
  }

  if ( checkFeedback( getLinesWritten() ) ) {
    if ( log.isBasic() ) {
      logBasic( BaseMessages.getString( PKG, "HL7Input.Log.LineNumber" ) + getLinesWritten() );
    }
  }

  return true;
}