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 | end
|
---|
53 |
|
---|
54 | class CObject < ArchetypeConstraint
|
---|
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
|
---|
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
|
---|
70 | end
|
---|
71 |
|
---|
72 | class CAttribute < ArchetypeConstraint
|
---|
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
|
---|
81 | end
|
---|
82 |
|
---|
83 | class CDefinedObject < CObject
|
---|
84 | attr_accessor :assumed_value
|
---|
85 |
|
---|
86 | def initialize(args = { })
|
---|
87 | @assumed_value = args[:assumed_value] if args[:assumed_value]
|
---|
88 | super
|
---|
89 | end
|
---|
90 | end
|
---|
91 |
|
---|
92 | class CPrimitiveObject < CDefinedObject
|
---|
93 | attr_accessor :item
|
---|
94 |
|
---|
95 | def initialize(args = { })
|
---|
96 | @attributes = args[:item] if args[:item]
|
---|
97 | super
|
---|
98 | end
|
---|
99 | end
|
---|
100 |
|
---|
101 | class CComplexObject < CDefinedObject
|
---|
102 | attr_accessor :attributes, :attributes_valid
|
---|
103 |
|
---|
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
|
---|
116 | end
|
---|
117 |
|
---|
118 | class CDomainType < CDefinedObject
|
---|
119 |
|
---|
120 | end
|
---|
121 |
|
---|
122 | class CReferenceObject < CObject
|
---|
123 | end
|
---|
124 |
|
---|
125 | class ArchetypeInternalRef < CReferenceObject
|
---|
126 | attr_accessor :target_path
|
---|
127 | end
|
---|
128 |
|
---|
129 | class ArchetypeSlot < CReferenceObject
|
---|
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
|
---|
141 | end
|
---|
142 |
|
---|
143 | class ConstantRef < CReferenceObject
|
---|
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
|
---|
154 | end
|
---|
155 |
|
---|
156 | class CSingleAttribute < CAttribute
|
---|
157 | attr_accessor :alternatives
|
---|
158 |
|
---|
159 | def initialize(args = { })
|
---|
160 | @alternatives = args[:alternatives] ? args[:alternatives] : []
|
---|
161 | super
|
---|
162 | end
|
---|
163 | end
|
---|
164 |
|
---|
165 | class CMultipleAttribute < CAttribute
|
---|
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
|
---|
174 | end
|
---|
175 | end
|
---|
176 | end
|
---|
177 | end
|
---|
178 |
|
---|