openehr 1.2.15 → 1.2.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -478,12 +478,7 @@ module OpenEHR
478
478
  end
479
479
 
480
480
  rule c_primitive
481
- c_boolean '' {
482
- def value
483
- c_boolean.value
484
- end
485
- }
486
- / c_date_time '' {
481
+ c_date_time '' {
487
482
  def value
488
483
  c_date_time.value
489
484
  end
@@ -513,6 +508,11 @@ module OpenEHR
513
508
  c_integer.value
514
509
  end
515
510
  }
511
+ / c_boolean '' {
512
+ def value
513
+ c_boolean.value
514
+ end
515
+ }
516
516
  / c_string '' {
517
517
  def value
518
518
  c_string.value
@@ -1083,7 +1083,7 @@ module OpenEHR
1083
1083
  end
1084
1084
 
1085
1085
  rule c_boolean_spec
1086
- SYM_TRUE ',' white_space SYM_FALSE {
1086
+ SYM_TRUE white_space ',' white_space SYM_FALSE {
1087
1087
  def value
1088
1088
  {:true_valid => true, :false_valid => true}
1089
1089
  end
@@ -5,44 +5,84 @@ require_relative '../parser'
5
5
 
6
6
  module OpenEHR
7
7
  module Parser
8
-
9
8
  class ADLParser < ::OpenEHR::Parser::Base
10
- Treetop.load(File.dirname(__FILE__)+'/adl_grammar.tt')
9
+ require_relative './adl_grammar'
10
+ # Treetop.load('adl_grammar')
11
11
 
12
12
  def initialize(filename)
13
13
  super(filename)
14
- file = File.open(filename, 'r:bom|utf-8')
15
- data = file.read
16
- ap = ADLGrammarParser.new
17
- @result = ap.parse(data)
18
- file.close
19
- unless @result
20
- puts ap.failure_reason
21
- puts ap.failure_line
22
- puts ap.failure_column
14
+ end
15
+
16
+ def parse
17
+ archetype
18
+ end
19
+
20
+ private
21
+
22
+ def adl_grammar_parser
23
+ @adl_grammar_parser ||= ADLGrammarParser.new
24
+ end
25
+
26
+ def parsed_data
27
+ filestream = File.open(filename, 'r:bom|utf-8')
28
+ @parsed_data ||= adl_grammar_parser.parse(filestream.read)
29
+ filestream.close
30
+ unless @parsed_data
31
+ puts adl_grammar_parser.failure_reason
32
+ puts adl_grammar_parser.failure_line
33
+ puts adl_grammar_parser.failure_column
23
34
  end
35
+ @parsed_data
24
36
  end
25
37
 
26
- def parse
27
- archetype_id = OpenEHR::RM::Support::Identification::ArchetypeID.new(:value => @result.archetype_id)
28
- ontology = @result.ontology
38
+ def archetype_id
39
+ OpenEHR::RM::Support::Identification::ArchetypeID.new(:value => parsed_data.archetype_id)
40
+ end
41
+
42
+ def ontology
43
+ parsed_data.ontology
44
+ end
45
+
46
+ def original_language
29
47
  original_language = nil
30
- if @result.original_language
31
- original_language = @result.original_language
48
+ if parsed_data.original_language
49
+ original_language = parsed_data.original_language
32
50
  else
33
51
  terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(:value => 'ISO639-1')
34
- original_language = OpenEHR::RM::DataTypes::Text::CodePhrase.new(:terminology_id => terminology_id,
35
- :code_string =>ontology.primary_language)
52
+ original_language = OpenEHR::RM::DataTypes::Text::CodePhrase.new(:terminology_id => terminology_id, :code_string => ontology.primary_language)
36
53
  end
37
- archetype = OpenEHR::AM::Archetype::Archetype.new(:archetype_id => archetype_id,
38
- :adl_version => @result.adl_version,
39
- :concept => @result.concept,
54
+ original_language
55
+ end
56
+
57
+ def adl_version
58
+ parsed_data.adl_version
59
+ end
60
+
61
+ def concept
62
+ parsed_data.concept
63
+ end
64
+
65
+ def description
66
+ parsed_data.description
67
+ end
68
+
69
+ def translations
70
+ parsed_data.translations
71
+ end
72
+
73
+ def definition
74
+ parsed_data.definition
75
+ end
76
+
77
+ def archetype
78
+ OpenEHR::AM::Archetype::Archetype.new(:archetype_id => archetype_id,
79
+ :adl_version => adl_version,
80
+ :concept => concept,
40
81
  :original_language => original_language,
41
- :translations => @result.translations,
42
- :description => @result.description,
43
- :definition => @result.definition,
44
- :ontology => @result.ontology)
45
- return archetype
82
+ :translations => translations,
83
+ :description => description,
84
+ :definition => definition,
85
+ :ontology => ontology)
46
86
  end
47
87
  end
48
88
  end # of Parser
@@ -0,0 +1,269 @@
1
+ require 'nokogiri'
2
+
3
+ module OpenEHR
4
+ module Parser
5
+ class OPTParser < ::OpenEHR::Parser::Base
6
+ TEMPLATE_LANGUAGE_CODE_PATH = '/template/language/code_string'
7
+ TEMPLATE_LANGUAGE_TERM_ID_PATH = '/template/language/terminology_id/value'
8
+ TEMPLATE_ID_PATH = '/template/template_id/value'
9
+ CONCEPT_PATH = '/template/concept'
10
+ DESC_ORIGINAL_AUTHOR_PATH = '/template/description/original_author'
11
+ DESC_LIFECYCLE_STATE_PATH = '/template/description/lifecycle_state'
12
+ DESC_DETAILS_LANGUAGE_TERM_ID_PATH = '/template/description/details/language/terminology_id/value'
13
+ DESC_DETAILS_LANGUAGE_CODE_PATH = '/template/description/details/language/code_string'
14
+ DESC_DETAILS_PURPOSE_PATH = '/template/description/details/purpose'
15
+ DESC_DETAILS_KEYWORDS_PATH = '/template/description/details/keywords'
16
+ DESC_DETAILS_USE_PATH = '/template/description/details/use'
17
+ DESC_DETAILS_MISUSE_PATH = '/template/description/details/misuse'
18
+ DESC_DETAILS_COPYRIGHT_PATH = '/template/description/details/copyright'
19
+ DEFINITION_PATH = '/template/definition'
20
+ OCCURRENCE_PATH = '/occurrences'
21
+
22
+ def initialize(filename)
23
+ super(filename)
24
+ end
25
+
26
+ def parse
27
+ @opt = Nokogiri::XML::Document.parse(File.open(@filename))
28
+ @opt.remove_namespaces!
29
+ terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(value: text_on_path(@opt,TEMPLATE_LANGUAGE_TERM_ID_PATH))
30
+ language = OpenEHR::RM::DataTypes::Text::CodePhrase.new(code_string: text_on_path(@opt, TEMPLATE_LANGUAGE_CODE_PATH), terminology_id: terminology_id)
31
+ OpenEHR::AM::Template::OperationalTemplate.new(concept: concept, language: language, description: description, template_id: template_id, definition: definition)
32
+ end
33
+
34
+ private
35
+
36
+ def template_id
37
+ OpenEHR::RM::Support::Identification::TemplateID.new(value: text_on_path(@opt, TEMPLATE_ID_PATH))
38
+ end
39
+
40
+ def concept
41
+ text_on_path(@opt, CONCEPT_PATH)
42
+ end
43
+
44
+ def description
45
+ original_author = text_on_path(@opt, DESC_ORIGINAL_AUTHOR_PATH)
46
+ lifecycle_state = text_on_path(@opt, DESC_LIFECYCLE_STATE_PATH)
47
+ OpenEHR::RM::Common::Resource::ResourceDescription.new(original_author: original_author, lifecycle_state: lifecycle_state, details: [description_details])
48
+ end
49
+
50
+ def description_details
51
+ terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(value: text_on_path(@opt, DESC_DETAILS_LANGUAGE_TERM_ID_PATH))
52
+ language = OpenEHR::RM::DataTypes::Text::CodePhrase.new(code_string: text_on_path(@opt, DESC_DETAILS_LANGUAGE_CODE_PATH), terminology_id: terminology_id)
53
+ purpose = text_on_path(@opt, DESC_DETAILS_PURPOSE_PATH)
54
+ keywords = @opt.xpath(DESC_DETAILS_KEYWORDS_PATH).inject([]) {|a, i| a << i.text}
55
+ use = empty_then_nil text_on_path(@opt, DESC_DETAILS_USE_PATH)
56
+ misuse = empty_then_nil text_on_path(@opt, DESC_DETAILS_MISUSE_PATH)
57
+ copyright = empty_then_nil text_on_path(@opt, DESC_DETAILS_COPYRIGHT_PATH)
58
+ OpenEHR::RM::Common::Resource::ResourceDescriptionItem.new(language: language, purpose: purpose, keywords: keywords, use: use, misuse: misuse, copyright: copyright)
59
+ end
60
+
61
+ def definition
62
+ root_rm_type = text_on_path(@opt, DEFINITION_PATH + '/rm_type_name')
63
+ root_node = Node.new
64
+ root_node.id = text_on_path(@opt, DEFINITION_PATH + '/node_id')
65
+ root_occurrences = occurrences(@opt.xpath(DEFINITION_PATH + OCCURRENCE_PATH))
66
+ root_archetype_id = OpenEHR::RM::Support::Identification::ArchetypeID.new(value: text_on_path(@opt, DEFINITION_PATH+'/archetype_id/value'))
67
+ root_node.path = "/[#{root_archetype_id.value}]"
68
+ OpenEHR::AM::Archetype::ConstraintModel::CArchetypeRoot.new(rm_type_name: root_rm_type, node_id: root_node.id, path: root_node.path, occurrences: root_occurrences, archetype_id: root_archetype_id, attributes: attributes(@opt.xpath(DEFINITION_PATH+'/attributes'), root_node))
69
+ end
70
+
71
+ def children(children_xml, node)
72
+ children_xml.map do |child|
73
+ send child.attributes['type'].text.downcase, child, node
74
+ end
75
+ end
76
+
77
+ def c_archetype_root(xml, node = Node.new)
78
+ rm_type_name = text_on_path(xml, './rm_type_name')
79
+ id = text_on_path(xml, './node_id')
80
+ node.id = id unless id.nil? or id.empty?
81
+ occurrences = occurrences(xml.xpath('./occurrences'))
82
+ archetype_id = OpenEHR::RM::Support::Identification::ArchetypeID.new(value: text_on_path(xml, './archetype_id/value'))
83
+ if node.root? or node.id.nil?
84
+ node.path = "/[#{archetype_id.value}]"
85
+ else
86
+ node.path += "/[#{archetype_id.value}]"
87
+ end
88
+ OpenEHR::AM::Archetype::ConstraintModel::CArchetypeRoot.new(rm_type_name: rm_type_name, node_id: node.id, path: node.path, occurrences: occurrences, archetype_id: archetype_id, attributes: attributes(xml.xpath('./attributes'), node))
89
+ end
90
+
91
+ def c_complex_object(xml, node)
92
+ rm_type_name = xml.xpath('./rm_type_name').text
93
+ node_id = xml.xpath('./node_id').text
94
+ unless node_id.nil? or node_id.empty?
95
+ node.id = node_id
96
+ node.path += "[#{node_id}]"
97
+ end
98
+ OpenEHR::AM::Archetype::ConstraintModel::CComplexObject.new(rm_type_name: rm_type_name, node_id: node.id, path: node.path, occurrences: occurrences(xml.xpath('./occurrences')), attributes: attributes(xml.xpath('./attributes'), node))
99
+ end
100
+
101
+ def attributes(attributes_xml, node)
102
+ attributes_xml.map do |attr|
103
+ send attr.attributes['type'].text.downcase, attr, node
104
+ end
105
+ end
106
+
107
+ def c_single_attribute(attr_xml, node)
108
+ rm_attribute_name = attr_xml.at('rm_attribute_name').text
109
+ existence = occurrences(attr_xml.at('existence'))
110
+ if node.root?
111
+ path = "/#{rm_attribute_name}"
112
+ elsif node.id
113
+ path = "#{node.path}[#{node.id}]/#{rm_attribute_name}"
114
+ else
115
+ path = "#{node.path}/#{rm_attribute_name}"
116
+ end
117
+ child_node = Node.new(node)
118
+ child_node.path = node.path
119
+ child_node.id = node.id
120
+ OpenEHR::AM::Archetype::ConstraintModel::CSingleAttribute.new(rm_attribute_name: rm_attribute_name, existence: existence, path: path, children: children(attr_xml.xpath('./children'), child_node))
121
+ end
122
+
123
+ def c_multiple_attribute(attr_xml, node)
124
+ rm_attribute_name = attr_xml.at('rm_attribute_name').text
125
+ existence = occurrences(attr_xml.at('existence'))
126
+ if node.root?
127
+ path = "/#{rm_attribute_name}"
128
+ elsif node.id
129
+ path = "#{node.path}[#{node.id}]/#{rm_attribute_name}"
130
+ else
131
+ path = "#{node.path}/#{rm_attribute_name}"
132
+ end
133
+ child_node = Node.new(node)
134
+ child_node.path = node.path
135
+ child_node.id = node.id
136
+ OpenEHR::AM::Archetype::ConstraintModel::CMultipleAttribute.new(rm_attribute_name: rm_attribute_name, existence: existence, path: path, children: children(attr_xml.xpath('./children'), child_node))
137
+ end
138
+
139
+ def c_code_phrase(attr_xml, node)
140
+ terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(value: attr_xml.at('terminology_id/value').text.strip)
141
+ path = node.path
142
+ code_list = attr_xml.xpath('code_list').text.strip
143
+ occurrences = occurrences(attr_xml.at('occurrences'))
144
+ OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodePhrase.new(terminology_id: terminology_id, code_list: [code_list], path: path, occurrences: occurrences, rm_type_name: 'CodePhrase')
145
+ end
146
+
147
+ def archetype_slot(attr_xml,node)
148
+ path = node.path
149
+ node.id = attr_xml.at('node_id').text
150
+ rm_type_name = attr_xml.at('rm_type_name').text
151
+ occurrences = occurrences(attr_xml.at('occurrences'))
152
+ includes_leaf = attr_xml.at('includes')
153
+ includes = assertions(includes_leaf.children, node) if includes_leaf
154
+ excludes_leaf = attr_xml.at('excludes')
155
+ excludes = assertions(excludes_leaf.children, node) if excludes_leaf
156
+ OpenEHR::AM::Archetype::ConstraintModel::ArchetypeSlot.new(path: path, node_id: node.id, rm_type_name: rm_type_name, occurrences: occurrences, includes: includes, excludes: excludes)
157
+ end
158
+
159
+ def occurrences(occurrence_xml)
160
+ lower_node = occurrence_xml.at('lower')
161
+ upper_node = occurrence_xml.at('upper')
162
+ lower = lower_node.text.to_i if lower_node
163
+ upper = upper_node.text.to_i if upper_node
164
+ lower_included = to_bool(occurrence_xml.at('lower_included'))
165
+ upper_included = to_bool(occurrence_xml.at('upper_included'))
166
+ OpenEHR::AssumedLibraryTypes::Interval.new(lower: lower, upper: upper, lower_included: lower_included, upper_included: upper_included)
167
+ end
168
+
169
+ def constraint_ref(attr_xml, node)
170
+ rm_type_name = attr_xml.at('rm_type_name').text
171
+ reference = attr_xml.at('reference').text
172
+ occurrences = occurrences(attr_xml.at('occurrences'))
173
+ OpenEHR::AM::Archetype::ConstraintModel::ConstraintRef.new(rm_type_name: rm_type_name, occurrences: occurrences, reference: reference)
174
+ end
175
+
176
+ def assertions(attr_xml, node)
177
+ string_expression = attr_xml.at('string_expression')
178
+ string_expression = string_expression.nil? ? nil : string_expression.text
179
+ expression_leaf = attr_xml.at 'expression'
180
+ expression = send expression_leaf.attributes['type'].text.downcase, expression_leaf
181
+ [OpenEHR::AM::Archetype::Assertion::Assertion.new(expression: expression, string_expression: string_expression)]
182
+ end
183
+
184
+ def expr_binary_operator(attr_xml)
185
+ type = attr_xml.at('type').text
186
+ operator = OpenEHR::AM::Archetype::Assertion::OperatorKind.new(value: attr_xml.at('operator').text.to_i)
187
+
188
+ precedence_overridden = attr_xml.at('precedence_overridden').text == 'true' ? true : false
189
+ right_operand_leaf = attr_xml.at 'right_operand'
190
+ right_operand = send right_operand_leaf.attributes['type'].text.downcase, right_operand_leaf
191
+ left_operand_leaf = attr_xml.at 'left_operand'
192
+ left_operand = send left_operand_leaf.attributes['type'].text.downcase, left_operand_leaf
193
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(type: type, operator: operator, precedence_overridden: precedence_overridden, right_operand: right_operand, left_operand: left_operand)
194
+ end
195
+
196
+ def expr_leaf(attr_xml)
197
+ type = attr_xml.at('type').text
198
+ item_leaf = attr_xml.at('item')
199
+ item = send type.downcase, item_leaf
200
+ reference_type = attr_xml.at('reference_type').text
201
+ OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(type: type, item: item, reference_type: reference_type)
202
+ end
203
+
204
+ def c_primitive_object(attr_xml, node)
205
+ rm_type_name = attr_xml.at('rm_type_name').text
206
+ occurrences = occurrences(attr_xml.at('occurrences'))
207
+ OpenEHR::AM::Archetype::ConstraintModel::CPrimitiveObject.new(rm_type_name: rm_type_name, occurrences: occurrences, node_id: node.id)
208
+ end
209
+
210
+ def c_string(attr_xml)
211
+ pattern = attr_xml.at('pattern').text
212
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(pattern: pattern)
213
+ end
214
+
215
+ def c_dv_quantity(attr_xml, node)
216
+ rm_type_name = attr_xml.at('rm_type_name').text
217
+ occurrences = occurrences(attr_xml.at('occurrences'))
218
+ property_terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(value: attr_xml.at('property/terminology_id/value').text)
219
+ property_code_string = attr_xml.at('property/code_string').text
220
+ property = OpenEHR::RM::DataTypes::Text::CodePhrase.new(terminology_id: property_terminology_id, code_string: property_code_string)
221
+ list = attr_xml.xpath('.//list').map do |element|
222
+ units = element.at('units').text if element.at('units')
223
+ magnitude = occurrences(element.at('magnitude')) if element.at('magnitude')
224
+ precision = occurrences(element.at('precision')) if element.at('precision')
225
+ OpenEHR::AM::OpenEHRProfile::DataTypes::Quantity::CQuantityItem.new(magnitude: magnitude, precision: precision, units: units)
226
+ end
227
+ OpenEHR::AM::OpenEHRProfile::DataTypes::Quantity::CDvQuantity.new(rm_type_name: rm_type_name, occurrences: occurrences, list: list, property: property)
228
+ end
229
+
230
+ def string(attr_xml)
231
+ attr_xml.text
232
+ end
233
+ def empty_then_nil(val)
234
+ if val.empty?
235
+ return nil
236
+ else
237
+ return val
238
+ end
239
+ end
240
+
241
+ def text_on_path(xml, path)
242
+ xml.xpath(path).text
243
+ end
244
+
245
+ def to_bool(str)
246
+ if str =~ /true/i
247
+ return true
248
+ elsif str =~ /false/i
249
+ return false
250
+ end
251
+ return nil
252
+ end
253
+ end
254
+ end
255
+ end
256
+
257
+ class Node
258
+ attr_accessor :id, :path
259
+ attr_reader :parent
260
+
261
+ def initialize(parent = nil)
262
+ @parent = parent
263
+ @path = '/' if parent.nil?
264
+ end
265
+
266
+ def root?
267
+ parent.nil?
268
+ end
269
+ end
@@ -3,7 +3,9 @@
3
3
  # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109157527311_729550_7234Report.html
4
4
  # refs #55
5
5
  require 'time'
6
+ require 'active_support'
6
7
  require 'active_support/core_ext'
8
+ #require 'active_support/deprecation'
7
9
 
8
10
  require_relative '../common/archetyped'
9
11
  require_relative '../data_structures'
@@ -107,7 +109,7 @@ module OpenEHR
107
109
  unless @width.fractional_second.nil?
108
110
  seconds += @width.fractional_second
109
111
  end
110
- start_time = seconds.ago start_time
112
+ start_time = seconds.seconds.ago start_time
111
113
  return OpenEHR::RM::DataTypes::Quantity::DateTime::DvDateTime.new(:value => start_time.iso8601)
112
114
  end
113
115
  end
@@ -176,5 +176,11 @@ module OpenEHR
176
176
  DataTypes::URI::DvEhrUri.new(*param)
177
177
  end
178
178
  end
179
+
180
+ class OBSERVATIONFactory
181
+ def self.create(*param)
182
+ Composition::Content::Entry::Observation.new(*param)
183
+ end
184
+ end
179
185
  end
180
186
  end
@@ -1,3 +1,3 @@
1
1
  module OpenEHR
2
- VERSION = "1.2.15"
2
+ VERSION = "1.2.16"
3
3
  end