001package ca.cdr.api.hl7v2;
002
003/*
004 * #%L
005 * Smile CDR - CDR
006 * %%
007 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
008 * %%
009 * All rights reserved.
010 * #L%
011 */
012
013import ca.uhn.hl7v2.HL7Exception;
014import ca.uhn.hl7v2.Version;
015import ca.uhn.hl7v2.model.GenericMessage;
016import ca.uhn.hl7v2.model.Message;
017import ca.uhn.hl7v2.parser.CanonicalModelClassFactory;
018
019import java.io.Serializable;
020
021public class CdrModelClassFactory extends CanonicalModelClassFactory implements Serializable {
022        private static final long serialVersionUID = 1L;
023
024        public CdrModelClassFactory() {
025                super("2.5");
026        }
027
028        @Override
029        public Class<? extends Message> getMessageClass(String theName, String theVersion, boolean theIsExplicit)
030                        throws HL7Exception {
031                if ("RDE_O01".equals(theName)) {
032                        return super.getMessageClass("RDE_O11", theVersion, theIsExplicit);
033                }
034
035                Class<? extends Message> retVal = super.getMessageClass(theName, theVersion, theIsExplicit);
036
037                /*
038                 * This is here to handle invalid MSH-9 values where someone constructs MSH-9-3 by combining MSH-9-1 + MSH-9-2
039                 * instead of putting the correct value there.. E.g. if someone incorrectly puts
040                 * ADT^A04^ADT_A04 instead of the correct ADT^A04^ADT_A01 (since the A04 trigger reuses the A01 structure)
041                 */
042                if (retVal == null || GenericMessage.class.isAssignableFrom(retVal)) {
043                        String struct = super.getMessageStructureForEvent(theName, Version.V25);
044                        retVal = super.getMessageClass(struct, theVersion, theIsExplicit);
045                }
046
047                return retVal;
048        }
049}