cqm-validators 0.1.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.github/PULL_REQUEST_TEMPLATE.md +23 -0
  3. data/.gitignore +3 -1
  4. data/.overcommit.yml +18 -0
  5. data/.rubocop.yml +68 -0
  6. data/.simplecov +12 -0
  7. data/.travis.yml +20 -0
  8. data/Gemfile +11 -3
  9. data/README.md +20 -6
  10. data/Rakefile +8 -6
  11. data/config/mongoid.yml +6 -0
  12. data/cqm_validators.gemspec +23 -14
  13. data/lib/base_validator.rb +20 -20
  14. data/lib/cqm_validators.rb +4 -2
  15. data/lib/cqm_validators/version.rb +3 -1
  16. data/lib/data_validator.rb +74 -79
  17. data/lib/measure_validator.rb +104 -107
  18. data/lib/performance_rate_validator.rb +43 -63
  19. data/lib/qrda_qdm_template_validator.rb +164 -311
  20. data/lib/reported_result_extractor.rb +137 -139
  21. data/lib/schema_validator.rb +20 -19
  22. data/lib/schematron/c_processor.rb +19 -19
  23. data/lib/schematron/java_processor.rb +66 -68
  24. data/lib/schematron/qrda/{cat_1_r4/HL7 QRDA Category I STU 4.sch → cat_1_r5_1/HL7 QRDA Category I STU 5.1.sch } +1684 -2082
  25. data/lib/schematron/qrda/{cat_1_r3_1 → cat_1_r5_1}/voc.xml +1223 -1228
  26. data/lib/schematron_validator.rb +31 -32
  27. data/lib/validation_error.rb +11 -9
  28. data/lib/validators.rb +40 -106
  29. data/notice.md +9 -0
  30. metadata +97 -36
  31. data/lib/schematron/qrda/cat_1/HL7_CDAR2_QRDA_Category_I_2_12_16.sch +0 -4693
  32. data/lib/schematron/qrda/cat_1/voc.xml +0 -1177
  33. data/lib/schematron/qrda/cat_1_r2/QRDA Category I Release 2.sch +0 -4069
  34. data/lib/schematron/qrda/cat_1_r2/voc.xml +0 -1065
  35. data/lib/schematron/qrda/cat_1_r3_1/HL7 QRDA Category I STU 3.1.sch +0 -3573
  36. data/lib/schematron/qrda/cat_1_r3_1/HL7 QRDA Category III STU 1.1.sch +0 -464
  37. data/lib/schematron/qrda/cat_1_r3_1/QRDA Category I STU Release 3.1.sch +0 -5394
  38. data/lib/schematron/qrda/cat_1_r4/voc.xml +0 -1186
  39. data/lib/schematron/qrda/cat_3/QRDA Category III.sch +0 -675
  40. data/lib/schematron/qrda/cat_3/voc.xml +0 -21
  41. data/lib/schematron/qrda/cat_3_r1_1/HL7 QRDA Category III STU 1.1.sch +0 -528
  42. data/lib/schematron/qrda/cat_3_r1_1/voc.xml +0 -8
  43. data/lib/schematron/qrda/cat_3_r2/HL7 QRDA Category III STU 2.sch +0 -677
  44. data/lib/schematron/qrda/cat_3_r2/voc.xml +0 -1186
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 10e594bbe1c549eff2f2c0ac550bdc0216dbb916
4
- data.tar.gz: 25adc665de422d0744c7d3e02dc27645d8c56de9
2
+ SHA256:
3
+ metadata.gz: 4c8067796e458fb6576378bcfedadb762e75cfc3222e7b71288a1ac24f706087
4
+ data.tar.gz: 5ee8cfad30be91371fee0b0ebcd454d5c7bd5993d6ff96b3e565fd148039e5b8
5
5
  SHA512:
6
- metadata.gz: bf33635af5df0ab3d962b17f76e10a60f36c934d6fb2808c481e579d72b881e77400af43ab6ffa5b244d0fe20d7cf10f8b698fdbe8921badcd7d9ff4165e94b9
7
- data.tar.gz: 1bac808ffaf3a2c635a44568f61618c079547d59eb7f5f48f60de09025634d3cf0130c3ab286fb7438bca818daa5230eb1871e6187ce1a5047c082b6f8731f38
6
+ metadata.gz: 0333e138838bda558b17d0612b5f270d9d549c908531e5e1792433941aaaa913c7d0d7754d09f60ca91df98cd355612418a68cb122a2d9440479d923fbff2989
7
+ data.tar.gz: 58deb72053f7e7e29e9c2174b21e7b603bbd5fffe954665add5899de6d0438b0b24d40c403b08735358bb10001585731230c4452d8a345295c19fab1bb49308c
@@ -0,0 +1,23 @@
1
+ Pull requests into cqm-validators require the following. Submitter and reviewer should :white_check_mark: when done. For items that are not-applicable, note it's not-applicable ("N/A") and :white_check_mark:.
2
+
3
+ **Submitter:**
4
+ - [ ] This pull request describes why these changes were made.
5
+ - [ ] Internal ticket for this PR:
6
+ - [ ] Internal ticket links to this PR
7
+ - [ ] Code diff has been done and been reviewed
8
+ - [ ] Tests are included and test edge cases
9
+ - [ ] Tests have been run locally and pass
10
+
11
+ **Reviewer 1:**
12
+
13
+ Name:
14
+ - [ ] Code is maintainable and reusable, reuses existing code and infrastructure where appropriate, and accomplishes the task’s purpose
15
+ - [ ] The tests appropriately test the new code, including edge cases
16
+ - [ ] You have tried to break the code
17
+
18
+ **Reviewer 2:**
19
+
20
+ Name:
21
+ - [ ] Code is maintainable and reusable, reuses existing code and infrastructure where appropriate, and accomplishes the task’s purpose
22
+ - [ ] The tests appropriately test the new code, including edge cases
23
+ - [ ] You have tried to break the code
data/.gitignore CHANGED
@@ -4,4 +4,6 @@ test/xsd
4
4
  tmp
5
5
  .DS_Store
6
6
  .idea
7
- .rvmrc
7
+ .rvmrc
8
+ Gemfile.lock
9
+ .byebug_history
@@ -0,0 +1,18 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ on_warn: 'fail'
5
+ HardTabs:
6
+ enabled: true
7
+ exclude: ['test/fixtures/**/*', 'lib/schema/**/*', 'lib/schematron/iso-schematron-xslt1/**/*', 'lib/schematron/iso-schematron-xslt2/**/*', 'lib/schematron/qrda/**/*']
8
+ AuthorName:
9
+ enabled: false
10
+ CommitMsg:
11
+ RussianNovel:
12
+ enabled: true
13
+ HardTabs:
14
+ enabled: true
15
+ TextWidth:
16
+ enabled: false
17
+ CapitalizedSubject:
18
+ enabled: false
@@ -0,0 +1,68 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - bin/*
5
+ Documentation:
6
+ Enabled: false
7
+ # TODO: remove this exception when java_processor.rb is fixed to rescue StandardError
8
+ Lint/RescueException:
9
+ Exclude:
10
+ - 'lib/schematron/java_processor.rb'
11
+ Layout/LineLength:
12
+ Max: 150
13
+ Exclude:
14
+ - 'test/**/*'
15
+ # TODO: remove exclusions below this line as line length is fixed
16
+ - 'lib/reported_result_extractor.rb'
17
+ - 'lib/data_validator.rb'
18
+ - 'lib/measure_validator.rb'
19
+ Metrics/AbcSize:
20
+ # The ABC size is a calculated magnitude, so this number can be a Fixnum or
21
+ # a Float.
22
+ Max: 32
23
+ Exclude:
24
+ - 'test/**/*.rb'
25
+ # TODO: remove exclusions below this line as ABC Size is fixed
26
+ - 'lib/performance_rate_validator.rb'
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - 'test/factories/*'
30
+ Metrics/ClassLength:
31
+ Max: 120
32
+ Exclude:
33
+ - 'test/**/*'
34
+ # TODO: remove exclusions below this line as Class length is fixed
35
+ - 'lib/qrda_qdm_template_validator.rb'
36
+ Metrics/MethodLength:
37
+ CountComments: false # count full line comments?
38
+ Max: 20
39
+ Exclude:
40
+ - 'test/**/*'
41
+ # TODO: remove exclusions below this line as method length is fixed
42
+ - 'lib/reported_result_extractor.rb'
43
+ Metrics/ModuleLength:
44
+ Max: 110
45
+ Exclude:
46
+ # TODO: remove exclusions below this line as module length is fixed
47
+ - 'lib/reported_result_extractor.rb'
48
+ # Avoid complex methods.
49
+ Metrics/CyclomaticComplexity:
50
+ Max: 10
51
+ Metrics/PerceivedComplexity:
52
+ Max: 10
53
+ Exclude:
54
+ - 'lib/reported_result_extractor.rb'
55
+ Naming/MethodParameterName:
56
+ Enabled: false
57
+ Style/DateTime:
58
+ Enabled: false
59
+ Style/GuardClause:
60
+ MinBodyLength: 100
61
+ Exclude:
62
+ # TODO: remove exclusions below this line as ABC Size is fixed
63
+ - 'lib/performance_rate_validator.rb'
64
+ Style/MixinUsage:
65
+ Exclude:
66
+ - 'test/test_helper.rb'
67
+ Style/RescueStandardError:
68
+ Enabled: false
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ merge_timeout 3600
5
+ end
6
+
7
+ if ENV['CI'] == 'true'
8
+ require 'codecov'
9
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
10
+ else
11
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
12
+ end
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ - 2.5
5
+ cache:
6
+ - bundler
7
+ sudo: required
8
+ services:
9
+ - mongodb
10
+ branches:
11
+ only:
12
+ - master
13
+ - cqm_validators_2_x
14
+ before_script:
15
+ - git config --global user.email "travis@travis.ci"
16
+ - git config --global user.name "Travis CI"
17
+ script:
18
+ - bundle exec overcommit --sign
19
+ - bundle exec overcommit --run
20
+ - travis_retry bundle exec rake test
data/Gemfile CHANGED
@@ -1,6 +1,14 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in cqm_validators.gemspec
6
- gemspec
8
+ gemspec development_group: :test
9
+
10
+ group :test do
11
+ gem 'codecov', require: false
12
+ gem 'cqm-models', git: 'https://github.com/projecttacoma/cqm-models.git', branch: 'master'
13
+ gem 'simplecov', require: false
14
+ end
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- This is a validation library that is used by Cypress for QRDA validation.
1
+ This is a library that is used by Cypress for QRDA validation. It contains Schematron validators, schema validators, and validators for QRDA-specific features (measure IDs, performance rates, result extraction, etc).
2
2
 
3
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cqm_validators.
3
+ Bug reports and pull requests are welcome on GitHub at https://github.com/projecttacoma/cqm_validators.
4
4
 
5
5
  Environment
6
6
  ===========
7
7
 
8
- This project currently uses Ruby 2.0.0, Ruby 2.1.1, Ruby 2.2.1, and JRuby 1.7.11 and is built using [Bundler](http://gembundler.com/). To get all of the dependencies for the project, first install bundler:
8
+ This project currently uses Ruby 2.3, Ruby 2.4, Ruby 2.5 and Ruby 2.6 and is built using [Bundler](http://gembundler.com/). To get all of the dependencies for the project, first install bundler:
9
9
 
10
10
  gem install bundler
11
11
 
@@ -13,9 +13,23 @@ Then run bundler to grab all of the necessary gems:
13
13
 
14
14
  bundle install
15
15
 
16
- The Quality Measure engine relies on a MongoDB [MongoDB](http://www.mongodb.org/) running a minimum of version 2.4.* or higher. To get and install Mongo refer to:
17
16
 
18
- http://www.mongodb.org/display/DOCS/Quickstart
17
+
18
+ Versioning
19
+ ==========
20
+
21
+ Starting with version **1.0.1.0** released on 5/22/2019, cqm-validators versioning has the format **W.X.Y.Z**, where:
22
+
23
+ * **W** maps to a version of QRDA Category 1 and QRDA Category 3. See the table below to see the existing mapping to QRDA versions.
24
+
25
+ | W | QRDA Cat 1 | QRDA Cat 3 |
26
+ | --- | --- | --- |
27
+ | 1 | R1 STU5.1 | R1 STU2.1 |
28
+
29
+ * **X.Y.Z** uses [SemVer](http://semver.org/) for versioning. **X.Y.Z** starts at 0.0.0 when **W** is incremented.
30
+
31
+ For the versions available, see [tags on this repository](https://github.com/projecttacoma/cqm-validators/tags).
32
+
19
33
 
20
34
  Project Practices
21
35
  =================
@@ -37,4 +51,4 @@ Unless required by applicable law or agreed to in writing, software
37
51
  distributed under the License is distributed on an "AS IS" BASIS,
38
52
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
53
  See the License for the specific language governing permissions and
40
- limitations under the License.
54
+ limitations under the License.
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ database: cqmv_test
5
+ hosts:
6
+ - <%= ENV['TEST_DB_HOST'] || '127.0.0.1' %>:27017
@@ -1,28 +1,37 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "cqm_validators/version"
5
+ require 'cqm_validators/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "cqm-validators"
8
+ spec.name = 'cqm-validators'
8
9
  spec.version = CqmValidators::VERSION
9
- spec.authors = ["Laura", "Michael O'Keefe"]
10
- spec.email = ["laclark@mitre.org", 'mokeefe@mitre.org']
10
+ spec.authors = ['Laura', "Michael O'Keefe"]
11
+ spec.email = ['laclark@mitre.org', 'mokeefe@mitre.org']
11
12
  spec.license = 'Apache-2.0'
12
13
 
13
- spec.summary = "new cqm validator library"
14
- spec.description = "new cqm validator library"
15
- spec.homepage = "https://github.com/projecttacoma/cqm-validators"
14
+ spec.summary = 'new cqm validator library'
15
+ spec.description = 'new cqm validator library'
16
+ spec.homepage = 'https://github.com/projecttacoma/cqm-validators'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
19
20
  end
20
- spec.bindir = "exe"
21
+ spec.bindir = 'exe'
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
23
24
 
24
- spec.add_dependency "nokogiri", "~>1.8.2"
25
- spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.required_ruby_version = '>= 2.5.0'
26
+
27
+ spec.add_dependency 'nokogiri', '~>1.10'
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'byebug'
31
+ spec.add_development_dependency 'minitest', '~> 5.0'
32
+ spec.add_development_dependency 'minitest-reporters'
33
+ spec.add_development_dependency 'mongoid'
34
+ spec.add_development_dependency 'overcommit'
35
+ spec.add_development_dependency 'rake', '>= 12.3.3'
36
+ spec.add_development_dependency 'rubocop', '~> 0.93'
28
37
  end
@@ -1,22 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CqmValidators
2
- module BaseValidator
3
-
4
- def build_error(msg, loc, file_name)
5
- ValidationError.new(message: msg, location: loc, file_name: file_name, validator: @name)
6
- end
7
-
8
- def get_document(input)
9
- doc = case input
10
- when File
11
- input.read
12
- when Nokogiri::XML::Document
13
- return input
14
- else
15
- input
16
- end
17
- Nokogiri::XML(doc.to_s) { |conf| conf.strict.nonet.noblanks } #grumble, grumble nokogiri java @SS
18
- end
19
- end
20
-
4
+ module BaseValidator
5
+ def build_error(msg, loc, file_name)
6
+ ValidationError.new(message: msg, location: loc, file_name: file_name, validator: @name)
7
+ end
8
+
9
+ def get_document(input)
10
+ doc = case input
11
+ when File
12
+ input.rewind
13
+ input.read
14
+ when Nokogiri::XML::Document
15
+ return input
16
+ else
17
+ input
18
+ end
19
+ Nokogiri::XML(doc.to_s) { |conf| conf.strict.nonet.noblanks } # grumble, grumble nokogiri java @SS
20
+ end
21
+ end
21
22
  end
22
-
@@ -1,4 +1,6 @@
1
- require "cqm_validators/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'cqm_validators/version'
2
4
  require 'reported_result_extractor'
3
5
  require 'base_validator'
4
6
  require 'data_validator'
@@ -8,7 +10,7 @@ require 'qrda_qdm_template_validator'
8
10
  require 'schema_validator'
9
11
  require 'schematron_validator'
10
12
  require 'validators'
11
- require "schematron/c_processor"
13
+ require 'schematron/c_processor'
12
14
 
13
15
  module CqmValidators
14
16
  # Your code goes here...
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CqmValidators
2
- VERSION = "0.1.0"
4
+ VERSION = '2.0.2'
3
5
  end
@@ -1,82 +1,77 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CqmValidators
2
- class DataValidator
3
- include BaseValidator
4
-
5
- HL7_QRDA_OIDS = ["2.16.840.1.113883.3.221.5",
6
- "2.16.840.1.113883.3.88.12.3221.8.7",
7
- "2.16.840.1.113883.3.88.12.3221.8.9",
8
- "2.16.840.1.113883.1.11.12839",
9
- "2.16.840.1.113883.3.88.12.3221.8.11",
10
- "2.16.840.1.113883.3.88.12.3221.6.2",
11
- "2.16.840.1.113883.11.20.9.40",
12
- "2.16.840.1.113883.11.20.9.23",
13
- "2.16.840.1.113883.3.88.12.3221.7.4",
14
- "2.16.840.1.113883.11.20.9.18",
15
- "2.16.840.1.113883.11.20.9.22",
16
- "2.16.840.1.113883.1.11.16866",
17
- "2.16.840.1.113883.1.11.20275",
18
- "2.16.840.1.113883.11.20.9.34",
19
- "2.16.840.1.113883.3.88.12.3221.7.2",
20
- "2.16.840.1.113883.3.88.12.80.17",
21
- "2.16.840.1.113883.3.88.12.80.22",
22
- "2.16.840.1.113883.3.88.12.80.64",
23
- "2.16.840.1.113883.3.88.12.3221.6.8",
24
- "2.16.840.1.113883.1.11.78",
25
- "2.16.840.1.113883.11.20.9.25",
26
- "2.16.840.1.113883.11.20.9.39",
27
- "2.16.840.1.113883.3.88.12.80.32",
28
- "2.16.840.1.113883.11.20.9.21",
29
- "2.16.840.1.113883.3.88.12.80.68",
30
- "2.16.840.1.113883.1.11.20.12",
31
- "2.16.840.1.113883.11.20.9.24",
32
- "2.16.840.1.113883.11.20.9.41",
33
- "2.16.840.1.113883.1.11.16926",
34
- "2.16.840.1.113883.1.11.12212",
35
- "2.16.840.1.113883.1.11.19185",
36
- "2.16.840.1.113883.1.11.14914",
37
- "2.16.840.1.114222.4.11.837",
38
- "2.16.840.1.113883.1.11.19563",
39
- "2.16.840.1.113883.1.11.11526",
40
- "2.16.840.1.113883.11.20.9.20",
41
- "2.16.840.1.113883.3.88.12.80.2",
42
- "2.16.840.1.113883.3.88.12.80.63",
43
- "2.16.840.1.113883.1.11.12249",
44
- "2.16.840.1.113883.1.11.1",
45
- "2.16.840.1.113883.1.11.12199",
46
- "2.16.840.1.113883.11.20.9.33",
47
- "2.16.840.1.114222.4.11.1066",
48
- "2.16.840.1.113883.1.11.19579"]
49
-
50
- def initialize(bundle, measure_ids)
51
- @bundle = bundle
52
- measures = @bundle.measures.in(hqmf_id: measure_ids)
53
-
54
- @oids = measures.collect{|m| m.oids}.flatten.uniq + HL7_QRDA_OIDS
4
+ class DataValidator
5
+ include BaseValidator
6
+
7
+ HL7_QRDA_OIDS = ['2.16.840.1.113883.3.221.5',
8
+ '2.16.840.1.113883.3.88.12.3221.8.7',
9
+ '2.16.840.1.113883.3.88.12.3221.8.9',
10
+ '2.16.840.1.113883.1.11.12839',
11
+ '2.16.840.1.113883.3.88.12.3221.8.11',
12
+ '2.16.840.1.113883.3.88.12.3221.6.2',
13
+ '2.16.840.1.113883.11.20.9.40',
14
+ '2.16.840.1.113883.11.20.9.23',
15
+ '2.16.840.1.113883.3.88.12.3221.7.4',
16
+ '2.16.840.1.113883.11.20.9.18',
17
+ '2.16.840.1.113883.11.20.9.22',
18
+ '2.16.840.1.113883.1.11.16866',
19
+ '2.16.840.1.113883.1.11.20275',
20
+ '2.16.840.1.113883.11.20.9.34',
21
+ '2.16.840.1.113883.3.88.12.3221.7.2',
22
+ '2.16.840.1.113883.3.88.12.80.17',
23
+ '2.16.840.1.113883.3.88.12.80.22',
24
+ '2.16.840.1.113883.3.88.12.80.64',
25
+ '2.16.840.1.113883.3.88.12.3221.6.8',
26
+ '2.16.840.1.113883.1.11.78',
27
+ '2.16.840.1.113883.11.20.9.25',
28
+ '2.16.840.1.113883.11.20.9.39',
29
+ '2.16.840.1.113883.3.88.12.80.32',
30
+ '2.16.840.1.113883.11.20.9.21',
31
+ '2.16.840.1.113883.3.88.12.80.68',
32
+ '2.16.840.1.113883.1.11.20.12',
33
+ '2.16.840.1.113883.11.20.9.24',
34
+ '2.16.840.1.113883.11.20.9.41',
35
+ '2.16.840.1.113883.1.11.16926',
36
+ '2.16.840.1.113883.1.11.12212',
37
+ '2.16.840.1.113883.1.11.19185',
38
+ '2.16.840.1.113883.1.11.14914',
39
+ '2.16.840.1.114222.4.11.837',
40
+ '2.16.840.1.113883.1.11.19563',
41
+ '2.16.840.1.113883.1.11.11526',
42
+ '2.16.840.1.113883.11.20.9.20',
43
+ '2.16.840.1.113883.3.88.12.80.2',
44
+ '2.16.840.1.113883.3.88.12.80.63',
45
+ '2.16.840.1.113883.1.11.12249',
46
+ '2.16.840.1.113883.1.11.1',
47
+ '2.16.840.1.113883.1.11.12199',
48
+ '2.16.840.1.113883.11.20.9.33',
49
+ '2.16.840.1.114222.4.11.1066',
50
+ '2.16.840.1.113883.1.11.19579'].freeze
51
+
52
+ def initialize(measure_ids)
53
+ measures = CQM::Measure.find(measure_ids)
54
+ @value_set_ids = measures.collect { |m| m.value_sets.map(&:_id) }.flatten.uniq
55
+ end
56
+
57
+ def validate(file, options = {})
58
+ doc = get_document(file)
59
+
60
+ doc.xpath('//*[@sdtc:valueSet]').each_with_object([]) do |node, errors|
61
+ oid = node.at_xpath('@sdtc:valueSet')
62
+ vs = CQM::ValueSet.where('oid' => oid, '_id' => { '$in' => @value_set_ids }).first
63
+ next unless vs
64
+
65
+ code = node.at_xpath('@code')
66
+ code_system_oid = node.at_xpath('@codeSystem')
67
+ null_flavor = node.at_xpath('@nullFlavor')
68
+ next unless vs.concepts.where(code: code, code_system_oid: code_system_oid).count.zero?
69
+
70
+ unless null_flavor
71
+ errors << build_error("The code #{code} in codeSystem #{code_system_oid} cannot be found in the declared valueset #{oid}",
72
+ node.path, options[:file_name])
55
73
  end
56
-
57
- def validate(file, options={})
58
- doc = get_document(file)
59
-
60
- doc.xpath("//*[@sdtc:valueSet]").inject([]) do |errors, node|
61
- oid = node.at_xpath("@sdtc:valueSet")
62
- vs = @bundle.value_sets.where({"oid" => oid}).first
63
- code = node.at_xpath("@code")
64
- code_system = node.at_xpath("@codeSystem")
65
- null_flavor = node.at_xpath("@nullFlavor")
66
- if !vs
67
- errors << build_error("The valueset #{oid} declared in the document cannot be found", node.path, options[:file_name])
68
- elsif !@oids.include?(oid.value)
69
- errors << build_error("File appears to contain data criteria outside that required by the measures. Valuesets in file not in measures tested #{oid}'",
70
- node.path, options[:file_name])
71
- elsif vs.concepts.where({"code" => code, "code_system"=>code_system}).count() == 0
72
- if !null_flavor
73
- errors << build_error("The code #{code} in codeSystem #{code_system} cannot be found in the declared valueset #{oid}",
74
- node.path, options[:file_name])
75
- end
76
- end
77
- errors
78
- end
79
- end
80
-
81
74
  end
82
- end
75
+ end
76
+ end
77
+ end