openehr 2.3.0 → 2.3.2
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.
- checksums.yaml +4 -4
- data/lib/openehr/am/openehr_profile/data_types/text.rb +21 -0
- data/lib/openehr/parser/opt_parser.rb +3 -1
- data/lib/openehr/parser/xml_archetype_parser.rb +3 -1
- data/lib/openehr/parser/xml_constraint_parsing.rb +12 -1
- data/lib/openehr/parser/xml_domain_type_parsing.rb +16 -2
- data/lib/openehr/parser.rb +28 -0
- data/lib/openehr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3d85dcafa7ccea7c1ae4a7cd794297b9b7c4b6a6126bae494fb5a6d9538fffc
|
|
4
|
+
data.tar.gz: 34bfec35b2de56cc2c97a02d049f6233b011d3e93908db2b5065f5fc1ede068e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9793f50126a31f5d84a21304cd55ecb1fcc3a65569ba9eb1c3c73de1e15ea991a7cc245cec6c37dde71ed8fa861df809d919e02e13baad328ee75d2f0b44a5c5
|
|
7
|
+
data.tar.gz: a79ea4ee8a7981000548c16405561f255f6c08b5a0fa413f7cc9301fa165894f1401ec0bcd9c7669f0f0018e3178cf479643212ae3feaa31c20225ef249cc35e
|
|
@@ -42,6 +42,27 @@ module OpenEHR
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
# C_CODE_REFERENCE is defined by Template.xsd (Template OM) as a
|
|
47
|
+
# C_CODE_PHRASE extension carrying a referenceSetUri. nil is accepted
|
|
48
|
+
# for tolerant parsing of real artifacts. valid_value? is inherited:
|
|
49
|
+
# without a terminology service, this class cannot expand the URI's
|
|
50
|
+
# reference set and must retain CCodePhrase's permissive behavior.
|
|
51
|
+
class CCodeReference < CCodePhrase
|
|
52
|
+
attr_reader :reference_set_uri
|
|
53
|
+
|
|
54
|
+
def initialize(args = { })
|
|
55
|
+
super
|
|
56
|
+
self.reference_set_uri = args[:reference_set_uri]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def reference_set_uri=(reference_set_uri)
|
|
60
|
+
if !reference_set_uri.nil? && reference_set_uri.empty?
|
|
61
|
+
raise ArgumentError, 'invalid reference_set_uri'
|
|
62
|
+
end
|
|
63
|
+
@reference_set_uri = reference_set_uri
|
|
64
|
+
end
|
|
65
|
+
end
|
|
45
66
|
end # of Text
|
|
46
67
|
end # of Data_Types
|
|
47
68
|
end # of OpenEHR Profile
|
|
@@ -40,7 +40,9 @@ module OpenEHR
|
|
|
40
40
|
OCCURRENCE_PATH = '/occurrences'
|
|
41
41
|
|
|
42
42
|
def parse
|
|
43
|
-
@opt =
|
|
43
|
+
@opt = File.open(@filename) do |file|
|
|
44
|
+
Nokogiri::XML::Document.parse(file, options: SAFE_PARSE_OPTIONS)
|
|
45
|
+
end
|
|
44
46
|
@opt.remove_namespaces!
|
|
45
47
|
|
|
46
48
|
uid = build_uid
|
|
@@ -30,7 +30,9 @@ module OpenEHR
|
|
|
30
30
|
|
|
31
31
|
def doc
|
|
32
32
|
@doc ||= begin
|
|
33
|
-
parsed =
|
|
33
|
+
parsed = File.open(@filename, 'rb:bom|utf-8') do |file|
|
|
34
|
+
Nokogiri::XML::Document.parse(file, options: SAFE_PARSE_OPTIONS)
|
|
35
|
+
end
|
|
34
36
|
parsed.remove_namespaces!
|
|
35
37
|
parsed
|
|
36
38
|
end
|
|
@@ -65,7 +65,18 @@ module OpenEHR
|
|
|
65
65
|
child_node = Node.new(node)
|
|
66
66
|
child_node.path = node.path
|
|
67
67
|
child_node.id = node.id
|
|
68
|
-
|
|
68
|
+
type_name = child.attributes['type'].text
|
|
69
|
+
handler = type_name.downcase
|
|
70
|
+
if respond_to?(handler, true)
|
|
71
|
+
send handler, child, child_node
|
|
72
|
+
else
|
|
73
|
+
# children is open to vendor/newer-model constraint extensions;
|
|
74
|
+
# the other xsi:type dispatch sites are schema-closed. Preserve
|
|
75
|
+
# the C_OBJECT core here, while warning that type-specific
|
|
76
|
+
# constraints are dropped and validation becomes more permissive.
|
|
77
|
+
warn "openehr parser: unknown constraint type \"#{type_name}\" at #{child_node.path}; treating as C_COMPLEX_OBJECT (type-specific constraints dropped)"
|
|
78
|
+
c_complex_object(child, child_node)
|
|
79
|
+
end
|
|
69
80
|
end
|
|
70
81
|
end
|
|
71
82
|
|
|
@@ -11,6 +11,20 @@ module OpenEHR
|
|
|
11
11
|
private
|
|
12
12
|
|
|
13
13
|
def c_code_phrase(attr_xml, node)
|
|
14
|
+
OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodePhrase.new(
|
|
15
|
+
code_phrase_constraint_args(attr_xml, node)
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def c_code_reference(attr_xml, node)
|
|
20
|
+
args = code_phrase_constraint_args(attr_xml, node)
|
|
21
|
+
args[:code_list] = nil if args[:code_list] && args[:code_list].empty?
|
|
22
|
+
uri = attr_xml.at('referenceSetUri')&.text&.strip
|
|
23
|
+
args[:reference_set_uri] = uri unless uri.nil? || uri.empty?
|
|
24
|
+
OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodeReference.new(args)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def code_phrase_constraint_args(attr_xml, node)
|
|
14
28
|
terminology_id_node = attr_xml.at('terminology_id/value')
|
|
15
29
|
terminology_id = terminology_id_node ? OpenEHR::RM::Support::Identification::TerminologyID.new(value: terminology_id_node.text.strip) : nil
|
|
16
30
|
|
|
@@ -21,13 +35,13 @@ module OpenEHR
|
|
|
21
35
|
occurrences_node = attr_xml.at('occurrences')
|
|
22
36
|
occurrences_obj = occurrences_node ? occurrences(occurrences_node) : nil
|
|
23
37
|
|
|
24
|
-
|
|
38
|
+
{
|
|
25
39
|
terminology_id: terminology_id,
|
|
26
40
|
code_list: code_list,
|
|
27
41
|
path: node.path,
|
|
28
42
|
occurrences: occurrences_obj,
|
|
29
43
|
rm_type_name: 'CODE_PHRASE'
|
|
30
|
-
|
|
44
|
+
}
|
|
31
45
|
end
|
|
32
46
|
|
|
33
47
|
# The <property> element is optional in real templates; return nil rather
|
data/lib/openehr/parser.rb
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
|
|
1
3
|
module OpenEHR
|
|
2
4
|
module Parser
|
|
3
5
|
class Base
|
|
6
|
+
# Explicit, safe Nokogiri ParseOptions for untrusted OPT/archetype XML.
|
|
7
|
+
# Deliberately lists RECOVER|NONET|BIG_LINES by name rather than
|
|
8
|
+
# referencing Nokogiri::XML::ParseOptions::DEFAULT_XML - the whole
|
|
9
|
+
# point is to not silently follow that constant if a future Nokogiri
|
|
10
|
+
# release (or a downstream app pinning an older one) changes it.
|
|
11
|
+
#
|
|
12
|
+
# - RECOVER: parse malformed-but-well-intentioned XML leniently
|
|
13
|
+
# (matches today's implicit default; see
|
|
14
|
+
# docs/design/xxe-safe-parse-options-plan.md for real-fixture
|
|
15
|
+
# evidence that at least one downstream consumer OPT currently
|
|
16
|
+
# depends on this).
|
|
17
|
+
# - NONET: forbid network access during parsing. Nokogiri's own docs:
|
|
18
|
+
# "UNSAFE to unset this option" for untrusted input.
|
|
19
|
+
# - BIG_LINES: line numbers as `long int`, unrelated to safety.
|
|
20
|
+
# - NOENT (entity substitution) and DTDLOAD (external DTD subset
|
|
21
|
+
# loading) are deliberately NOT set - both default off in Nokogiri
|
|
22
|
+
# and both documented "UNSAFE to set...for untrusted documents".
|
|
23
|
+
# This is what actually gates XXE (see the plan's attack-proof
|
|
24
|
+
# section: enabling either makes local-file and external-DTD
|
|
25
|
+
# entity resolution succeed).
|
|
26
|
+
SAFE_PARSE_OPTIONS = Nokogiri::XML::ParseOptions.new(
|
|
27
|
+
Nokogiri::XML::ParseOptions::RECOVER |
|
|
28
|
+
Nokogiri::XML::ParseOptions::NONET |
|
|
29
|
+
Nokogiri::XML::ParseOptions::BIG_LINES
|
|
30
|
+
)
|
|
31
|
+
|
|
4
32
|
attr_reader :filename
|
|
5
33
|
|
|
6
34
|
def initialize(filename)
|
data/lib/openehr/version.rb
CHANGED