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 | @assumed_value = args[:assumed_value] if args[:assumed_value]
|
---|
156 | super
|
---|
157 | end
|
---|
158 | end
|
---|
159 |
|
---|
160 | class CPrimitiveObject < CDefinedObject
|
---|
161 | attr_accessor :item
|
---|
162 |
|
---|
163 | def initialize(args = { })
|
---|
164 | @attributes = args[:item] if args[:item]
|
---|
165 | super
|
---|
166 | end
|
---|
167 | end
|
---|
168 |
|
---|
169 | class CComplexObject < CDefinedObject
|
---|
170 | attr_accessor :attributes, :attributes_valid
|
---|
171 |
|
---|
172 | def initialize(args = { })
|
---|
173 | @attributes = args[:attributes] ? args[:attributes] : []
|
---|
174 | super
|
---|
175 | end
|
---|
176 |
|
---|
177 | def self.create(args = { }, &block)
|
---|
178 | c_complex_object = new(args)
|
---|
179 | if block_given?
|
---|
180 | yield c_complex_object
|
---|
181 | end
|
---|
182 | return c_complex_object
|
---|
183 | end
|
---|
184 | end
|
---|
185 |
|
---|
186 | class CDomainType < CDefinedObject
|
---|
187 |
|
---|
188 | end
|
---|
189 |
|
---|
190 | class CReferenceObject < CObject
|
---|
191 | end
|
---|
192 |
|
---|
193 | class ArchetypeInternalRef < CReferenceObject
|
---|
194 | attr_accessor :target_path
|
---|
195 | end
|
---|
196 |
|
---|
197 | class ArchetypeSlot < CReferenceObject
|
---|
198 | attr_accessor :includes, :excludes
|
---|
199 |
|
---|
200 | def self.create(args = { }, &block)
|
---|
201 | archetype_slot = new(args)
|
---|
202 | archetype_slot.includes = args[:includes]
|
---|
203 | archetype_slot.excludes = args[:excludes]
|
---|
204 | if block_given?
|
---|
205 | yield archetype_slot
|
---|
206 | end
|
---|
207 | return archetype_slot
|
---|
208 | end
|
---|
209 | end
|
---|
210 |
|
---|
211 | class ConstantRef < CReferenceObject
|
---|
212 | attr_accessor :reference
|
---|
213 |
|
---|
214 | def self.create(args = { }, &block)
|
---|
215 | constraint_ref = new(args)
|
---|
216 | constraint_ref.reference = args[:reference]
|
---|
217 | if block_given?
|
---|
218 | yield constraint_ref
|
---|
219 | end
|
---|
220 | return constraint_ref
|
---|
221 | end
|
---|
222 | end
|
---|
223 |
|
---|
224 | class CSingleAttribute < CAttribute
|
---|
225 | attr_accessor :alternatives
|
---|
226 |
|
---|
227 | def initialize(args = { })
|
---|
228 | @alternatives = args[:alternatives] ? args[:alternatives] : []
|
---|
229 | super
|
---|
230 | end
|
---|
231 | end
|
---|
232 |
|
---|
233 | class CMultipleAttribute < CAttribute
|
---|
234 | attr_accessor :members, :cardinality
|
---|
235 |
|
---|
236 | def initialize(args = { })
|
---|
237 | @members = args[:members] ? args[:members] : []
|
---|
238 | @cardinality = args[:cardinality] if args[:cardinality]
|
---|
239 | super
|
---|
240 | end
|
---|
241 | end
|
---|
242 | end
|
---|
243 | end
|
---|
244 | end
|
---|
245 | end
|
---|
246 |
|
---|