[372] | 1 | module OpenEHR
|
---|
[4] | 2 | module AM
|
---|
| 3 | module Archetype
|
---|
[372] | 4 | module ConstraintModel
|
---|
| 5 | class ArchetypeConstraint
|
---|
[373] | 6 | attr_reader :path
|
---|
| 7 | attr_accessor :parent
|
---|
[372] | 8 |
|
---|
[373] | 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
|
---|
[4] | 42 | end
|
---|
[21] | 43 |
|
---|
[372] | 44 | class Cardinality
|
---|
[35] | 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
|
---|
[375] | 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?
|
---|
[21] | 82 | end
|
---|
| 83 |
|
---|
[372] | 84 | class CObject < ArchetypeConstraint
|
---|
[375] | 85 | attr_reader :rm_type_name, :node_id, :occurrences
|
---|
[23] | 86 |
|
---|
| 87 | def initialize(args = { })
|
---|
[375] | 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 |
|
---|
[23] | 93 | end
|
---|
[32] | 94 |
|
---|
[375] | 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 |
|
---|
[32] | 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
|
---|
[23] | 123 | end
|
---|
| 124 |
|
---|
[372] | 125 | class CAttribute < ArchetypeConstraint
|
---|
[375] | 126 | attr_reader :rm_attribute_name, :existence
|
---|
| 127 | attr_accessor :children
|
---|
[23] | 128 |
|
---|
| 129 | def initialize(args = { })
|
---|
[375] | 130 | super(args)
|
---|
| 131 | self.rm_attribute_name = args[:rm_attribute_name]
|
---|
| 132 | self.existence = args[:existence]
|
---|
| 133 | self.children = args[:children]
|
---|
[23] | 134 | end
|
---|
[375] | 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
|
---|
[21] | 149 | end
|
---|
| 150 |
|
---|
[372] | 151 | class CDefinedObject < CObject
|
---|
[380] | 152 | attr_accessor :assumed_value
|
---|
[21] | 153 |
|
---|
[23] | 154 | def initialize(args = { })
|
---|
| 155 | super
|
---|
[379] | 156 | self.assumed_value = args[:assumed_value]
|
---|
[23] | 157 | end
|
---|
[379] | 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
|
---|
[380] | 170 |
|
---|
| 171 | def any_allowed?
|
---|
| 172 | raise NotImplementedError, 'subclass should implement this method'
|
---|
| 173 | end
|
---|
[21] | 174 | end
|
---|
| 175 |
|
---|
[372] | 176 | class CPrimitiveObject < CDefinedObject
|
---|
[23] | 177 | attr_accessor :item
|
---|
[32] | 178 |
|
---|
[23] | 179 | def initialize(args = { })
|
---|
| 180 | super
|
---|
[380] | 181 | self.item = args[:item]
|
---|
[23] | 182 | end
|
---|
[380] | 183 |
|
---|
| 184 | def any_allowed?
|
---|
[381] | 185 | return item.nil?
|
---|
[380] | 186 | end
|
---|
[21] | 187 | end
|
---|
| 188 |
|
---|
[372] | 189 | class CComplexObject < CDefinedObject
|
---|
[381] | 190 | attr_accessor :attributes
|
---|
[32] | 191 |
|
---|
[23] | 192 | def initialize(args = { })
|
---|
| 193 | super
|
---|
[381] | 194 | self.attributes = args[:attributes]
|
---|
[23] | 195 | end
|
---|
| 196 |
|
---|
[381] | 197 | def any_allowed?
|
---|
| 198 | return (@attributes.nil? or @attributes.empty?)
|
---|
| 199 | end
|
---|
| 200 |
|
---|
[23] | 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
|
---|
[21] | 208 | end
|
---|
| 209 |
|
---|
[372] | 210 | class CDomainType < CDefinedObject
|
---|
[381] | 211 | def standard_equivalent
|
---|
| 212 | raise NotImplementedError, 'subclass should be defined'
|
---|
| 213 | end
|
---|
[21] | 214 | end
|
---|
| 215 |
|
---|
[372] | 216 | class CReferenceObject < CObject
|
---|
[382] | 217 |
|
---|
[21] | 218 | end
|
---|
| 219 |
|
---|
[372] | 220 | class ArchetypeInternalRef < CReferenceObject
|
---|
[382] | 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
|
---|
[21] | 234 | end
|
---|
| 235 |
|
---|
[372] | 236 | class ArchetypeSlot < CReferenceObject
|
---|
[382] | 237 | attr_reader :includes, :excludes
|
---|
[32] | 238 |
|
---|
[382] | 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 |
|
---|
[32] | 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
|
---|
[21] | 272 | end
|
---|
| 273 |
|
---|
[382] | 274 | class ConstraintRef < CReferenceObject
|
---|
| 275 | attr_reader :reference
|
---|
[32] | 276 |
|
---|
[382] | 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 |
|
---|
[32] | 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
|
---|
[21] | 297 | end
|
---|
| 298 |
|
---|
[372] | 299 | class CSingleAttribute < CAttribute
|
---|
[376] | 300 | attr_reader :alternatives
|
---|
[23] | 301 |
|
---|
| 302 | def initialize(args = { })
|
---|
| 303 | super
|
---|
[376] | 304 | self.alternatives = args[:alternatives]
|
---|
[23] | 305 | end
|
---|
[376] | 306 |
|
---|
| 307 | def alternatives=(alternatives)
|
---|
| 308 | if alternatives.nil?
|
---|
| 309 | raise ArgumentError, 'alternatives are mandatory'
|
---|
| 310 | end
|
---|
| 311 | @alternatives = alternatives
|
---|
| 312 | end
|
---|
[23] | 313 | end
|
---|
| 314 |
|
---|
[372] | 315 | class CMultipleAttribute < CAttribute
|
---|
[377] | 316 | attr_accessor :members
|
---|
| 317 | attr_reader :cardinality
|
---|
[23] | 318 |
|
---|
| 319 | def initialize(args = { })
|
---|
[377] | 320 | super
|
---|
[378] | 321 | self.members = args[:members]
|
---|
[377] | 322 | self.cardinality = args[:cardinality]
|
---|
[23] | 323 | end
|
---|
[377] | 324 |
|
---|
| 325 | def cardinality=(cardinality)
|
---|
| 326 | if cardinality.nil?
|
---|
| 327 | raise ArgumentError, 'cardinality is mandatory'
|
---|
| 328 | end
|
---|
| 329 | @cardinality = cardinality
|
---|
| 330 | end
|
---|
[23] | 331 | end
|
---|
[4] | 332 | end
|
---|
| 333 | end
|
---|
| 334 | end
|
---|
| 335 | end
|
---|
| 336 |
|
---|