001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2024 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.pub.hl7v2.common.abstraction; 011 012import ca.uhn.hl7v2.model.AbstractMessage; 013import ca.uhn.hl7v2.model.v25.message.ADT_A01; 014import ca.uhn.hl7v2.model.v25.message.ADT_A02; 015import ca.uhn.hl7v2.model.v25.message.ADT_A03; 016import ca.uhn.hl7v2.model.v25.message.ADT_A05; 017import ca.uhn.hl7v2.model.v25.message.DFT_P03; 018import ca.uhn.hl7v2.model.v25.message.OMG_O19; 019import ca.uhn.hl7v2.model.v25.message.ORM_O01; 020 021/** 022 * Wraps the relevant portion of an HL7 V2 message to an {@link IEventMessage} 023 */ 024public class EventMessageFactory { 025 026 public IEventMessage asEventMessage(AbstractMessage theMsg) { 027 if (theMsg instanceof ADT_A01) { 028 return asEventMessage((ADT_A01) theMsg); 029 } else if (theMsg instanceof ADT_A02) { 030 return asEventMessage((ADT_A02) theMsg); 031 } else if (theMsg instanceof ADT_A03) { 032 return asEventMessage((ADT_A03) theMsg); 033 } else if (theMsg instanceof ADT_A05) { 034 return asEventMessage((ADT_A05) theMsg); 035 } else if (theMsg instanceof DFT_P03) { 036 return asEventMessage((DFT_P03) theMsg); 037 } else if (theMsg instanceof OMG_O19) { 038 return asEventMessage((OMG_O19) theMsg); 039 } else if (theMsg instanceof ORM_O01) { 040 return asEventMessage((ORM_O01) theMsg); 041 } else { 042 return null; 043 } 044 } 045 046 private IEventMessage asEventMessage(ADT_A01 theMsg) { 047 return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN()); 048 } 049 050 private IEventMessage asEventMessage(ADT_A02 theMsg) { 051 return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN()); 052 } 053 054 private IEventMessage asEventMessage(ADT_A03 theMsg) { 055 return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN()); 056 } 057 058 private IEventMessage asEventMessage(ADT_A05 theMsg) { 059 return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN()); 060 } 061 062 private IEventMessage asEventMessage(OMG_O19 theMessage) { 063 return new EventMessage().setMsh(theMessage.getMSH()); 064 } 065 066 private IEventMessage asEventMessage(ORM_O01 theMessage) { 067 return new EventMessage().setMsh(theMessage.getMSH()); 068 } 069 070 private IEventMessage asEventMessage(DFT_P03 theMessage) { 071 return new EventMessage().setMsh(theMessage.getMSH()).setEvn(theMessage.getEVN()); 072 } 073}