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.MDM_T01;
019import ca.uhn.hl7v2.model.v25.message.MDM_T02;
020import ca.uhn.hl7v2.model.v25.message.OMG_O19;
021import ca.uhn.hl7v2.model.v25.message.ORM_O01;
022
023/**
024 * Wraps the relevant portion of an HL7 V2 message to an {@link IEventMessage}
025 */
026public class EventMessageFactory {
027
028        public IEventMessage asEventMessage(AbstractMessage theMsg) {
029                if (theMsg instanceof ADT_A01 adtA01) {
030                        return asEventMessage(adtA01);
031                } else if (theMsg instanceof ADT_A02 adtA02) {
032                        return asEventMessage(adtA02);
033                } else if (theMsg instanceof ADT_A03 adtA03) {
034                        return asEventMessage(adtA03);
035                } else if (theMsg instanceof ADT_A05 adtA05) {
036                        return asEventMessage(adtA05);
037                } else if (theMsg instanceof DFT_P03 dftP03) {
038                        return asEventMessage(dftP03);
039                } else if (theMsg instanceof OMG_O19 omgO19) {
040                        return asEventMessage(omgO19);
041                } else if (theMsg instanceof ORM_O01 ormO01) {
042                        return asEventMessage(ormO01);
043                } else if (theMsg instanceof MDM_T01 mdmT01) {
044                        return asEventMessage(mdmT01);
045                } else if (theMsg instanceof MDM_T02 mdmT02) {
046                        return asEventMessage(mdmT02);
047                } else {
048                        return null;
049                }
050        }
051
052        private IEventMessage asEventMessage(ADT_A01 theMsg) {
053                return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN());
054        }
055
056        private IEventMessage asEventMessage(ADT_A02 theMsg) {
057                return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN());
058        }
059
060        private IEventMessage asEventMessage(ADT_A03 theMsg) {
061                return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN());
062        }
063
064        private IEventMessage asEventMessage(ADT_A05 theMsg) {
065                return new EventMessage().setMessage(theMsg).setMsh(theMsg.getMSH()).setEvn(theMsg.getEVN());
066        }
067
068        private IEventMessage asEventMessage(OMG_O19 theMessage) {
069                return new EventMessage().setMsh(theMessage.getMSH());
070        }
071
072        private IEventMessage asEventMessage(ORM_O01 theMessage) {
073                return new EventMessage().setMsh(theMessage.getMSH());
074        }
075
076        private IEventMessage asEventMessage(DFT_P03 theMessage) {
077                return new EventMessage().setMsh(theMessage.getMSH()).setEvn(theMessage.getEVN());
078        }
079
080        private IEventMessage asEventMessage(MDM_T01 theMessage) {
081                return new EventMessage().setMsh(theMessage.getMSH()).setEvn(theMessage.getEVN());
082        }
083
084        private IEventMessage asEventMessage(MDM_T02 theMessage) {
085                return new EventMessage().setMsh(theMessage.getMSH()).setEvn(theMessage.getEVN());
086        }
087}