fhir_models 4.1.2 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68f887e4edac39b8eaa531ab225b2a33753b6048f08e3ebfa047299494754d96
4
- data.tar.gz: dee551b676cdefe72315ce96bef9fbf87192b17f2fbd9549ff37fbd526a8a3d1
3
+ metadata.gz: 1519a66581a704c52e44ce3aa98f23528fe691ecf3af22bce5b0eaa8b45af05f
4
+ data.tar.gz: ed8c1093325205391c68b9f71ab81e2c80d6515660aaf59e4d51bbf4ebd80ba0
5
5
  SHA512:
6
- metadata.gz: 1147f42000517894330092a862e16a5419b02362d3ad49f31cff326d73ec600f1b43a83dab789cee039d8c263d1fcc0e4d1c57e0bdcf6f3e107d1bea6cc8bd62
7
- data.tar.gz: b2d33004faa1027461ca9baebaff8ec1e3d086156e55ab98b013c3e7498a8c279e0f9023559d59399ff250ee017a4dfbfb8aa1d588b1c876f457c7d308917892
6
+ metadata.gz: 886b58b3631c5a7ba06f10b40f5721d12ededddc20ad692b830c88a1ea370e635fe6dae144ec90746588fc33415045936aed6f04cc803a1ec3275751d615caab
7
+ data.tar.gz: 2f29ad97d1f8b68a3f7e3631d7e06d6656982eff5efff162f560cd7dc715860c6d6a46d7f86b8da606bbf0e61dcec89eb80a5c732c26489c690d24d95b037939
@@ -0,0 +1,26 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.6', '2.7']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
23
+ - name: Run tests
24
+ run: bundle exec rake
25
+ - name: Rubocop
26
+ run: bundle exec rubocop
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fhir_models (4.1.2)
4
+ fhir_models (4.2.2)
5
5
  bcp47 (>= 0.3)
6
6
  date_time_precision (>= 0.8)
7
7
  mime-types (>= 3.0)
8
- nokogiri (>= 1.10.4)
8
+ nokogiri (>= 1.11.4)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -14,7 +14,7 @@ GEM
14
14
  bcp47 (0.3.3)
15
15
  i18n
16
16
  coderay (1.1.3)
17
- concurrent-ruby (1.1.8)
17
+ concurrent-ruby (1.1.10)
18
18
  coolline (0.5.0)
19
19
  unicode_utils (~> 1.4)
20
20
  date_time_precision (0.8.1)
@@ -39,7 +39,7 @@ GEM
39
39
  guard-test (2.0.8)
40
40
  guard-compat (~> 1.2)
41
41
  test-unit (~> 3.0)
42
- i18n (1.8.9)
42
+ i18n (1.12.0)
43
43
  concurrent-ruby (~> 1.0)
44
44
  jaro_winkler (1.5.4)
45
45
  json (2.3.1)
@@ -48,12 +48,12 @@ GEM
48
48
  rb-inotify (~> 0.9, >= 0.9.10)
49
49
  lumberjack (1.2.8)
50
50
  method_source (1.0.0)
51
- mime-types (3.3.1)
51
+ mime-types (3.4.1)
52
52
  mime-types-data (~> 3.2015)
53
- mime-types-data (3.2021.0225)
54
- mini_portile2 (2.5.0)
53
+ mime-types-data (3.2022.0105)
54
+ mini_portile2 (2.5.3)
55
55
  nenv (0.3.0)
56
- nokogiri (1.11.2)
56
+ nokogiri (1.11.7)
57
57
  mini_portile2 (~> 2.5.0)
58
58
  racc (~> 1.4)
59
59
  nokogiri-diff (0.2.0)
@@ -77,7 +77,7 @@ GEM
77
77
  rb-fsevent (0.10.4)
78
78
  rb-inotify (0.10.1)
79
79
  ffi (~> 1.0)
80
- rexml (3.2.4)
80
+ rexml (3.2.5)
81
81
  rspec (3.10.0)
82
82
  rspec-core (~> 3.10.0)
83
83
  rspec-expectations (~> 3.10.0)
@@ -131,7 +131,7 @@ DEPENDENCIES
131
131
  test-unit
132
132
 
133
133
  RUBY VERSION
134
- ruby 2.7.2p137
134
+ ruby 2.7.4p191
135
135
 
136
136
  BUNDLED WITH
137
- 2.1.4
137
+ 2.2.21
data/README.md CHANGED
@@ -54,6 +54,16 @@ $ bundle exec rake fhir:console
54
54
  'system' => 'http://unitsofmeasure.org'
55
55
  )
56
56
  ```
57
+
58
+ Iterating over all elements in a resource, including nested elements...
59
+ ```ruby
60
+ patient.each_element do |value, metadata, path|
61
+ puts "Info for #{path}:"
62
+ puts "- value: #{value}"
63
+ puts "- type: #{metadata['type']}"
64
+ puts "- cardinality: #{metadata['min']}..#{metadata['max']}"
65
+ end
66
+ ```
57
67
 
58
68
  ### Validation
59
69
 
data/fhir_models.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'nokogiri', '>= 1.10.4'
24
+ spec.add_dependency 'nokogiri', '>= 1.11.4'
25
25
  spec.add_dependency 'date_time_precision', '>= 0.8'
26
26
  spec.add_dependency 'bcp47', '>= 0.3'
27
27
  spec.add_dependency 'mime-types', '>= 3.0'
@@ -27,23 +27,26 @@ module FHIR
27
27
  blank = ->(obj) { obj.respond_to?(:empty?) ? obj.empty? : obj.nil? }
28
28
  if thing.is_a?(Array)
29
29
  return nil if thing.empty?
30
- thing.map! { |i| prune(i) }
31
- thing.reject!(&blank)
30
+
31
+ thing
32
+ .map { |i| prune(i) }
33
+ .reject(&blank)
32
34
  elsif thing.is_a?(Hash)
33
35
  return {} if thing.empty?
36
+
37
+ new_thing = {}
34
38
  thing.each do |key, value|
35
- thing[key] = prune(value)
36
- end
37
- thing.delete_if do |_key, value|
38
- blank.call(value)
39
+ new_thing[key] = prune(value) unless blank.call(value)
39
40
  end
41
+ new_thing
42
+ else
43
+ thing
40
44
  end
41
- thing
42
45
  end
43
46
 
44
- def from_hash(hash)
47
+ def from_hash(original_hash)
45
48
  # eliminate empty stuff
46
- hash = prune(hash) unless hash.empty?
49
+ pruned_hash = prune(original_hash) unless original_hash.empty?
47
50
  # clear the existing variables
48
51
  self.class::METADATA.each do |key, value|
49
52
  local_name = key
@@ -51,7 +54,8 @@ module FHIR
51
54
  instance_variable_set("@#{local_name}", nil)
52
55
  end
53
56
  # set the variables to the hash values
54
- hash.each do |key, value|
57
+ pruned_hash&.each_key do |key|
58
+ value = original_hash[key]
55
59
  key = key.to_s
56
60
  meta = self.class::METADATA[key]
57
61
  next if meta.nil?
@@ -6,8 +6,8 @@ module FHIR
6
6
  # This module includes methods to serialize or deserialize FHIR resources to and from JSON.
7
7
  #
8
8
 
9
- def to_json
10
- JSON.pretty_unparse(to_hash)
9
+ def to_json(opts = nil)
10
+ JSON.pretty_generate(to_hash, opts)
11
11
  end
12
12
 
13
13
  def self.from_json(json)
@@ -55,7 +55,7 @@ module FHIR
55
55
  return ext.first.value.nil? ? ext.first : ext.first.value
56
56
  end
57
57
  end
58
- raise NoMethodError.new("undefined method `#{method}' for #{inspect}", method)
58
+ raise NoMethodError.new("undefined method `#{method}' for #{self.class.name}", method)
59
59
  end
60
60
 
61
61
  def to_reference
@@ -300,6 +300,27 @@ module FHIR
300
300
  valid
301
301
  end
302
302
 
303
+ def each_element(path = nil, &block)
304
+ self.class::METADATA.each do |element_name, metadata|
305
+ local_name = metadata.fetch :local_name, element_name
306
+ values = [instance_variable_get("@#{local_name}")].flatten.compact
307
+ next if values.empty?
308
+
309
+ values.each_with_index do |value, i|
310
+ child_path =
311
+ if path.nil?
312
+ element_name
313
+ else
314
+ "#{path}.#{element_name}"
315
+ end
316
+ child_path += "[#{i}]" if metadata['max'] > 1
317
+ yield value, metadata, child_path
318
+ value.each_element child_path, &block unless FHIR::PRIMITIVES.include? metadata['type']
319
+ end
320
+ end
321
+ self
322
+ end
323
+
303
324
  private :validate_reference_type, :check_binding_uri, :validate_field
304
325
  end
305
326
  end
@@ -1,5 +1,5 @@
1
1
  module FHIR
2
2
  module Models
3
- VERSION = '4.1.2'.freeze
3
+ VERSION = '4.2.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fhir_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Walonoski
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2021-03-31 00:00:00.000000000 Z
15
+ date: 2022-09-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -20,14 +20,14 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.10.4
23
+ version: 1.11.4
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 1.10.4
30
+ version: 1.11.4
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: date_time_precision
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -233,12 +233,12 @@ extra_rdoc_files: []
233
233
  files:
234
234
  - ".codeclimate.yml"
235
235
  - ".gitattributes"
236
+ - ".github/workflows/ruby.yml"
236
237
  - ".gitignore"
237
238
  - ".rspec"
238
239
  - ".rubocop.yml"
239
240
  - ".rubocop_todo.yml"
240
241
  - ".simplecov"
241
- - ".travis.yml"
242
242
  - Gemfile
243
243
  - Gemfile.lock
244
244
  - Guardfile
@@ -3974,7 +3974,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
3974
3974
  - !ruby/object:Gem::Version
3975
3975
  version: '0'
3976
3976
  requirements: []
3977
- rubygems_version: 3.1.4
3977
+ rubygems_version: 3.1.6
3978
3978
  signing_key:
3979
3979
  specification_version: 4
3980
3980
  summary: A Gem for handling FHIR models in ruby
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- env:
3
- - TESTMEMORY=0 GCDELAY=2.0
4
- rvm:
5
- - 2.6
6
- - 2.7
7
- before_script:
8
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
- - chmod +x ./cc-test-reporter
10
- - ./cc-test-reporter before-build
11
- script:
12
- - travis_wait bundle exec rake
13
- after_script:
14
- - ./cc-test-reporter after-build -t simplecov --exit-code $TRAVIS_TEST_RESULT
15
- notifications:
16
- email:
17
- recipients:
18
- - fhir-testing-list@lists.mitre.org
19
- on_failure: change
20
- before_install:
21
- - gem update --system
22
- - gem update bundler