medivo 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Medivo
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
@@ -2,62 +2,33 @@ module Medivo
2
2
  module FdfGenerator
3
3
 
4
4
  def self.file(info)
5
- afile = Tempfile.new('fdf', :encoding => 'ascii-8bit')
6
- afile.write "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"; # header
7
- afile.write "1 0 obj\x0d<< " # open the Root dictionary
8
- afile.write "\x0d/FDF << " # open the FDF dictionary
9
- afile.write "/Fields [ " # open the form Fields array
5
+ PdfGenerator.tmp_pdf do |afile|
6
+ afile.write "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"; # header
7
+ afile.write "1 0 obj\x0d<< " # open the Root dictionary
8
+ afile.write "\x0d/FDF << " # open the FDF dictionary
9
+ afile.write "/Fields [ " # open the form Fields array
10
10
 
11
- info.each { |key, value|
12
- if value.class == Hash
13
- value.each { |sub_key, sub_value|
14
- afile.write '<< /T (' + key.to_s + '_' + sub_key.to_s + ') /V '
15
- afile.write '(' + escape_data(sub_value) + ') /ClrF 2 /ClrFf 1 >> '
16
- }
17
- else
18
- afile.write '<< /T (' + key.to_s + ') /V (' + escape_data(value) + ') /ClrF 2 /ClrFf 1 >> '
19
- end
20
- }
11
+ info.each { |key, value|
12
+ if value.class == Hash
13
+ value.each { |sub_key, sub_value|
14
+ afile.write '<< /T (' + key.to_s + '_' + sub_key.to_s + ') /V '
15
+ afile.write '(' + escape_data(sub_value) + ') /ClrF 2 /ClrFf 1 >> '
16
+ }
17
+ else
18
+ afile.write '<< /T (' + key.to_s + ') /V (' + escape_data(value) + ') /ClrF 2 /ClrFf 1 >> '
19
+ end
20
+ }
21
21
 
22
- afile.write "] \x0d" # close the Fields array
23
- afile.write ">> \x0d" # close the FDF dictionary
24
- afile.write ">> \x0dendobj\x0d" # close the Root dictionary
22
+ afile.write "] \x0d" # close the Fields array
23
+ afile.write ">> \x0d" # close the FDF dictionary
24
+ afile.write ">> \x0dendobj\x0d" # close the Root dictionary
25
25
 
26
- # trailer note the "1 0 R" reference to "1 0 obj" above
27
- afile.write "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d"
28
- afile.write "%%EOF\x0d\x0a"
29
- afile.close
30
- afile
26
+ # trailer note the "1 0 R" reference to "1 0 obj" above
27
+ afile.write "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d"
28
+ afile.write "%%EOF\x0d\x0a"
29
+ end
31
30
  end
32
31
 
33
- #def self.file(info)
34
- # PdfGenerator.tmp_pdf do |afile|
35
- # afile.write "%FDF-1.2\x0d%\xe2\xe3\xcf\xd3\x0d\x0a"; # header
36
- # afile.write "1 0 obj\x0d<< " # open the Root dictionary
37
- # afile.write "\x0d/FDF << " # open the FDF dictionary
38
- # afile.write "/Fields [ " # open the form Fields array
39
- #
40
- # info.each { |key, value|
41
- # if value.class == Hash
42
- # value.each { |sub_key, sub_value|
43
- # afile.write '<< /T (' + key.to_s + '_' + sub_key.to_s + ') /V '
44
- # afile.write '(' + escape_data(sub_value) + ') /ClrF 2 /ClrFf 1 >> '
45
- # }
46
- # else
47
- # afile.write '<< /T (' + key.to_s + ') /V (' + escape_data(value) + ') /ClrF 2 /ClrFf 1 >> '
48
- # end
49
- # }
50
- #
51
- # afile.write "] \x0d" # close the Fields array
52
- # afile.write ">> \x0d" # close the FDF dictionary
53
- # afile.write ">> \x0dendobj\x0d" # close the Root dictionary
54
- #
55
- # # trailer note the "1 0 R" reference to "1 0 obj" above
56
- # afile.write "trailer\x0d<<\x0d/Root 1 0 R \x0d\x0d>>\x0d"
57
- # afile.write "%%EOF\x0d\x0a"
58
- # end
59
- #end
60
-
61
32
  def self.escape_data(value)
62
33
  value.to_s.strip.gsub(/[\(]/, '\\(').gsub(/[\)]/, '\\)')
63
34
  end
@@ -5,7 +5,7 @@ module Medivo
5
5
  pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
6
6
  yield pdf
7
7
  # if you don't close here the helper method pdf_to_text does not work
8
- # its also a good idea to close the temp file
8
+ # its also a good idea to close the temp file anyway
9
9
  pdf.close
10
10
  pdf
11
11
  end
@@ -15,11 +15,12 @@ module Medivo
15
15
  # variables Hash the hash of variables to fill in
16
16
  #
17
17
  # return pdf File
18
+ #
18
19
  def self.variable_fields(file_path, variables)
19
20
  raise "variables #{variables} should be a hash" unless variables.is_a? Hash
20
21
  tmp_pdf do |pdf|
21
22
  fdf = FdfGenerator.file(variables)
22
- system 'pdftk', file_path, 'fill_form', fdf.path, 'output', pdf.path#, 'flatten'
23
+ system 'pdftk', file_path, 'fill_form', fdf.path, 'output', pdf.path, 'flatten'
23
24
  fdf.unlink
24
25
  end
25
26
  end
@@ -28,13 +29,17 @@ module Medivo
28
29
  # file_path String path to pdf file with variable fields
29
30
  # variables Hash the hash of variables to fill in
30
31
  # images Array of image info like:
31
- # [ {:path=>'/absolute/path/to/image1.jpg', :at=>[x_pos,y_pos]},
32
- # {:path=>'/absolute/path/to/image2.jpg', :at=>[20,800], :width=>20, :height=>40} ]
32
+ # [ {:path=>'/absolute/path/to/image1.jpg', :options=>{ :at=>[x_pos, y_pos]} },
33
+ # {:path=>'/absolute/path/to/image2.jpg', :options=>{ :at=>[20, 800], :width=>20, :height=>40} }
34
+ # ]
33
35
  #
34
36
  # return pdf File
37
+ #
38
+ # NOTE: need to create tmp dir in home directory for temporary image files
39
+ #
35
40
  def self.variable_fields_with_images(file_path, variables, images=[])
36
41
  content_pdf = variable_fields(file_path, variables)
37
- image_path = Rails.root.join "tmp/image_path_#{SecureRandom.hex(6)}_#{Time.now.to_i}.pdf"
42
+ image_path = "#{ENV['HOME']}/tmp/image_path_#{SecureRandom.hex(6)}_#{Time.now.to_i}.pdf"
38
43
  img_pdf = Prawn::Document.generate(image_path) do |pdf|
39
44
  images.each do |img_info|
40
45
  pdf.image img_info[:path], img_info[:options]
@@ -151,3 +151,67 @@ Served asset /medivo/markerB.png - 200 OK (3ms)
151
151
 
152
152
  Started GET "/assets/medivo/arrow.png" for 127.0.0.1 at 2011-11-06 19:34:34 -0500
153
153
  Served asset /medivo/arrow.png - 200 OK (6ms)
154
+
155
+
156
+ Started GET "/medivo/labs/lab_data?zip_code=90210" for 127.0.0.1 at 2011-11-06 21:00:16 -0500
157
+ Processing by Medivo::LabsController#lab_data as HTML
158
+ Parameters: {"zip_code"=>"90210"}
159
+ Completed 200 OK in 322ms (Views: 1.1ms)
160
+
161
+
162
+ Started GET "/labs/lab_search?zip_code=90210" for 127.0.0.1 at 2011-11-06 21:00:19 -0500
163
+ Processing by LabsController#lab_search as HTML
164
+ Parameters: {"zip_code"=>"90210"}
165
+ Completed 200 OK in 293ms (Views: 99.7ms)
166
+
167
+
168
+ Started GET "/assets/application.css" for 127.0.0.1 at 2011-11-06 21:00:20 -0500
169
+ Served asset /application.css - 200 OK (5ms)
170
+
171
+
172
+ Started GET "/assets/application.js" for 127.0.0.1 at 2011-11-06 21:00:20 -0500
173
+ Served asset /application.js - 200 OK (24ms)
174
+
175
+
176
+ Started GET "/assets/medivo/markerA.png" for 127.0.0.1 at 2011-11-06 21:00:20 -0500
177
+ Served asset /medivo/markerA.png - 200 OK (2ms)
178
+
179
+
180
+ Started GET "/assets/medivo/markerB.png" for 127.0.0.1 at 2011-11-06 21:00:20 -0500
181
+ Served asset /medivo/markerB.png - 200 OK (2ms)
182
+
183
+
184
+ Started GET "/assets/medivo/arrow.png" for 127.0.0.1 at 2011-11-06 21:00:21 -0500
185
+ Served asset /medivo/arrow.png - 200 OK (2ms)
186
+
187
+
188
+ Started GET "/medivo/labs/lab_data?zip_code=90210" for 127.0.0.1 at 2011-11-07 08:16:41 -0500
189
+ Processing by Medivo::LabsController#lab_data as HTML
190
+ Parameters: {"zip_code"=>"90210"}
191
+ Completed 200 OK in 284ms (Views: 1.0ms)
192
+
193
+
194
+ Started GET "/labs/lab_search?zip_code=90210" for 127.0.0.1 at 2011-11-07 08:16:44 -0500
195
+ Processing by LabsController#lab_search as HTML
196
+ Parameters: {"zip_code"=>"90210"}
197
+ Completed 200 OK in 320ms (Views: 95.1ms)
198
+
199
+
200
+ Started GET "/assets/application.css" for 127.0.0.1 at 2011-11-07 08:16:44 -0500
201
+ Served asset /application.css - 200 OK (654ms)
202
+
203
+
204
+ Started GET "/assets/application.js" for 127.0.0.1 at 2011-11-07 08:16:45 -0500
205
+ Served asset /application.js - 200 OK (33ms)
206
+
207
+
208
+ Started GET "/assets/medivo/markerA.png" for 127.0.0.1 at 2011-11-07 08:16:45 -0500
209
+ Served asset /medivo/markerA.png - 200 OK (1ms)
210
+
211
+
212
+ Started GET "/assets/medivo/markerB.png" for 127.0.0.1 at 2011-11-07 08:16:45 -0500
213
+ Served asset /medivo/markerB.png - 200 OK (3ms)
214
+
215
+
216
+ Started GET "/assets/medivo/arrow.png" for 127.0.0.1 at 2011-11-07 08:16:45 -0500
217
+ Served asset /medivo/arrow.png - 200 OK (2ms)
@@ -21,7 +21,7 @@ describe Medivo::PdfGenerator do
21
21
  :first_name => 'me!!!!!',
22
22
  :sched_date => 'todays date',
23
23
  :app_date => 'my appt date',
24
- :app_time => 'my appt time',
24
+ :app_time => 'appt time', # small field .. so too much text will break test
25
25
  :lab_name => 'LabCorp',
26
26
  :lab_address => 'the lab address',
27
27
  :order_number => 'the lab id'
@@ -31,8 +31,9 @@ describe Medivo::PdfGenerator do
31
31
  pdf_file = Medivo::PdfGenerator.variable_fields(path, fields)
32
32
 
33
33
  text = pdf_to_text(pdf_file)
34
+ text = text.strip_space
34
35
  fields.values.each do |value|
35
- text.should match value
36
+ text.should match value.strip_space
36
37
  end
37
38
  pdf_file.unlink
38
39
  end
@@ -53,9 +54,9 @@ Southeast Region
53
54
  {:director_name=>md},
54
55
  [{:path=> img_path, :options=>{:at=> [40, 100], :width=>170, :height=>40}}]
55
56
  )
56
- show_me_the_pdf(pdf_file, '/tmp/test.pdf')
57
+ #show_me_the_pdf(pdf_file, '/tmp/test.pdf')
57
58
  text = pdf_to_text(pdf_file)
58
- text.should match "Catherine E. Palmier, M.D."
59
+ text.strip_space.should match "Catherine E. Palmier, M.D.".strip_space
59
60
  pdf_file.unlink
60
61
  end
61
62
  end
@@ -30,7 +30,7 @@ describe Medivo::PdfGroup do
30
30
  end
31
31
 
32
32
  text = pdf_to_text(pdf_group.pdf)
33
- text.should match "Account #:111111111 Req\/Control #:#{requisition_id}"
33
+ text.should match /Account #:111111111 Req\/Control #:#{requisition_id}/x
34
34
  end
35
35
 
36
36
  it "#lab_result" do
@@ -42,7 +42,7 @@ describe Medivo::PdfGroup do
42
42
  end
43
43
 
44
44
  text = pdf_to_text(pdf_group.pdf)
45
- text.should match "COLLECTED:2011-09-06 RECEIVED:2011-09-06 REPORTED:2011-09-06"
45
+ text.strip_space.should match "COLLECTED:2011-09-06 RECEIVED:2011-09-06 REPORTED:2011-09-06".strip_space
46
46
  end
47
47
 
48
48
  it "#static_pdf" do
@@ -52,7 +52,7 @@ describe Medivo::PdfGroup do
52
52
  end
53
53
 
54
54
  text = pdf_to_text(pdf_group.pdf)
55
- text.should match "Q: What does a positive result mean"
55
+ text.strip_space.should match "Q: What does a positive result mean".strip_space
56
56
  end
57
57
 
58
58
  it "handles a combination of pdfs" do
@@ -71,8 +71,9 @@ describe Medivo::PdfGroup do
71
71
  end
72
72
 
73
73
  text = pdf_to_text(pdf_group.pdf)
74
+ text = text.strip_space
74
75
  text.should match name
75
- text.should match "Account #:111111111 Req\/Control #:#{requisition_id}"
76
- text.should match "Q: What does a positive result mean"
76
+ text.should match "Account #:111111111 Req\/Control #:#{requisition_id}".strip_space
77
+ text.should match "Q: What does a positive result mean".strip_space
77
78
  end
78
79
  end
@@ -1,6 +1,6 @@
1
1
  class String
2
2
  def strip_space
3
- gsub(/\s/, '')
3
+ gsub(/\s|\n|\r/, '')
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: medivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-06 01:00:00.000000000 -04:00
12
+ date: 2011-11-07 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &2161952680 !ruby/object:Gem::Requirement
17
+ requirement: &2173814200 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2161952680
25
+ version_requirements: *2173814200
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jquery-rails
28
- requirement: &2161952260 !ruby/object:Gem::Requirement
28
+ requirement: &2173813780 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2161952260
36
+ version_requirements: *2173813780
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: coffee-script
39
- requirement: &2161951720 !ruby/object:Gem::Requirement
39
+ requirement: &2173813240 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2161951720
47
+ version_requirements: *2173813240
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: haml-rails
50
- requirement: &2161951300 !ruby/object:Gem::Requirement
50
+ requirement: &2173812800 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2161951300
58
+ version_requirements: *2173812800
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: geocoder
61
- requirement: &2161950880 !ruby/object:Gem::Requirement
61
+ requirement: &2173812380 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *2161950880
69
+ version_requirements: *2173812380
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rest-client
72
- requirement: &2161950460 !ruby/object:Gem::Requirement
72
+ requirement: &2173811960 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *2161950460
80
+ version_requirements: *2173811960
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: pdfkit
83
- requirement: &2161950040 !ruby/object:Gem::Requirement
83
+ requirement: &2173811520 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *2161950040
91
+ version_requirements: *2173811520
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: prawn
94
- requirement: &2161949620 !ruby/object:Gem::Requirement
94
+ requirement: &2173811100 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0'
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *2161949620
102
+ version_requirements: *2173811100
103
103
  description: Use the medivo platform to find lab locations, make labcorp appointments,
104
104
  place lab orders
105
105
  email:
@@ -293,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
293
  version: '0'
294
294
  segments:
295
295
  - 0
296
- hash: 1719666100364276602
296
+ hash: 1540401396263977125
297
297
  required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  none: false
299
299
  requirements:
@@ -302,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
302
  version: '0'
303
303
  segments:
304
304
  - 0
305
- hash: 1719666100364276602
305
+ hash: 1540401396263977125
306
306
  requirements: []
307
307
  rubyforge_project:
308
308
  rubygems_version: 1.6.2