openehr 2.3.1 → 2.4.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.
- checksums.yaml +4 -4
- data/lib/openehr/parser/opt_parser.rb +3 -1
- data/lib/openehr/parser/xml_archetype_parser.rb +3 -1
- data/lib/openehr/parser.rb +28 -0
- data/lib/openehr/rm/factory.rb +7 -1
- data/lib/openehr/rm/support/identification.rb +1 -0
- data/lib/openehr/serializer/rm_json_serializer.rb +16 -1
- 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: 2d4cd8f720ac22f26e89145ebfd23cb474b2ad3e900c97fd6ff01c20a90bf638
|
|
4
|
+
data.tar.gz: ac478e309b65a00d314d3bf425b8d3ce25a7f07dd196e76c223508eca7410619
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f72f3492c23d458ed840da441359318e03a58c4bc55ee2d35df060ff635f4ab98e9be5aafafd126d149d81dcc355620a5931f65b05ff6d9dee65666df371a62
|
|
7
|
+
data.tar.gz: d4ca02374caaf65f3d6a29087fa788f4a6c57c9415d5c5ac576f9e746d56f4a6d25c4ef95fa3b2b56d905823f2ff7c08cb6bdb2f2f92944ab04d3b4f0734b97a
|
|
@@ -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
|
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/rm/factory.rb
CHANGED
|
@@ -20,6 +20,8 @@ module OpenEHR
|
|
|
20
20
|
terminology_id: 'TERMINOLOGY_ID'
|
|
21
21
|
}.freeze
|
|
22
22
|
|
|
23
|
+
KNOWN_DERIVED_CACHE_TYPES = %w[TIMEZONE UID VERSION_TREE_ID].freeze
|
|
24
|
+
|
|
23
25
|
def initialize(cobject)
|
|
24
26
|
@cobject = cobject
|
|
25
27
|
end
|
|
@@ -80,6 +82,11 @@ module OpenEHR
|
|
|
80
82
|
"and #{key.inspect} is not a known non-polymorphic attribute (keys: #{value.keys.inspect})"
|
|
81
83
|
end
|
|
82
84
|
Factory.create(type, **value)
|
|
85
|
+
rescue NameError
|
|
86
|
+
return nil if KNOWN_DERIVED_CACHE_TYPES.include?(type)
|
|
87
|
+
|
|
88
|
+
warn "openehr factory: unknown type \"#{type}\" for attribute #{key.inspect}; ignoring"
|
|
89
|
+
nil
|
|
83
90
|
end
|
|
84
91
|
end
|
|
85
92
|
|
|
@@ -610,4 +617,3 @@ module OpenEHR
|
|
|
610
617
|
end
|
|
611
618
|
end
|
|
612
619
|
|
|
613
|
-
|
|
@@ -249,6 +249,7 @@ module OpenEHR
|
|
|
249
249
|
self.objectid = UID.new(:value => $1)
|
|
250
250
|
self.creating_system_id = UID.new(:value => $2)
|
|
251
251
|
self.version_tree_id = VersionTreeID.new(:value => $3)
|
|
252
|
+
@value = value
|
|
252
253
|
@root = @oid
|
|
253
254
|
@extension = @creating_system_id.value + '::' + @version_tree_id.value
|
|
254
255
|
else
|
|
@@ -10,7 +10,22 @@ module OpenEHR
|
|
|
10
10
|
# which would otherwise make every subtree cyclic). A defensive
|
|
11
11
|
# visited-object guard covers any other unexpected back-reference.
|
|
12
12
|
class RMJSONSerializer
|
|
13
|
-
|
|
13
|
+
# Instance variables that value=-style setters derive and cache from a
|
|
14
|
+
# single canonical attribute (e.g. `value`), but which are not part of
|
|
15
|
+
# openEHR ITS-JSON canonical form and have no corresponding
|
|
16
|
+
# OpenEHR::RM::Factory::<Type>Factory to reconstruct them on read - see
|
|
17
|
+
# docs/design/fix-rmjson-roundtrip-plan.md for the full inventory and
|
|
18
|
+
# how each was found (DvDate/DvTime/DvDateTime's value= in
|
|
19
|
+
# lib/openehr/rm/data_types/quantity/date_time.rb; UIDBasedID/
|
|
20
|
+
# ObjectVersionID's value= in lib/openehr/rm/support/identification.rb).
|
|
21
|
+
EXCLUDED_IVARS = [
|
|
22
|
+
:@parent,
|
|
23
|
+
:@year, :@month, :@day, # DvDate, DvDateTime
|
|
24
|
+
:@hour, :@minute, :@second, :@fractional_second, # DvTime, DvDateTime
|
|
25
|
+
:@timezone, # DvTime (String), DvDateTime (Timezone)
|
|
26
|
+
:@root, :@extension, # UIDBasedID, HierObjectID, ObjectVersionID
|
|
27
|
+
:@oid, :@creating_system_id, :@version_tree_id # ObjectVersionID
|
|
28
|
+
].freeze
|
|
14
29
|
|
|
15
30
|
def initialize(rm_instance)
|
|
16
31
|
@rm_instance = rm_instance
|
data/lib/openehr/version.rb
CHANGED