1 | module 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, :attributes_valid
|
---|
191 |
|
---|
192 | def initialize(args = { })
|
---|
193 | @attributes = args[:attributes] ? args[:attributes] : []
|
---|
194 | super
|
---|
195 | end
|
---|
196 |
|
---|
197 | def self.create(args = { }, &block)
|
---|
198 | c_complex_object = new(args)
|
---|
199 | if block_given?
|
---|
200 | yield c_complex_object
|
---|
201 | end
|
---|
202 | return c_complex_object
|
---|
203 | end
|
---|
204 | end
|
---|
205 |
|
---|
206 | class CDomainType < CDefinedObject
|
---|
207 |
|
---|
208 | end
|
---|
209 |
|
---|
210 | class CReferenceObject < CObject
|
---|
211 | end
|
---|
212 |
|
---|
213 | class ArchetypeInternalRef < CReferenceObject
|
---|
214 | attr_accessor :target_path
|
---|
215 | end
|
---|
216 |
|
---|
217 | class ArchetypeSlot < CReferenceObject
|
---|
218 | attr_accessor :includes, :excludes
|
---|
219 |
|
---|
220 | def self.create(args = { }, &block)
|
---|
221 | archetype_slot = new(args)
|
---|
222 | archetype_slot.includes = args[:includes]
|
---|
223 | archetype_slot.excludes = args[:excludes]
|
---|
224 | if block_given?
|
---|
225 | yield archetype_slot
|
---|
226 | end
|
---|
227 | return archetype_slot
|
---|
228 | end
|
---|
229 | end
|
---|
230 |
|
---|
231 | class ConstantRef < CReferenceObject
|
---|
232 | attr_accessor :reference
|
---|
233 |
|
---|
234 | def self.create(args = { }, &block)
|
---|
235 | constraint_ref = new(args)
|
---|
236 | constraint_ref.reference = args[:reference]
|
---|
237 | if block_given?
|
---|
238 | yield constraint_ref
|
---|
239 | end
|
---|
240 | return constraint_ref
|
---|
241 | end
|
---|
242 | end
|
---|
243 |
|
---|
244 | class CSingleAttribute < CAttribute
|
---|
245 | attr_reader :alternatives
|
---|
246 |
|
---|
247 | def initialize(args = { })
|
---|
248 | super
|
---|
249 | self.alternatives = args[:alternatives]
|
---|
250 | end
|
---|
251 |
|
---|
252 | def alternatives=(alternatives)
|
---|
253 | if alternatives.nil?
|
---|
254 | raise ArgumentError, 'alternatives are mandatory'
|
---|
255 | end
|
---|
256 | @alternatives = alternatives
|
---|
257 | end
|
---|
258 | end
|
---|
259 |
|
---|
260 | class CMultipleAttribute < CAttribute
|
---|
261 | attr_accessor :members
|
---|
262 | attr_reader :cardinality
|
---|
263 |
|
---|
264 | def initialize(args = { })
|
---|
265 | super
|
---|
266 | self.members = args[:members]
|
---|
267 | self.cardinality = args[:cardinality]
|
---|
268 | end
|
---|
269 |
|
---|
270 | def cardinality=(cardinality)
|
---|
271 | if cardinality.nil?
|
---|
272 | raise ArgumentError, 'cardinality is mandatory'
|
---|
273 | end
|
---|
274 | @cardinality = cardinality
|
---|
275 | end
|
---|
276 | end
|
---|
277 | end
|
---|
278 | end
|
---|
279 | end
|
---|
280 | end
|
---|
281 |
|
---|