View Javadoc
1   
2   package ca.uhn.fhir.model.dstu.valueset;
3   
4   /*
5    * #%L
6    * HAPI FHIR - Core Library
7    * %%
8    * Copyright (C) 2014 University Health Network
9    * %%
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   * #L%
22   */
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import ca.uhn.fhir.model.api.IValueSetEnumBinder;
28  
29  public enum ExtensionContextEnum {
30  
31  	/**
32  	 * Code Value: <b>resource</b>
33  	 *
34  	 * The context is all elements matching a particular resource element path.
35  	 */
36  	RESOURCE("resource", "http://hl7.org/fhir/extension-context"),
37  	
38  	/**
39  	 * Code Value: <b>datatype</b>
40  	 *
41  	 * The context is all nodes matching a particular data type element path (root or repeating element) or all elements referencing a particular primitive data type (expressed as the datatype name).
42  	 */
43  	DATATYPE("datatype", "http://hl7.org/fhir/extension-context"),
44  	
45  	/**
46  	 * Code Value: <b>mapping</b>
47  	 *
48  	 * The context is all nodes whose mapping to a specified reference model corresponds to a particular mapping structure.  The context identifies the mapping target. The mapping should clearly identify where such an extension could be used.
49  	 */
50  	MAPPING("mapping", "http://hl7.org/fhir/extension-context"),
51  	
52  	/**
53  	 * Code Value: <b>extension</b>
54  	 *
55  	 * The context is a particular extension from a particular profile.  Expressed as uri#name, where uri identifies the profile and #name identifies the extension code.
56  	 */
57  	EXTENSION("extension", "http://hl7.org/fhir/extension-context"),
58  	
59  	;
60  	
61  	/**
62  	 * Identifier for this Value Set:
63  	 * http://hl7.org/fhir/vs/extension-context
64  	 */
65  	public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/extension-context";
66  
67  	/**
68  	 * Name for this Value Set:
69  	 * ExtensionContext
70  	 */
71  	public static final String VALUESET_NAME = "ExtensionContext";
72  
73  	private static Map<String, ExtensionContextEnum> CODE_TO_ENUM = new HashMap<String, ExtensionContextEnum>();
74  	private static Map<String, Map<String, ExtensionContextEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, ExtensionContextEnum>>();
75  	
76  	private final String myCode;
77  	private final String mySystem;
78  	
79  	static {
80  		for (ExtensionContextEnum next : ExtensionContextEnum.values()) {
81  			CODE_TO_ENUM.put(next.getCode(), next);
82  			
83  			if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
84  				SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, ExtensionContextEnum>());
85  			}
86  			SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);			
87  		}
88  	}
89  	
90  	/**
91  	 * Returns the code associated with this enumerated value
92  	 */
93  	public String getCode() {
94  		return myCode;
95  	}
96  	
97  	/**
98  	 * Returns the code system associated with this enumerated value
99  	 */
100 	public String getSystem() {
101 		return mySystem;
102 	}
103 	
104 	/**
105 	 * Returns the enumerated value associated with this code
106 	 */
107 	public ExtensionContextEnum forCode(String theCode) {
108 		ExtensionContextEnum retVal = CODE_TO_ENUM.get(theCode);
109 		return retVal;
110 	}
111 
112 	/**
113 	 * Converts codes to their respective enumerated values
114 	 */
115 	public static final IValueSetEnumBinder<ExtensionContextEnum> VALUESET_BINDER = new IValueSetEnumBinder<ExtensionContextEnum>() {
116 		@Override
117 		public String toCodeString(ExtensionContextEnum theEnum) {
118 			return theEnum.getCode();
119 		}
120 
121 		@Override
122 		public String toSystemString(ExtensionContextEnum theEnum) {
123 			return theEnum.getSystem();
124 		}
125 		
126 		@Override
127 		public ExtensionContextEnum fromCodeString(String theCodeString) {
128 			return CODE_TO_ENUM.get(theCodeString);
129 		}
130 		
131 		@Override
132 		public ExtensionContextEnum fromCodeString(String theCodeString, String theSystemString) {
133 			Map<String, ExtensionContextEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
134 			if (map == null) {
135 				return null;
136 			}
137 			return map.get(theCodeString);
138 		}
139 		
140 	};
141 	
142 	/** 
143 	 * Constructor
144 	 */
145 	ExtensionContextEnum(String theCode, String theSystem) {
146 		myCode = theCode;
147 		mySystem = theSystem;
148 	}
149 
150 	
151 }