Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CodeMapper |
|
| 1.1428571428571428;1.143 |
1 | package ca.uhn.hl7v2.util; | |
2 | ||
3 | import ca.uhn.hl7v2.HL7Exception; | |
4 | ||
5 | /** | |
6 | * <p>Maps local codes to interface codes and vice versa. The default implementation | |
7 | * of CodeMapper is FileCodeMapper. An instance of FileCodeMapper can be obtained | |
8 | * by calling <code>CodeMapper.getInstance()</code>. See FileCodeMapper for instructions | |
9 | * on how to set up code map files. </p> | |
10 | * <p>Please note that this class is not intended for the purpose of enumerating valid codes. | |
11 | * If that is what you are looking for please see <code>ca.uhn.hl7v2.TableRepository</code></p> | |
12 | * @author Bryan Tripp | |
13 | */ | |
14 | 0 | public abstract class CodeMapper { |
15 | ||
16 | 0 | private static CodeMapper codeMapper = null; |
17 | ||
18 | /** | |
19 | * Returns a singleton instance of CodeMapper. This is currently | |
20 | * a FileCodeMapper by default. | |
21 | */ | |
22 | public synchronized static CodeMapper getInstance() throws HL7Exception { | |
23 | 0 | if (codeMapper == null) { |
24 | //create new file code mapper | |
25 | 0 | codeMapper = new FileCodeMapper(); |
26 | } | |
27 | 0 | return codeMapper; |
28 | } | |
29 | ||
30 | /** | |
31 | * A convenience method that returns a local code from an underlying | |
32 | * CodeMapper instance by calling <code>CodeMapper.getInstance().getLocalCode(...)</code> | |
33 | */ | |
34 | public static String getLocal(String interfaceName, int hl7Table, String interfaceCode) throws HL7Exception { | |
35 | 0 | return CodeMapper.getInstance().getLocalCode(interfaceName, hl7Table, interfaceCode); |
36 | } | |
37 | ||
38 | /** | |
39 | * A convenience method that returns an interface code from an underlying | |
40 | * CodeMapper instance by calling <code>CodeMapper.getInstance().getInterfaceCode(...)</code> | |
41 | */ | |
42 | public static String getInt(String interfaceName, int hl7Table, String localCode) throws HL7Exception { | |
43 | 0 | return CodeMapper.getInstance().getInterfaceCode(interfaceName, hl7Table, localCode); |
44 | } | |
45 | ||
46 | /** | |
47 | * Returns the interface code for the given local code, for use in the context | |
48 | * of the given interface. | |
49 | */ | |
50 | public abstract String getInterfaceCode(String interfaceName, int hl7Table, String localCode) throws HL7Exception; | |
51 | ||
52 | /** | |
53 | * Returns the local code for the given interface code as it appears in | |
54 | * the given interface. | |
55 | */ | |
56 | public abstract String getLocalCode(String interfaceName, int hl7Table, String interfaceCode) throws HL7Exception; | |
57 | ||
58 | /** | |
59 | * Determines what happens if no matching code is found during a lookup. If set to true, | |
60 | * an HL7Exception is thrown if there is no match. If false, null is returned. The default | |
61 | * is false. | |
62 | */ | |
63 | public abstract void throwExceptionIfNoMatch(boolean throwException); | |
64 | ||
65 | /** | |
66 | * If values are cached in such a way that they are not guaranteed to be current, a call | |
67 | * to this method refreshes the values. | |
68 | */ | |
69 | public abstract void refreshCache() throws HL7Exception; | |
70 | ||
71 | /* may add these functions later to allow consistent maintenance e.g via a UI ... | |
72 | public abstract String[] getInterfaceNames(); | |
73 | public abstract void addInterface(String name); | |
74 | public abstract void addCodeMap(String interface, int hl7table, String localCode, String interfaceCode); | |
75 | */ | |
76 | } |