hl7-exporter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e2b3cd0e7fb20caf79caf410c300a4c809f71c6dc5827848e66d03ed32169813
4
+ data.tar.gz: b0b4e7378500b1b1928f89618f78dd9a3b403fa1634c9b4460ca7a0dcb175623
5
+ SHA512:
6
+ metadata.gz: 289ca7eafc4ef48a48565e9d7c90a8ff7ccb736e34bbced39ef2f831ca768d5a568479c2fc0ca08a7778bc0ee96329e0055826a94f1925bb51ed23e0921b3802
7
+ data.tar.gz: 9d1600d1cc239ac200d7e9668048d9bb28763bea610a4a6a2400a2317c133f5f1fa79e222225e99f9c1c99468ce3157f524783a66de163d54e19caee146a2c54
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,16 @@
1
+ branches:
2
+ only:
3
+ - master
4
+ language: ruby
5
+ matrix:
6
+ allow_failures:
7
+ - rvm: ruby-head
8
+ rvm:
9
+ - 2.2.0
10
+ - 2.1.0
11
+ - 2.0.0
12
+ - 1.9.3
13
+ - ruby-head
14
+ - jruby-19mode # JRuby in 1.9 mode
15
+ - rbx-2.2
16
+ bundler_args: --without ruby2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hl7-exporter.gemspec
4
+ gemspec
5
+
6
+ group :ruby2 do
7
+ gem 'byebug'
8
+ gem 'pry'
9
+ gem 'looksee'
10
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Enrique Carlos Mogollan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # HL7::Exporter
2
+
3
+ A simple library to export 'ruby-hl7' messages into different formats.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hl7-exporter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hl7-exporter
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ cvs_exporter = HL7::Exporter::Csv
23
+ message = HL7::Message.parse('hl7_file.dat')
24
+
25
+ # In progress:
26
+ cvs_exporter.export(message) # returns the data
27
+
28
+
29
+ # Future implementation:
30
+ cvs_exporter.export(message, template)
31
+
32
+ # I'm also thinking about this one:
33
+ json_exporter = HL7::Exporter::Json
34
+ json_exporter.export(message)
35
+
36
+ # Next goal after simple json is
37
+ fhir_exporter = HL7::Exporter::Fhir
38
+ fhir_exporter.export(message)
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/ruby-hl7/hl7-exporter/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hl7/exporter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hl7-exporter"
8
+ spec.version = HL7::Exporter::VERSION
9
+ spec.authors = ["Enrique Carlos Mogollan"]
10
+ spec.email = ["emogollan@gmail.com"]
11
+ spec.summary = %q{A library to export messages from the ruby-hl7 gem}
12
+ spec.description = %q{A simple library to export messages from the ruby-hl7 gem}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ruby-hl7", "~> 1.1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.5"
26
+ end
@@ -0,0 +1,2 @@
1
+ require "ruby-hl7"
2
+ require "hl7/exporter"
@@ -0,0 +1,32 @@
1
+ require_relative "exporter/version"
2
+ require_relative "exporter/csv"
3
+ require_relative "exporter/observation"
4
+ require_relative "exporter/patient"
5
+
6
+
7
+ module HL7
8
+ class Exporter
9
+ attr_reader :message
10
+
11
+ def initialize(message = nil)
12
+ self.message = message
13
+ end
14
+
15
+ def message=(msg)
16
+ if hl7? msg
17
+ @message = msg
18
+ else
19
+ @message = HL7::Message.parse msg
20
+ end
21
+ end
22
+
23
+ private
24
+ def hl7?(msg)
25
+ msg.respond_to? :to_hl7
26
+ end
27
+
28
+ def export
29
+ raise "Not implemented"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,65 @@
1
+ module HL7
2
+ class Exporter::Csv < HL7::Exporter
3
+ attr_accessor :template
4
+
5
+ def export
6
+ template % data
7
+ end
8
+
9
+ def template
10
+ @template ||= default_template
11
+ end
12
+
13
+ private
14
+ def default_template
15
+ %[Sending Facility: %{sending_facility}
16
+ Name: %{patient_name}
17
+ DOB: %{patient_dob}
18
+ Nick: %{nick_name}
19
+ Sex: %{sex}
20
+ test, result, flag, units, reference interval
21
+ %{test_results}
22
+ ]
23
+ end
24
+
25
+ def obr_row_template(observation)
26
+ "#{observation.name}, #{observation.result}, #{observation.flags}, " +
27
+ "#{observation.units}, #{observation.reference_range}"
28
+ end
29
+
30
+ def getDate(date)
31
+ Date.parse(date).strftime("%Y/%m/%d")
32
+ end
33
+
34
+ def sending_facility
35
+ return '' unless message[:MSH]
36
+ message[:MSH].sending_facility || ''
37
+ end
38
+
39
+ def test_results
40
+ message[:OBR].children.map{ |obr|
41
+ observation_row(obr)
42
+ }.join("\n")
43
+ end
44
+
45
+ def observation_row(obr)
46
+ observation = HL7::Exporter::Observation.new(obr)
47
+ obr_row_template(observation)
48
+ end
49
+
50
+ def patient
51
+ @patient ||= HL7::Exporter::Patient.new(message[:PID])
52
+ end
53
+
54
+ def data
55
+ {
56
+ sending_facility: sending_facility,
57
+ patient_name: patient.name,
58
+ patient_dob: getDate(patient.dob),
59
+ nick_name: patient.nick_name,
60
+ sex: patient.sex,
61
+ test_results: test_results,
62
+ }
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ module HL7
2
+ class Exporter::Observation
3
+ attr_accessor :obr
4
+
5
+ def initialize(obr)
6
+ @obr = obr
7
+ end
8
+
9
+ def name
10
+ obr.observation_id.split('^')[1].sub(",","")
11
+ end
12
+
13
+ def result
14
+ obr.observation_value
15
+ end
16
+
17
+ def units
18
+ obr.units
19
+ end
20
+
21
+ def flags
22
+ obr.abnormal_flags
23
+ end
24
+
25
+ def reference_range
26
+ obr.references_range
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module HL7
2
+ class Exporter::Patient
3
+ def initialize(pid)
4
+ @pid_patient_name = pid.patient_name.split("^")
5
+ @pid_sex = pid.admin_sex
6
+ @pid_dob = pid.patient_dob
7
+ end
8
+
9
+ def name
10
+ "#{patient_data[1]} #{patient_data[0]}"
11
+ end
12
+
13
+ def nick_name
14
+ "#{patient_data[4]}"
15
+ end
16
+
17
+ def sex
18
+ @pid_sex ? 'Female' : 'Male'
19
+ end
20
+
21
+ def dob
22
+ @pid_dob
23
+ end
24
+
25
+ def patient_data
26
+ @patient_name_data ||= @pid_patient_name
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module HL7
2
+ class Exporter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ Sending Facility: TEST_LAB_INC
2
+ Name: FirstName LastName
3
+ DOB: 1976/02/28
4
+ Nick: NickName
5
+ Sex: Female
6
+ test, result, flag, units, reference interval
7
+ Cholesterol Total, 232, H, mg/dL, 100-199
8
+ Triglycerides, 179, H, mg/dL, 0-149
9
+ HDL Cholesterol, 40, , mg/dL, >39
@@ -0,0 +1,4 @@
1
+ test, result, flag, units, reference interval
2
+ Cholesterol Total, 232, H, mg/dL, 100-199
3
+ Triglycerides, 179, H, mg/dL, 0-149
4
+ HDL Cholesterol, 40, , mg/dL, >39
@@ -0,0 +1,7 @@
1
+ MSH|^~\&|SOURCE|TEST_LAB_INC|HEALTH|382715520|2014100914484648||ORU^R01|0129938170710091448|P|2.3|
2
+ PID|1||333||LastName^FirstName^MiddleInitial^SR^NickName||19760228|F||2106-3^White^HL70005^CAUC^Caucasian^L||||||
3
+ ORC|RE|35748030580^LAB|35748030580^LAB||||||201312240000|||FEDA^^^^^^^L
4
+ OBR|1|35748030580^LAB|35748030580^LAB|221010^Lipid Panel w/ Chol/HDL Ratio^L|||201312230656|||||||201312240329||||||35748030580||201312241108|||F
5
+ OBX|1|NM|001065^Cholesterol, Total^L^2093-3^Cholesterol^LN||232|mg/dL|100-199|H||N|F|20120910||201312241053|01
6
+ OBX|2|NM|001172^Triglycerides^L^2571-8^Triglyceride^LN||179|mg/dL|0-149|H||N|F|20120910||201312241053|01
7
+ OBX|3|NM|011817^HDL Cholesterol^L^2085-9^Cholesterol.in HDL^LN||40|mg/dL|>39|||N|F|20020107||201312241053|01
@@ -0,0 +1,13 @@
1
+ require 'hl7-exporter'
2
+ message = %[MSH|^~\&|SOURCE|TEST_LAB_INC|HEALTH|382715520|2014100914484648||ORU^R01|0129938170710091448|P|2.3|
3
+ \rPID|1||333||LastName^FirstName^MiddleInitial^SR^NickName||19760228|F||2106-3^White^HL70005^CAUC^Caucasian^L||||||
4
+ \rORC|RE|35748030580^LAB|35748030580^LAB||||||201312240000|||FEDA^^^^^^^L
5
+ \rOBR|1|35748030580^LAB|35748030580^LAB|221010^Lipid Panel w/ Chol/HDL Ratio^L|||201312230656|||||||201312240329||||||35748030580||201312241108|||F
6
+ \rOBX|1|NM|001065^Cholesterol, Total^L^2093-3^Cholesterol^LN||232|mg/dL|100-199|H||N|F|20120910||201312241053|01
7
+ \rOBX|2|NM|001172^Triglycerides^L^2571-8^Triglyceride^LN||179|mg/dL|0-149|H||N|F|20120910||201312241053|01
8
+ \rOBX|3|NM|011817^HDL Cholesterol^L^2085-9^Cholesterol.in HDL^LN||40|mg/dL|>39|||N|F|20020107||201312241053|01
9
+ ]
10
+
11
+ hl7_message = HL7::Message.parse(message)
12
+ exporter = HL7::Exporter::Csv.new(hl7_message)
13
+ exporter.export
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ describe HL7::Exporter::Csv do
3
+ let(:message) {
4
+ %[MSH|^~\&|SOURCE|TEST_LAB_INC|HEALTH|382715520|2014100914484648||ORU^R01|0129938170710091448|P|2.3|
5
+ \rPID|1||333||LastName^FirstName^MiddleInitial^SR^NickName||19760228|F||2106-3^White^HL70005^CAUC^Caucasian^L||||||
6
+ \rORC|RE|35748030580^LAB|35748030580^LAB||||||201312240000|||FEDA^^^^^^^L
7
+ \rOBR|1|35748030580^LAB|35748030580^LAB|221010^Lipid Panel w/ Chol/HDL Ratio^L|||201312230656|||||||201312240329||||||35748030580||201312241108|||F
8
+ \rOBX|1|NM|001065^Cholesterol, Total^L^2093-3^Cholesterol^LN||232|mg/dL|100-199|H||N|F|20120910||201312241053|01
9
+ \rOBX|2|NM|001172^Triglycerides^L^2571-8^Triglyceride^LN||179|mg/dL|0-149|H||N|F|20120910||201312241053|01
10
+ \rOBX|3|NM|011817^HDL Cholesterol^L^2085-9^Cholesterol.in HDL^LN||40|mg/dL|>39|||N|F|20020107||201312241053|01
11
+ ]
12
+ }
13
+
14
+ let(:exporter) { HL7::Exporter::Csv.new(hl7_message) }
15
+ subject(:csv) { exporter.export.split("\n") }
16
+
17
+ context "with a full message" do
18
+ let(:hl7_message) { HL7::Message.parse(message) }
19
+
20
+ it { expect(csv[0]).to eq "Sending Facility: TEST_LAB_INC" }
21
+ it { expect(csv[1]).to eq "Name: FirstName LastName" }
22
+ it { expect(csv[2]).to eq "DOB: 1976/02/28" }
23
+ it { expect(csv[3]).to eq "Nick: NickName" }
24
+ it { expect(csv[4]).to eq "Sex: Female" }
25
+ it { expect(csv[5]).to eq "test, result, flag, units, reference interval" }
26
+ it { expect(csv[6]).to eq "Cholesterol Total, 232, H, mg/dL, 100-199" }
27
+ it { expect(csv[8]).to include "Cholesterol" }
28
+ end
29
+
30
+ context "with an empty message" do
31
+ let(:hl7_message) { "" }
32
+
33
+ it { expect { exporter.export }.to raise_error(HL7::ParseError) }
34
+ end
35
+
36
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require 'ruby-hl7'
3
+
4
+ # Development gems
5
+ # require 'byebug'
6
+ # require 'pry'
7
+ # require 'looksee'
8
+
9
+ LOCALE_PATH = File.expand_path(File.dirname(__FILE__) + '/../lib/hl7')
10
+
11
+ require LOCALE_PATH + '/exporter'
12
+ require LOCALE_PATH + '/exporter/csv'
13
+ require LOCALE_PATH + '/exporter/observation'
14
+ require LOCALE_PATH + '/exporter/patient'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hl7-exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Enrique Carlos Mogollan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-hl7
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ description: A simple library to export messages from the ruby-hl7 gem
70
+ email:
71
+ - emogollan@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - hl7-exporter.gemspec
84
+ - lib/hl7-exporter.rb
85
+ - lib/hl7/exporter.rb
86
+ - lib/hl7/exporter/csv.rb
87
+ - lib/hl7/exporter/observation.rb
88
+ - lib/hl7/exporter/patient.rb
89
+ - lib/hl7/exporter/version.rb
90
+ - spec/example/test1.csv
91
+ - spec/example/test1_custom_template.csv
92
+ - spec/example/test_1.hl7
93
+ - spec/generate_case_base.rb
94
+ - spec/hl7/exporter_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.6
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A library to export messages from the ruby-hl7 gem
120
+ test_files:
121
+ - spec/example/test1.csv
122
+ - spec/example/test1_custom_template.csv
123
+ - spec/example/test_1.hl7
124
+ - spec/generate_case_base.rb
125
+ - spec/hl7/exporter_spec.rb
126
+ - spec/spec_helper.rb