source: ruby/trunk/lib/models/tests/rm/test_support.rb@ 291

Last change on this file since 291 was 291, checked in by KOBAYASHI, Shinji, 15 years ago

merged branches/0.5 to trunk

File size: 19.0 KB
Line 
1require 'test/unit'
2require 'set'
3require 'rm'
4
5class RM_Support_Definition_Test < Test::Unit::TestCase
6 def test_constant
7 assert_equal("\r", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::CR)
8 assert_equal("\n", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::LF)
9 end
10end
11
12
13class RM_Support_Identification_Test < Test::Unit::TestCase
14 def setup
15<<<<<<< .working
16 assert_nothing_raised(Exception){@object_id = OpenEHR::RM::Support::Identification::Object_ID.new("0.0.3")}
17 assert_nothing_raised(Exception){@object_ref = OpenEHR::RM::Support::Identification::Object_Ref.new('local', 'ANY', @object_id)}
18 assert_nothing_raised(Exception){@archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new('openEHR-EHR-SECTION.physical_examination-prenatal.v2')}
19 assert_nothing_raised(Exception){@terminology_id = OpenEHR::RM::Support::Identification::Terminology_ID.new('ICD10(2003)')}
20 assert_nothing_raised(Exception){@generic_id = OpenEHR::RM::Support::Identification::Generic_ID.new("0.0.3", "openehr")}
21 assert_nothing_raised(Exception){@uid_based_id = OpenEHR::RM::Support::Identification::UID_Based_ID.new('rrip::0.0.3')}
22 assert_nothing_raised(Exception){@hier_object_id = OpenEHR::RM::Support::Identification::Hier_Object_ID.new('0.0.4')}
23 assert_nothing_raised(Exception){@locatable_ref = OpenEHR::RM::Support::Identification::Locatable_Ref.new('unknown', 'PERSON', @uid_based_id, 'data/event[at0001, standing]')}
24 assert_nothing_raised(Exception){@party_ref = OpenEHR::RM::Support::Identification::Party_Ref.new('unknown', 'ORGANISATION', @object_id)}
25 assert_nothing_raised(Exception){@access_group_ref = OpenEHR::RM::Support::Identification::Access_Group_Ref.new('unknown', 'ACCESS_GROUP', @object_id)}
26 assert_nothing_raised(Exception){@version_tree_id = OpenEHR::RM::Support::Identification::Version_Tree_ID.new('1.2.3')}
27 assert_nothing_raised(Exception){@object_version_id = OpenEHR::RM::Support::Identification::Object_Version_ID.new('ABC::DEF::1.2.3')}
28=======
29 assert_nothing_raised(Exception){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.3")}
30 assert_nothing_raised(Exception){@object_ref = OpenEhr::RM::Support::Identification::ObjectRef.new('local', 'ANY', @object_id)}
31 assert_nothing_raised(Exception){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
32 assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('ICD10(2003)')}
33 assert_nothing_raised(Exception){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "openehr")}
34 assert_nothing_raised(Exception){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.3')}
35 assert_nothing_raised(Exception){@hier_object_id = OpenEhr::RM::Support::Identification::HierObjectId.new('0.0.4')}
36 assert_nothing_raised(Exception){@locatable_ref = OpenEhr::RM::Support::Identification::LocatableRef.new('unknown', 'PERSON', @uid_based_id, 'data/event[at0001, standing]')}
37 assert_nothing_raised(Exception){@party_ref = OpenEhr::RM::Support::Identification::PartyRef.new('unknown', 'ORGANISATION', @object_id)}
38 assert_nothing_raised(Exception){@access_group_ref = OpenEhr::RM::Support::Identification::AccessGroupRef.new('unknown', 'ACCESS_GROUP', @object_id)}
39 assert_nothing_raised(Exception){@version_tree_id = OpenEhr::RM::Support::Identification::VersionTreeId.new('1.2.3')}
40 assert_nothing_raised(Exception){@object_version_id = OpenEhr::RM::Support::Identification::ObjectVersionId.new('ABC::DEF::1.2.3')}
41>>>>>>> .merge-right.r168
42 end
43
44 def test_init
45 assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
46 assert_instance_of OpenEhr::RM::Support::Identification::ObjectRef, @object_ref
47 assert_instance_of OpenEhr::RM::Support::Identification::ArchetypeId, @archetype_id
48 assert_instance_of OpenEhr::RM::Support::Identification::TerminologyId, @terminology_id
49 assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
50 assert_instance_of OpenEhr::RM::Support::Identification::GenericId, @generic_id
51 assert_instance_of OpenEhr::RM::Support::Identification::UidBasedId, @uid_based_id
52 assert_instance_of OpenEhr::RM::Support::Identification::HierObjectId, @hier_object_id
53 assert_instance_of OpenEhr::RM::Support::Identification::LocatableRef, @locatable_ref
54 assert_instance_of OpenEhr::RM::Support::Identification::PartyRef, @party_ref
55 assert_instance_of OpenEhr::RM::Support::Identification::AccessGroupRef, @access_group_ref
56 assert_instance_of OpenEhr::RM::Support::Identification::VersionTreeId, @version_tree_id
57 assert_instance_of OpenEhr::RM::Support::Identification::ObjectVersionId, @object_version_id
58 end
59
60 def test_object_id
61 assert_equal "0.0.3", @object_id.value
62 assert_nothing_raised(Exception){@object_id.value = "0.0.4"}
63 assert_equal "0.0.4", @object_id.value
64 assert_raise(ArgumentError){@object_id.value=nil}
65 assert_raise(ArgumentError){@object_id.value=""}
66 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new}
67 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new(nil)}
68 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("")}
69 assert_equal @object_id, OpenEhr::RM::Support::Identification::ObjectId.new("0.0.4")
70 end
71
72 def test_object_refs
73 assert_equal 'local', @object_ref.namespace
74 assert_equal 'ANY', @object_ref.type
75 assert_equal @object_id, @object_ref.id
76
77 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new}
78 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, 'ANY', @object_id)}
79 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('', 'ANY', @object_id)}
80 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', nil, @object_id)}
81 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', '', @object_id)}
82 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', 'ANY', nil)}
83
84 assert_nothing_raised(Exception){@object_ref.namespace = 'terminology'}
85 assert_equal 'terminology', @object_ref.namespace
86 assert_raise(ArgumentError){@object_ref.namespace = nil}
87 assert_raise(ArgumentError){@object_ref.namespace = ''}
88 assert_raise(ArgumentError){@object_ref.namespace = '?&&'}
89 assert_raise(ArgumentError){@object_ref.namespace = '843'}
90
91 assert_nothing_raised(Exception){@object_ref.type = 'GUIDELINE'}
92 assert_equal 'GUIDELINE', @object_ref.type
93 assert_raise(ArgumentError){@object_ref.type = nil}
94 assert_raise(ArgumentError){@object_ref.type = ''}
95
96 assert_nothing_raised(Exception){@object_ref.id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5")}
97 assert_equal OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5"), @object_ref.id
98 assert_raise(ArgumentError){@object_ref.id = nil}
99 end
100
101 def test_archetype_id
102<<<<<<< .working
103 assert_equal 'openEHR-EHR-SECTION.physical_examination-prenatal.v2', @archetype_id.value
104 assert_equal 'openEHR-EHR-SECTION', @archetype_id.qualified_rm_entity
105 assert_equal 'openEHR', @archetype_id.rm_originator
106 assert_equal 'EHR', @archetype_id.rm_name
107 assert_equal 'SECTION', @archetype_id.rm_entity
108 assert_equal 'physical_examination', @archetype_id.concept_name
109 assert_equal 'prenatal', @archetype_id.specialisation
110 assert_equal 'v2', @archetype_id.version_id
111=======
112 assert_equal "0.0.5", @archetype_id.value
113 assert_nothing_raised(Exception){@archetype_id.value = "0.0.6"}
114 assert_equal "0.0.6", @archetype_id.value
115 assert_raise(ArgumentError){@archetype_id.value=nil}
116 assert_raise(ArgumentError){@archetype_id.value=""}
117 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new}
118 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
119 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
120 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", nil, "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
121 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
122 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", nil, "ehr_rm", "openehr","cholesterol","0.0.3")}
123 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "", "ehr_rm", "openehr","cholesterol","0.0.3")}
124 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", nil, "openehr","cholesterol","0.0.3")}
125 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "", "openehr","cholesterol","0.0.3")}
126 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", nil,"cholesterol","0.0.3")}
127 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "","cholesterol","0.0.3")}
128 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr",nil ,"0.0.3")}
129 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","","0.0.3")}
130 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol", nil)}
131 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","")}
132
133 assert_equal "biochemistry result_cholesterol", @archetype_id.domain_concept
134 assert_nothing_raised(Exception){(@archetype_id.domain_concept = "biochemistry result_triglyceride")}
135 assert_equal "biochemistry result_triglyceride", @archetype_id.domain_concept
136 assert_raise(ArgumentError){@archetype_id.domain_concept = nil}
137 assert_raise(ArgumentError){@archetype_id.domain_concept = ""}
138
139 assert_equal "entry", @archetype_id.rm_name
140 assert_nothing_raised(Exception){@archetype_id.rm_name = "section"}
141 assert_equal "section", @archetype_id.rm_name
142 assert_raise(ArgumentError){@archetype_id.rm_name = nil}
143 assert_raise(ArgumentError){@archetype_id.rm_name = ""}
144
145 assert_equal "ehr_rm", @archetype_id.rm_entity
146 assert_nothing_raised(Exception){@archetype_id.rm_entity = "13606"}
147 assert_equal "13606", @archetype_id.rm_entity
148 assert_raise(ArgumentError){@archetype_id.rm_entity = nil}
149 assert_raise(ArgumentError){@archetype_id.rm_entity = ""}
150
151 assert_equal "openehr", @archetype_id.rm_originator
152 assert_nothing_raised(Exception){@archetype_id.rm_originator = "cen"}
153 assert_equal "cen", @archetype_id.rm_originator
154 assert_raise(ArgumentError){@archetype_id.rm_originator = nil}
155 assert_raise(ArgumentError){@archetype_id.rm_originator = ""}
156
157 assert_equal "cholesterol", @archetype_id.specialisation
158 assert_nothing_raised(Exception){@archetype_id.specialisation = "triglyceride"}
159 assert_equal "triglyceride", @archetype_id.specialisation
160 assert_raise(ArgumentError){@archetype_id.specialisation = nil}
161 assert_raise(ArgumentError){@archetype_id.specialisation = ""}
162
163 assert_equal "0.0.3", @archetype_id.version_id
164 assert_nothing_raised(Exception){@archetype_id.version_id = "0.0.7"}
165 assert_equal "0.0.7", @archetype_id.version_id
166 assert_raise(ArgumentError){@archetype_id.version_id = nil}
167 assert_raise(ArgumentError){@archetype_id.version_id = ""}
168>>>>>>> .merge-right.r168
169 end
170
171 def test_terminology_id
172 assert_equal "ICD10(2003)", @terminology_id.value
173 assert_nothing_raised(Exception){@terminology_id.value = "ICD9(1999)"}
174 assert_equal "ICD9", @terminology_id.name
175 assert_equal "1999", @terminology_id.version_id
176 assert_raise(ArgumentError){@terminology_id.value = nil}
177 assert_raise(ArgumentError){@terminology_id.value = ""}
178
179 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new}
180 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new(nil,'2008')}
181 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('','02008')}
182 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED", nil)}
183 assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED")}
184
185 assert_equal "SNOMED", @terminology_id.name
186 assert_nothing_raised(Exception){@terminology_id.name = "LOINC"}
187 assert_equal "LOINC", @terminology_id.name
188 assert_raise(ArgumentError){@terminology_id.name = nil}
189 assert_raise(ArgumentError){@terminology_id.name = ""}
190
191 assert_equal "", @terminology_id.version_id
192 assert_nothing_raised(Exception){@terminology_id.version_id = "2008"}
193 assert_equal "2008", @terminology_id.version_id
194 assert_equal 'LOINC(2008)', @terminology_id.value
195 assert_raise(ArgumentError){@terminology_id.version_id = nil}
196 assert_nothing_raised(Exception){@terminology_id.version_id = ''}
197 end
198
199 def test_generic_id
200 assert_equal "0.0.3", @generic_id.value
201 assert_equal "openehr", @generic_id.scheme
202
203 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new(nil, "openehr")}
204 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("", "openehr")}
205 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", nil)}
206 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "")}
207
208 assert_raise(ArgumentError){@generic_id.value = nil}
209 assert_raise(ArgumentError){@generic_id.value = ""}
210 assert_nothing_raised(Exception){@generic_id.value = "0.0.5"}
211 assert_equal "0.0.5", @generic_id.value
212
213 assert_raise(ArgumentError){@generic_id.scheme = nil}
214 assert_raise(ArgumentError){@generic_id.scheme = ""}
215 assert_nothing_raised(Exception){@generic_id.scheme = "cen"}
216 assert_equal "cen", @generic_id.scheme
217 end
218
219 def test_uid_based_id
220 assert_equal "rrip::0.0.3", @uid_based_id.value
221 assert_equal "rrip", @uid_based_id.root
222 assert_equal '0.0.3', @uid_based_id.extension
223 assert @uid_based_id.has_extension?
224
225 assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new(nil)}
226 assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('')}
227 assert_raise(ArgumentError){@uid_based_id.value = nil}
228 assert_raise(ArgumentError){@uid_based_id.value = ''}
229
230 assert_nothing_raised(Exception){@uid_based_id.value = 'rrip'}
231 assert_equal 'rrip', @uid_based_id.value
232 assert_equal 'rrip', @uid_based_id.root
233 assert_equal '', @uid_based_id.extension
234 end
235
236 def test_hier_object_id
237 assert_equal '0.0.4', @hier_object_id.value
238 assert !@hier_object_id.root.nil?
239 assert !@hier_object_id.has_extension?
240# in the specification 1.0.1 has_extension? xor extention != Void void is not nil?
241 assert @hier_object_id.extension.empty?
242 assert_nothing_raised(Exception){@hier_object_id.value = "ehr::test"}
243 assert !@hier_object_id.root.nil?
244 assert @hier_object_id.has_extension?
245 assert !@hier_object_id.extension.empty?
246 end
247
248 def test_object_version_id
249 assert_equal 'ABC::DEF::1.2.3', @object_version_id.value
250 assert_equal 'ABC', @object_version_id.object_id.value
251 assert_equal 'DEF', @object_version_id.creating_system_id.value
252 assert_equal '1', @object_version_id.version_tree_id.trunk_version
253 end
254
255 def test_locatable_ref
256# test constructor
257 assert_equal 'unknown', @locatable_ref.namespace
258 assert_equal 'PERSON', @locatable_ref.type
259 assert_equal @uid_based_id, @locatable_ref.id
260 assert_equal 'data/event[at0001, standing]', @locatable_ref.path
261 assert_equal 'ehr://rrip::0.0.3/data/event[at0001, standing]', @locatable_ref.as_uri
262#test path
263 assert_nothing_raised(Exception){@locatable_ref.path = 'data/event[at0002, tilting]'}
264 assert_equal 'data/event[at0002, tilting]', @locatable_ref.path
265 assert_equal 'ehr://rrip::0.0.3/data/event[at0002, tilting]', @locatable_ref.as_uri
266 end
267
268 def test_party_ref
269# test constructor
270 assert_equal 'unknown', @party_ref.namespace
271 assert_equal 'ORGANISATION', @party_ref.type
272 assert_equal @object_id, @party_ref.id
273# test type validation
274 assert_raise(ArgumentError){@party_ref.type = 'GUIDELINE'}
275 assert_nothing_raised(Exception){@party_ref.type = 'PERSON'}
276 assert_equal 'PERSON', @party_ref.type
277 assert_nothing_raised(Exception){@party_ref.type = 'GROUP'}
278 assert_nothing_raised(Exception){@party_ref.type = 'AGENT'}
279 assert_nothing_raised(Exception){@party_ref.type = 'ROLE'}
280 assert_nothing_raised(Exception){@party_ref.type = 'PARTY'}
281 assert_nothing_raised(Exception){@party_ref.type = 'ACTOR'}
282 end
283
284 def test_access_group_ref
285# test constructor
286 assert_equal 'unknown', @access_group_ref.namespace
287 assert_equal 'ACCESS_GROUP', @access_group_ref.type
288 assert_equal @object_id, @access_group_ref.id
289# test type validation
290 assert_raise(ArgumentError){@access_group_ref.type = 'PERSON'}
291 assert_nothing_raised(Exception){@access_group_ref.type = 'ACCESS_GROUP'}
292 end
293
294 def test_version_tree_id
295 assert_equal '1.2.3', @version_tree_id.value
296 assert_equal '1', @version_tree_id.trunk_version
297 assert_equal '2', @version_tree_id.branch_number
298 assert_equal '3', @version_tree_id.branch_version
299 assert @version_tree_id.is_first?
300 assert @version_tree_id.is_branch?
301 assert_nothing_raised(Exception){@version_tree_id.value = '2'}
302 assert_equal '2', @version_tree_id.trunk_version
303 assert !@version_tree_id.is_first?
304 assert !@version_tree_id.is_branch?
305 assert_nil @version_tree_id.branch_number
306 assert_nil @version_tree_id.branch_version
307 assert_raise(ArgumentError){@version_tree_id.branch_version = '5'}
308 end
309end
Note: See TracBrowser for help on using the repository browser.