1 | require 'test/unit'
|
---|
2 | require 'set'
|
---|
3 | require 'rm'
|
---|
4 |
|
---|
5 | include OpenEhr::RM::DataTypes::Text
|
---|
6 | include OpenEhr::RM::Common::Resource
|
---|
7 | include OpenEhr::RM::Common::Archetyped
|
---|
8 | include OpenEhr::RM::Common::Generic
|
---|
9 | include OpenEhr::RM::Common::ChangeControl
|
---|
10 | include OpenEhr::RM::Common::Directory
|
---|
11 | include OpenEhr::RM::Support::Identification
|
---|
12 | include OpenEhr::RM::DataTypes::Basic
|
---|
13 | include OpenEhr::RM::DataTypes::Quantity
|
---|
14 | include OpenEhr::RM::DataTypes::Uri
|
---|
15 |
|
---|
16 | class RM_Common_Resource_Test < Test::Unit::TestCase
|
---|
17 | def setup
|
---|
18 | terminology_id = TerminologyId.new('openehr')
|
---|
19 | code_phrase = CodePhrase.new('ja', terminology_id)
|
---|
20 | @translation_details = OpenEhr::RM::Common::Resource::TranslationDetails.new(:language => code_phrase, :author => {'KOBAYASHI, Shinji', 'Ehime Univ'},
|
---|
21 | :accreditation => 'jp', :other_details => {'ruby', 'test'})
|
---|
22 | @authored_resource = OpenEhr::RM::Common::Resource::AuthoredResource.new(:original_language => code_phrase, :translations => {'ja', @translation_details}, :description => "test")
|
---|
23 | @resource_description_item = OpenEhr::RM::Common::Resource::ResourceDescriptionItem.new(:language => code_phrase,
|
---|
24 | :purpose => 'test',
|
---|
25 | :keywords => %w[test ruby],
|
---|
26 | :use => 'unit test',
|
---|
27 | :misuse => 'real use',
|
---|
28 | :copyright => 'openEHR.jp',
|
---|
29 | :original_resource_uri => {'issuer', 'http://openehr.jp/'},
|
---|
30 | :other_details => {'samos', 'icicth7'})
|
---|
31 | @resource_description = OpenEhr::RM::Common::Resource::ResourceDescription.new(:original_author => {'KOBAYASHI, Shinji' => 'Ehime University'},
|
---|
32 | :lifecycle_state => 'experimental',
|
---|
33 | :details => {'ja', @resource_description_item},
|
---|
34 | :other_contributors => %w[aki tim hugh],
|
---|
35 | :resource_package_uri => 'http://openehr.jp/svn/ruby',
|
---|
36 | :other_details => {'ja', 'shikoku'},
|
---|
37 | :parent_resource => @authored_resource)
|
---|
38 | @authored_resource = OpenEhr::RM::Common::Resource::AuthoredResource.new(:original_language => code_phrase, :translations => {'ja', @translation_details}, :description => @resource_description)
|
---|
39 | end
|
---|
40 |
|
---|
41 | def test_init
|
---|
42 | assert_instance_of OpenEhr::RM::Common::Resource::AuthoredResource, @authored_resource
|
---|
43 | assert_instance_of OpenEhr::RM::Common::Resource::TranslationDetails, @translation_details
|
---|
44 | assert_instance_of OpenEhr::RM::Common::Resource::ResourceDescriptionItem, @resource_description_item
|
---|
45 | assert_instance_of OpenEhr::RM::Common::Resource::ResourceDescription, @resource_description
|
---|
46 | end
|
---|
47 |
|
---|
48 | def test_translation_details
|
---|
49 | assert_equal 'ja', @translation_details.language.code_string
|
---|
50 | assert_equal 'Ehime Univ', @translation_details.author['KOBAYASHI, Shinji']
|
---|
51 | assert_equal 'jp', @translation_details.accreditation
|
---|
52 | assert_equal 'test', @translation_details.other_details['ruby']
|
---|
53 | end
|
---|
54 |
|
---|
55 | def test_authoured_resource
|
---|
56 | assert_equal 'ja', @authored_resource.original_language.code_string
|
---|
57 | assert_equal @translation_details, @authored_resource.translations['ja']
|
---|
58 | assert_equal 'experimental', @authored_resource.description.lifecycle_state
|
---|
59 | assert !@authored_resource.is_controlled?
|
---|
60 | assert_equal(Set['ja'], @authored_resource.languages_available)
|
---|
61 | end
|
---|
62 |
|
---|
63 | def test_resource_description_item
|
---|
64 | assert_equal 'ja', @resource_description_item.language.code_string
|
---|
65 | assert_equal 'test', @resource_description_item.purpose
|
---|
66 | assert_equal %w[test ruby], @resource_description_item.keywords
|
---|
67 | assert_equal 'unit test', @resource_description_item.use
|
---|
68 | assert_equal 'real use', @resource_description_item.misuse
|
---|
69 | assert_equal 'openEHR.jp', @resource_description_item.copyright
|
---|
70 | assert_equal 'http://openehr.jp/', @resource_description_item.original_resource_uri['issuer']
|
---|
71 | assert_equal 'icicth7', @resource_description_item.other_details['samos']
|
---|
72 | end
|
---|
73 |
|
---|
74 | def test_resource_description
|
---|
75 | assert_equal 'Ehime University', @resource_description.original_author['KOBAYASHI, Shinji']
|
---|
76 | assert_equal 'experimental', @resource_description.lifecycle_state
|
---|
77 | assert_equal 'test', @resource_description.details['ja'].purpose
|
---|
78 | assert_equal %w[aki tim hugh], @resource_description.other_contributors
|
---|
79 | assert_equal 'http://openehr.jp/svn/ruby', @resource_description.resource_package_uri
|
---|
80 | assert_equal 'shikoku', @resource_description.other_details['ja']
|
---|
81 | assert_equal 'ja', @resource_description.parent_resource.original_language.code_string
|
---|
82 | end
|
---|
83 | end
|
---|
84 |
|
---|
85 |
|
---|
86 | class RM_Common_Archetyped_Test < Test::Unit::TestCase
|
---|
87 | def setup
|
---|
88 |
|
---|
89 | @dv_text = OpenEhr::RM::DataTypes::Text::DvText.new('Test')
|
---|
90 | @uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.5')
|
---|
91 | @archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
|
---|
92 | @template_id = OpenEhr::RM::Support::Identification::TemplateId.new('1.0.1')
|
---|
93 | assert_nothing_raised(Exception){@archetyped = OpenEhr::RM::Common::Archetyped::Archetyped.new(@archetype_id, '1.0.1')}
|
---|
94 | assert_nothing_raised(Exception){@link = OpenEhr::RM::Common::Archetyped::Link.new(OpenEhr::RM::DataTypes::Text::DvText.new("generic"), OpenEhr::RM::DataTypes::Uri::DvEhrUri.new("ehr://test/"),OpenEhr::RM::DataTypes::Text::DvText.new("problem"))}
|
---|
95 | assert_nothing_raised(Exception){
|
---|
96 | @pathable = OpenEhr::RM::Common::Archetyped::Pathable.new }
|
---|
97 | name = OpenEhr::RM::DataTypes::Text::DvText.new('blood')
|
---|
98 | links = Set.new([@uid_based_id])
|
---|
99 | assert_nothing_raised(Exception){
|
---|
100 | @locatable = Locatable.new(:archetype_node_id => 'at0001',
|
---|
101 | :name => name,
|
---|
102 | :links => links)}
|
---|
103 | provider = PartyIdentified.new(:name => 'NERV')
|
---|
104 | location = PartyIdentified.new(:name => 'GEOFRONT')
|
---|
105 | object_version_id = ObjectVersionId.new('ABC::DEF::1.3.4')
|
---|
106 | party_ref = PartyRef.new('local', 'ORGANISATION', object_id)
|
---|
107 | assert_nothing_raised(Exception){
|
---|
108 | @feeder_audit_details = FeederAuditDetails.new(:system_id => 'MAGI',
|
---|
109 | :provider => provider,
|
---|
110 | :location => location,
|
---|
111 | :time => DvDateTime.new('2009-07-03T12:16:31'),
|
---|
112 | :subject => PartyProxy.new(:external_ref => party_ref),
|
---|
113 | :version_id => '0.0.4')}
|
---|
114 | feeder_audit_details = FeederAuditDetails.new(:system_id => 'AKAGI')
|
---|
115 | dv_identifier = DvIdentifier.new('NERV', 'MELCHIOR', 'RITSUKO', 'COMPUTER')
|
---|
116 | feeder_audit_details2 = FeederAuditDetails.new(:system_id => 'KATSURAGI')
|
---|
117 | dv_identifier2 = DvIdentifier.new('NERV', 'SHOGOUKI', 'MISATO', 'EVANGELION')
|
---|
118 | charset = OpenEhr::RM::DataTypes::Text::CodePhrase.new('UTF-8','character-sets')
|
---|
119 | language = OpenEhr::RM::DataTypes::Text::CodePhrase.new('ja', 'languages')
|
---|
120 |
|
---|
121 | dv_encapsulated = OpenEhr::RM::DataTypes::Encapsulated::DvEncapsulated.new(charset, language, 10)
|
---|
122 | assert_nothing_raised(Exception){
|
---|
123 | @feeder_audit = FeederAudit.new(:originating_system_audit => feeder_audit_details,
|
---|
124 | :originating_system_item_ids => [dv_identifier],
|
---|
125 | :feeder_system_audit => feeder_audit_details2,
|
---|
126 | :feeder_system_item_ids => [dv_identifier2],
|
---|
127 | :original_content => dv_encapsulated)}
|
---|
128 | end
|
---|
129 |
|
---|
130 | def test_init
|
---|
131 | assert_instance_of OpenEhr::RM::Common::Archetyped::Archetyped, @archetyped
|
---|
132 | assert_instance_of OpenEhr::RM::Common::Archetyped::Link, @link
|
---|
133 | assert_instance_of OpenEhr::RM::Common::Archetyped::Pathable, @pathable
|
---|
134 | assert_instance_of OpenEhr::RM::Common::Archetyped::Locatable, @locatable
|
---|
135 | assert_instance_of FeederAuditDetails, @feeder_audit_details
|
---|
136 | assert_instance_of FeederAudit, @feeder_audit
|
---|
137 | end
|
---|
138 |
|
---|
139 | def test_archetyped
|
---|
140 | assert_equal @archetype_id, @archetyped.archetype_id
|
---|
141 | assert_equal '1.0.1', @archetyped.rm_version
|
---|
142 | assert_raise(ArgumentError){@archetyped.archetype_id = nil}
|
---|
143 | assert_raise(ArgumentError){@archetyped.rm_version = nil}
|
---|
144 | assert_raise(ArgumentError){@archetyped.rm_version = ''}
|
---|
145 | assert_nothing_raised(Exception){@archetyped.template_id = @template_id}
|
---|
146 | assert_equal @template_id, @archetyped.template_id
|
---|
147 | archetype_id2 = OpenEhr::RM::Support::Identification::ArchetypeId.new("1.0.2", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
|
---|
148 | assert_nothing_raised(ArgumentError){@archetyped.archetype_id = archetype_id2}
|
---|
149 | assert_equal archetype_id2, @archetyped.archetype_id
|
---|
150 | assert_nothing_raised(ArgumentError){@archetyped.rm_version = '1.0.2'}
|
---|
151 | assert_equal '1.0.2', @archetyped.rm_version
|
---|
152 | end
|
---|
153 |
|
---|
154 | def test_link
|
---|
155 | # test constructor
|
---|
156 | assert_equal 'generic', @link.meaning.value
|
---|
157 | assert_equal 'ehr://test/', @link.target.value
|
---|
158 | assert_equal 'problem', @link.type.value
|
---|
159 | # test meaning
|
---|
160 | assert_nothing_raised(Exception){@link.meaning = OpenEhr::RM::DataTypes::Text::DvText.new('clinical')}
|
---|
161 | assert_equal 'clinical', @link.meaning.value
|
---|
162 | assert_raise(ArgumentError){@link.meaning = nil}
|
---|
163 | # test target
|
---|
164 | assert_nothing_raised(Exception){@link.target = OpenEhr::RM::DataTypes::Uri::DvEhrUri.new("ehr://try/")}
|
---|
165 | assert_equal 'ehr://try/', @link.target.value
|
---|
166 | assert_raise(ArgumentError){@link.target = nil}
|
---|
167 | # test type
|
---|
168 | assert_nothing_raised(Exception){@link.type = OpenEhr::RM::DataTypes::Text::DvText.new("issue")}
|
---|
169 | assert_equal 'issue', @link.type.value
|
---|
170 | assert_raise(ArgumentError){@link.type = nil}
|
---|
171 | end
|
---|
172 |
|
---|
173 | def test_feeder_audit
|
---|
174 | assert_equal 'AKAGI', @feeder_audit.originating_system_audit.system_id
|
---|
175 | assert_equal 'RITSUKO', @feeder_audit.originating_system_item_ids[0].issuer
|
---|
176 | assert_equal 'KATSURAGI', @feeder_audit.feeder_system_audit.system_id
|
---|
177 | assert_equal 'MISATO', @feeder_audit.feeder_system_item_ids[0].issuer
|
---|
178 | assert_equal 'UTF-8', @feeder_audit.original_content.charset.code_string
|
---|
179 | end
|
---|
180 |
|
---|
181 | def test_feeder_audit_detail
|
---|
182 | assert_equal 'MAGI', @feeder_audit_details.system_id
|
---|
183 | assert_equal 'NERV', @feeder_audit_details.provider.name
|
---|
184 | assert_equal 'GEOFRONT', @feeder_audit_details.location.name
|
---|
185 | assert_equal 2009, @feeder_audit_details.time.year
|
---|
186 | assert_equal 'local', @feeder_audit_details.subject.external_ref.namespace
|
---|
187 | assert_equal '0.0.4', @feeder_audit_details.version_id
|
---|
188 | end
|
---|
189 | end
|
---|
190 |
|
---|
191 | class RM_Common_Generic_Test < Test::Unit::TestCase
|
---|
192 | def setup
|
---|
193 | assert_nothing_raised(Exception){party_proxy = PartyProxy.new}
|
---|
194 | object_id = ObjectId.new('0.0.4')
|
---|
195 | party_ref = PartyRef.new('unknown', 'ORGANISATION', object_id)
|
---|
196 | assert_nothing_raised(Exception){
|
---|
197 | @party_proxy = PartyProxy.new(:external_ref => party_ref)}
|
---|
198 | assert_nothing_raised(Exception){party_self = PartySelf.new}
|
---|
199 | assert_nothing_raised(Exception){
|
---|
200 | @party_self = PartySelf.new(:external_ref => party_ref)}
|
---|
201 | assert_raise(ArgumentError){
|
---|
202 | party_identified = PartyIdentified.new}
|
---|
203 |
|
---|
204 | identifiers = []
|
---|
205 | identifiers << DvIdentifier.new('NERV', 'MELCHIOR', 'GENDO', 'COMPUTER')
|
---|
206 | identifiers << DvIdentifier.new('NERV', 'CASPER', 'GENDO', 'COMPUTER')
|
---|
207 | identifiers << DvIdentifier.new('NERV', 'BALTHAZAR', 'GENDO', 'COMPUTER')
|
---|
208 | assert_nothing_raised(Exception){
|
---|
209 | @party_identified = PartyIdentified.new(:name => 'NERV',
|
---|
210 | :external_ref => party_ref,
|
---|
211 | :identifier => identifiers)}
|
---|
212 |
|
---|
213 | terminology_id = TerminologyId.new('test(0.04)')
|
---|
214 | code_phrase = CodePhrase.new('self', terminology_id)
|
---|
215 | dv_coded_text = DvCodedText.new('Seele',code_phrase)
|
---|
216 | assert_nothing_raised(Exception){
|
---|
217 | @party_related = PartyRelated.new(:name => 'GEHIRN',
|
---|
218 | :relationship => dv_coded_text)}
|
---|
219 | dv_text = DvText.new('commiter')
|
---|
220 | dv_coded_text = DvCodedText.new('present',terminology_id)
|
---|
221 | dv_date_time1 = DvDateTime.new('2009-07-04T16:30:00')
|
---|
222 | dv_date_time2 = DvDateTime.new('2009-07-14T00:00:00')
|
---|
223 | dv_interval = DvInterval.new(dv_date_time1, dv_date_time2)
|
---|
224 | assert_nothing_raised(Exception){
|
---|
225 | @participation = Participation.new(:performer => @party_proxy,
|
---|
226 | :function => dv_text,
|
---|
227 | :mode => dv_coded_text,
|
---|
228 | :time => dv_interval)}
|
---|
229 | dv_date_time = DvDateTime.new('2009-07-04T18:56:00')
|
---|
230 | terminology_id = TerminologyId.new('openehr(1.0.2)')
|
---|
231 | code_phrase = CodePhrase.new('249', terminology_id)
|
---|
232 | dv_coded_text = DvCodedText.new('creation', code_phrase)
|
---|
233 | dv_text = DvText.new('test environment')
|
---|
234 | assert_nothing_raised(Exception){
|
---|
235 | @audit_details = AuditDetails.new(:system_id => 'MAGI',
|
---|
236 | :committer => @party_proxy,
|
---|
237 | :time_committed => dv_date_time,
|
---|
238 | :change_type => dv_coded_text,
|
---|
239 | :description => dv_text)}
|
---|
240 | dv_text = DvText.new('authorisation')
|
---|
241 | dv_ehr_uri = DvEhrUri.new('ehr://test/')
|
---|
242 | assert_nothing_raised(Exception){
|
---|
243 | @attestation = Attestation.new(:system_id => 'NERV',
|
---|
244 | :committer => @party_proxy,
|
---|
245 | :time_committed => dv_date_time,
|
---|
246 | :change_type => dv_coded_text,
|
---|
247 | :reason => dv_text,
|
---|
248 | :description => dv_text,
|
---|
249 | :proof => 'hashedstring',
|
---|
250 | :items => Set[dv_ehr_uri])}
|
---|
251 | object_version_id = ObjectVersionId.new('SHOGOUKI::NERV::1.1.1')
|
---|
252 | audit_details2 = AuditDetails.new(:system_id => 'MAGI',
|
---|
253 | :committer => @party_proxy,
|
---|
254 | :time_committed => dv_date_time2,
|
---|
255 | :change_type => dv_coded_text)
|
---|
256 | assert_nothing_raised(Exception){
|
---|
257 | @revision_history_item = RevisionHistoryItem.new(:audits => [@audit_details, audit_details2],
|
---|
258 | :version_id => object_version_id)}
|
---|
259 | dv_date_time3 = DvDateTime.new('2009-07-14T12:00:00')
|
---|
260 | dv_date_time4 = DvDateTime.new('2009-07-15T00:00:00')
|
---|
261 | audit_details3 = AuditDetails.new(:system_id => 'MAGI',
|
---|
262 | :committer => @party_proxy,
|
---|
263 | :time_committed => dv_date_time3,
|
---|
264 | :change_type => dv_coded_text)
|
---|
265 | audit_details4 = AuditDetails.new(:system_id => 'MAGI',
|
---|
266 | :committer => @party_proxy,
|
---|
267 | :time_committed => dv_date_time4,
|
---|
268 | :change_type => dv_coded_text)
|
---|
269 | object_version_id = ObjectVersionId.new('NIGOUKI::NERV::2.2.2')
|
---|
270 | revision_history_item2 = RevisionHistoryItem.new(:audits => [audit_details3, audit_details4],
|
---|
271 | :version_id => object_version_id)
|
---|
272 | assert_nothing_raised(Exception){
|
---|
273 | @revision_history = RevisionHistory.new([@revision_history_item, revision_history_item2])}
|
---|
274 | end
|
---|
275 |
|
---|
276 | def test_init
|
---|
277 | assert_instance_of PartyProxy, @party_proxy
|
---|
278 | assert_instance_of PartySelf, @party_self
|
---|
279 | assert_instance_of PartyIdentified, @party_identified
|
---|
280 | assert_instance_of Participation, @participation
|
---|
281 | assert_instance_of AuditDetails, @audit_details
|
---|
282 | assert_instance_of Attestation, @attestation
|
---|
283 | assert_instance_of RevisionHistoryItem, @revision_history_item
|
---|
284 | assert_instance_of RevisionHistory, @revision_history
|
---|
285 | end
|
---|
286 |
|
---|
287 | def test_party_proxy
|
---|
288 | assert_equal 'unknown', @party_proxy.external_ref.namespace
|
---|
289 | end
|
---|
290 |
|
---|
291 | def test_party_self
|
---|
292 | assert_equal 'ORGANISATION', @party_self.external_ref.type
|
---|
293 | end
|
---|
294 |
|
---|
295 | def test_party_identified
|
---|
296 | assert_equal 'NERV', @party_identified.name
|
---|
297 | assert_equal '0.0.4', @party_identified.external_ref.id.value
|
---|
298 | identifiers = @party_identified.identifier
|
---|
299 | ids = [ ]
|
---|
300 | identifiers.each do |id|
|
---|
301 | ids << id.id
|
---|
302 | end
|
---|
303 | assert_equal %w[MELCHIOR CASPER BALTHAZAR], ids
|
---|
304 | end
|
---|
305 |
|
---|
306 | def test_party_related
|
---|
307 | assert_equal 'GEHIRN', @party_related.name
|
---|
308 | end
|
---|
309 |
|
---|
310 | def test_participation
|
---|
311 | assert_equal 'unknown', @participation.performer.external_ref.namespace
|
---|
312 | assert_equal 'commiter', @participation.function.value
|
---|
313 | assert_equal 'present', @participation.mode.value
|
---|
314 | assert_equal 2009, @participation.time.lower.year
|
---|
315 | end
|
---|
316 |
|
---|
317 | def test_audit_details
|
---|
318 | assert_equal 'MAGI', @audit_details.system_id
|
---|
319 | assert_equal 'unknown', @audit_details.committer.external_ref.namespace
|
---|
320 | assert_equal '2009-07-04T18:56:00', @audit_details.time_committed.as_string
|
---|
321 | assert_equal 'creation', @audit_details.change_type.value
|
---|
322 | assert_equal 'test environment', @audit_details.description.value
|
---|
323 | end
|
---|
324 |
|
---|
325 | def test_attestation
|
---|
326 | assert_equal 'NERV', @attestation.system_id
|
---|
327 | assert_equal 'unknown', @attestation.committer.external_ref.namespace
|
---|
328 | assert_equal '249', @attestation.change_type.defining_code.code_string
|
---|
329 | assert_equal 7, @attestation.time_committed.month
|
---|
330 | assert_equal 'authorisation', @attestation.reason.value
|
---|
331 | assert_equal 'authorisation', @attestation.description.value
|
---|
332 | assert_equal 'hashedstring', @attestation.proof
|
---|
333 | assert_equal 'ehr://test/', @attestation.items.to_a[0].value
|
---|
334 | end
|
---|
335 |
|
---|
336 | def test_revision_history_item
|
---|
337 | assert_equal 'SHOGOUKI::NERV::1.1.1', @revision_history_item.version_id.value
|
---|
338 | assert_equal 'MAGI', @revision_history_item.audits[0].system_id
|
---|
339 | end
|
---|
340 |
|
---|
341 | def test_revision_history
|
---|
342 | assert_equal 'NIGOUKI::NERV::2.2.2', @revision_history.most_recent_version
|
---|
343 | assert_equal '2009-07-14T12:00:00', @revision_history.most_recent_version_time_committed
|
---|
344 | end
|
---|
345 | end
|
---|
346 |
|
---|
347 | class RM_Common_Directory_Test < Test::Unit::TestCase
|
---|
348 | def setup
|
---|
349 | archetype_node_id = 'at0001'
|
---|
350 | name = DvText.new('folder_test')
|
---|
351 | object_id = ObjectId.new('1.1.1')
|
---|
352 | object_ref = ObjectRef.new('local', 'PARTY', object_id)
|
---|
353 | assert_nothing_raised(Exception){
|
---|
354 | @folder = Folder.new(:archetype_node_id => archetype_node_id,
|
---|
355 | :name => name,
|
---|
356 | :items => [object_ref])}
|
---|
357 |
|
---|
358 |
|
---|
359 | end
|
---|
360 |
|
---|
361 | def test_init
|
---|
362 | assert_instance_of OpenEhr::RM::Common::Directory::Folder, @folder
|
---|
363 | end
|
---|
364 |
|
---|
365 | def test_folder
|
---|
366 | assert_equal 'at0001', @folder.archetype_node_id
|
---|
367 | assert_equal 'local', @folder.items[0].namespace
|
---|
368 | end
|
---|
369 | end
|
---|
370 |
|
---|
371 | class RM_Common_Change_Control_Test < Test::Unit::TestCase
|
---|
372 | def setup
|
---|
373 | object_version_id1 = ObjectVersionId.new('ABC::DEF::2.2.3')
|
---|
374 | object_version_id2 = ObjectVersionId.new('GHI::JKL::4.5.6')
|
---|
375 | object_id = ObjectId.new('ehr://uniqueid1020')
|
---|
376 | dv_date_time = DvDateTime.new('2009-07-06T21:10:12')
|
---|
377 | party_ref = PartyRef.new('unknown', 'ORGANISATION', object_id)
|
---|
378 | party_proxy = PartyProxy.new(:external_ref => party_ref)
|
---|
379 | terminology_id = TerminologyId.new('openehr(1.0.2)')
|
---|
380 | code_phrase = CodePhrase.new('249', terminology_id)
|
---|
381 | dv_coded_text = DvCodedText.new('creation', code_phrase)
|
---|
382 | audit_details = AuditDetails.new(:system_id => 'MAGI',
|
---|
383 | :committer => party_proxy,
|
---|
384 | :time_committed => dv_date_time,
|
---|
385 | :change_type => dv_coded_text)
|
---|
386 | code_phrase = CodePhrase.new('532', terminology_id)
|
---|
387 | dv_coded_text = DvCodedText.new('complete', code_phrase)
|
---|
388 | object_id = ObjectId.new('ehr://test_location')
|
---|
389 | object_ref = ObjectRef.new('local', 'PARTY', object_id)
|
---|
390 | hier_object_id = HierObjectId.new('ABC')
|
---|
391 | assert_nothing_raised(Exception){
|
---|
392 | @version = Version.new(:uid => object_version_id1,
|
---|
393 | :preceding_version_uid => object_version_id2,
|
---|
394 | :lifecycle_state => dv_coded_text,
|
---|
395 | :commit_audit => audit_details,
|
---|
396 | :contribution => object_ref,
|
---|
397 | :signature => 'test_version',
|
---|
398 | :data => 'data')}
|
---|
399 | object_version_id3 = ObjectVersionId.new('MNO::PQR::7.8.9')
|
---|
400 | object_version_id4 = ObjectVersionId.new('STU::VWX::1.2.3')
|
---|
401 | code_phrase = CodePhrase.new('240', terminology_id)
|
---|
402 | dv_coded_text2 = DvCodedText.new('signed', code_phrase)
|
---|
403 | attestation = Attestation.new(:system_id => 'NERV',
|
---|
404 | :committer => party_proxy,
|
---|
405 | :time_committed => dv_date_time,
|
---|
406 | :change_type => dv_coded_text,
|
---|
407 | :reason => DvText.new('signed'))
|
---|
408 | dv_date_time = DvDateTime.new('2009-07-07T21:10:12')
|
---|
409 | audit_details = AuditDetails.new(:system_id => 'MAGI',
|
---|
410 | :committer => party_proxy,
|
---|
411 | :time_committed => dv_date_time,
|
---|
412 | :change_type => dv_coded_text)
|
---|
413 | assert_nothing_raised(Exception){
|
---|
414 | @original_version = OriginalVersion.new(:uid => object_version_id3,
|
---|
415 | :preceding_version_uid => object_version_id4,
|
---|
416 | :other_input_version_uids => Set[object_version_id1, object_version_id2],
|
---|
417 | :commit_audit => audit_details,
|
---|
418 | :contribution => object_ref,
|
---|
419 | :attestations => [attestation],
|
---|
420 | :data => 'data',
|
---|
421 | :lifecycle_state => dv_coded_text)}
|
---|
422 | dv_date_time = DvDateTime.new('2009-07-08T21:10:12')
|
---|
423 | audit_details = AuditDetails.new(:system_id => 'CASPER',
|
---|
424 | :committer => party_proxy,
|
---|
425 | :time_committed => dv_date_time,
|
---|
426 | :change_type => dv_coded_text,
|
---|
427 | :description => 'for contribution')
|
---|
428 | object_ref = ObjectRef.new('unknown', 'PARTY', object_id)
|
---|
429 | assert_nothing_raised(Exception){
|
---|
430 | @imported_version = ImportedVersion.new(:item => @original_version,
|
---|
431 | :commit_audit => audit_details,
|
---|
432 | :contribution => object_ref,
|
---|
433 | :signature => 'import test')}
|
---|
434 | assert_nothing_raised(Exception){
|
---|
435 | @contribution = Contribution.new(:uid => hier_object_id,
|
---|
436 | :versions => Set[object_ref],
|
---|
437 | :audit => audit_details)}
|
---|
438 | dv_date_time = DvDateTime.new('2009-07-08T18:10:12')
|
---|
439 | audit_details = AuditDetails.new(:system_id => 'MAGI',
|
---|
440 | :committer => party_proxy,
|
---|
441 | :time_committed => dv_date_time,
|
---|
442 | :change_type => dv_coded_text)
|
---|
443 | @trunk_version = Version.new(:uid => object_version_id4,
|
---|
444 | :lifecycle_state => dv_coded_text,
|
---|
445 | :commit_audit => audit_details,
|
---|
446 | :contribution => object_ref,
|
---|
447 | :change_type => dv_coded_text)
|
---|
448 | assert_nothing_raised(Exception){
|
---|
449 | @versioned_object = VersionedObject.new(:uid => hier_object_id,
|
---|
450 | :owner_id => object_ref,
|
---|
451 | :time_created => dv_date_time,
|
---|
452 | :all_versions => [@version,@original_version,@imported_version,@trunk_version])}
|
---|
453 | end
|
---|
454 |
|
---|
455 | def test_init
|
---|
456 | assert_instance_of OpenEhr::RM::Common::ChangeControl::Version, @version
|
---|
457 | assert_instance_of OriginalVersion, @original_version
|
---|
458 | assert_instance_of ImportedVersion, @imported_version
|
---|
459 | assert_instance_of OpenEhr::RM::Common::ChangeControl::Contribution, @contribution
|
---|
460 | assert_instance_of VersionedObject, @versioned_object
|
---|
461 | end
|
---|
462 |
|
---|
463 | def test_version
|
---|
464 | assert_equal 'ABC::DEF::2.2.3', @version.uid.value
|
---|
465 | assert !@version.uid.version_tree_id.is_first?
|
---|
466 | assert_equal 'GHI::JKL::4.5.6', @version.preceding_version_uid.value
|
---|
467 | assert_equal '532', @version.lifecycle_state.defining_code.code_string
|
---|
468 | assert_equal 'MAGI', @version.commit_audit.system_id
|
---|
469 | assert_equal 'local', @version.contribution.namespace
|
---|
470 | assert_equal 'test_version', @version.signature
|
---|
471 | assert_equal 'ABC', @version.owner_id.value
|
---|
472 | assert_equal 'data', @version.data
|
---|
473 | assert @version.is_branch?
|
---|
474 | end
|
---|
475 |
|
---|
476 | def test_original_version
|
---|
477 | assert_equal 'MNO::PQR::7.8.9', @original_version.uid.value
|
---|
478 | assert_equal 'NERV', @original_version.attestations[0].system_id
|
---|
479 | end
|
---|
480 |
|
---|
481 | def test_imported_version
|
---|
482 | assert_equal 'import test', @imported_version.signature
|
---|
483 | assert_equal 'MNO::PQR::7.8.9', @imported_version.item.uid.value
|
---|
484 | assert_equal 'CASPER', @imported_version.commit_audit.system_id
|
---|
485 | assert_equal 'unknown', @imported_version.contribution.namespace
|
---|
486 | assert_equal 'STU::VWX::1.2.3', @imported_version.preceding_version_uid.value
|
---|
487 | assert_equal '532', @imported_version.lifecycle_state.defining_code.code_string
|
---|
488 | end
|
---|
489 |
|
---|
490 | def test_contribution
|
---|
491 | assert_equal 'ABC', @contribution.uid.value
|
---|
492 | assert_equal 'PARTY', @contribution.versions.to_a[0].type
|
---|
493 | assert_equal 'for contribution', @contribution.audit.description
|
---|
494 | end
|
---|
495 |
|
---|
496 | def test_versioned_object
|
---|
497 | assert_equal 'ABC', @versioned_object.uid.value
|
---|
498 | assert_equal 'unknown', @versioned_object.owner_id.namespace
|
---|
499 | assert_equal 18, @versioned_object.time_created.hour
|
---|
500 | assert_equal [@version, @original_version, @imported_version, @trunk_version],
|
---|
501 | @versioned_object.all_versions
|
---|
502 | assert_equal 4, @versioned_object.version_count
|
---|
503 | assert_equal [@version.uid, @original_version.uid, @imported_version.uid, @trunk_version.uid],
|
---|
504 | @versioned_object.all_version_ids
|
---|
505 | assert @versioned_object.has_version_id?(@version.uid)
|
---|
506 | assert !@versioned_object.is_original_version?(@version.uid)
|
---|
507 | assert @versioned_object.is_original_version?(@original_version.uid)
|
---|
508 | assert @versioned_object.has_version_at_time?(DvDateTime.new('2009-07-06T21:10:12'))
|
---|
509 | assert_equal @version, @versioned_object.version_with_id(@version.uid)
|
---|
510 | assert_equal @version, @versioned_object.version_at_time(@version.commit_audit.time_committed)
|
---|
511 | assert_equal @imported_version, @versioned_object.latest_version
|
---|
512 | assert_equal @trunk_version, @versioned_object.latest_trunk_version
|
---|
513 | assert_equal 'complete', @versioned_object.trunk_lifecycle_state.value
|
---|
514 | assert_equal '2009-07-08T18:10:12', @versioned_object.revision_history.most_recent_version_time_committed
|
---|
515 | assert_nothing_raised(Exception){
|
---|
516 | @versioned_object.commit_original_version(:contribution => @original_version.contribution,
|
---|
517 | :uid => @original_version.uid,
|
---|
518 | :preceding_version_uid => @original_version.preceding_version_uid,
|
---|
519 | :commit_audit => @original_version.commit_audit,
|
---|
520 | :attestations => @original_version.attestations,
|
---|
521 | :lifecycle_state => @original_version.lifecycle_state,
|
---|
522 | :data => 'commit original',
|
---|
523 | :signature => 'testtett')}
|
---|
524 | assert_equal 5, @versioned_object.version_count
|
---|
525 | assert_nothing_raised(Exception){
|
---|
526 | @versioned_object.commit_original_merged_version(:contribution => @original_version.contribution,
|
---|
527 | :uid => @original_version.uid,
|
---|
528 | :preceding_version_uid => @original_version.preceding_version_uid,
|
---|
529 | :commit_audit => @original_version.commit_audit,
|
---|
530 | :lifecycle_state => @original_version.lifecycle_state,
|
---|
531 | :attestations => @original_version.attestations,
|
---|
532 | :data => @original_version.data,
|
---|
533 | :other_input_version_uids => @original_version.other_input_version_uids,
|
---|
534 | :signature => @original_version.signature)}
|
---|
535 | assert_equal 6, @versioned_object.version_count
|
---|
536 | assert_nothing_raised(Exception){
|
---|
537 | @versioned_object.commit_imported_version(:contribution => @imported_version.contribution,
|
---|
538 | :commit_audit => @imported_version.commit_audit,
|
---|
539 | :item => @imported_version.item)}
|
---|
540 | assert_equal 7, @versioned_object.version_count
|
---|
541 | dv_date_time = DvDateTime.new('2009-07-07T22:11:31')
|
---|
542 | attestation = Attestation.new(:system_id => 'NERV2',
|
---|
543 | :committer => @version.contribution,
|
---|
544 | :time_committed => dv_date_time,
|
---|
545 | :change_type => @original_version.commit_audit.change_type,
|
---|
546 | :reason => DvText.new('signed'))
|
---|
547 | assert_nothing_raised(Exception){
|
---|
548 | @versioned_object.commit_attestation(:attestation => attestation,
|
---|
549 | :uid => @original_version.uid,
|
---|
550 | :signature => 'new signature')}
|
---|
551 | end
|
---|
552 | end
|
---|