openehr 1.2.999999 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +95 -14
  3. data/lib/openehr/am/archetype/constraint_model/primitive.rb +204 -6
  4. data/lib/openehr/am/archetype/constraint_model.rb +228 -4
  5. data/lib/openehr/am/archetype/ontology.rb +2 -2
  6. data/lib/openehr/am/archetype.rb +101 -2
  7. data/lib/openehr/am/openehr_profile/data_types/basic.rb +28 -0
  8. data/lib/openehr/am/openehr_profile/data_types/quantity.rb +88 -0
  9. data/lib/openehr/am/openehr_profile/data_types/text.rb +23 -0
  10. data/lib/openehr/am/template.rb +77 -24
  11. data/lib/openehr/aql/engine/binding.rb +13 -0
  12. data/lib/openehr/aql/engine/contains_resolver.rb +161 -0
  13. data/lib/openehr/aql/engine/dataset.rb +122 -0
  14. data/lib/openehr/aql/engine/path_evaluator.rb +137 -0
  15. data/lib/openehr/aql/engine/predicate_evaluator.rb +65 -0
  16. data/lib/openehr/aql/engine.rb +119 -0
  17. data/lib/openehr/aql/errors.rb +27 -0
  18. data/lib/openehr/aql/lexer.rb +295 -0
  19. data/lib/openehr/aql/model/containment.rb +45 -0
  20. data/lib/openehr/aql/model/from_clause.rb +35 -0
  21. data/lib/openehr/aql/model/function_call.rb +56 -0
  22. data/lib/openehr/aql/model/identified_path.rb +20 -0
  23. data/lib/openehr/aql/model/literal.rb +15 -0
  24. data/lib/openehr/aql/model/object_path.rb +34 -0
  25. data/lib/openehr/aql/model/order_by_and_limit.rb +50 -0
  26. data/lib/openehr/aql/model/predicate.rb +84 -0
  27. data/lib/openehr/aql/model/query.rb +24 -0
  28. data/lib/openehr/aql/model/select_clause.rb +29 -0
  29. data/lib/openehr/aql/model/where_clause.rb +105 -0
  30. data/lib/openehr/aql/model.rb +14 -0
  31. data/lib/openehr/aql/parser.rb +484 -0
  32. data/lib/openehr/aql/result_set.rb +54 -0
  33. data/lib/openehr/aql.rb +28 -0
  34. data/lib/openehr/assumed_library_types.rb +68 -17
  35. data/lib/openehr/parser/adl_grammar.tt +29 -13
  36. data/lib/openehr/parser/adl_parser.rb +18 -4
  37. data/lib/openehr/parser/archetype_validator.rb +126 -0
  38. data/lib/openehr/parser/exception.rb +13 -0
  39. data/lib/openehr/parser/opt_parser.rb +306 -27
  40. data/lib/openehr/parser.rb +2 -0
  41. data/lib/openehr/path.rb +195 -0
  42. data/lib/openehr/rm/common/archetyped.rb +117 -7
  43. data/lib/openehr/rm/common/change_control.rb +3 -8
  44. data/lib/openehr/rm/common/directory.rb +4 -0
  45. data/lib/openehr/rm/common/generic.rb +24 -10
  46. data/lib/openehr/rm/composition/content/entry.rb +24 -5
  47. data/lib/openehr/rm/composition/content/navigation.rb +2 -1
  48. data/lib/openehr/rm/composition.rb +19 -2
  49. data/lib/openehr/rm/data_structures/history.rb +3 -0
  50. data/lib/openehr/rm/data_structures/item_structure/representation.rb +13 -9
  51. data/lib/openehr/rm/data_structures/item_structure.rb +28 -15
  52. data/lib/openehr/rm/data_types/encapsulated.rb +23 -3
  53. data/lib/openehr/rm/data_types/quantity/date_time.rb +9 -1
  54. data/lib/openehr/rm/data_types/quantity.rb +66 -14
  55. data/lib/openehr/rm/data_types/text.rb +8 -0
  56. data/lib/openehr/rm/data_types/time_specification.rb +5 -4
  57. data/lib/openehr/rm/data_types/uri.rb +0 -1
  58. data/lib/openehr/rm/demographic.rb +4 -3
  59. data/lib/openehr/rm/ehr.rb +20 -1
  60. data/lib/openehr/rm/factory.rb +345 -36
  61. data/lib/openehr/rm/integration.rb +1 -0
  62. data/lib/openehr/rm/support/identification.rb +37 -8
  63. data/lib/openehr/rm/support/measurement.rb +32 -0
  64. data/lib/openehr/rm/type_name.rb +90 -0
  65. data/lib/openehr/rm.rb +3 -0
  66. data/lib/openehr/serializer/adl_serializer.rb +335 -0
  67. data/lib/openehr/serializer/base.rb +20 -0
  68. data/lib/openehr/serializer/opt_serializer.rb +49 -0
  69. data/lib/openehr/serializer/rm_json_serializer.rb +62 -0
  70. data/lib/openehr/serializer/xml_serializer.rb +260 -0
  71. data/lib/openehr/serializer.rb +5 -291
  72. data/lib/openehr/terminology_service.rb +44 -0
  73. data/lib/openehr/version.rb +1 -1
  74. data/lib/openehr.rb +5 -2
  75. metadata +36 -11
  76. data/lib/openehr/parser/validator.rb +0 -18
  77. data/lib/openehr/parser/xml_parser.rb +0 -13
  78. data/lib/openehr/rm/data_types/charset_extract.rb +0 -24
  79. data/lib/openehr/writer.rb +0 -12
@@ -0,0 +1,50 @@
1
+ module OpenEHR
2
+ module AQL
3
+ module Model
4
+ # orderByClause : ORDER BY orderByExpr (SYM_COMMA orderByExpr)* ;
5
+ class OrderByClause
6
+ attr_reader :items
7
+
8
+ def initialize(items:)
9
+ @items = items.freeze
10
+ freeze
11
+ end
12
+ end
13
+
14
+ # orderByExpr : identifiedPath order=(DESCENDING|DESC|ASCENDING|ASC)? ;
15
+ # `direction` is always :asc or :desc - the grammar's four spellings
16
+ # (ASC/ASCENDING/DESC/DESCENDING) collapse to one of these two.
17
+ class OrderByItem
18
+ attr_reader :path, :direction
19
+
20
+ def initialize(path:, direction: :asc)
21
+ @path = path
22
+ @direction = direction
23
+ freeze
24
+ end
25
+ end
26
+
27
+ # limitClause : LIMIT limit=INTEGER (OFFSET offset=INTEGER)? ;
28
+ class LimitClause
29
+ attr_reader :limit, :offset
30
+
31
+ def initialize(limit:, offset: 0)
32
+ @limit = limit
33
+ @offset = offset
34
+ freeze
35
+ end
36
+ end
37
+
38
+ # top : TOP INTEGER direction=(FORWARD|BACKWARD)? ; (deprecated)
39
+ class Top
40
+ attr_reader :count, :direction
41
+
42
+ def initialize(count:, direction: nil)
43
+ @count = count
44
+ @direction = direction
45
+ freeze
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,84 @@
1
+ module OpenEHR
2
+ module AQL
3
+ module Model
4
+ # standardPredicate : objectPath COMPARISON_OPERATOR pathPredicateOperand ;
5
+ # (nodePredicate's 4th alternative has this identical shape - see
6
+ # Parser#parse_standard_predicate's comment.)
7
+ class StandardPredicate
8
+ attr_reader :path, :operator, :operand
9
+
10
+ def initialize(path:, operator:, operand:)
11
+ @path = path
12
+ @operator = operator
13
+ @operand = operand
14
+ freeze
15
+ end
16
+ end
17
+
18
+ # archetypePredicate : ARCHETYPE_HRID (SYM_COMMA (STRING | PARAMETER | TERM_CODE | AT_CODE | ID_CODE))? | PARAMETER ;
19
+ # `value` is the optional SYM_COMMA suffix: a raw String (for
20
+ # STRING/AT_CODE/ID_CODE) or a Parameter. The bare-PARAMETER
21
+ # alternative (a whole predicate substituted at execution time,
22
+ # e.g. "[$archetypeId]") isn't needed by any current example and is
23
+ # deferred - see Parser#parse_predicate_primary.
24
+ class ArchetypePredicate
25
+ attr_reader :archetype_id, :value
26
+
27
+ def initialize(archetype_id:, value: nil)
28
+ @archetype_id = archetype_id
29
+ @value = value
30
+ freeze
31
+ end
32
+ end
33
+
34
+ # nodePredicate : (ID_CODE | AT_CODE) (SYM_COMMA (STRING | PARAMETER | TERM_CODE | AT_CODE | ID_CODE))? | ... ;
35
+ # `value` is the optional SYM_COMMA suffix, same shape as
36
+ # ArchetypePredicate#value.
37
+ class NodePredicate
38
+ attr_reader :code, :value
39
+
40
+ def initialize(code:, value: nil)
41
+ @code = code
42
+ @value = value
43
+ freeze
44
+ end
45
+ end
46
+
47
+ # nodePredicate : ... | nodePredicate AND nodePredicate | ... ;
48
+ # Combines any pathPredicate-body primaries (ArchetypePredicate,
49
+ # NodePredicate, Parameter, StandardPredicate). AND binds tighter
50
+ # than OR, same precedence-climbing convention used for whereExpr
51
+ # (M5) and containsExpr (M7).
52
+ class PredicateAnd
53
+ attr_reader :left, :right
54
+
55
+ def initialize(left:, right:)
56
+ @left = left
57
+ @right = right
58
+ freeze
59
+ end
60
+ end
61
+
62
+ # nodePredicate : ... | nodePredicate OR nodePredicate ;
63
+ class PredicateOr
64
+ attr_reader :left, :right
65
+
66
+ def initialize(left:, right:)
67
+ @left = left
68
+ @right = right
69
+ freeze
70
+ end
71
+ end
72
+
73
+ # PARAMETER: '$' IDENTIFIER_CHAR ;
74
+ class Parameter
75
+ attr_reader :name
76
+
77
+ def initialize(name:)
78
+ @name = name
79
+ freeze
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,24 @@
1
+ module OpenEHR
2
+ module AQL
3
+ module Model
4
+ # The parsed, immutable representation of an AQL selectQuery.
5
+ # Clauses that a milestone hasn't implemented yet are nil.
6
+ class Query
7
+ attr_reader :select_clause, :from_clause, :where_clause, :order_by_clause, :limit_clause
8
+
9
+ def initialize(select_clause:, from_clause:, where_clause: nil, order_by_clause: nil, limit_clause: nil)
10
+ @select_clause = select_clause
11
+ @from_clause = from_clause
12
+ @where_clause = where_clause
13
+ @order_by_clause = order_by_clause
14
+ @limit_clause = limit_clause
15
+ freeze
16
+ end
17
+
18
+ def execute(dataset, params: {})
19
+ OpenEHR::AQL::Engine.new(self).execute(dataset, params: params)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module OpenEHR
2
+ module AQL
3
+ module Model
4
+ # selectClause : SELECT DISTINCT? top? selectExpr (SYM_COMMA selectExpr)* ;
5
+ class SelectClause
6
+ attr_reader :columns, :distinct, :top
7
+ alias distinct? distinct
8
+
9
+ def initialize(columns:, distinct: false, top: nil)
10
+ @columns = columns.freeze
11
+ @distinct = distinct
12
+ @top = top
13
+ freeze
14
+ end
15
+ end
16
+
17
+ # selectExpr : columnExpr (AS aliasName=IDENTIFIER)? ;
18
+ class SelectColumn
19
+ attr_reader :expression, :alias_name
20
+
21
+ def initialize(expression:, alias_name: nil)
22
+ @expression = expression
23
+ @alias_name = alias_name
24
+ freeze
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,105 @@
1
+ module OpenEHR
2
+ module AQL
3
+ module Model
4
+ # whereClause : WHERE whereExpr ;
5
+ class WhereClause
6
+ attr_reader :expression
7
+
8
+ def initialize(expression:)
9
+ @expression = expression
10
+ freeze
11
+ end
12
+ end
13
+
14
+ # whereExpr : ... | whereExpr AND whereExpr | ... ;
15
+ class AndExpr
16
+ attr_reader :left, :right
17
+
18
+ def initialize(left:, right:)
19
+ @left = left
20
+ @right = right
21
+ freeze
22
+ end
23
+ end
24
+
25
+ # whereExpr : ... | whereExpr OR whereExpr | ... ;
26
+ class OrExpr
27
+ attr_reader :left, :right
28
+
29
+ def initialize(left:, right:)
30
+ @left = left
31
+ @right = right
32
+ freeze
33
+ end
34
+ end
35
+
36
+ # whereExpr : ... | NOT whereExpr | ... ;
37
+ class NotExpr
38
+ attr_reader :operand
39
+
40
+ def initialize(operand:)
41
+ @operand = operand
42
+ freeze
43
+ end
44
+ end
45
+
46
+ # identifiedExpr : identifiedPath COMPARISON_OPERATOR terminal | functionCall COMPARISON_OPERATOR terminal ;
47
+ # The functionCall-on-the-left alternative is added by M8.
48
+ class Comparison
49
+ attr_reader :left, :operator, :right
50
+
51
+ def initialize(left:, operator:, right:)
52
+ @left = left
53
+ @operator = operator
54
+ @right = right
55
+ freeze
56
+ end
57
+ end
58
+
59
+ # identifiedExpr : EXISTS identifiedPath | ... ;
60
+ class ExistsExpr
61
+ attr_reader :path
62
+
63
+ def initialize(path:)
64
+ @path = path
65
+ freeze
66
+ end
67
+ end
68
+
69
+ # identifiedExpr : identifiedPath LIKE likeOperand | ... ;
70
+ class LikeExpr
71
+ attr_reader :path, :operand
72
+
73
+ def initialize(path:, operand:)
74
+ @path = path
75
+ @operand = operand
76
+ freeze
77
+ end
78
+ end
79
+
80
+ # identifiedExpr : identifiedPath MATCHES matchesOperand | ... ;
81
+ class MatchesExpr
82
+ attr_reader :path, :operand
83
+
84
+ def initialize(path:, operand:)
85
+ @path = path
86
+ @operand = operand
87
+ freeze
88
+ end
89
+ end
90
+
91
+ # matchesOperand's value-list alternative:
92
+ # SYM_LEFT_CURLY valueListItem (SYM_COMMA valueListItem)* SYM_RIGHT_CURLY
93
+ # The terminologyFunction-item and bare-URI alternatives need a URI
94
+ # lexer token that doesn't exist yet, and are deferred.
95
+ class MatchesValueList
96
+ attr_reader :items
97
+
98
+ def initialize(items:)
99
+ @items = items.freeze
100
+ freeze
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,14 @@
1
+ # OpenEHR::AQL::Model holds the immutable object model that the Parser
2
+ # builds and the execution Engine walks: one class per relevant
3
+ # AqlParser.g4 rule (see lib/openehr/aql/parser.rb for the mapping).
4
+ require_relative 'model/query'
5
+ require_relative 'model/select_clause'
6
+ require_relative 'model/from_clause'
7
+ require_relative 'model/identified_path'
8
+ require_relative 'model/literal'
9
+ require_relative 'model/object_path'
10
+ require_relative 'model/predicate'
11
+ require_relative 'model/containment'
12
+ require_relative 'model/where_clause'
13
+ require_relative 'model/order_by_and_limit'
14
+ require_relative 'model/function_call'