source: ruby/trunk/lib/open_ehr/am/archetype/constraint_model.rb@ 382

Last change on this file since 382 was 382, checked in by KOBAYASHI, Shinji, 14 years ago

refs #74
implemented release 1.0.2

File size: 8.5 KB
Line 
1module OpenEHR
2 module AM
3 module Archetype
4 module ConstraintModel
5 class ArchetypeConstraint
6 attr_reader :path
7 attr_accessor :parent
8
9 def initialize(args = { })
10 self.path = args[:path]
11 self.parent = args[:parent]
12 end
13
14 def path=(path)
15 if path.nil?
16 raise ArgumentError, 'path is mandatory'
17 end
18 @path = path
19 end
20
21 def has_path?(path)
22 return @path.include?(path)
23 end
24
25 def congruent?
26 if @path.index(@parent.path) == 0
27 return true
28 else
29 return false
30 end
31 end
32
33 alias is_congruent? congruent?
34
35 def node_conforms_to?(other)
36 if @path.index(other.path) == 0
37 return true
38 else
39 return false
40 end
41 end
42 end
43
44 class Cardinality
45 attr_accessor :interval, :is_ordered, :is_unique
46
47 def initialize(args = { })
48 @interval = args[:interval]
49 @is_ordered = args[:is_ordered]
50 @is_unique = args[:is_unique]
51 end
52
53 def is_ordered?
54 return @is_ordered
55 end
56
57 alias ordered? is_ordered?
58
59 def is_unique?
60 return @is_unique
61 end
62
63 alias unique? is_unique?
64
65 def is_set?
66 return !@is_ordered && @is_unique
67 end
68
69 alias set? is_set?
70
71 def is_list?
72 return @is_ordered && !@is_unique
73 end
74
75 alias list? is_list?
76
77 def is_bag?
78 return !@is_ordered && !@is_unique
79 end
80
81 alias bag? is_bag?
82 end
83
84 class CObject < ArchetypeConstraint
85 attr_reader :rm_type_name, :node_id, :occurrences
86
87 def initialize(args = { })
88 super(args)
89 self.rm_type_name = args[:rm_type_name]
90 self.node_id = args[:node_id]
91 self.occurrences = args[:occurrences]
92
93 end
94
95 def rm_type_name=(rm_type_name)
96 if rm_type_name.nil? || rm_type_name.empty?
97 raise ArgumentError, 'invalid rm_type_name'
98 end
99 @rm_type_name = rm_type_name
100 end
101
102 def node_id=(node_id)
103 if node_id.nil? || node_id.empty?
104 raise ArgumentError, 'invalid node_id'
105 end
106 @node_id = node_id
107 end
108
109 def occurrences=(occurrences)
110 if occurrences.nil?
111 raise ArgumentError, 'invaild occurrences'
112 end
113 @occurrences = occurrences
114 end
115
116 def self.create(args = { }, &block)
117 c_object = new(args)
118 if block_given?
119 yield c_object
120 end
121 return c_object
122 end
123 end
124
125 class CAttribute < ArchetypeConstraint
126 attr_reader :rm_attribute_name, :existence
127 attr_accessor :children
128
129 def initialize(args = { })
130 super(args)
131 self.rm_attribute_name = args[:rm_attribute_name]
132 self.existence = args[:existence]
133 self.children = args[:children]
134 end
135
136 def rm_attribute_name=(rm_attribute_name)
137 if rm_attribute_name.nil? or rm_attribute_name.empty?
138 raise ArgumentError, 'invalid rm_attribute_name'
139 end
140 @rm_attribute_name = rm_attribute_name
141 end
142
143 def existence=(existence)
144 if existence.nil? || existence.lower < 0 || existence.upper > 1
145 raise ArgumentError, 'invalid existence'
146 end
147 @existence = existence
148 end
149 end
150
151 class CDefinedObject < CObject
152 attr_accessor :assumed_value
153
154 def initialize(args = { })
155 super
156 self.assumed_value = args[:assumed_value]
157 end
158
159 def has_assumed_value?
160 return !@assumed_value.nil?
161 end
162
163 def default_value
164 raise NotImplementedError, 'subclass should implement this method'
165 end
166
167 def valid_value?(value)
168 raise NotImplementedError, 'subclass should implement this method'
169 end
170
171 def any_allowed?
172 raise NotImplementedError, 'subclass should implement this method'
173 end
174 end
175
176 class CPrimitiveObject < CDefinedObject
177 attr_accessor :item
178
179 def initialize(args = { })
180 super
181 self.item = args[:item]
182 end
183
184 def any_allowed?
185 return item.nil?
186 end
187 end
188
189 class CComplexObject < CDefinedObject
190 attr_accessor :attributes
191
192 def initialize(args = { })
193 super
194 self.attributes = args[:attributes]
195 end
196
197 def any_allowed?
198 return (@attributes.nil? or @attributes.empty?)
199 end
200
201 def self.create(args = { }, &block)
202 c_complex_object = new(args)
203 if block_given?
204 yield c_complex_object
205 end
206 return c_complex_object
207 end
208 end
209
210 class CDomainType < CDefinedObject
211 def standard_equivalent
212 raise NotImplementedError, 'subclass should be defined'
213 end
214 end
215
216 class CReferenceObject < CObject
217
218 end
219
220 class ArchetypeInternalRef < CReferenceObject
221 attr_reader :target_path
222
223 def initialize(args = { })
224 super
225 self.target_path = args[:target_path]
226 end
227
228 def target_path=(target_path)
229 if target_path.nil? or target_path.empty?
230 raise ArgumentError, 'target_path is mandatory'
231 end
232 @target_path = target_path
233 end
234 end
235
236 class ArchetypeSlot < CReferenceObject
237 attr_reader :includes, :excludes
238
239 def initialize(args = { })
240 super
241 self.includes = args[:includes]
242 self.excludes = args[:excludes]
243 end
244
245 def includes=(includes)
246 if !includes.nil? && includes.empty?
247 raise ArgumentError, 'includes should not be empty'
248 end
249 @includes = includes
250 end
251
252 def excludes=(excludes)
253 if !excludes.nil? && excludes.empty?
254 raise ArgumentError, 'excludes should not be empty'
255 end
256 @excludes = excludes
257 end
258
259 def any_allowed?
260 return includes.nil? && excludes.nil?
261 end
262
263 def self.create(args = { }, &block)
264 archetype_slot = new(args)
265 archetype_slot.includes = args[:includes]
266 archetype_slot.excludes = args[:excludes]
267 if block_given?
268 yield archetype_slot
269 end
270 return archetype_slot
271 end
272 end
273
274 class ConstraintRef < CReferenceObject
275 attr_reader :reference
276
277 def initialize(args = { })
278 super
279 self.reference = args[:reference]
280 end
281
282 def reference=(reference)
283 if reference.nil?
284 raise ArgumentError, 'reference is mandatory'
285 end
286 @reference = reference
287 end
288
289 def self.create(args = { }, &block)
290 constraint_ref = new(args)
291 constraint_ref.reference = args[:reference]
292 if block_given?
293 yield constraint_ref
294 end
295 return constraint_ref
296 end
297 end
298
299 class CSingleAttribute < CAttribute
300 attr_reader :alternatives
301
302 def initialize(args = { })
303 super
304 self.alternatives = args[:alternatives]
305 end
306
307 def alternatives=(alternatives)
308 if alternatives.nil?
309 raise ArgumentError, 'alternatives are mandatory'
310 end
311 @alternatives = alternatives
312 end
313 end
314
315 class CMultipleAttribute < CAttribute
316 attr_accessor :members
317 attr_reader :cardinality
318
319 def initialize(args = { })
320 super
321 self.members = args[:members]
322 self.cardinality = args[:cardinality]
323 end
324
325 def cardinality=(cardinality)
326 if cardinality.nil?
327 raise ArgumentError, 'cardinality is mandatory'
328 end
329 @cardinality = cardinality
330 end
331 end
332 end
333 end
334 end
335end
336
Note: See TracBrowser for help on using the repository browser.