medivo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/app/assets/javascripts/medivo/lab_appointment/handlers.coffee +12 -6
  2. data/app/assets/javascripts/medivo/lab_list/handlers.coffee +6 -1
  3. data/app/controllers/medivo/labs_controller.rb +1 -1
  4. data/app/models/medivo/order.rb +14 -1
  5. data/lib/medivo/version.rb +1 -1
  6. data/lib/medivo.rb +6 -1
  7. data/lib/{medivo → pdf/medivo}/fdf_generator.rb +0 -0
  8. data/lib/pdf/medivo/pdf_generator.rb +18 -0
  9. data/lib/pdf/medivo/pdf_group.rb +42 -0
  10. data/lib/{medivo → support}/validators.rb +0 -0
  11. data/spec/dummy/app/views/labs/search.html.haml +8 -8
  12. data/spec/dummy/log/development.log +1080 -0
  13. data/spec/dummy/tmp/cache/assets/C46/F00/sprockets%2F2281d588b540056c5a7306c32a3761b9 +0 -0
  14. data/spec/dummy/tmp/cache/assets/CB4/BD0/sprockets%2F3378f27c0d4f5e6d708665b22707a31f +0 -0
  15. data/spec/dummy/tmp/cache/assets/CD8/DA0/sprockets%2F622aa5281d15503829a5f7a0bf56fc29 +0 -0
  16. data/spec/dummy/tmp/cache/assets/D20/F10/sprockets%2Fb2e907e4faa85fe755f4439e3b229088 +0 -0
  17. data/spec/dummy/tmp/cache/assets/D29/000/sprockets%2F61a10ddf57f1129c02a1049bfed6e007 +0 -0
  18. data/spec/dummy/tmp/cache/assets/D41/250/sprockets%2F7b3c4426715dcd1feedc4a95e5444256 +0 -0
  19. data/spec/dummy/tmp/cache/assets/D4C/7A0/sprockets%2Fbc635c7b186d1ef5178f4ed3722d868b +0 -0
  20. data/spec/dummy/tmp/cache/assets/D5D/3E0/sprockets%2F63fea6cc142b5f02da93bf81e70b2116 +0 -0
  21. data/spec/dummy/tmp/cache/assets/D60/030/sprockets%2Ffc9485f617fc5e9b8918755d2e08ecc6 +0 -0
  22. data/spec/dummy/tmp/cache/assets/D69/130/sprockets%2Fbaa4ec50a34ce938c986612c2a47a64e +0 -0
  23. data/spec/dummy/tmp/cache/assets/D74/9A0/sprockets%2F0ca4e6e833c72156fc7e7d5f007d9ce3 +0 -0
  24. data/spec/dummy/tmp/cache/assets/D76/720/sprockets%2F88d8aa1d2fb41ce79b8ec4150ea74748 +0 -0
  25. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  26. data/spec/dummy/tmp/cache/assets/DCE/E80/sprockets%2Fc71ec62157b9cc7aabfc030955cef87b +0 -0
  27. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  28. data/spec/dummy/tmp/pids/server.pid +1 -0
  29. data/spec/fixtures/lc_order_with_normal_results.xml +98 -0
  30. data/spec/fixtures/{lc_positive_results.xml → lc_order_with_positive_results.xml} +0 -0
  31. data/spec/fixtures/{order_with_requisition.xml → lc_order_with_requisition.xml} +0 -0
  32. data/spec/fixtures/negative_results.pdf +0 -0
  33. data/spec/lib/fdf_generator_spec.rb +22 -0
  34. data/spec/lib/pdf_generator_spec.rb +12 -0
  35. data/spec/lib/pdf_group_spec.rb +42 -0
  36. data/spec/models/orders_spec.rb +46 -28
  37. data/spec/spec_helper.rb +3 -0
  38. metadata +54 -29
@@ -6,23 +6,28 @@ $(document).ready ->
6
6
  ###### handle ajax appointment data search ########
7
7
  $("form#appointment_data_search")
8
8
  .bind('ajax:beforeSend', (event, data)->
9
+ form = $(this)
9
10
  messages = []
10
- date = $(this).find('input#appointment_date').val()
11
+ date = form.find('input#appointment_date').val()
11
12
  valid_date = Date.parseExact(date, "M/d/yyyy")
12
13
  messages.push("Date is invalid, must be mm/dd/yyyy format") unless valid_date
13
- lab_code = $(this).find('input#lab_code').val()
14
+ # find the selected lab from the lab list and get the lab code
15
+ selected_lab = $('#lab_list_container input:radio:checked')
16
+ lab_code = $('#lab_list_container input:radio:checked').parent('li').find('form > input#lab_code').val()
17
+ # set the value in this forms lab_code input field
18
+ form.find('input#lab_code').val(lab_code)
14
19
  messages.push("Labcode is missing") unless lab_code
15
20
  if (messages.length > 0)
16
21
  span = $("<span>#{messages.join("<br>")}</span>")
17
- $(this).find('.error_message').append(span)
22
+ form.find('.error_message').append(span)
18
23
  span.fadeOut(4000)
19
24
  false
20
-
21
25
  )
22
26
  .bind('ajax:success', (event, data)->
23
27
  window.appointment_list.setList(data.times)
24
- # set the first as selected
28
+ # set the first appointment time as selected
25
29
  $('input:radio[name=appointment_time]:first').prop('checked',true)
30
+ # re enable searching for appointment times
26
31
  $('form#appointment_data_search input[type=submit]').prop("disabled", false)
27
32
  )
28
33
  .bind('ajax:complete', (event, data)->
@@ -32,6 +37,7 @@ $(document).ready ->
32
37
  ###### handle toggle to show more appointments ########
33
38
  $("#more_appointments_list_toggler").live("click", ->
34
39
  window.appointment_list.setShowNumber(window.max_appointment_show_number)
35
- $("#more_appointments_list_toggler").parent('p').hide()
40
+ $('input:radio[name=appointment_time]:first').prop('checked',true)
41
+ $("#more_appointments_list_toggler").hide()
36
42
  )
37
43
 
@@ -13,6 +13,8 @@ $(document).ready ->
13
13
  .bind('ajax:success', (event, data)->
14
14
  window.map_view.center_point = data.zip_location
15
15
  window.lab_list.setList(data.labs)
16
+ # set the first lab as selected
17
+ $('input:radio[name=selected_lab]:first').prop('checked',true)
16
18
  $('form#lab_data_search input[type=submit]').prop("disabled", false)
17
19
  )
18
20
  .bind('ajax:complete', (event, data)->
@@ -21,5 +23,8 @@ $(document).ready ->
21
23
  ###### handle toggle to show more labs ########
22
24
  $("#more_labs_list_toggler").live("click", ->
23
25
  window.lab_list.setShowNumber(window.max_lab_show_number)
24
- $("#more_labs_list_toggler").parent('p').hide()
26
+ # set the first lab as selected
27
+ $('input:radio[name=selected_lab]:first').prop('checked',true)
28
+ # hide the toggle to show more after they have been shown
29
+ $("#more_labs_list_toggler").hide()
25
30
  )
@@ -9,7 +9,7 @@ module Medivo
9
9
  data = if Rails.env.development?
10
10
  "{\"times\":[\"11/03/2011|08:30 AM\",\"11/04/2011|08:30 AM\",\"11/02/2011|09:00 AM\",\"11/01/2011|09:30 AM\",\"11/02/2011|09:30 AM\",\"11/03/2011|09:30 AM\",\"11/04/2011|09:30 AM\",\"10/31/2011|10:00 AM\",\"11/01/2011|10:00 AM\",\"11/02/2011|10:00 AM\",\"11/03/2011|10:00 AM\",\"11/04/2011|10:00 AM\",\"11/05/2011|10:00 AM\",\"10/31/2011|10:30 AM\",\"11/01/2011|10:30 AM\",\"11/02/2011|10:30 AM\",\"11/03/2011|10:30 AM\",\"10/31/2011|11:00 AM\",\"11/01/2011|11:00 AM\",\"11/02/2011|11:00 AM\",\"11/03/2011|11:00 AM\",\"11/04/2011|11:00 AM\",\"11/05/2011|11:00 AM\",\"10/31/2011|01:30 PM\",\"11/01/2011|01:30 PM\",\"11/02/2011|01:30 PM\",\"11/03/2011|01:30 PM\",\"11/04/2011|01:30 PM\",\"10/31/2011|02:00 PM\",\"11/01/2011|02:00 PM\",\"11/02/2011|02:00 PM\",\"11/03/2011|02:00 PM\",\"10/31/2011|02:30 PM\",\"11/01/2011|02:30 PM\",\"11/02/2011|02:30 PM\",\"11/03/2011|02:30 PM\",\"11/04/2011|02:30 PM\",\"10/31/2011|03:00 PM\",\"11/01/2011|03:00 PM\",\"11/02/2011|03:00 PM\",\"11/03/2011|03:00 PM\",\"11/04/2011|03:00 PM\",\"10/31/2011|03:30 PM\",\"11/01/2011|03:30 PM\",\"11/02/2011|03:30 PM\",\"11/03/2011|03:30 PM\",\"11/04/2011|03:30 PM\",\"10/31/2011|04:00 PM\",\"11/01/2011|04:00 PM\",\"11/02/2011|04:00 PM\",\"11/03/2011|04:00 PM\",\"11/04/2011|04:00 PM\"]}"
11
11
  else
12
- Medivo::Appointment.find(params[:lab_code], params[:date])
12
+ Medivo::Appointment.find(params[:lab_code], params[:appointment_date])
13
13
  end
14
14
  render :json=> data, :layout => nil
15
15
  end
@@ -61,10 +61,15 @@ module Medivo
61
61
  end
62
62
 
63
63
  # gets the lab requisition pdf
64
- def requisition
64
+ def pdf_requisition
65
65
  Base64::decode64(try(:sameday_requisition))
66
66
  end
67
67
 
68
+ # get a lab requisition pdf from requisition id
69
+ def self.pdf_requisition(requsition_id)
70
+ find_with_requisition(requsition_id).pdf_requisition
71
+ end
72
+
68
73
  # loads the results with order
69
74
  def self.find_with_results(requsition_id)
70
75
  find(requsition_id, :params=>{:include=>:reconciled_results})
@@ -80,6 +85,14 @@ module Medivo
80
85
  try(:reconciled_results).try(:results_summary)
81
86
  end
82
87
 
88
+ def pdf_result
89
+ Base64::decode64(try(:reconciled_results).try(:results_pdf))
90
+ end
91
+
92
+ def self.pdf_result(requsition_id)
93
+ find_with_results(requsition_id).pdf_result
94
+ end
95
+
83
96
  def simulate_result(lab_prefix, type='normal')
84
97
  raise "Incorrect Result Type" unless %w(normal false_positive positive).include?(type) and %w(qd lc).include?(lab_prefix)
85
98
  body = case type
@@ -1,3 +1,3 @@
1
1
  module Medivo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/medivo.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require "medivo/engine"
2
- require "medivo/validators"
3
2
 
4
3
  require 'jquery-rails'
5
4
  require 'coffee-script'
6
5
  require 'haml-rails'
6
+ require 'pdf/toolkit'
7
+ require 'pdfkit'
7
8
  require 'geocoder'
8
9
  # yahoo has 5,000 a day limit, google is 2,500
9
10
  Geocoder::Configuration.lookup = :yahoo
11
+
12
+ ENGINE_PATH = File.expand_path('../..', __FILE__) unless defined? ENGINE_PATH
13
+ Dir["#{ENGINE_PATH}/lib/pdf/**/*.rb"].each { |f| p f; require f }
14
+ Dir["#{ENGINE_PATH}/lib/support/**/*.rb"].each { |f| require f }
File without changes
@@ -0,0 +1,18 @@
1
+ module Medivo
2
+ class PdfGenerator
3
+
4
+ ##
5
+ # file_path string path to pdf file with variable fields
6
+ # variables hash the hash of variables to fill in
7
+ #
8
+ # return pdf file handler
9
+ def self.variable_fields(file_path, variables)
10
+ raise "variables #{variables} should be a hash" unless variables.is_a? Hash
11
+ pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
12
+ fdf = FdfGenerator.file(variables)
13
+ system 'pdftk', file_path, 'fill_form', fdf.path, 'output', pdf.path, 'flatten'
14
+ pdf
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ module Medivo
2
+ class PdfGroup
3
+ def initialize
4
+ @pdfs = []
5
+ end
6
+
7
+ def self.create(&block)
8
+ raise "need to pass a block do create" unless block_given?
9
+ pdf_group = PdfGroup.new
10
+ yield pdf_group
11
+ # combine the pdfs
12
+ pdf_group.pdf
13
+ end
14
+
15
+ def variable_fields(file_path, variables)
16
+ @pdfs << PdfGenerator.variable_fields(file_path, variables)
17
+ end
18
+
19
+ def lab_requisition(requisition_id)
20
+ pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
21
+ pdf.write Medivo::Order.pdf_requisition(requisition_id)
22
+ pdf.close
23
+ @pdfs << pdf
24
+ end
25
+
26
+ def lab_result(requisition_id)
27
+ pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
28
+ pdf.write Medivo::Order.pdf_result(requisition_id)
29
+ pdf.close
30
+ @pdfs << pdf
31
+ end
32
+
33
+ ##
34
+ # Combines the PDFs
35
+ def pdf
36
+ pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
37
+ args = [@pdfs.collect(&:path), 'cat', 'output', pdf.path].flatten
38
+ system 'pdftk', *args
39
+ pdf
40
+ end
41
+ end
42
+ end
File without changes
@@ -1,6 +1,7 @@
1
1
  // sample template for rendering lab info
2
2
  %script{:id=>"lab_item_template", :type=>"text/x-handlebars-template"}
3
3
  %li.lab_info
4
+ = radio_button_tag :selected_lab, "{{data/id}}", 'yes'
4
5
  .lab_image
5
6
  %img{:src=>"{{icon}}", :width=>'12px'} &nbsp;
6
7
  %div
@@ -15,7 +16,7 @@
15
16
  = form_for :lab, :url=>'/select', :method=>'post' do |f|
16
17
  %input{ :type=>:hidden, :name => 'id', :value=>"{{data/id}}" }
17
18
  %input{ :type=>:hidden, :name => 'lab_id', :value=>"{{data/lab_id}}" }
18
- %input{ :type=>:hidden, :name => 'lab_code', :value=>"{{data/code}}" }
19
+ %input{ :type=>:hidden, :name => 'lab_code', :value=>"{{data/code}}", :id=>'lab_code' }
19
20
  %input{ :type=>:hidden, :name => 'lab_info[name]', :value=>"{{data/lab_name}}" }
20
21
  %input{ :type=>:hidden, :name => 'lab_info[address]', :value=>"{{address_without_comma}}" }
21
22
  %input{ :type=>:hidden, :name => 'lab_info[city]', :value=>"{{titleize data/city}}" }
@@ -32,8 +33,7 @@
32
33
  #lab_list_container{ 'data-labs'=>@lab_data.to_json }
33
34
  %ul#lab_list
34
35
 
35
- %p{:style => 'padding-left:50px;'}
36
- = link_to 'View more locations', '#', :id => 'more_labs_list_toggler'
36
+ = link_to 'View more locations', '#', :id => 'more_labs_list_toggler', :style => 'padding-left:50px;'
37
37
 
38
38
  // form for ajax lab searches ..the code to handle return data is in app/assets/medivo/labs/handle_ajax.coffee
39
39
  = form_tag(medivo.data_labs_path, :method=>:get, :id=>'lab_data_search', :remote=>true) do
@@ -48,8 +48,8 @@
48
48
 
49
49
  // sample template for rendering appointment info
50
50
  %script{:id=>"appointment_item_template", :type=>"text/x-handlebars-template"}
51
- %br
52
- %input{ :type=>'radio', :name=>"appointment_time", :value=>"{{data}}"} {{formattedDate}}
51
+ %li.appointment_time
52
+ %input{ :type=>'radio', :name=>"appointment_time", :value=>"{{data}}"} {{formattedDate}}
53
53
 
54
54
  Search for appointment times
55
55
 
@@ -57,8 +57,8 @@ Search for appointment times
57
57
  #appointment_list_container
58
58
  %ul#appointment_list
59
59
 
60
- %p{:style => 'display:none;padding-left:50px;'}
61
- = link_to 'View more times', '#', :id => 'more_appointment_list_toggler'
60
+ // if you want to allow the showing of more appointment times
61
+ = link_to 'View more times', '#', :id => 'more_appointment_list_toggler', :style => 'display:none;padding-left:50px;'
62
62
 
63
63
  // form for ajax appointment searches ..the code to handle return data is in app/assets/medivo/lab_appointments/handlers.coffee
64
64
  = form_tag(medivo.data_appointments_path, :method=>:get, :id=>'appointment_data_search', :remote=>true) do
@@ -66,7 +66,7 @@ Search for appointment times
66
66
  Enter a Date
67
67
  .error_message
68
68
  &nbsp;
69
- = text_field_tag :date, (Date.today+3.days).strftime("%m/%d/%Y")
69
+ = text_field_tag :appointment_date, (Date.today+3.days).strftime("%m/%d/%Y")
70
70
  = hidden_field_tag :lab_code, '' # you have to fill this in dynamically with a lab_code
71
71
  %p
72
72
  = submit_tag "Search for appointments", :id=> :find_appointments, :class=>'button'