Skip to content

Instantly share code, notes, and snippets.

View EminenceHC's full-sized avatar

EminenceHC EminenceHC

  • Eminence Healthcare
  • Fresno CA
View GitHub Profile
@EminenceHC
EminenceHC / file.js
Last active August 29, 2015 14:16
Fire action if all three values are "0"
varAlcohol = $("[name='escreen[alcohol]']").val();
varMarijuana = $("[name='escreen[marijuana]']").val();
varElse = $("[name='escreen[anything_else]']").val();
var $select = $(varAlcohol & varMarijuana & varElse),
getAllValues = function() {
return $select.map(function() {
return this.value;
}).get();
};
@EminenceHC
EminenceHC / model.rb
Created March 2, 2015 17:35
OR value validation
#SINGLE VALUE (WORKS)
validates :relationship_other, presence: true, if: Proc.new { |o| o.relationship == 'Other' }
# FLAGS VALIDATION WHEN 'OTHER' IS SELECTED, DOES NOT FLAG WHEN 'OTHER FAMILY MEMBER' IS SELECTED
validates :relationship_other, presence: true, if: Proc.new { |o| o.relationship == 'Other' } || Proc.new { |o| o.relationship == 'Other Family Member' }
@EminenceHC
EminenceHC / referrals_controller.rb
Last active August 29, 2015 14:16
add invalid date to errors
def create
@referral = Referral.new(referral_params)
begin
params[:referral][:dob] = Date.strptime(params[:referral][:dob], '%m/%d/%Y')
rescue
@referral.errors.add(:dob, 'Invalid Date')
end
@EminenceHC
EminenceHC / controller.rb
Created February 26, 2015 00:12
controller.rb
def create
params[:referral][:dob] = Date.strptime(params[:referral][:dob], '%m/%d/%Y')
@referral = Referral.new(referral_params)
if verify_recaptcha(:model => @referral, message: "Please click the box labeled 'I'm not a robot' above.") && @referral.save
redirect_to confirmation_page_referrals_path, notice: "Thank you for submitting this referral to Eminence Healthcare."
else
render :new
end
@EminenceHC
EminenceHC / query.rb
Created February 12, 2015 16:27
Query for ALL matching.
runquery = Student.joins(:user)
runquery = runquery.where(users: {first_name: params[:first_name]}) if params[:first_name].present?
runquery = runquery.where(users: {last_name: params[:last_name]}) if params[:last_name].present?
runquery = runquery.where(users: {social_security_no: params[:social_security_no]}) if params[:social_security_no].present?
runquery = runquery.where(program: params[:program]) if params[:program].present?
runquery = runquery.select('students.*, students.id as sid, users.*')
@query = runquery
def self.calculate_drug_usage(drug)
if drug == "alcohol"
map = DrugAssessment.where(student_id: students_of_school).map { |m| [m.date, m.alcohol.to_i]}
else
end
end
@EminenceHC
EminenceHC / efficiency.rb
Created January 6, 2015 17:48
Multiple Email Recepients
class Efficiency < ActionMailer::Base
default from: "e@eminencehc.com"
def blast(date, int)
attachments.inline['ecore2.png'] = File.read(Rails.root.join('app/assets/images/mail_attachments/ecore2.png'))
@date = date.to_date
@int = int
@counselor_blast = EpitomaxServiceUtilization.new(@date).counselor
@EminenceHC
EminenceHC / service_import.rb
Created December 16, 2014 17:36
Merge multiple records into one during import.
class EpitomaxServiceImport
#ActiveModel::Model
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
attr_accessor :file
def initialize(attributes = {})
class Calculation < ActiveRecord::Base
def initialize(date)
@date = date
end
self.calculate_date
@date = @date + 1.day
return @date
end
@EminenceHC
EminenceHC / calculation.rb
Last active August 29, 2015 14:11
Class for calculation
class Calculation < ActiveRecord::Base
self.abstract_class = true
include ActiveModel::Model
def initialize(date)
@date = date
end
def plus_one_day