diff --git a/app/controllers/ref_consult_requests_controller.rb b/app/controllers/ref_consult_requests_controller.rb index 44bfa4c..a48e17d 100644 --- a/app/controllers/ref_consult_requests_controller.rb +++ b/app/controllers/ref_consult_requests_controller.rb @@ -3,7 +3,34 @@ class RefConsultRequestsController < ApplicationController # GET /ref_consult_requests # GET /ref_consult_requests.json def index - @ref_consult_requests = RefConsultRequest.all + + if params[:record_id].nil? + ## list all patients + @ref_consult_requests = RefConsultRequest.all + @patient_names = Hash.new + @ref_consult_requests.each do |ref_consult_request| + if ref_consult_request.patientRecordId + record = Record.find( ref_consult_request.patientRecordId ) + next if record.nil? + @patient_names["#{ref_consult_request.patientRecordId}"] = record.last.upcase + ', ' + record.first + end + end + + else + ## list refs for this patient only + @patient_names = Hash.new + @ref_consult_requests = [] + ref_consults = RefConsultRequest.all().to_a + ref_consults.each do |ref_consult| + record = Record.find( ref_consult.patientRecordId ) + next if record.nil? + if record.medical_record_number == params[:record_id] + @ref_consult_requests << ref_consult + @patient_names["#{ref_consult.patientRecordId}"] = record.last.upcase + ', ' + record.first + end + end + + end respond_to do |format| format.html # index.html.erb @@ -12,6 +39,32 @@ def index end end + # GET /ref_consult_requests/1 + # GET /ref_consult_requests/1.json + def email + @ref_consult_request = RefConsultRequest.find( params[:id] ) + + end + + + # GET /ref_consult_requests/email/1 + def email + @ref_consult_request = RefConsultRequest.find( params[:id] ) + + end + + # GET /ref_consult_requests/sendemail/1 + def send_email + @ref_consult_request = RefConsultRequest.find( params[:id] ) + @record = Record.find( @ref_consult_request.patientRecordId ) if !@ref_consult_request.patientRecordId.nil? + + PdsMail.consult(@ref_consult_request, @record).deliver ## + respond_to do |format| + format.html { redirect_to ref_consult_requests_url, notice: 'PDS Direct Email sent!' } + end + end + + # GET /ref_consult_requests/1 # GET /ref_consult_requests/1.json def show @@ -22,10 +75,22 @@ def show return end @record = Record.find( @ref_consult_request.patientRecordId ) if !@ref_consult_request.patientRecordId.nil? + @medications = @record.medications.map {|x| "http://direct.rhex.us:3000/records/#{@record.medical_record_number}/medications/#{x._id}" } + @conditions = @record.conditions.map {|x| "http://direct.rhex.us:3000/records/#{@record.medical_record_number}/conditions/#{x._id}" } + @vital_signs = @record.vital_signs.map {|x| "http://direct.rhex.us:3000/records/#{@record.medical_record_number}/vital_signs/#{x._id}" } + # @conditions = @record.conditions.map {|x| x.description } + # @medications = @record.medications.map {|x| x.description } + @vitals = @record.vital_signs.sort { |a,b| b.time <=> a.time } + @vitals.map! {|y| [ Time.at(y.time).strftime("%Y-%m-%d"), y.description.split(" ")[0], y.value['scalar']] } + respond_to do |format| format.html # show.html.erb - format.json { render json: @ref_consult_request } + format.json { render json: { :ref_consult_requests => @ref_consult_request, + :conditions => @conditions, + :medications => @medications, + :vital_signs => @vital_signs } + } format.xml { render xml: @ref_consult_request.to_xml } end end @@ -41,11 +106,15 @@ def new if params[:id] @ref_consult_request.patientRecordId = params[:id] @record = Record.find( @ref_consult_request.patientRecordId ) + @conditions = @record.conditions.map {|x| x.description } + @medications = @record.medications.map {|x| x.description } + @vitals = @record.vital_signs.sort { |a,b| b.time <=> a.time } + @vitals.map! {|y| [ Time.at(y.time).strftime("%Y-%m-%d"), y.description.split(" ")[0], y.value['scalar']] } end respond_to do |format| format.html # new.html.erb - format.json { render json: @ref_consult_request } + format.json { render json: { :ref_consult_requests => @ref_consult_request } } end end @@ -53,6 +122,10 @@ def new def edit @ref_consult_request = RefConsultRequest.find(params[:id]) @record = Record.find( @ref_consult_request.patientRecordId ) if @ref_consult_request.patientRecordId + @conditions = @record.conditions.map {|x| x.description } + @medications = @record.medications.map {|x| x.description } + @vitals = @record.vital_signs.sort { |a,b| b.time <=> a.time } + @vitals.map! {|y| [ Time.at(y.time).strftime("%Y-%m-%d"), y.description.split(" ")[0], y.value['scalar']] } end # POST /ref_consult_requests diff --git a/app/mailers/pds_mail.rb b/app/mailers/pds_mail.rb new file mode 100644 index 0000000..02aa576 --- /dev/null +++ b/app/mailers/pds_mail.rb @@ -0,0 +1,22 @@ +class PdsMail < ActionMailer::Base + #default from: "gganley@direct.rhex.us" + add_template_helper(ApplicationHelper) + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.rhex_mail.consult.subject + # + def consult(ref_consult_request, record) + @ref_consult_request = ref_consult_request + @record = record + @greeting = "Hi" + + begin + mail from: "gganley@direct.rhex.us", to: "gganley@direct.healthvault-stage.com", subject: "RHEx email from PDS - Consult REF##{@ref_consult_request.refNumber}" + rescue Exception=>e + puts e.inspect + end + + end +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 56e7e12..70b96f3 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -13,7 +13,8 @@ Settings Audit Log Alerts - <% end %> + Consult Requests + <% end %> <% unless current_user.nil? || current_user.username.nil? %> Welcome, <%= current_user.username %> diff --git a/app/views/pds_mail/consult.text.erb b/app/views/pds_mail/consult.text.erb new file mode 100644 index 0000000..1ed5f33 --- /dev/null +++ b/app/views/pds_mail/consult.text.erb @@ -0,0 +1,29 @@ +Dear <%= @ref_consult_request.requestedConsultingProviderId %> + +The following email is a request for consultation regarding the patient below. +Please click on this link for more details: + +>Consult REF#<%= @ref_consult_request.refNumber %> + +Please checkout the following consult: + + +Date: <%= @ref_consult_request.refDate %> + +Priority: <%= @ref_consult_request.priority %> + +Reason: <%= @ref_consult_request.reasonText %> + +Patient Name: <%= (@record.last.upcase + ', ' + @record.first).html_safe if @record %> +Gender: <%= (@record.gender).html_safe if @record %> +Age: <%= getAgeText(@record.birthdate).html_safe if @record %> + +Conditions: <%= @ref_consult_request.reasonConditionId %> + +Specialty: <%= @ref_consult_request.requestedSpecialty %> + +Specialist: <%= @ref_consult_request.requestedConsultingProviderId %> + +Description: <%= @ref_consult_request.reasonDescription %> + + diff --git a/app/views/ref_consult_requests/_form.html.erb b/app/views/ref_consult_requests/_form.html.erb index bcfdd67..211168b 100644 --- a/app/views/ref_consult_requests/_form.html.erb +++ b/app/views/ref_consult_requests/_form.html.erb @@ -78,19 +78,32 @@
<%= f.label "Conditions:" %> - <%= f.select :reasonConditionId, [ "DJD/Osteoarthritis, spine", "Diabetes Mellitus, Non-Insulin Dependent"], :prompt => 'Select...' %> + <%= f.select :reasonConditionId, @conditions, :prompt => 'Select...' %>
- <%= f.label "Specialty:" %> - <%= f.select :requestedSpecialty, RefConsultRequest.get_requestedSpecialty_values, :prompt => 'Select Specialty...' %> + <%= f.label "Medications:" %> + <%= @medications.inspect %>
-
- <%= f.label "Specialist:" %> - <%= f.select :requestedConsultingProviderId, [ "Dr. Bill Schwartz", "Dr. Tom Jones"], :prompt => 'Select...' %> +
+ <%= f.label "Recent Vitals:" %> + + + <% cnt = 0 + @vitals.each do |x| %> + <%= x.inspect %> + <% break if cnt > 4 + cnt += 1 + end %> + +
+

+

+ <%= f.label "Specialty:" %> + <%= f.select :requestedSpecialty, RefConsultRequest.get_requestedSpecialty_values, :prompt => 'Select Specialty...' %>
diff --git a/app/views/ref_consult_requests/email.html.erb b/app/views/ref_consult_requests/email.html.erb new file mode 100644 index 0000000..4b44d43 --- /dev/null +++ b/app/views/ref_consult_requests/email.html.erb @@ -0,0 +1,100 @@ +<%= stylesheet_link_tag :common %> +

<%= notice %>

+ + + + +

+ + + +
<%= @ref_consult_request.reasonConditionId %> <%= @ref_consult_request.refNumber %>         Status: <%= @ref_consult_request.status %>
+

+Email this consult ? +

+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + + +
+
+ + + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + + + +
+
+ + + + +
Date:<%= @ref_consult_request.refDate %>
Priority: <%= @ref_consult_request.priority %>
Reason:<%= @ref_consult_request.reasonText %>
Patient Name:     <%= (@record.last.upcase + ', ' + @record.first).html_safe if @record %>
Insurance:
Gender: <%= (@record.gender).html_safe if @record %>
Age:<%= getAgeText(@record.birthdate).html_safe if @record %>
Conditions: <%= @ref_consult_request.reasonConditionId %>
Specialty: <%= @ref_consult_request.requestedSpecialty %>
Specialist: <%= @ref_consult_request.requestedConsultingProviderId %>
Description:<%= @ref_consult_request.reasonDescription %>
<%= link_to 'Send Email', send_email_ref_consult_request_path(@ref_consult_request) %> + <%= link_to 'Back', ref_consult_requests_path %>
+ + diff --git a/app/views/ref_consult_requests/index.html.erb b/app/views/ref_consult_requests/index.html.erb index 7262625..cb66b38 100644 --- a/app/views/ref_consult_requests/index.html.erb +++ b/app/views/ref_consult_requests/index.html.erb @@ -1,3 +1,6 @@ +<%= stylesheet_link_tag :common %> +

<%= notice %>

+

Consults You've Initiated

To initiate a consult, search for a patient and then press the @@ -13,7 +16,6 @@ Or, you can click create consult request and then select the patient from the Pa Reason Patient Status - Specialist <% @ref_consult_requests.each do |ref_consult_request| %> @@ -22,14 +24,14 @@ Or, you can click create consult request and then select the patient from the Pa <%= ref_consult_request.refNumber %> <%= ref_consult_request.priority %> <%= ref_consult_request.reasonText %> - Fred Smith + <%= @patient_names[ref_consult_request.patientRecordId] if ref_consult_request.patientRecordId %> <%= ref_consult_request.status %> - <%= ref_consult_request.requestedConsultingProviderId %> <%= link_to 'Show', ref_consult_request %> <%= link_to 'Edit', edit_ref_consult_request_path(ref_consult_request) %> <%= link_to 'Destroy', ref_consult_request, confirm: 'Are you sure?', method: :delete %> - + <%= link_to 'Email Request w/Direct', email_ref_consult_request_path(ref_consult_request) %> + <% end %> diff --git a/app/views/ref_consult_requests/show.html.erb b/app/views/ref_consult_requests/show.html.erb index 4a52284..109ccc5 100644 --- a/app/views/ref_consult_requests/show.html.erb +++ b/app/views/ref_consult_requests/show.html.erb @@ -48,6 +48,26 @@ Your consult request has been submitted for authorization by the insurance provi
+
+ Medications: + <%= @medications.inspect %> +
+ + +
+ Recent Vitals: + + + <% cnt = 0 + @vitals.each do |x| %> + <%= x.inspect %> + <% break if cnt > 4 + cnt += 1 + end %> + +
+ +
Gender: <%= (@record.gender).html_safe if @record %> @@ -72,12 +92,6 @@ Your consult request has been submitted for authorization by the insurance provi Specialty: <%= @ref_consult_request.requestedSpecialty %>
- - -
- Specialist: - <%= @ref_consult_request.requestedConsultingProviderId %> -
diff --git a/config/environments/development.rb b/config/environments/development.rb index 7033c6f..f03c2ee 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,9 +13,6 @@ config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger config.active_support.deprecation = :log @@ -27,4 +24,21 @@ # Expands the lines which load the assets config.assets.debug = true + + + ###### + ## action mailer config for DIRECT + config.action_mailer.raise_delivery_errors = true + config.action_mailer.delivery_method = :smtp + + config.action_mailer.smtp_settings = { + address: "mail.direct.rhex.us", + port: 25, + domain: "direct.rhex.us", + authentication: "plain", + user_name: "gganley", + password: "mitre1", + enable_starttls_auto: true + } + end diff --git a/config/routes.rb b/config/routes.rb index 6951750..be35acd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,13 @@ HdataServer::Application.routes.draw do ## + resources :records do + resources :ref_consult_requests + end resources :ref_consult_requests match "ref_consult_requests/new/:id" => "ref_consult_requests#new", :as => :new_ref_consult_request_patient, :method => :get + match "ref_consult_requests/email/:id" => "ref_consult_requests#email", :as => :email_ref_consult_request, :method => :get + match "ref_consult_requests/send_email/:id" => "ref_consult_requests#send_email", :as => :send_email_ref_consult_request, :method => :get resources :ref_consult_summaries diff --git a/test/functional/pds_mail_test.rb b/test/functional/pds_mail_test.rb new file mode 100644 index 0000000..2984939 --- /dev/null +++ b/test/functional/pds_mail_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' + +class PdsMail < ActionMailer::TestCase + test "consult" do + mail = PdsMail.consult + assert_equal "Consult", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +end