hqmf-parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/Gemfile +23 -0
  2. data/README.md +903 -0
  3. data/Rakefile +19 -0
  4. data/VERSION +1 -0
  5. data/lib/hqmf-generator/hqmf-generator.rb +308 -0
  6. data/lib/hqmf-model/attribute.rb +35 -0
  7. data/lib/hqmf-model/data_criteria.rb +322 -0
  8. data/lib/hqmf-model/document.rb +172 -0
  9. data/lib/hqmf-model/population_criteria.rb +90 -0
  10. data/lib/hqmf-model/precondition.rb +85 -0
  11. data/lib/hqmf-model/types.rb +318 -0
  12. data/lib/hqmf-model/utilities.rb +52 -0
  13. data/lib/hqmf-parser.rb +54 -0
  14. data/lib/hqmf-parser/1.0/attribute.rb +68 -0
  15. data/lib/hqmf-parser/1.0/comparison.rb +34 -0
  16. data/lib/hqmf-parser/1.0/data_criteria.rb +105 -0
  17. data/lib/hqmf-parser/1.0/document.rb +209 -0
  18. data/lib/hqmf-parser/1.0/expression.rb +52 -0
  19. data/lib/hqmf-parser/1.0/population_criteria.rb +79 -0
  20. data/lib/hqmf-parser/1.0/precondition.rb +89 -0
  21. data/lib/hqmf-parser/1.0/range.rb +65 -0
  22. data/lib/hqmf-parser/1.0/restriction.rb +157 -0
  23. data/lib/hqmf-parser/1.0/utilities.rb +41 -0
  24. data/lib/hqmf-parser/2.0/data_criteria.rb +319 -0
  25. data/lib/hqmf-parser/2.0/document.rb +165 -0
  26. data/lib/hqmf-parser/2.0/population_criteria.rb +53 -0
  27. data/lib/hqmf-parser/2.0/precondition.rb +44 -0
  28. data/lib/hqmf-parser/2.0/types.rb +223 -0
  29. data/lib/hqmf-parser/2.0/utilities.rb +30 -0
  30. data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +254 -0
  31. data/lib/hqmf-parser/converter/pass1/document_converter.rb +183 -0
  32. data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +135 -0
  33. data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +164 -0
  34. data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +159 -0
  35. data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +35 -0
  36. data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
  37. data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
  38. data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +63 -0
  39. data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
  40. data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +91 -0
  41. data/lib/hqmf-parser/converter/pass2/operator_converter.rb +169 -0
  42. data/lib/hqmf-parser/converter/pass3/specific_occurrence_converter.rb +86 -0
  43. data/lib/hqmf-parser/converter/pass3/specific_occurrence_converter_bak.rb +70 -0
  44. data/lib/hqmf-parser/parser.rb +22 -0
  45. data/lib/hqmf-parser/value_sets/value_set_parser.rb +206 -0
  46. data/lib/tasks/coverme.rake +8 -0
  47. data/lib/tasks/hqmf.rake +141 -0
  48. data/lib/tasks/value_sets.rake +23 -0
  49. metadata +159 -0
@@ -0,0 +1,8 @@
1
+ namespace :cover_me do
2
+
3
+ task :report do
4
+ require 'cover_me'
5
+ CoverMe.complete!
6
+ end
7
+
8
+ end
@@ -0,0 +1,141 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'json'
4
+
5
+ namespace :hqmf do
6
+
7
+ desc 'Open a console for interacting with parsed HQMF'
8
+ task :console do
9
+
10
+ def load_hqmf(id)
11
+ HQMF1::Document.new(File.expand_path(File.join(".","test","fixtures","NQF_Retooled_Measure_#{id}.xml")))
12
+ end
13
+
14
+ Pry.start
15
+ end
16
+
17
+ desc 'Parse all xml files to JSON and save them to ./tmp'
18
+ task :parse_all, [:path, :version] do |t, args|
19
+
20
+ raise "You must specify the HQMF XML file path to convert" unless args.path
21
+
22
+
23
+ FileUtils.mkdir_p File.join(".","tmp",'json','all')
24
+ path = File.expand_path(args.path)
25
+ version = args.version || HQMF::Parser::HQMF_VERSION_1
26
+
27
+ Dir.glob(File.join(path,'**','*.xml')) do |measure_def|
28
+ puts "####################################"
29
+ puts "### processing: #{measure_def}..."
30
+ puts "####################################"
31
+ doc = HQMF::Parser.parse(File.open(measure_def).read, version)
32
+ filename = Pathname.new(measure_def).basename
33
+
34
+ File.open(File.join(".","tmp",'json','all',"#{filename}.json"), 'w') {|f| f.write(doc.to_json.to_json(max_nesting: 100).gsub(/",/,"\",\n")) }
35
+ puts "\n"
36
+ end
37
+
38
+ end
39
+
40
+ desc 'Parse specified xml file to JSON and save it to ./tmp'
41
+ task :parse, [:file,:version] do |t, args|
42
+ FileUtils.mkdir_p File.join(".","tmp",'json')
43
+
44
+ raise "You must specify the HQMF XML file to convert" unless args.file
45
+
46
+ version = args.version || HQMF::Parser::HQMF_VERSION_1
47
+ file = File.expand_path(args.file)
48
+ filename = Pathname.new(file).basename
49
+
50
+ doc = HQMF::Parser.parse(File.open(file).read, version)
51
+ outfile = File.join(".","tmp",'json',"#{filename}.json")
52
+ File.open(outfile, 'w') {|f| f.write(doc.to_json.to_json(max_nesting: 100).gsub(/",/,"\",\n")) }
53
+
54
+ puts "wrote result to: #{outfile}"
55
+
56
+ end
57
+
58
+ desc 'Parse specified xml file to V1 JSON and save it to ./tmp'
59
+ task :parse_v1, [:file] do |t, args|
60
+ FileUtils.mkdir_p File.join(".","tmp",'json')
61
+
62
+ raise "You must specify the HQMF XML file to convert" unless args.file
63
+
64
+ file = File.expand_path(args.file)
65
+ filename = Pathname.new(file).basename
66
+
67
+ doc = HQMF1::Document.new(File.open(file).read).to_json
68
+ outfile = File.join(".","tmp",'json',"#{filename}_v1.json")
69
+ File.open(outfile, 'w') {|f| f.write(doc.to_json(max_nesting: 100).gsub(/",/,"\",\n")) }
70
+ puts "wrote result to: #{outfile}"
71
+
72
+ end
73
+
74
+ desc 'Convert V1 JSON to V2 JSON and save it to ./tmp'
75
+ task :convert, [:file] do |t, args|
76
+ FileUtils.mkdir_p File.join(".","tmp",'json')
77
+
78
+ raise "You must specify the V1 JSON file to convert" unless args.file
79
+
80
+ file = File.expand_path(args.file)
81
+ filename = Pathname.new(file).basename
82
+
83
+ converted = HQMF::DocumentConverter.convert(JSON.parse(File.open(file).read,:symbolize_names => true))
84
+
85
+ outfile = File.join(".","tmp",'json',"#{filename}_v2.json")
86
+ File.open(outfile, 'w') {|f| f.write(converted.to_json.to_json.gsub(/",/,"\",\n")) }
87
+ puts "wrote result to: #{outfile}"
88
+
89
+ end
90
+
91
+ desc 'Convert specified HQMF V1 xml file to HQMF V2 and save it to ./tmp'
92
+ task :upgrade, [:file] do |t, args|
93
+ FileUtils.mkdir_p File.join(".","tmp",'xml')
94
+
95
+ raise "You must specify the HQMF XML file to convert" unless args.file
96
+
97
+ version = HQMF::Parser::HQMF_VERSION_1
98
+ file = File.expand_path(args.file)
99
+ filename = Pathname.new(file).basename
100
+
101
+ doc = HQMF::Parser.parse(File.open(file).read, version)
102
+
103
+ hqmf_xml = HQMF2::Generator::ModelProcessor.to_hqmf(doc)
104
+ xml = Nokogiri.XML(hqmf_xml) do |config|
105
+ config.default_xml.noblanks
106
+ end
107
+
108
+ outfile = File.join(".","tmp",'xml',"#{filename}")
109
+ File.open(outfile, 'w') {|f| f.write(xml.to_xml(:indent => 2)) }
110
+
111
+ puts "wrote result to: #{outfile}"
112
+
113
+ end
114
+
115
+ desc 'Roundtrip specified HQMF V2 xml file through the model and back to HQMF V2 and save it to ./tmp'
116
+ task :roundtrip, [:file] do |t, args|
117
+ FileUtils.mkdir_p File.join(".","tmp",'xml')
118
+
119
+ raise "You must specify the HQMF XML file to roundtrip" unless args.file
120
+
121
+ version = HQMF::Parser::HQMF_VERSION_2
122
+ file = File.expand_path(args.file)
123
+ filename = Pathname.new(file).basename
124
+
125
+ doc = HQMF::Parser.parse(File.open(file).read, version)
126
+
127
+ hqmf_xml = HQMF2::Generator::ModelProcessor.to_hqmf(doc)
128
+ xml = Nokogiri.XML(hqmf_xml) do |config|
129
+ config.default_xml.noblanks
130
+ end
131
+
132
+ outfile = File.join(".","tmp",'xml',"#{filename}")
133
+ File.open(outfile, 'w') {|f| f.write(xml.to_xml(:indent => 2)) }
134
+
135
+ puts "wrote result to: #{outfile}"
136
+
137
+ end
138
+
139
+
140
+
141
+ end
@@ -0,0 +1,23 @@
1
+ namespace :value_set do
2
+
3
+ desc 'Parse a value set to JSON'
4
+ task :parse, [:path] do |t, args|
5
+
6
+ raise "You must specify the value set xls file path to parse" unless args.path
7
+
8
+ FileUtils.mkdir_p File.join(".","tmp",'json','value_sets')
9
+ path = File.expand_path(args.path)
10
+
11
+ parser = HQMF::ValueSet::Parser.new
12
+ parsed = parser.parse path
13
+
14
+ file = File.expand_path(path)
15
+ filename = Pathname.new(file).basename
16
+
17
+ outfile = File.join(".","tmp",'json', 'value_sets', "#{filename}.json")
18
+ File.open(outfile, 'w') {|f| f.write(parsed.to_json) }
19
+ puts "wrote result to: #{outfile}"
20
+
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hqmf-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Goldstein
9
+ - Andre Quina
10
+ - Marc Hadley
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-11-01 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rubyzip
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: spreadsheet
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.6.8
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.8
48
+ - !ruby/object:Gem::Dependency
49
+ name: google-spreadsheet-ruby
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.8
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - '='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.1.8
64
+ - !ruby/object:Gem::Dependency
65
+ name: roo
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - '='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.10.1
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - '='
78
+ - !ruby/object:Gem::Version
79
+ version: 1.10.1
80
+ description: A library for parsing HQMF XML files.
81
+ email: talk@projectpophealth.org
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/hqmf-generator/hqmf-generator.rb
87
+ - lib/hqmf-model/attribute.rb
88
+ - lib/hqmf-model/data_criteria.rb
89
+ - lib/hqmf-model/document.rb
90
+ - lib/hqmf-model/population_criteria.rb
91
+ - lib/hqmf-model/precondition.rb
92
+ - lib/hqmf-model/types.rb
93
+ - lib/hqmf-model/utilities.rb
94
+ - lib/hqmf-parser/1.0/attribute.rb
95
+ - lib/hqmf-parser/1.0/comparison.rb
96
+ - lib/hqmf-parser/1.0/data_criteria.rb
97
+ - lib/hqmf-parser/1.0/document.rb
98
+ - lib/hqmf-parser/1.0/expression.rb
99
+ - lib/hqmf-parser/1.0/population_criteria.rb
100
+ - lib/hqmf-parser/1.0/precondition.rb
101
+ - lib/hqmf-parser/1.0/range.rb
102
+ - lib/hqmf-parser/1.0/restriction.rb
103
+ - lib/hqmf-parser/1.0/utilities.rb
104
+ - lib/hqmf-parser/2.0/data_criteria.rb
105
+ - lib/hqmf-parser/2.0/document.rb
106
+ - lib/hqmf-parser/2.0/population_criteria.rb
107
+ - lib/hqmf-parser/2.0/precondition.rb
108
+ - lib/hqmf-parser/2.0/types.rb
109
+ - lib/hqmf-parser/2.0/utilities.rb
110
+ - lib/hqmf-parser/converter/pass1/data_criteria_converter.rb
111
+ - lib/hqmf-parser/converter/pass1/document_converter.rb
112
+ - lib/hqmf-parser/converter/pass1/population_criteria_converter.rb
113
+ - lib/hqmf-parser/converter/pass1/precondition_converter.rb
114
+ - lib/hqmf-parser/converter/pass1/precondition_extractor.rb
115
+ - lib/hqmf-parser/converter/pass1/simple_data_criteria.rb
116
+ - lib/hqmf-parser/converter/pass1/simple_operator.rb
117
+ - lib/hqmf-parser/converter/pass1/simple_population_criteria.rb
118
+ - lib/hqmf-parser/converter/pass1/simple_precondition.rb
119
+ - lib/hqmf-parser/converter/pass1/simple_restriction.rb
120
+ - lib/hqmf-parser/converter/pass2/comparison_converter.rb
121
+ - lib/hqmf-parser/converter/pass2/operator_converter.rb
122
+ - lib/hqmf-parser/converter/pass3/specific_occurrence_converter.rb
123
+ - lib/hqmf-parser/converter/pass3/specific_occurrence_converter_bak.rb
124
+ - lib/hqmf-parser/parser.rb
125
+ - lib/hqmf-parser/value_sets/value_set_parser.rb
126
+ - lib/hqmf-parser.rb
127
+ - lib/tasks/coverme.rake
128
+ - lib/tasks/hqmf.rake
129
+ - lib/tasks/value_sets.rake
130
+ - Gemfile
131
+ - README.md
132
+ - Rakefile
133
+ - VERSION
134
+ homepage: http://github.com/pophealth/hqmf-parser
135
+ licenses: []
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.24
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: A library for parsing HQMF XML files.
158
+ test_files: []
159
+ has_rdoc: