[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
|
---|
[21] | 52 | end
|
---|
| 53 |
|
---|
[372] | 54 | class CObject < ArchetypeConstraint
|
---|
[23] | 55 | attr_accessor :node_id, :occurrences, :rm_type_name
|
---|
| 56 |
|
---|
| 57 | def initialize(args = { })
|
---|
| 58 | @node_id = args[:node_id] if args[:node_id]
|
---|
| 59 | @occurrences = args[:occurrences] if args[:occurrences]
|
---|
| 60 | @rm_type_name = args[:rm_type_name] if args[:rm_type_name]
|
---|
| 61 | end
|
---|
[32] | 62 |
|
---|
| 63 | def self.create(args = { }, &block)
|
---|
| 64 | c_object = new(args)
|
---|
| 65 | if block_given?
|
---|
| 66 | yield c_object
|
---|
| 67 | end
|
---|
| 68 | return c_object
|
---|
| 69 | end
|
---|
[23] | 70 | end
|
---|
| 71 |
|
---|
[372] | 72 | class CAttribute < ArchetypeConstraint
|
---|
[23] | 73 | attr_accessor :rm_attribute_name, :existence, :children
|
---|
| 74 |
|
---|
| 75 | def initialize(args = { })
|
---|
| 76 | @rm_attribute_name = args[:rm_attribute_name] if args[:rm_attribute_name]
|
---|
| 77 | @existence = args[:existence] if args[:existence]
|
---|
| 78 | @children = args[:children] ? args[:children] : []
|
---|
| 79 |
|
---|
| 80 | end
|
---|
[21] | 81 | end
|
---|
| 82 |
|
---|
[372] | 83 | class CDefinedObject < CObject
|
---|
[23] | 84 | attr_accessor :assumed_value
|
---|
[21] | 85 |
|
---|
[23] | 86 | def initialize(args = { })
|
---|
| 87 | @assumed_value = args[:assumed_value] if args[:assumed_value]
|
---|
| 88 | super
|
---|
| 89 | end
|
---|
[21] | 90 | end
|
---|
| 91 |
|
---|
[372] | 92 | class CPrimitiveObject < CDefinedObject
|
---|
[23] | 93 | attr_accessor :item
|
---|
[32] | 94 |
|
---|
[23] | 95 | def initialize(args = { })
|
---|
| 96 | @attributes = args[:item] if args[:item]
|
---|
| 97 | super
|
---|
| 98 | end
|
---|
[21] | 99 | end
|
---|
| 100 |
|
---|
[372] | 101 | class CComplexObject < CDefinedObject
|
---|
[21] | 102 | attr_accessor :attributes, :attributes_valid
|
---|
[32] | 103 |
|
---|
[23] | 104 | def initialize(args = { })
|
---|
| 105 | @attributes = args[:attributes] ? args[:attributes] : []
|
---|
| 106 | super
|
---|
| 107 | end
|
---|
| 108 |
|
---|
| 109 | def self.create(args = { }, &block)
|
---|
| 110 | c_complex_object = new(args)
|
---|
| 111 | if block_given?
|
---|
| 112 | yield c_complex_object
|
---|
| 113 | end
|
---|
| 114 | return c_complex_object
|
---|
| 115 | end
|
---|
[21] | 116 | end
|
---|
| 117 |
|
---|
[372] | 118 | class CDomainType < CDefinedObject
|
---|
[21] | 119 |
|
---|
| 120 | end
|
---|
| 121 |
|
---|
[372] | 122 | class CReferenceObject < CObject
|
---|
[21] | 123 | end
|
---|
| 124 |
|
---|
[372] | 125 | class ArchetypeInternalRef < CReferenceObject
|
---|
[32] | 126 | attr_accessor :target_path
|
---|
[21] | 127 | end
|
---|
| 128 |
|
---|
[372] | 129 | class ArchetypeSlot < CReferenceObject
|
---|
[32] | 130 | attr_accessor :includes, :excludes
|
---|
| 131 |
|
---|
| 132 | def self.create(args = { }, &block)
|
---|
| 133 | archetype_slot = new(args)
|
---|
| 134 | archetype_slot.includes = args[:includes]
|
---|
| 135 | archetype_slot.excludes = args[:excludes]
|
---|
| 136 | if block_given?
|
---|
| 137 | yield archetype_slot
|
---|
| 138 | end
|
---|
| 139 | return archetype_slot
|
---|
| 140 | end
|
---|
[21] | 141 | end
|
---|
| 142 |
|
---|
[372] | 143 | class ConstantRef < CReferenceObject
|
---|
[32] | 144 | attr_accessor :reference
|
---|
| 145 |
|
---|
| 146 | def self.create(args = { }, &block)
|
---|
| 147 | constraint_ref = new(args)
|
---|
| 148 | constraint_ref.reference = args[:reference]
|
---|
| 149 | if block_given?
|
---|
| 150 | yield constraint_ref
|
---|
| 151 | end
|
---|
| 152 | return constraint_ref
|
---|
| 153 | end
|
---|
[21] | 154 | end
|
---|
| 155 |
|
---|
[372] | 156 | class CSingleAttribute < CAttribute
|
---|
[23] | 157 | attr_accessor :alternatives
|
---|
| 158 |
|
---|
| 159 | def initialize(args = { })
|
---|
| 160 | @alternatives = args[:alternatives] ? args[:alternatives] : []
|
---|
| 161 | super
|
---|
| 162 | end
|
---|
| 163 | end
|
---|
| 164 |
|
---|
[372] | 165 | class CMultipleAttribute < CAttribute
|
---|
[23] | 166 | attr_accessor :members, :cardinality
|
---|
| 167 |
|
---|
| 168 | def initialize(args = { })
|
---|
| 169 | @members = args[:members] ? args[:members] : []
|
---|
| 170 | @cardinality = args[:cardinality] if args[:cardinality]
|
---|
| 171 | super
|
---|
| 172 | end
|
---|
| 173 | end
|
---|
[4] | 174 | end
|
---|
| 175 | end
|
---|
| 176 | end
|
---|
| 177 | end
|
---|
| 178 |
|
---|