001 package ca.uhn.hl7v2.util;
002
003 import ca.uhn.hl7v2.HL7Exception;
004
005 /**
006 * <p>Maps local codes to interface codes and vice versa. The default implementation
007 * of CodeMapper is FileCodeMapper. An instance of FileCodeMapper can be obtained
008 * by calling <code>CodeMapper.getInstance()</code>. See FileCodeMapper for instructions
009 * on how to set up code map files. </p>
010 * <p>Please note that this class is not intended for the purpose of enumerating valid codes.
011 * If that is what you are looking for please see <code>ca.uhn.hl7v2.TableRepository</code></p>
012 * @author Bryan Tripp
013 */
014 public abstract class CodeMapper {
015
016 private static CodeMapper codeMapper = null;
017
018 /**
019 * Returns a singleton instance of CodeMapper. This is currently
020 * a FileCodeMapper by default.
021 */
022 public synchronized static CodeMapper getInstance() throws HL7Exception {
023 if (codeMapper == null) {
024 //create new file code mapper
025 codeMapper = new FileCodeMapper();
026 }
027 return codeMapper;
028 }
029
030 /**
031 * A convenience method that returns a local code from an underlying
032 * CodeMapper instance by calling <code>CodeMapper.getInstance().getLocalCode(...)</code>
033 */
034 public static String getLocal(String interfaceName, int hl7Table, String interfaceCode) throws HL7Exception {
035 return CodeMapper.getInstance().getLocalCode(interfaceName, hl7Table, interfaceCode);
036 }
037
038 /**
039 * A convenience method that returns an interface code from an underlying
040 * CodeMapper instance by calling <code>CodeMapper.getInstance().getInterfaceCode(...)</code>
041 */
042 public static String getInt(String interfaceName, int hl7Table, String localCode) throws HL7Exception {
043 return CodeMapper.getInstance().getInterfaceCode(interfaceName, hl7Table, localCode);
044 }
045
046 /**
047 * Returns the interface code for the given local code, for use in the context
048 * of the given interface.
049 */
050 public abstract String getInterfaceCode(String interfaceName, int hl7Table, String localCode) throws HL7Exception;
051
052 /**
053 * Returns the local code for the given interface code as it appears in
054 * the given interface.
055 */
056 public abstract String getLocalCode(String interfaceName, int hl7Table, String interfaceCode) throws HL7Exception;
057
058 /**
059 * Determines what happens if no matching code is found during a lookup. If set to true,
060 * an HL7Exception is thrown if there is no match. If false, null is returned. The default
061 * is false.
062 */
063 public abstract void throwExceptionIfNoMatch(boolean throwException);
064
065 /**
066 * If values are cached in such a way that they are not guaranteed to be current, a call
067 * to this method refreshes the values.
068 */
069 public abstract void refreshCache() throws HL7Exception;
070
071 /* may add these functions later to allow consistent maintenance e.g via a UI ...
072 public abstract String[] getInterfaceNames();
073 public abstract void addInterface(String name);
074 public abstract void addCodeMap(String interface, int hl7table, String localCode, String interfaceCode);
075 */
076 }