open_ehr 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/History.txt +6 -0
  2. data/README.rdoc +6 -8
  3. data/VERSION +1 -1
  4. data/lib/open_ehr/am/archetype/constraint_model/primitive.rb +2 -2
  5. data/lib/open_ehr/am/archetype/ontology.rb +23 -28
  6. data/lib/open_ehr/am/archetype.rb +1 -1
  7. data/lib/open_ehr/parser/adl.rb +42 -4
  8. data/lib/open_ehr/parser/adl_grammar.tt +67 -42
  9. data/lib/open_ehr/parser/adl_parser.rb +1 -1
  10. data/lib/open_ehr/parser/cadl_grammar.tt +227 -61
  11. data/lib/open_ehr/parser/cadl_node.rb +1 -0
  12. data/lib/open_ehr/parser/dadl_grammar.tt +10 -10
  13. data/lib/open_ehr/parser/shared_token_grammar.tt +13 -13
  14. data/open_ehr.gemspec +14 -4
  15. data/spec/lib/open_ehr/am/archetype/archetype_spec.rb +1 -1
  16. data/spec/lib/open_ehr/am/archetype/ontology/archetype_ontology_spec.rb +22 -13
  17. data/spec/lib/open_ehr/parser/adl14/adl-test-SOME_TYPE.generic_type_use_node.draft.adl +1 -1
  18. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_bindings.test.adl +1 -1
  19. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_internal_ref.test.adl +1 -1
  20. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_internal_ref2.test.adl +1 -1
  21. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_language.test.adl +1 -1
  22. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_language_no_accreditation.test.adl +1 -1
  23. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_language_order_of_translation_details.test.adl +1 -1
  24. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_ontology.test.adl +1 -1
  25. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.translations_author_language.test.adl +1 -1
  26. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.translations_language_author.test.adl +1 -1
  27. data/spec/lib/open_ehr/parser/adl_archetype_internal_ref2_spec.rb +42 -0
  28. data/spec/lib/open_ehr/parser/adl_archetype_internal_ref_spec.rb +125 -0
  29. data/spec/lib/open_ehr/parser/adl_archetype_internal_ref_with_generics_spec.rb +258 -0
  30. data/spec/lib/open_ehr/parser/adl_archetype_ontology_binding_spec.rb +98 -0
  31. data/spec/lib/open_ehr/parser/adl_archetype_ontology_spec.rb +42 -0
  32. data/spec/lib/open_ehr/parser/adl_description_spec.rb +13 -2
  33. data/spec/lib/open_ehr/parser/adl_language_no_accreditation_spec.rb +66 -0
  34. data/spec/lib/open_ehr/parser/adl_language_order_spec.rb +68 -0
  35. data/spec/lib/open_ehr/parser/adl_language_spec.rb +119 -0
  36. data/spec/lib/open_ehr/parser/adl_language_translation_author_language_spec.rb +50 -0
  37. data/spec/lib/open_ehr/parser/adl_language_translation_language_author_spec.rb +46 -0
  38. data/spec/lib/open_ehr/parser/adl_parser_spec.rb +2 -2
  39. data/spec/lib/open_ehr/parser/parser_spec_helper.rb +7 -0
  40. data/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb +4 -4
  41. metadata +49 -39
  42. data/Gemfile.lock +0 -85
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.9.4 2011-11-22
2
+ Bug fix around ADL parser, ArchetypeOntology
3
+
4
+ === 0.9.3 2011-11-19
5
+ Bug fix around ADL parser
6
+
1
7
  === 0.9.1 2011-10-04
2
8
  Archetype instance generated from ADL file.
3
9
 
data/README.rdoc CHANGED
@@ -5,22 +5,20 @@ Ruby openEHR implementation project.
5
5
 
6
6
  = Version
7
7
 
8
- Release-0.9.3
8
+ Release-0.9.4
9
9
 
10
10
  = Requirements
11
11
 
12
12
  * Ruby 1.9.2 reccomended
13
- * RubyGems
14
13
  * Tested with Ruby 1.9.2 on Linux and FreeBSD.
15
- * If you use early version of Ruby 1.8, you should
16
- prepare racc runtime environment and some
17
- adjustment. We do not support Ruby 1.6 anymore.
14
+ * It would work with some adjustment on Ruby 1.8 or earlier,
15
+ but not confirmed.
18
16
  * It should work on other platforms with Ruby
19
17
  support as well.
20
18
 
21
19
  == DESCRIPTION:
22
20
 
23
- This is the beta version 0.9.3 release of Ruby openEHR implementation
21
+ This is the beta version 0.9.4 release of Ruby openEHR implementation
24
22
  project. This release is still experimental preview of our work based
25
23
  on openEHR specification release 1.0.2. We implemented almost of the
26
24
  specifications of the openEHR. The work is still in progress. The
@@ -31,7 +29,7 @@ Parser is nearly performing completely. We now consider to descrive
31
29
  archetype as another formalism such as YAML, instead of ADL.
32
30
 
33
31
  Almost all classes passed the test constructed by RSpec2 (formaly used
34
- test/unit). These test specifications are under /spec.
32
+ test/unit). These spec files are under /spec.
35
33
 
36
34
  Some specifications are not well determined yet, such as rm/security
37
35
  and so on. We postponed to implement such classes.
@@ -41,7 +39,7 @@ project.
41
39
 
42
40
  = Authors
43
41
  * Main codes
44
- Akimichi Tatsukawa, Shinji Kobayashi
42
+ Shinji Kobayashi, Akimichi Tatsukawa
45
43
  openEHR.jp, <http://openehr.jp>
46
44
 
47
45
  * ADL parser test cases are derived from Java and Eiffel
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
@@ -39,7 +39,7 @@ module OpenEHR
39
39
 
40
40
  def default_value=(default_value)
41
41
  super
42
- default_value_consistency(default_value)
42
+ default_value_consistency(default_value) unless default_value.nil?
43
43
  end
44
44
 
45
45
  def true_valid=(true_valid)
@@ -68,7 +68,7 @@ module OpenEHR
68
68
  end
69
69
 
70
70
  def default_value_consistency(default_value)
71
- if (!@true_valid && default_value) || (!@false_valid && !default_value)
71
+ if (!@true_valid && default_value) || ((!@false_valid) && (!default_value))
72
72
  raise ArgumentError, 'default value inconsistency'
73
73
  end
74
74
  end
@@ -5,86 +5,81 @@ module OpenEHR
5
5
  class ArchetypeOntology
6
6
  attr_accessor :specialisation_depth, :primary_language
7
7
  attr_accessor :term_attribute_names, :term_bindings
8
- attr_accessor :languages_available
8
+ attr_accessor :languages_available, :terminologies_available
9
+ attr_accessor :constraint_bindings
9
10
  attr_reader :term_definitions, :constraint_definitions
10
11
 
11
12
  def initialize(args = { })
12
13
  self.primary_language = args[:primary_language]
13
14
  self.languages_available = args[:languages_available]
15
+ self.terminologies_available = args[:terminologies_available]
14
16
  self.specialisation_depth = args[:specialisation_depth]
15
17
  self.term_definitions = args[:term_definitions]
16
18
  if args[:constraint_definitions]
17
19
  self.constraint_definitions = args[:constraint_definitions]
18
20
  end
19
21
  self.term_bindings = args[:term_bindings]
22
+ self.constraint_bindings = args[:constraint_bindings]
20
23
  end
21
24
 
22
25
  def term_definitions=(term_definitions)
23
26
  if term_definitions.nil?
24
27
  raise ArgumentError, 'term_definitions is mandatory'
25
28
  end
26
- @term_definition_map = definition_mapper(term_definitions)
27
29
  @term_definitions = term_definitions
28
30
  end
29
31
 
30
32
  def term_codes
31
- return @term_definitions.values.collect {|value|
32
- value.collect {|term| term.code}}.flatten.uniq
33
+ code_set @term_definitions
33
34
  end
34
35
 
35
36
  def constraint_codes
36
37
  if @constraint_definitions.nil?
37
38
  return nil
38
39
  else
39
- return @constraint_definitions.values.collect {|value|
40
- value.collect {|term| term.code}}.flatten.uniq
40
+ code_set @constraint_definitions
41
41
  end
42
42
  end
43
43
 
44
- def terminologies_available
45
- return @term_bindings.keys
46
- end
47
-
48
- def constraint_binding(a_terminology, a_code)
49
-
44
+ def constraint_binding(args = {})
45
+ return @constraint_bindings[args[:terminology]][args[:code]]
50
46
  end
51
47
 
52
48
  def constraint_definitions=(constraint_definitions)
53
- @constraint_definition_map = definition_mapper(constraint_definitions)
54
49
  @constraint_definitions = constraint_definitions
55
50
  end
56
51
 
57
52
  def constraint_definition(args = {})
58
- return @constraint_definition_map[args[:lang]][args[:code]]
53
+ return @constraint_definitions[args[:lang]][args[:code]]
59
54
  end
60
55
 
61
56
  def has_language?(a_lang)
62
- return @term_definition_map.has_key? a_lang
57
+ return @term_definitions.has_key? a_lang
63
58
  end
64
59
 
65
60
  def has_terminology?(a_terminology)
66
- return @term_bindings.has_key? a_terminology
61
+ if !@terminologies_available.nil? &&
62
+ (@terminologies_available.include? a_terminology)
63
+ return true
64
+ else
65
+ return false
66
+ end
67
67
  end
68
68
 
69
69
  def term_binding(args = { })
70
-
70
+ return @term_bindings[args[:terminology]][args[:code]]
71
71
  end
72
72
 
73
73
  def term_definition(args = { })
74
- return @term_definition_map[args[:lang]][args[:code]]
74
+ return @term_definitions[args[:lang]][args[:code]]
75
75
  end
76
76
 
77
- private
78
- def definition_mapper(definitions)
79
- map = { }
80
- definitions.each do |lang, defs|
81
- defs_map = { }
82
- defs.each do |d|
83
- defs_map[d.code] = d.items
84
- end
85
- map[lang] = defs_map
77
+ protected
78
+ def code_set(definitions)
79
+ codes = definitions.values.inject([]) do |codes, item|
80
+ item.keys
86
81
  end
87
- return map
82
+ codes.uniq
88
83
  end
89
84
  end
90
85
 
@@ -68,7 +68,7 @@ module OpenEHR
68
68
  end
69
69
 
70
70
  def concept_name(a_lang)
71
- return @ontology.term_definition(:lang => a_lang, :code => @concept)[:text]
71
+ return @ontology.term_definition(:lang => a_lang, :code => @concept).items[:text]
72
72
  end
73
73
 
74
74
  def constraint_references_valid?
@@ -1,3 +1,7 @@
1
+ include OpenEHR::RM::Support::Identification
2
+ include OpenEHR::RM::Common::Resource
3
+ include OpenEHR::RM::DataTypes::Text
4
+
1
5
  module OpenEHR
2
6
  module Parser
3
7
  module ADLGrammar
@@ -6,12 +10,46 @@ module OpenEHR
6
10
  end
7
11
 
8
12
  class ArchLanguage < Base
9
- def original_language
10
- lang.value[:original_language]
13
+ def value
14
+ Language.new(lang.value)
11
15
  end
16
+ end
17
+
12
18
 
13
- def translations
14
- lang.value[:translations]
19
+ class Language
20
+ attr_reader :original_language, :translations
21
+
22
+ def initialize(value)
23
+ self.original_language = value['original_language']
24
+ self.translations = value['translations']
25
+ end
26
+
27
+ def original_language=(original_language)
28
+ @original_language = code2lang original_language
29
+ end
30
+
31
+ def translations=(translations)
32
+ if translations.nil?
33
+ @translations = nil
34
+ else
35
+ tr = translations.inject({ }) do |trans, lang|
36
+ code, details = lang
37
+ td = TranslationDetails.new(
38
+ :language => code2lang(details['language']),
39
+ :author => details['author'],
40
+ :accreditation => details['accreditation'],
41
+ :other_details => details['other_details'])
42
+ trans.update Hash[code, td]
43
+ end
44
+ @translations = tr
45
+ end
46
+ end
47
+
48
+ protected
49
+ def code2lang(code)
50
+ ti, la = code.split '::'
51
+ ti = TerminologyID.new(:value => ti)
52
+ CodePhrase.new(:code_string => la, :terminology_id => ti)
15
53
  end
16
54
  end
17
55
  end
@@ -33,15 +33,11 @@ module OpenEHR
33
33
  end
34
34
 
35
35
  def original_language
36
- tid, la = lang.original_language.split('::')
37
- OpenEHR::RM::DataTypes::Text::CodePhrase.new(
38
- :terminology_id =>
39
- OpenEHR::RM::Support::Identification::TerminologyID.new(:value => tid),
40
- :code_string => la)
36
+ lang.value.original_language
41
37
  end
42
38
 
43
39
  def translations
44
- lang.translations
40
+ lang.value.translations
45
41
  end
46
42
 
47
43
  def description
@@ -147,40 +143,35 @@ module OpenEHR
147
143
  def value
148
144
  params = desc.value
149
145
  details = { }
150
- params[:details].each do |lang, attrs|
151
- term_id, la = attrs[:language].split('::')
146
+ params['details'].each do |lang, attrs|
147
+ term_id, la = attrs['language'].split('::')
152
148
  terminology_id =
153
149
  OpenEHR::RM::Support::Identification::TerminologyID.new(
154
150
  :value => term_id)
155
- misuse = attrs[:misuse].empty? ? nil : attrs[:misuse]
151
+ misuse = attrs['misuse']
152
+ misuse = nil if misuse.nil? or misuse.empty?
156
153
  item =
157
154
  OpenEHR::RM::Common::Resource::ResourceDescriptionItem.new(
158
155
  :language => OpenEHR::RM::DataTypes::Text::CodePhrase.new(
159
156
  :terminology_id => terminology_id,
160
157
  :code_string => la),
161
- :purpose => attrs[:purpose],
162
- :keywords => attrs[:keywords],
163
- :use => attrs[:use],
158
+ :purpose => attrs["purpose"],
159
+ :keywords => attrs["keywords"],
160
+ :use => attrs["use"],
164
161
  :misuse => misuse,
165
- :copyright => attrs[:copyright],
166
- :original_resource_uri => attrs[:original_resource_uri],
167
- :other_details => attrs[:other_details])
168
- details[lang.to_s] = item
162
+ :copyright => attrs['copyright'],
163
+ :original_resource_uri => attrs['original_resource_uri'],
164
+ :other_details => attrs['other_details'])
165
+ details[lang] = item
169
166
  end
170
- oc = params[:other_contributors].nil? ? nil : params[:other_contributors].values
171
- original_author = key_s params[:original_author]
172
- other_details = key_s params[:other_details] if params[:other_details]
167
+ oc = params['other_contributors'].nil? ? nil : params['other_contributors'].values
173
168
  OpenEHR::RM::Common::Resource::ResourceDescription.new(
174
- :original_author => original_author,
169
+ :original_author => params['original_author'],
175
170
  :other_contributors => oc,
176
- :lifecycle_state => params[:lifecycle_state],
171
+ :lifecycle_state => params['lifecycle_state'],
177
172
  :details => details,
178
- :resource_package_uri => params[:archetype_package_uri],
179
- :other_details => other_details)
180
- end
181
-
182
- def key_s(hash)
183
- hash.inject({ }) {|h,i| h.update Hash[i[0].to_s,i[1]]}
173
+ :resource_package_uri => params['archetype_package_uri'],
174
+ :other_details => params['other_details'])
184
175
  end
185
176
  }
186
177
  end
@@ -200,21 +191,55 @@ module OpenEHR
200
191
  rule arch_ontology
201
192
  SYM_ONTOLOGY ontology:V_DADL_TEXT space {
202
193
  def value
203
- ao = ontology.value[:term_definitions]
204
- term_definitions = {}
205
- ao.each do |lang, term_defs|
206
- items = term_defs[:items]
207
- terms = items.map do |code, item|
208
- OpenEHR::AM::Archetype::Ontology::ArchetypeTerm.new(
209
- :code => code.to_s, :items => item)
210
- end
211
- term_definitions[lang.to_s] = terms
194
+ ao = ontology.value
195
+ arc_term = Proc.new do |code, item|
196
+ OpenEHR::AM::Archetype::Ontology::ArchetypeTerm.new(
197
+ :code => code, :items => item)
198
+ end
199
+ td = itemizer(ao['term_definitions'], arc_term)
200
+ cd = ao['constraint_definitions']
201
+ if cd
202
+ cd = itemizer(cd , arc_term)
203
+ end
204
+ tb = ao['term_bindings']
205
+ term_bind = Proc.new do |code, item|
206
+ term_id, code_string = item.split '::'
207
+ term_id = OpenEHR::RM::Support::Identification::TerminologyID.new(:value => term_id)
208
+ OpenEHR::RM::DataTypes::Text::CodePhrase.new(:terminology_id => term_id, :code_string => code_string)
209
+ end
210
+ if tb
211
+ tb = itemizer(tb, term_bind)
212
+ end
213
+ cons_bind = Proc.new do |code, item|
214
+ item
215
+ end
216
+ cb = ao['constraint_bindings']
217
+ if cb
218
+ cb = itemizer(cb, cons_bind)
212
219
  end
213
220
  OpenEHR::AM::Archetype::Ontology::ArchetypeOntology.new(
214
- :term_definitions => term_definitions)
215
- end
221
+ :primary_language => ao['primary_language'],
222
+ :languages_available => ao['languages_available'],
223
+ :terminologies_available => ao['terminologies_available'],
224
+ :term_definitions => td,
225
+ :constraint_definitions => cd,
226
+ :term_bindings => tb,
227
+ :constraint_bindings => cb)
228
+ end
229
+
230
+ def itemizer(defs, itemize)
231
+ defs.inject({ }) do |term_defs, langs|
232
+ lang, items = langs
233
+ terms = items['items'].inject({ }) do |items, term|
234
+ code, item = term
235
+ item = itemize.call code, item
236
+ items.update Hash[code => item]
237
+ end
238
+ term_defs.update Hash[lang => terms]
239
+ end
240
+ end
216
241
  }
217
- end
218
- end
219
- end
220
- end
242
+ end # of arch_ontology
243
+ end # of ADLGrammar
244
+ end # of Parser
245
+ end # of openEHR
@@ -33,7 +33,7 @@ module OpenEHR
33
33
  :adl_version => @result.adl_version,
34
34
  :concept => @result.concept,
35
35
  :original_language => original_language,
36
- :translation => @result.translations,
36
+ :translations => @result.translations,
37
37
  :description => @result.description,
38
38
  :definition => @result.definition,
39
39
  :ontology => @result.ontology)