[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
|
---|
[379] | 152 | attr_accessor :assumed_value, :any_allowed
|
---|
[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
|
---|
[21] | 170 | end
|
---|
| 171 |
|
---|
[372] | 172 | class CPrimitiveObject < CDefinedObject
|
---|
[23] | 173 | attr_accessor :item
|
---|
[32] | 174 |
|
---|
[23] | 175 | def initialize(args = { })
|
---|
| 176 | @attributes = args[:item] if args[:item]
|
---|
| 177 | super
|
---|
| 178 | end
|
---|
[21] | 179 | end
|
---|
| 180 |
|
---|
[372] | 181 | class CComplexObject < CDefinedObject
|
---|
[21] | 182 | attr_accessor :attributes, :attributes_valid
|
---|
[32] | 183 |
|
---|
[23] | 184 | def initialize(args = { })
|
---|
| 185 | @attributes = args[:attributes] ? args[:attributes] : []
|
---|
| 186 | super
|
---|
| 187 | end
|
---|
| 188 |
|
---|
| 189 | def self.create(args = { }, &block)
|
---|
| 190 | c_complex_object = new(args)
|
---|
| 191 | if block_given?
|
---|
| 192 | yield c_complex_object
|
---|
| 193 | end
|
---|
| 194 | return c_complex_object
|
---|
| 195 | end
|
---|
[21] | 196 | end
|
---|
| 197 |
|
---|
[372] | 198 | class CDomainType < CDefinedObject
|
---|
[21] | 199 |
|
---|
| 200 | end
|
---|
| 201 |
|
---|
[372] | 202 | class CReferenceObject < CObject
|
---|
[21] | 203 | end
|
---|
| 204 |
|
---|
[372] | 205 | class ArchetypeInternalRef < CReferenceObject
|
---|
[32] | 206 | attr_accessor :target_path
|
---|
[21] | 207 | end
|
---|
| 208 |
|
---|
[372] | 209 | class ArchetypeSlot < CReferenceObject
|
---|
[32] | 210 | attr_accessor :includes, :excludes
|
---|
| 211 |
|
---|
| 212 | def self.create(args = { }, &block)
|
---|
| 213 | archetype_slot = new(args)
|
---|
| 214 | archetype_slot.includes = args[:includes]
|
---|
| 215 | archetype_slot.excludes = args[:excludes]
|
---|
| 216 | if block_given?
|
---|
| 217 | yield archetype_slot
|
---|
| 218 | end
|
---|
| 219 | return archetype_slot
|
---|
| 220 | end
|
---|
[21] | 221 | end
|
---|
| 222 |
|
---|
[372] | 223 | class ConstantRef < CReferenceObject
|
---|
[32] | 224 | attr_accessor :reference
|
---|
| 225 |
|
---|
| 226 | def self.create(args = { }, &block)
|
---|
| 227 | constraint_ref = new(args)
|
---|
| 228 | constraint_ref.reference = args[:reference]
|
---|
| 229 | if block_given?
|
---|
| 230 | yield constraint_ref
|
---|
| 231 | end
|
---|
| 232 | return constraint_ref
|
---|
| 233 | end
|
---|
[21] | 234 | end
|
---|
| 235 |
|
---|
[372] | 236 | class CSingleAttribute < CAttribute
|
---|
[376] | 237 | attr_reader :alternatives
|
---|
[23] | 238 |
|
---|
| 239 | def initialize(args = { })
|
---|
| 240 | super
|
---|
[376] | 241 | self.alternatives = args[:alternatives]
|
---|
[23] | 242 | end
|
---|
[376] | 243 |
|
---|
| 244 | def alternatives=(alternatives)
|
---|
| 245 | if alternatives.nil?
|
---|
| 246 | raise ArgumentError, 'alternatives are mandatory'
|
---|
| 247 | end
|
---|
| 248 | @alternatives = alternatives
|
---|
| 249 | end
|
---|
[23] | 250 | end
|
---|
| 251 |
|
---|
[372] | 252 | class CMultipleAttribute < CAttribute
|
---|
[377] | 253 | attr_accessor :members
|
---|
| 254 | attr_reader :cardinality
|
---|
[23] | 255 |
|
---|
| 256 | def initialize(args = { })
|
---|
[377] | 257 | super
|
---|
[378] | 258 | self.members = args[:members]
|
---|
[377] | 259 | self.cardinality = args[:cardinality]
|
---|
[23] | 260 | end
|
---|
[377] | 261 |
|
---|
| 262 | def cardinality=(cardinality)
|
---|
| 263 | if cardinality.nil?
|
---|
| 264 | raise ArgumentError, 'cardinality is mandatory'
|
---|
| 265 | end
|
---|
| 266 | @cardinality = cardinality
|
---|
| 267 | end
|
---|
[23] | 268 | end
|
---|
[4] | 269 | end
|
---|
| 270 | end
|
---|
| 271 | end
|
---|
| 272 | end
|
---|
| 273 |
|
---|