medivo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/images/medivo/arrow.png +0 -0
  5. data/app/assets/images/medivo/lab.png +0 -0
  6. data/app/assets/javascripts/medivo/application.js +5 -0
  7. data/app/assets/javascripts/medivo/handlebars.js +1494 -0
  8. data/app/assets/javascripts/medivo/map.coffee +59 -0
  9. data/app/assets/javascripts/medivo/models.coffee +37 -0
  10. data/app/assets/javascripts/medivo/show_labs.coffee +10 -0
  11. data/app/assets/stylesheets/medivo/application.css +7 -0
  12. data/app/controllers/medivo/application_controller.rb +4 -0
  13. data/app/controllers/medivo/labs_controller.rb +8 -0
  14. data/app/models/medivo/insurance_order.rb +39 -0
  15. data/app/models/medivo/lab.rb +33 -0
  16. data/app/models/medivo/order.rb +61 -0
  17. data/app/models/medivo/resource.rb +24 -0
  18. data/app/models/medivo/zip_code.rb +10 -0
  19. data/app/views/layouts/medivo/application.html.erb +14 -0
  20. data/config/routes.rb +3 -0
  21. data/db/zip_codes.sqlite3 +0 -0
  22. data/lib/generators/medivo/install/install_generator.rb +42 -0
  23. data/lib/medivo.rb +6 -0
  24. data/lib/medivo/engine.rb +5 -0
  25. data/lib/medivo/validators.rb +20 -0
  26. data/lib/medivo/version.rb +3 -0
  27. data/lib/tasks/load_zips.thor +16 -0
  28. data/lib/tasks/medivo_tasks.rake +4 -0
  29. data/spec/dummy/Rakefile +7 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  33. data/spec/dummy/app/controllers/labs_controller.rb +8 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/views/labs/search.html.haml +13 -0
  36. data/spec/dummy/app/views/layouts/application.html.haml +11 -0
  37. data/spec/dummy/config.ru +4 -0
  38. data/spec/dummy/config/application.rb +45 -0
  39. data/spec/dummy/config/boot.rb +10 -0
  40. data/spec/dummy/config/database.yml +25 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/development.rb +30 -0
  43. data/spec/dummy/config/environments/production.rb +60 -0
  44. data/spec/dummy/config/environments/test.rb +42 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/inflections.rb +10 -0
  47. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  48. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  49. data/spec/dummy/config/initializers/session_store.rb +8 -0
  50. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  51. data/spec/dummy/config/locales/en.yml +5 -0
  52. data/spec/dummy/config/medivo.yml +9 -0
  53. data/spec/dummy/config/routes.rb +4 -0
  54. data/spec/dummy/db/development.sqlite3 +0 -0
  55. data/spec/dummy/db/test.sqlite3 +0 -0
  56. data/spec/dummy/log/development.log +2304 -0
  57. data/spec/dummy/log/test.log +637 -0
  58. data/spec/dummy/public/404.html +26 -0
  59. data/spec/dummy/public/422.html +26 -0
  60. data/spec/dummy/public/500.html +26 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/dummy/script/rails +6 -0
  63. data/spec/dummy/tmp/cache/assets/C36/810/sprockets%2F5159467797298fb14cdd1716691362d5 +0 -0
  64. data/spec/dummy/tmp/cache/assets/C46/F00/sprockets%2F2281d588b540056c5a7306c32a3761b9 +0 -0
  65. data/spec/dummy/tmp/cache/assets/CAB/970/sprockets%2F6aa4308273851c94a14158394d4dcdc4 +0 -0
  66. data/spec/dummy/tmp/cache/assets/CC3/EF0/sprockets%2F453b504c1f8f374578636f699eaa455d +0 -0
  67. data/spec/dummy/tmp/cache/assets/CE4/E70/sprockets%2F091ec16b8699113092ce35de93ca1d87 +0 -0
  68. data/spec/dummy/tmp/cache/assets/CEE/250/sprockets%2F96688f33f2f8aa261bf6701c1d6d7575 +0 -0
  69. data/spec/dummy/tmp/cache/assets/CFF/7F0/sprockets%2F4007fd53da973506c55bc273a05c5c0d +0 -0
  70. data/spec/dummy/tmp/cache/assets/CFF/8D0/sprockets%2Fc1053414055bf81a6d316dc14f12f9fd +0 -0
  71. data/spec/dummy/tmp/cache/assets/D19/310/sprockets%2F110931639fc185699ea1aaaf87dd488b +0 -0
  72. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  73. data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  74. data/spec/dummy/tmp/cache/assets/D62/380/sprockets%2F712d93afe40570cc939133bddca13bc7 +0 -0
  75. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  76. data/spec/dummy/tmp/cache/assets/D9C/F50/sprockets%2F224e78bb9e1c414a2d518a3aaffd6f77 +0 -0
  77. data/spec/dummy/tmp/cache/assets/D9D/4E0/sprockets%2Fe9dab92986b1516fca08474613ccadcb +0 -0
  78. data/spec/dummy/tmp/cache/assets/DA2/040/sprockets%2F6ab79dcced8cc9933b734e7b21c3a183 +0 -0
  79. data/spec/dummy/tmp/cache/assets/DD2/A50/sprockets%2Fecb5dd9066b50eb678cd8c9dbb21d229 +0 -0
  80. data/spec/dummy/tmp/cache/assets/DD4/2B0/sprockets%2Fef214a63f29afe7f3cbffc65af943108 +0 -0
  81. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  82. data/spec/dummy/tmp/cache/assets/E59/D50/sprockets%2Fbe1cc4d9b0efb617e58baa16dd1dee58 +0 -0
  83. data/spec/dummy/tmp/pids/server.pid +1 -0
  84. data/spec/models/labs_spec.rb +13 -0
  85. data/spec/models/orders_spec.rb +59 -0
  86. data/spec/requests/labs_spec.rb +32 -0
  87. data/spec/spec_helper.rb +44 -0
  88. data/spec/support/blueprints.rb +54 -0
  89. metadata +278 -0
@@ -0,0 +1,59 @@
1
+ class window.MapView
2
+ constructor: (@collection, @center_point)->
3
+ throw "you need a collection to make a MapView" unless @collection
4
+
5
+ el: $('#map_canvas')
6
+ center_point: null
7
+ center_marker: null
8
+ view: null
9
+ markerBounds: new google.maps.LatLngBounds()
10
+ markerBoundsZoomOut: 0.1
11
+
12
+ options: {
13
+ mapTypeId: google.maps.MapTypeId.ROADMAP
14
+ mapTypeControl: false
15
+ }
16
+
17
+ prepareMap: ->
18
+ if !this.view
19
+ this.view = new google.maps.Map(document.getElementById("map_canvas"), this.options)
20
+
21
+ createCenterMarker: ->
22
+ if this.center_point
23
+ point = new google.maps.LatLng(this.center_point.lat, this.center_point.lng)
24
+ this.center_marker = new google.maps.Marker({
25
+ position: point,
26
+ map: this.view,
27
+ title: this.center_point.title
28
+ icon: "/assets/medivo/arrow.png"
29
+ })
30
+ this.markerBounds.extend(this.center_marker.position) if this.markerBounds and this.center_marker
31
+
32
+ setMarkers: (map, markerBounds) ->
33
+ $.each( @collection.labs, (index, model)-> model.setMarker(map, markerBounds) )
34
+
35
+ clear: ->
36
+ this.collection.clearMarkers()
37
+ if this.center_marker
38
+ this.center_marker.setMap(null)
39
+ this.center_marker = null
40
+ this.markerBounds = new google.maps.LatLngBounds()
41
+
42
+ render: ->
43
+ this.clear()
44
+ this.prepareMap()
45
+ this.createCenterMarker()
46
+ this.setMarkers(this.view, this.markerBounds)
47
+
48
+ # extend the bounds if its too small
49
+ if (this.markerBounds.getNorthEast().equals(this.markerBounds.getSouthWest()))
50
+ extendPoint = new google.maps.LatLng(
51
+ this.markerBounds.getNorthEast().lat() + this.markerBoundsZoomOut,
52
+ this.markerBounds.getNorthEast().lng() + this.markerBoundsZoomOut
53
+ )
54
+ this.markerBounds.extend(extendPoint)
55
+ this.view.fitBounds(this.markerBounds)
56
+
57
+
58
+
59
+
@@ -0,0 +1,37 @@
1
+ class window.Lab
2
+ constructor: (@data)->
3
+ marker: null
4
+ map_tooltip_template: Handlebars.compile("{{name}}\n{{address}}\n{{city}},{{state}} ")
5
+
6
+ clearMarker: ->
7
+ if this.marker
8
+ this.marker.setMap(null)
9
+ this.marker = null
10
+
11
+ setMarker: (map, markerBounds)->
12
+ this.point = new google.maps.LatLng(@data.lat, @data.lng)
13
+ this.marker = this.makeMarker(map)
14
+ if markerBounds
15
+ markerBounds.extend(this.point)
16
+
17
+ makeMarker: (map)->
18
+ new google.maps.Marker({
19
+ position: this.point
20
+ map: map
21
+ title: this.map_tooltip_template(@data)
22
+ icon: this.makeIcon()
23
+ })
24
+
25
+ makeIcon: ->
26
+ new google.maps.MarkerImage("/assets/medivo/lab.png")
27
+
28
+
29
+ class window.LabList
30
+
31
+ constructor: (@data)->
32
+ labs = @labs = []
33
+ $.each( @data, (index, lab_data)->
34
+ labs.push(new Lab(lab_data))
35
+ )
36
+
37
+ clearMarkers: -> $.each( @labs, (index, lab)-> lab.clearMarker() )
@@ -0,0 +1,10 @@
1
+ $(document).ready ->
2
+ data = $('#lab_list_container').data('labs')
3
+ if data
4
+ lab_list = new window.LabList( data.labs )
5
+ map_view = new window.MapView( lab_list, data.zip_location )
6
+ map_view.render()
7
+ else
8
+ console.log('no data')
9
+ # zip_code = $('input#zip_code').val()
10
+ # Labs.find(zip_code)
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,4 @@
1
+ module Medivo
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Medivo
2
+ class LabsController < ActionController::Base
3
+ def data
4
+ lab_data = Medivo::Lab.data_for_zip(params[:zip_code])
5
+ render :json=> lab_data, :layout => nil
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'resource'
2
+
3
+ module Medivo
4
+
5
+ class PrimaryInsurance
6
+ include ActiveModel::Validations
7
+
8
+ validates_presence_of :relationship, :company_name, :policy_number, :group_number
9
+
10
+ def initialize(attributes = {})
11
+ @attributes = attributes
12
+ end
13
+
14
+ def read_attribute_for_validation(key)
15
+ @attributes[key]
16
+ end
17
+
18
+ def validate(record)
19
+ primary_insurance = record.attributes[:primary_insurance]
20
+ record.errors.add(:primary_insurance, "primary_insurance field must be present") and return unless primary_insurance
21
+ record.errors.add(:primary_insurance, "primary_insurance field must be of PrimaryInsurance class") unless primary_insurance.is_a? PrimaryInsurance
22
+ primary_insurance.valid?
23
+ record.errors.add(:'primary_insurance.relationship', "primary_insurance relationship field must be the value 1") unless primary_insurance.read_attribute_for_validation(:relationship) == 1
24
+ for field in %w(company_name policy_number group_number)
25
+ record.errors.add(:"primary_insurance.#{field}", "primary_insurance #{field} must be present") unless primary_insurance.read_attribute_for_validation(field)
26
+ end
27
+ end
28
+ end
29
+
30
+ class InsuranceOrder < Order
31
+ validates_with Medivo::ArrayValidator, :fields => [:diagnosis_code]
32
+ validates_with PrimaryInsurance
33
+
34
+ # when getting the insurance info from medivo labs
35
+ def insurance
36
+ @insurance ||= try(:insurance_information).try(:primary_insurance_info)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'resource'
2
+
3
+ module Medivo
4
+ class Lab < Resource
5
+ LAB_CORP_ID = 129
6
+ QUEST_ID = 119
7
+ LAB_CORP_NAME = :lab_corp
8
+ QUEST_NAME = :quest
9
+ LAB_ID_TO_NAME = {LAB_CORP_ID => LAB_CORP_NAME, QUEST_ID => QUEST_NAME}
10
+ LAB_ID_TO_SHORT_NAME = {LAB_CORP_ID => 'LC', QUEST_ID => 'QD'}
11
+ LAB_ID_TO_PRETTY_NAME = {LAB_CORP_ID => 'Lab Corp', QUEST_ID => 'Quest Diagnostics'}
12
+
13
+ def self.findLabs(zip_code, radius = 15)
14
+ find(:all, :from => "/find_psc/#{zip_code}", :params=>{:radius=>radius}).sort_by(&:distance)
15
+ end
16
+
17
+ def self.data_for_zip(zip='')
18
+ zip = zip.to_s.match(/(\d{5})/) ? $1 : nil
19
+ return {} unless zip and zip_info = ZipCode.find_by_zip_code(zip)
20
+ labs = findLabs(zip)[0..1]
21
+ {:labs => labs, :zip_location => zip_info.center_info}
22
+ end
23
+
24
+ def lab_name
25
+ LAB_ID_TO_PRETTY_NAME[lab_id]
26
+ end
27
+
28
+
29
+ def as_json(options={})
30
+ attributes.merge(:lab_name => self.lab_name)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,61 @@
1
+ require_relative 'resource'
2
+
3
+ module Medivo
4
+ class Order < Resource
5
+ set_element_name 'customer'
6
+ set_collection_name 'customers'
7
+
8
+ validates_presence_of :email, :address, :zip, :dob, :home_phone, :psc,
9
+ :test_types, :gender, :account_number
10
+ validates_inclusion_of :gender, :in => %w(Male Female)
11
+ validates_with Medivo::DateValidator, :fields=>[:dob]
12
+ validates_with Medivo::ArrayValidator, :fields=>[:test_types]
13
+
14
+ def read_attribute_for_validation(key)
15
+ @attributes[key]
16
+ end
17
+
18
+ def initialize(attributes = {}, persisted = false)
19
+ super(attributes, persisted)
20
+ self.draw_location = 'PSC'
21
+ self.take_tests_same_day = true
22
+ end
23
+
24
+ def to_param
25
+ requisition_id
26
+ end
27
+
28
+ def requisition_id
29
+ requisition_number
30
+ end
31
+
32
+ def self.get_order(requsition_id)
33
+ find(requsition_id)
34
+ end
35
+
36
+ # medivo_order = create(values)
37
+ # unless medivo_order.valid?
38
+ # Rails.logger.error("Error creating Medivo Lab order")
39
+ # Rails.logger.error(medivo_order.inspect)
40
+ # raise "Errors in Medivo Lab order #{medivo_order.errors.messages}"
41
+ # end
42
+ # medivo_order
43
+ #end
44
+
45
+ def results
46
+ @results ||= Array.wrap(try(:reconciled_results).try(:result))
47
+ end
48
+
49
+ def simulate_result(lab_prefix, type='normal')
50
+ raise "Incorrect Result Type" unless %w(normal false_positive positive).include?(type) and %w(qd lc).include?(lab_prefix)
51
+ body = case type
52
+ when 'normal' then
53
+ "<mock><simulate>result</simulate><result kind='#{type}' complete='complete'></result></mock>"
54
+ when 'false_positive', 'positive' then
55
+ "<mock><simulate>result</simulate><result><hl7>#{Base64.encode64(File.read("lib/pdfs/#{lab_prefix}_#{type}.hl7"))}</hl7></result></mock>"
56
+ end
57
+
58
+ post(:mock_order, {}, body)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'active_resource'
4
+
5
+ module Medivo
6
+ class Locator
7
+ def self.find
8
+ return @location if @location
9
+ config_file = File.join(Rails.root.join('config', 'medivo.yml'))
10
+ config = YAML.load_file(config_file)
11
+ @location = OpenStruct.new config[Rails.env]
12
+ end
13
+ end
14
+
15
+ class Resource < ActiveResource::Base
16
+ location = Locator.find
17
+ self.include_root_in_json = false
18
+ self.site = location.href
19
+ self.user = location.user
20
+ self.password = location.password
21
+ self.format = :xml
22
+ end
23
+ end
24
+
@@ -0,0 +1,10 @@
1
+ module Medivo
2
+ class ZipCode < ActiveRecord::Base
3
+ ActiveRecord::Base.establish_connection({:adapter=>'sqlite3', :database=>"#{Medivo::Engine.config.root}/db/zip_codes.sqlite3"})
4
+ self.table_name = :zip_codes
5
+
6
+ def center_info
7
+ {:title=> "#{city}, #{state_short}, #{zip_code}", :lat=>lat, lng: lng}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Medivo</title>
5
+ <%= stylesheet_link_tag "medivo/application" %>
6
+ <%= javascript_include_tag "medivo/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Medivo::Engine.routes.draw do
2
+ match '/labs/data/:zip_code' => "labs#data", :via => :get, :as=>:data_labs
3
+ end
Binary file
@@ -0,0 +1,42 @@
1
+ module Medivo
2
+ module Generators #:nodoc:
3
+ class InstallGenerator < Rails::Generators::Base #:nodoc:
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+
7
+ def database_file
8
+ copy_file "medivo.yml", "config/medivo.yml"
9
+ end
10
+
11
+ def test_helper
12
+ if rspec?
13
+ inject_into_file("spec/spec_helper.rb", :after => "Rspec.configure do |config|\n") do
14
+ " # Reset the Machinist cache before each spec.\n" +
15
+ " config.before(:each) { Machinist.reset_before_test }\n\n"
16
+ end
17
+ else
18
+ inject_into_file("test/test_helper.rb", :after => "require 'rails/test_help'\n") do
19
+ "require File.expand_path(File.dirname(__FILE__) + '/blueprints')\n"
20
+ end
21
+ inject_into_class("test/test_helper.rb", ActiveSupport::TestCase) do
22
+ " # Reset the Machinist cache before each test.\n" +
23
+ " setup { Machinist.reset_before_test }\n\n"
24
+ end
25
+ end
26
+ end
27
+
28
+ def cucumber_support
29
+ if options[:cucumber]
30
+ template "machinist.rb.erb", "features/support/machinist.rb"
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def rspec?
37
+ options[:test_framework].to_sym == :rspec
38
+ end
39
+
40
+ end
41
+ end
42
+ end
data/lib/medivo.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "medivo/engine"
2
+ require "medivo/validators"
3
+
4
+ require 'jquery-rails'
5
+ require 'coffee-script'
6
+ require 'haml-rails'
@@ -0,0 +1,5 @@
1
+ module Medivo
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Medivo
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module Medivo
2
+ class ArrayValidator < ActiveModel::Validator
3
+ def validate(record)
4
+ for field in options[:fields]
5
+ value = record.attributes[field]
6
+ record.errors.add(field, "#{field} must be an array") unless value.is_a? Array
7
+ end
8
+ end
9
+ end
10
+
11
+ class DateValidator < ActiveModel::Validator
12
+ def validate(record)
13
+ for field in options[:fields]
14
+ value = record.attributes[field]
15
+ date = Date.strptime(value, '%Y%m%d') rescue nil
16
+ record.errors.add(field, "invalid #{field}. needs to be in '%Y%m%d' format") unless date
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Medivo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ class Zips < Thor
2
+
3
+ desc 'load [full path to zip_code file]', "Load geonames zips with lat longs into Redis"
4
+ def load(zip_code_file=nil)
5
+ require './config/environment'
6
+ raise "Can't find that zip code file '#{zip_code_file}'" unless File.exist? zip_code_file
7
+
8
+ ZipCode.connection.execute "TRUNCATE `zip_codes`"
9
+ st = ZipCode.connection.raw_connection.prepare "INSERT IGNORE INTO `zip_codes` (`zip_code`, `city`, `state_short`, `lat`, `lng`) VALUES (?, ?, ?, ?, ?)"
10
+ File.readlines(zip_code_file).each_with_index do |line|
11
+ data = line.force_encoding("UTF-8").split("\t")
12
+ st.execute(data[1],data[2],data[4], data[9], data[10])
13
+ end
14
+ st.close
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :medivo do
3
+ # # Task goes here
4
+ # end