healthcare_phony 0.7s.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/gem-push.yml +42 -42
  3. data/.github/workflows/ruby.yml +33 -33
  4. data/.gitignore +63 -63
  5. data/.rdoc_options +23 -23
  6. data/.rubocop.yml +10 -10
  7. data/CODE_OF_CONDUCT.md +84 -84
  8. data/Gemfile +8 -8
  9. data/LICENSE.txt +21 -21
  10. data/README.md +365 -365
  11. data/Rakefile +12 -12
  12. data/VERSION +1 -1
  13. data/examples/bigger_csv_example.erb +3 -3
  14. data/examples/phony_adt_sender.rb +111 -111
  15. data/examples/phony_adt_sender.yml +11 -11
  16. data/examples/phony_csv.yml +4 -4
  17. data/healthcare_phony.gemspec +36 -36
  18. data/lib/healthcare_phony.rb +138 -139
  19. data/lib/healthcare_phony/address.rb +89 -89
  20. data/lib/healthcare_phony/assigning_authority.rb +6 -6
  21. data/lib/healthcare_phony/cell_phone_number.rb +20 -20
  22. data/lib/healthcare_phony/data_files/address_type.yml +7 -7
  23. data/lib/healthcare_phony/data_files/adt_event_types.yml +59 -59
  24. data/lib/healthcare_phony/data_files/degree.yml +9 -9
  25. data/lib/healthcare_phony/data_files/discharge_disposition.yml +15 -15
  26. data/lib/healthcare_phony/data_files/ethnic_group.yml +9 -9
  27. data/lib/healthcare_phony/data_files/hl7_message_types.yml +4 -4
  28. data/lib/healthcare_phony/data_files/language.yml +7 -7
  29. data/lib/healthcare_phony/data_files/marital_status.yml +49 -49
  30. data/lib/healthcare_phony/data_files/mdm_event_types.yml +12 -12
  31. data/lib/healthcare_phony/data_files/oru_event_types.yml +2 -2
  32. data/lib/healthcare_phony/data_files/race.yml +13 -13
  33. data/lib/healthcare_phony/data_files/religion.yml +250 -250
  34. data/lib/healthcare_phony/data_files/tele_equipment_type.yml +10 -10
  35. data/lib/healthcare_phony/data_files/tele_use_code.yml +9 -9
  36. data/lib/healthcare_phony/diagnosis.rb +12 -12
  37. data/lib/healthcare_phony/doctor.rb +26 -26
  38. data/lib/healthcare_phony/email.rb +25 -25
  39. data/lib/healthcare_phony/ethnic_group.rb +34 -34
  40. data/lib/healthcare_phony/gender.rb +22 -22
  41. data/lib/healthcare_phony/helper.rb +72 -72
  42. data/lib/healthcare_phony/hl7_message.rb +159 -159
  43. data/lib/healthcare_phony/home_phone_number.rb +20 -20
  44. data/lib/healthcare_phony/identifier.rb +23 -23
  45. data/lib/healthcare_phony/insurance.rb +6 -6
  46. data/lib/healthcare_phony/language.rb +30 -30
  47. data/lib/healthcare_phony/marital_status.rb +31 -31
  48. data/lib/healthcare_phony/patient.rb +114 -114
  49. data/lib/healthcare_phony/patient_visit.rb +97 -97
  50. data/lib/healthcare_phony/person_name.rb +104 -104
  51. data/lib/healthcare_phony/phone_number.rb +85 -85
  52. data/lib/healthcare_phony/procedure.rb +6 -6
  53. data/lib/healthcare_phony/race.rb +31 -31
  54. data/lib/healthcare_phony/religion.rb +32 -32
  55. data/lib/healthcare_phony/templates/csv_example.erb +3 -3
  56. data/lib/healthcare_phony/version.rb +5 -5
  57. data/lib/healthcare_phony/visit_admission.rb +53 -53
  58. data/lib/healthcare_phony/visit_discharge.rb +62 -62
  59. data/lib/healthcare_phony/visit_doctors.rb +19 -19
  60. data/lib/healthcare_phony/visit_location.rb +106 -106
  61. data/lib/healthcare_phony/visit_type.rb +8 -8
  62. data/lib/healthcare_phony/work_phone_number.rb +20 -20
  63. metadata +5 -5
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
10
- end
11
-
12
- task default: :test
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7s.0
1
+ 0.7.0
@@ -1,4 +1,4 @@
1
- <% if write_header %>
2
- Patient_Identifier,First_Name,Middle_Name,Last_Name,Address_1,City,State,Zip,Home_Phone,Work_Phone,Cell_Phone,DOB,Gender,SSN
3
- <% end %>
1
+ <% if write_header %>
2
+ Patient_Identifier,First_Name,Middle_Name,Last_Name,Address_1,City,State,Zip,Home_Phone,Work_Phone,Cell_Phone,DOB,Gender,SSN
3
+ <% end %>
4
4
  "<%= patient.medical_record_number.identifier %>","<%= patient.names[0].given_name %>","<%= patient.names[0].middle_name %>","<%= patient.names[0].family_name %>","<%= patient.addresses[0].address_line1 %>","<%= patient.addresses[0].city %>","<%= patient.addresses[0].state %>","<%= patient.addresses[0].postal_code %>","(<%= patient.home_phone.area_code %>)<%= patient.home_phone.exchange_code %>-<%= patient.home_phone.subscriber_number %>","(<%= patient.work_phone.area_code %>)<%= patient.work_phone.exchange_code %>-<%= patient.work_phone.subscriber_number %>","(<%= patient.cell_phone.area_code %>)<%= patient.cell_phone.exchange_code %>-<%= patient.cell_phone.subscriber_number %>","<%= patient.date_of_birth.to_s %>","<%= patient.gender.code %>","<%= patient.ssn %>"
@@ -1,111 +1,111 @@
1
- # frozen_string_literal: true
2
-
3
- require 'socket'
4
- require 'healthcare_phony'
5
- require 'optparse'
6
- require 'psych'
7
-
8
- class PhonyAdtSender
9
- attr_reader :host, :port, :number_messages, :message_parameters, :mllp_start, :mllp_end
10
-
11
- def initialize
12
- @message_parameters = {}
13
- parse
14
- end
15
-
16
- def send
17
- puts "Sending #{@number_messages} messages to #{@host}:#{@port}"
18
-
19
- @number_messages.to_i.times do
20
- t = TCPSocket.new(@host, @port)
21
-
22
- m = HealthcarePhony::Adt.new(@message_parameters)
23
- # #{@mllp_start}
24
- t.send "#{[@mllp_start].pack("H*")}#{m.to_s}#{[@mllp_end].pack("H*")}", 0
25
-
26
- pp "Message With ID #{m.hl7_message.message_control_id} sent..."
27
-
28
- reading_response = true
29
- ack_response = ''
30
- while reading_response
31
- current_read = t.read(1)
32
- ack_response += current_read unless current_read.nil?
33
- reading_response = false if current_read.nil?
34
- end
35
-
36
- pp "ACK: #{ack_response}"
37
-
38
- t.close
39
- end
40
- end
41
-
42
- private
43
-
44
- def parse
45
- options = {}
46
- optparse = OptionParser.new do |parser|
47
- parser.banner = 'Usage: phony_adt_sender.rb [options]'
48
- parser.separator ''
49
-
50
- parser.on('-n', '--number NUMBER', Integer, 'Number of messages to send') do |number_messages|
51
- options[:number_messages] = number_messages
52
- end
53
-
54
- parser.on('-h', '--host HOST', String, 'IP or DNS for listening host') do |host|
55
- options[:host] = host
56
- end
57
-
58
- parser.on('-p', '--port PORT', Integer, 'Listening port') do |port|
59
- options[:port] = port
60
- end
61
-
62
- parser.on('-c', '--config CONFIGFILE', String, 'Path to configuration file (YAML) for message parameters') do |config|
63
- options[:config] = config
64
- end
65
-
66
- parser.on('--mllp-start HEX',
67
- 'Hex character(s) to denote start of message bytes. In form nn (example 0b for vertical tab) or nnnn (example 1c0d for file separator & carriage return)') do |mllp_start|
68
- options[:mllp_start] = mllp_start
69
- end
70
-
71
- parser.on('--mllp-end HEX', String,
72
- 'Hex character(s) to denote start of message bytes. In form nn (example 0b for vertical tab) or nnnn (example 1c0d for file separator & carriage return)') do |mllp_end|
73
- options[:mllp_end] = mllp_end
74
- end
75
-
76
- parser.on('--help', 'Show this message') do
77
- puts parser
78
- exit
79
- end
80
- end
81
-
82
- begin
83
- optparse.parse!
84
- mandatory = %i[host port number_messages]
85
- missing = mandatory.select { |param| options[param].nil? }
86
- raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
87
- rescue OptionParser::InvalidOption, OptionParser::MissingArgument
88
- puts $!.to_s
89
- puts optparse
90
- exit
91
- end
92
-
93
- @host = options[:host]
94
- @port = options[:port]
95
- @number_messages = options[:number_messages]
96
- @message_parameters = Psych.load_file(options[:config]) unless options[:config].nil?
97
- @mllp_start = if options[:mllp_start].nil?
98
- '0b'
99
- else
100
- options[:mllp_start]
101
- end
102
- @mllp_end = if options[:mllp_end].nil?
103
- '1c0d'
104
- else
105
- options[:mllp_end]
106
- end
107
- end
108
- end
109
-
110
- pas = PhonyAdtSender.new
111
- pas.send
1
+ # frozen_string_literal: true
2
+
3
+ require 'socket'
4
+ require 'healthcare_phony'
5
+ require 'optparse'
6
+ require 'psych'
7
+
8
+ class PhonyAdtSender
9
+ attr_reader :host, :port, :number_messages, :message_parameters, :mllp_start, :mllp_end
10
+
11
+ def initialize
12
+ @message_parameters = {}
13
+ parse
14
+ end
15
+
16
+ def send
17
+ puts "Sending #{@number_messages} messages to #{@host}:#{@port}"
18
+
19
+ @number_messages.to_i.times do
20
+ t = TCPSocket.new(@host, @port)
21
+
22
+ m = HealthcarePhony::Adt.new(@message_parameters)
23
+ # #{@mllp_start}
24
+ t.send "#{[@mllp_start].pack("H*")}#{m.to_s}#{[@mllp_end].pack("H*")}", 0
25
+
26
+ pp "Message With ID #{m.hl7_message.message_control_id} sent..."
27
+
28
+ reading_response = true
29
+ ack_response = ''
30
+ while reading_response
31
+ current_read = t.read(1)
32
+ ack_response += current_read unless current_read.nil?
33
+ reading_response = false if current_read.nil?
34
+ end
35
+
36
+ pp "ACK: #{ack_response}"
37
+
38
+ t.close
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def parse
45
+ options = {}
46
+ optparse = OptionParser.new do |parser|
47
+ parser.banner = 'Usage: phony_adt_sender.rb [options]'
48
+ parser.separator ''
49
+
50
+ parser.on('-n', '--number NUMBER', Integer, 'Number of messages to send') do |number_messages|
51
+ options[:number_messages] = number_messages
52
+ end
53
+
54
+ parser.on('-h', '--host HOST', String, 'IP or DNS for listening host') do |host|
55
+ options[:host] = host
56
+ end
57
+
58
+ parser.on('-p', '--port PORT', Integer, 'Listening port') do |port|
59
+ options[:port] = port
60
+ end
61
+
62
+ parser.on('-c', '--config CONFIGFILE', String, 'Path to configuration file (YAML) for message parameters') do |config|
63
+ options[:config] = config
64
+ end
65
+
66
+ parser.on('--mllp-start HEX',
67
+ 'Hex character(s) to denote start of message bytes. In form nn (example 0b for vertical tab) or nnnn (example 1c0d for file separator & carriage return)') do |mllp_start|
68
+ options[:mllp_start] = mllp_start
69
+ end
70
+
71
+ parser.on('--mllp-end HEX', String,
72
+ 'Hex character(s) to denote start of message bytes. In form nn (example 0b for vertical tab) or nnnn (example 1c0d for file separator & carriage return)') do |mllp_end|
73
+ options[:mllp_end] = mllp_end
74
+ end
75
+
76
+ parser.on('--help', 'Show this message') do
77
+ puts parser
78
+ exit
79
+ end
80
+ end
81
+
82
+ begin
83
+ optparse.parse!
84
+ mandatory = %i[host port number_messages]
85
+ missing = mandatory.select { |param| options[param].nil? }
86
+ raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
87
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
88
+ puts $!.to_s
89
+ puts optparse
90
+ exit
91
+ end
92
+
93
+ @host = options[:host]
94
+ @port = options[:port]
95
+ @number_messages = options[:number_messages]
96
+ @message_parameters = Psych.load_file(options[:config]) unless options[:config].nil?
97
+ @mllp_start = if options[:mllp_start].nil?
98
+ '0b'
99
+ else
100
+ options[:mllp_start]
101
+ end
102
+ @mllp_end = if options[:mllp_end].nil?
103
+ '1c0d'
104
+ else
105
+ options[:mllp_end]
106
+ end
107
+ end
108
+ end
109
+
110
+ pas = PhonyAdtSender.new
111
+ pas.send
@@ -1,12 +1,12 @@
1
- ---
2
- :message_sending_facility: HOSP1,HOSP2,HOSP3
3
- :message_sending_application: RUBY
4
- :message_receiving_application: MIRTH
5
- :message_receiving_facility: NCSAS
6
- :message_version: '2.5.1'
7
- :patient_class: I,O,E
8
- :adt_events: A01,A03,A04,A08
9
- :message_control_id_pattern: HEALTHCARE_PHONY_\d{15}
10
- :message_processing_id: P
11
- :given_name_append: ZZFAKE
1
+ ---
2
+ :message_sending_facility: HOSP1,HOSP2,HOSP3
3
+ :message_sending_application: RUBY
4
+ :message_receiving_application: MIRTH
5
+ :message_receiving_facility: NCSAS
6
+ :message_version: '2.5.1'
7
+ :patient_class: I,O,E
8
+ :adt_events: A01,A03,A04,A08
9
+ :message_control_id_pattern: HEALTHCARE_PHONY_\d{15}
10
+ :message_processing_id: P
11
+ :given_name_append: ZZFAKE
12
12
  :family_name_append: ZZPHONY
@@ -1,5 +1,5 @@
1
- ---
2
- :given_name_append: ZZFAKE
3
- :family_name_append: ZZPHONY
4
- :number_of_rows: 10000
1
+ ---
2
+ :given_name_append: ZZFAKE
3
+ :family_name_append: ZZPHONY
4
+ :number_of_rows: 1000
5
5
  :template_file: "D:/Users/amoody/RubymineProjects/healthcare_phony/examples/bigger_csv_example.erb"
@@ -1,36 +1,36 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'healthcare_phony/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'healthcare_phony'
9
- spec.version = HealthcarePhony::VERSION
10
- spec.authors = ['Austin Moody']
11
- spec.email = ['austin.moody@hey.com']
12
-
13
- spec.summary = 'A utility to create fake data and files for healthcare integration testing'
14
- spec.homepage = 'http://github.com/austinmoody/healthcare_phony'
15
- spec.license = 'MIT'
16
-
17
- # Specify which files should be added to the gem when it is released.
18
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
- end
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ['lib']
25
-
26
- spec.add_development_dependency 'bundler', '~> 2.2'
27
- spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'rake', '~> 12.3.3'
29
-
30
- spec.required_ruby_version = '>= 2.6'
31
- spec.required_rubygems_version = '>= 2.6.10'
32
-
33
- spec.add_dependency 'faker', '~> 2.13.0'
34
- spec.add_dependency 'psych', '~> 3.1.0'
35
- spec.add_dependency 'regexp-examples', '~> 1.5.1'
36
- end
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'healthcare_phony/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'healthcare_phony'
9
+ spec.version = HealthcarePhony::VERSION
10
+ spec.authors = ['Austin Moody']
11
+ spec.email = ['austin.moody@hey.com']
12
+
13
+ spec.summary = 'A utility to create fake data and files for healthcare integration testing'
14
+ spec.homepage = 'http://github.com/austinmoody/healthcare_phony'
15
+ spec.license = 'MIT'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 2.2'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'rake', '~> 12.3.3'
29
+
30
+ spec.required_ruby_version = '>= 2.6'
31
+ spec.required_rubygems_version = '>= 2.6.10'
32
+
33
+ spec.add_dependency 'faker', '~> 2.13.0'
34
+ spec.add_dependency 'psych', '~> 3.1.0'
35
+ spec.add_dependency 'regexp-examples', '~> 1.5.1'
36
+ end
@@ -1,139 +1,138 @@
1
- # frozen_string_literal: true
2
-
3
- require 'erb'
4
- require 'faker'
5
- require 'psych'
6
- require 'regexp-examples'
7
-
8
- Dir[File.join(__dir__, 'healthcare_phony', '*.rb')].sort.each { |file| require file }
9
-
10
- Faker::Config.locale = 'en-US'
11
-
12
- module HealthcarePhony
13
- class Adt
14
- attr_reader :template, :adt_arguments, :hl7_message, :patient, :visit
15
-
16
- def initialize(init_args = {})
17
- @adt_arguments = init_args
18
- @adt_arguments[:message_types] = 'ADT'
19
- set_template
20
- @hl7_message = Hl7Message.new(@adt_arguments)
21
- @patient = Patient.new(@adt_arguments)
22
- @visit = PatientVisit.new(@adt_arguments.merge({ visit_type: set_visit_type }))
23
- end
24
-
25
- def to_s
26
- erb_template = ERB.new(@template)
27
- erb_template.result_with_hash({ patient: @patient, hl7: @hl7_message, visit: @visit })
28
- end
29
-
30
- private
31
-
32
- def set_template
33
- unless @adt_arguments[:template].nil?
34
- @template = @adt_arguments[:template]
35
- return
36
- end
37
- @template = if @adt_arguments[:template_file].nil?
38
- File.read(File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'adt_example.erb'))
39
- else
40
- File.read(@adt_arguments[:template_file])
41
- end
42
- end
43
-
44
- def set_visit_type
45
- case @hl7_message.trigger_event
46
- when 'A01'
47
- HealthcarePhony::VisitType::ADMIT
48
- when 'A03'
49
- HealthcarePhony::VisitType::DISCHARGE
50
- when 'A04'
51
- HealthcarePhony::VisitType::REGISTRATION
52
- else
53
- HealthcarePhony::VisitType::OTHER
54
- end
55
- end
56
- end
57
-
58
- class CsvFile
59
- attr_reader :template_file, :number_of_rows, :csv_arguments
60
-
61
- def initialize(init_args = {}) #(number_of_rows, template_file = nil)
62
- @csv_arguments = init_args
63
- @number_of_rows = @csv_arguments[:number_of_rows] #@csv_arguments[:number_of_rows].nil? ? 1 : @csv_arguments[:number_of_rows]
64
- set_template
65
- end
66
-
67
- def to_s
68
- template = ERB.new(File.read(@template_file), trim_mode: '<>')
69
- counter = 0
70
- output_string = ''
71
- while counter < @number_of_rows
72
- output_string += "#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n"
73
- counter += 1
74
- end
75
- output_string
76
- end
77
-
78
- def to_file(file_name)
79
- template = ERB.new(File.read(@template_file), trim_mode: '<>')
80
- counter = 0
81
- #output_file = File.open(file_name, 'w')
82
- File.open(file_name, 'w') do |line|
83
- while counter < @number_of_rows
84
- #output_file.write("#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n")
85
- line.puts "#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n"
86
- counter += 1
87
- end
88
- end
89
- #output_file.close
90
-
91
- end
92
-
93
- private
94
-
95
- def set_template
96
- unless @csv_arguments[:template].nil?
97
- @template_file = @csv_arguments[:template]
98
- return
99
- end
100
- @template_file = if @csv_arguments[:template_file].nil?
101
- File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb') #File.read(File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb'))
102
- else
103
- @csv_arguments[:template_file]
104
- end
105
- end
106
- end
107
- end
108
-
109
- class String
110
- def to_hl7date
111
- self
112
- end
113
-
114
- def to_hl7datetime
115
- self
116
- end
117
- end
118
-
119
- class Date
120
- def to_hl7date
121
- strftime('%Y%m%d')
122
- end
123
- end
124
-
125
- class Time
126
- def to_hl7datetime
127
- strftime('%Y%m%d%H%M%S')
128
- end
129
- end
130
-
131
- class NilClass
132
- def to_hl7datetime
133
- ''
134
- end
135
-
136
- def to_hl7date
137
- ''
138
- end
139
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'faker'
5
+ require 'psych'
6
+ require 'regexp-examples'
7
+
8
+ Dir[File.join(__dir__, 'healthcare_phony', '*.rb')].sort.each { |file| require file }
9
+
10
+ Faker::Config.locale = 'en-US'
11
+
12
+ module HealthcarePhony
13
+ class Adt
14
+ attr_reader :template, :adt_arguments, :hl7_message, :patient, :visit
15
+
16
+ def initialize(init_args = {})
17
+ @adt_arguments = init_args
18
+ @adt_arguments[:message_types] = 'ADT'
19
+ set_template
20
+ @hl7_message = Hl7Message.new(@adt_arguments)
21
+ @patient = Patient.new(@adt_arguments)
22
+ @visit = PatientVisit.new(@adt_arguments.merge({ visit_type: set_visit_type }))
23
+ end
24
+
25
+ def to_s
26
+ erb_template = ERB.new(@template)
27
+ erb_template.result_with_hash({ patient: @patient, hl7: @hl7_message, visit: @visit })
28
+ end
29
+
30
+ private
31
+
32
+ def set_template
33
+ unless @adt_arguments[:template].nil?
34
+ @template = @adt_arguments[:template]
35
+ return
36
+ end
37
+ @template = if @adt_arguments[:template_file].nil?
38
+ File.read(File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'adt_example.erb'))
39
+ else
40
+ File.read(@adt_arguments[:template_file])
41
+ end
42
+ end
43
+
44
+ def set_visit_type
45
+ case @hl7_message.trigger_event
46
+ when 'A01'
47
+ HealthcarePhony::VisitType::ADMIT
48
+ when 'A03'
49
+ HealthcarePhony::VisitType::DISCHARGE
50
+ when 'A04'
51
+ HealthcarePhony::VisitType::REGISTRATION
52
+ else
53
+ HealthcarePhony::VisitType::OTHER
54
+ end
55
+ end
56
+ end
57
+
58
+ class CsvFile
59
+ attr_reader :template_file, :number_of_rows, :csv_arguments
60
+
61
+ def initialize(init_args = {}) #(number_of_rows, template_file = nil)
62
+ @csv_arguments = init_args
63
+ @number_of_rows = @csv_arguments[:number_of_rows] #@csv_arguments[:number_of_rows].nil? ? 1 : @csv_arguments[:number_of_rows]
64
+ set_template
65
+ end
66
+
67
+ def to_s
68
+ template = ERB.new(File.read(@template_file), trim_mode: '<>')
69
+ counter = 0
70
+ output_string = ''
71
+ while counter < @number_of_rows
72
+ output_string += "#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n"
73
+ counter += 1
74
+ end
75
+ output_string
76
+ end
77
+
78
+ def to_file(file_name)
79
+ template = ERB.new(File.read(@template_file), trim_mode: '<>')
80
+ counter = 0
81
+ output_file = File.open(file_name, 'w')
82
+ while counter < @number_of_rows
83
+ output_file.write("#{template.result_with_hash({ patient: Patient.new(@csv_arguments), write_header: counter.zero? })}\n")
84
+ counter += 1
85
+ end
86
+ output_file.close
87
+
88
+ return output_file
89
+
90
+ end
91
+
92
+ private
93
+
94
+ def set_template
95
+ unless @csv_arguments[:template].nil?
96
+ @template_file = @csv_arguments[:template]
97
+ return
98
+ end
99
+ @template_file = if @csv_arguments[:template_file].nil?
100
+ File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb') #File.read(File.join(File.dirname(__FILE__), 'healthcare_phony', 'templates', 'csv_example.erb'))
101
+ else
102
+ @csv_arguments[:template_file]
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ class String
109
+ def to_hl7date
110
+ self
111
+ end
112
+
113
+ def to_hl7datetime
114
+ self
115
+ end
116
+ end
117
+
118
+ class Date
119
+ def to_hl7date
120
+ strftime('%Y%m%d')
121
+ end
122
+ end
123
+
124
+ class Time
125
+ def to_hl7datetime
126
+ strftime('%Y%m%d%H%M%S')
127
+ end
128
+ end
129
+
130
+ class NilClass
131
+ def to_hl7datetime
132
+ ''
133
+ end
134
+
135
+ def to_hl7date
136
+ ''
137
+ end
138
+ end