Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
PDF Charts + Print Queue
Browse files Browse the repository at this point in the history
Squashed from the following commits

commit b8394a9
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Mon Mar 24 16:54:35 2014 -0400

    Remove outdated printer update

commit 2867aa6
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Mon Mar 24 16:54:14 2014 -0400

    Add configuration option for redis host and port

commit 0663c50
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Tue Mar 18 14:21:00 2014 -0400

    Remove dependency on redis from tests + make them :green_heart:

commit 8fc0ca1
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Tue Mar 18 11:02:46 2014 -0400

    Font awesome, fallback to old print method

commit 69bc374
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Fri Mar 14 16:36:21 2014 -0400

    Check-in printer selection

commit 00e819e
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Fri Mar 14 16:15:48 2014 -0400

    Don't clear all session data after logout

commit 53b3ba9
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Fri Mar 14 15:47:38 2014 -0400

    Add tests for PatientChart

commit 5db154e
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Tue Mar 11 12:28:00 2014 -0400

    Background printing for patient charts

commit 95b9730
Author: Gregory Brown <gregory.t.brown@gmail.com>
Date:   Wed Feb 26 15:38:17 2014 -0500

    Use a proxy rather than a subclass to wrap Prawn's methods

commit 9a22630
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Sun Feb 23 14:51:01 2014 -0500

    Restore tests after pdf-izing patient charts

commit 1efa454
Author: Jordan Byron <jordan.byron@gmail.com>
Date:   Sun Feb 23 13:49:16 2014 -0500

    Generate patient charts with prawn for great justice
  • Loading branch information
jordanbyron committed Mar 24, 2014
1 parent 9db68d3 commit 309d815
Show file tree
Hide file tree
Showing 29 changed files with 397 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ DB_USERNAME=
DB_PASSWORD=
DB_HOST=localhost

### Redis ###

REDIS_HOST=localhost
REDIS_PORT=6379

### Secrets - Generate using `rake secret`

SECRET_TOKEN=7b433023ce52cd60d3d5ae25583aff68436063d910ced8182739b8e61b6cb8c8a88103532638a31016314feda1c3945fd2a740c411c554dd315b2cc9875c4a30
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tmp/*
.rvmrc
.bundle
.env
dump.rdb

# CSV Import Files
/zipcode.csv
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ gem 'rack-pjax'
gem 'virtus'
gem 'axlsx'
gem 'axlsx_rails'
gem 'prawn', '~> 0.15.0'

gem 'resque'

gem 'jquery-rails'
gem 'will_paginate-bootstrap'
Expand All @@ -28,6 +31,7 @@ gem 'sass-rails', '~> 4.0.0'
gem 'uglifier'
gem 'compass-rails'
gem 'bootstrap-sass-rails'
gem 'font-awesome-rails'

group :development do
gem 'capistrano'
Expand All @@ -38,11 +42,13 @@ group :test do
gem 'minitest-spec-rails', '~> 4.7.6'
gem 'capybara_minitest_spec'
gem 'minitest-metadata'
gem 'minitest-stub_any_instance'
gem 'factory_girl_rails'
gem 'capybara'
gem 'capybara-webkit'
gem 'capybara-screenshot'
gem 'launchy'
gem 'database_cleaner'
gem 'timecop'
gem 'resque_unit'
end
33 changes: 33 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ GEM
railties (>= 3.0.0)
faker (1.1.2)
i18n (~> 0.5)
font-awesome-rails (4.0.3.1)
railties (>= 3.2, < 5.0)
fssm (0.2.10)
haml (4.0.5)
tilt
Expand All @@ -126,6 +128,8 @@ GEM
minitest-spec-rails (4.7.6)
minitest (~> 4.7)
rails (>= 3.0, < 4.1)
minitest-stub_any_instance (1.0.0)
mono_logger (1.1.0)
multi_json (1.8.4)
net-scp (1.1.0)
net-ssh (>= 2.6.5)
Expand All @@ -136,12 +140,18 @@ GEM
net-ssh (>= 2.6.5)
nokogiri (1.5.11)
orm_adapter (0.5.0)
pdf-core (0.1.6)
pg (0.14.1)
polyglot (0.3.4)
prawn (0.15.0)
pdf-core (~> 0.1.3)
ttfunk (~> 1.1.0)
rack (1.5.2)
rack-pjax (0.7.0)
nokogiri (~> 1.5)
rack (~> 1.3)
rack-protection (1.5.1)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.3)
Expand All @@ -163,13 +173,28 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (1.1.4)
rake (10.1.1)
redis (3.0.7)
redis-namespace (1.3.1)
redis (~> 3.0.0)
request_store (1.0.5)
resque (1.25.1)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque_unit (0.4.5)
json (>= 1.4.6)
rubyzip (0.9.9)
sass (3.2.14)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -187,10 +212,13 @@ GEM
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
ttfunk (1.1.0)
tzinfo (0.3.38)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
vegas (0.1.11)
rack (>= 1.0.0)
virtus (0.5.4)
backports (~> 2.6.1)
descendants_tracker (~> 0.0.1)
Expand Down Expand Up @@ -224,17 +252,22 @@ DEPENDENCIES
dynamic_form
factory_girl_rails
faker
font-awesome-rails
haml
jquery-rails
json (~> 1.7.7)
launchy
minitest-metadata
minitest-spec-rails (~> 4.7.6)
minitest-stub_any_instance
nokogiri (~> 1.5.11)
pg
prawn (~> 0.15.0)
rack-pjax
rails (= 4.0.3)
rails_setup
resque
resque_unit
rubyzip (= 0.9.9)
sass
sass-rails (~> 4.0.0)
Expand Down
4 changes: 0 additions & 4 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require twitter/bootstrap
//= require ../../../vendor/assets/javascripts
//= require mom.utilities
//= require_tree .
8 changes: 5 additions & 3 deletions app/assets/javascripts/mom.utilities.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ mom.utilities.disableEnterKey = (form) ->
e.preventDefault() if e.keyCode == 13

mom.utilities.openInBackground = (url) ->
window.open(url)
newWindow = window.open(url)
self.focus()
newWindow

mom.utilities.printChart = (patientId) ->
unless mom.mobile
mom.utilities.openInBackground "/patients/#{patientId}/chart"
xhr = $.get("/patients/#{patientId}/chart.js")
xhr.fail ->
alert "Chart failed to print!"

mom.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)

Expand Down
3 changes: 1 addition & 2 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree ../../../vendor/assets/stylesheets
*= require ../../../vendor/assets/stylesheets
*= require_tree ./screen
*/
3 changes: 2 additions & 1 deletion app/assets/stylesheets/screen/bootstrap-custom.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import twitter/bootstrap/pagination
@import twitter/bootstrap/tooltip
@import twitter/bootstrap/component-animations
@import twitter/bootstrap/dropdowns

a.btn
text-decoration: none
Expand Down Expand Up @@ -33,4 +34,4 @@ div.pagination ul
input, .add-on, select
vertical-align: bottom !important
.input-append select
width: 175px
width: 175px
26 changes: 21 additions & 5 deletions app/assets/stylesheets/screen/top_nav.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@
a.user-name
text-decoration: none

a, a:visited
color: #fff
text-decoration: underline
.warnings
margin-right: 5px
display: inline-block

a:hover
a, a:visited, a:hover
color: #fff
text-decoration: underline

.dropdown
display: inline-block
margin-right: 5px
li
&.selected a
padding-left: 20px
font-weight: bold
&:before
content: '✔︎ '
a
padding-left: 38px
text-align: left
color: #333
text-decoration: none
&:hover
color: #fff
form
display: inline-block

Expand All @@ -24,4 +40,4 @@
span#help_loading
display: none
img
padding-right: 5px
padding-right: 5px
23 changes: 21 additions & 2 deletions app/controllers/patients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,27 @@ def chart
@patient = Patient.find_by_id(params[:id])

if @patient
@patient.update_attributes(chart_printed: true)
render :layout => "print"
respond_to do |format|
format.html do
@patient.update_attributes(chart_printed: true)
render :layout => "print"
end
format.pdf do
@patient.update_attributes(chart_printed: true)
pdf = PatientChart.new(@patient)
send_data pdf.render, filename: "chart_#{@patient.id}.pdf",
type: "application/pdf",
disposition: "inline"
end
format.js do
if PrintChart.printers.any? && session[:printer]
Resque.enqueue(PrintChart, @patient.id, session[:printer])
@queued = true
else
@queued = false
end
end
end
else
raise ActionController::RoutingError.new('Not Found')
end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/printer_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class PrinterController < ApplicationController
before_filter :authenticate_user!

def update
session[:printer] = params[:printer]
end
end
68 changes: 68 additions & 0 deletions app/models/patient_chart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class PatientChart
def initialize(patient)
@document = Prawn::Document.new(top_margin: 20, left_margin: 20, right_margin: 20)
@patient = patient
chart_header
chart_table
end

def chart_header
text patient.chart_number.to_s, size: 36, style: :bold, align: :right
end

def chart_table
table [
[ label("Last name") + patient.last_name,
label("First name") + patient.first_name,
label("Date of birth") + patient.dob,
label("Age") + patient.age.to_s,
label("Phone") + phone_number,
label("Gender") + patient.sex
],
[
label("Address") + patient.street,
label("City") + patient.city,
{ content: label("State") + patient.state, colspan: 2 },
{ content: label("Zip") + patient.zip, colspan: 2 }
],
[
label("Reason for visit") + patient.chief_complaint,
label("Last dental visit") + patient.last_dental_visit,
{ content: label("In pain?") + in_pain, colspan: 2 },
{ content: label("In pain for") + pain_length, colspan: 2 }
]
],
cell_style: { inline_format: true, border_color: 'aaaaaa' },
position: :center
end

# proxy unhandled calls to Prawn
def method_missing(m, *a, &b)
@document.send(m, *a, &b)
end

private

attr_reader :patient

def label(text)
"<font size='9'><color rgb='808080'>#{text}\n</color></font>"
end

def pain_length
return "N/A" unless patient.pain? && patient.pain_length_in_days
h.distance_of_time_in_words patient.pain_length_in_days.days.ago, Date.today
end

def phone_number
h.number_to_phone(patient.phone.to_s.gsub(/[\(\)-\.]/,""), area_code: true)
end

def in_pain
@patient.pain? ? 'Yes' : 'No'
end

def h
ActionController::Base.helpers
end
end
Loading

0 comments on commit 309d815

Please sign in to comment.