Skip to content

Instantly share code, notes, and snippets.

@barek2k2
Created February 10, 2017 17:31
Show Gist options
  • Save barek2k2/617e1042a127ad932dd813f1fe21f658 to your computer and use it in GitHub Desktop.
Save barek2k2/617e1042a127ad932dd813f1fe21f658 to your computer and use it in GitHub Desktop.
2.1.9 :029 > def sample
2.1.9 :030?> @clinician = User.find_by_email('[email protected]')
2.1.9 :031?> invoice_events = @clinician.invoice_events
2.1.9 :032?> invoice_events = invoice_events.includes(:invoice).references(:invoices)
2.1.9 :033?> params = {}
2.1.9 :034?> params[:date] = '2010-10-10'
2.1.9 :035?> invoice_events = invoice_events.where("invoice_events.created_at BETWEEN ? AND ? AND payment_id IS NOT NULL", params[:date].to_date, params[:date].to_date.send(:end_of_month).end_of_day)
2.1.9 :036?> invoice_events = invoice_events.where("invoices.location_id=? AND (invoice_events.patient_amount < 0 OR invoice_events.insurance_amount < 0)", 602)
2.1.9 :037?> invoice_events
2.1.9 :038?> end
=> :sample
2.1.9 :039 > sample
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
SQL (18.3ms) SELECT "invoice_events"."id" AS t0_r0, "invoice_events"."invoice_id" AS t0_r1, "invoice_events"."event_at" AS t0_r2, "invoice_events"."name" AS t0_r3, "invoice_events"."actor_name" AS t0_r4, "invoice_events"."actorable_type" AS t0_r5, "invoice_events"."actorable_id" AS t0_r6, "invoice_events"."patient_amount" AS t0_r7, "invoice_events"."insurance_amount" AS t0_r8, "invoice_events"."sort" AS t0_r9, "invoice_events"."created_at" AS t0_r10, "invoice_events"."updated_at" AS t0_r11, "invoice_events"."submitted" AS t0_r12, "invoice_events"."patient_provider_id" AS t0_r13, "invoice_events"."procedure_report_id" AS t0_r14, "invoice_events"."clinician_id" AS t0_r15, "invoice_events"."payment_id" AS t0_r16, "invoice_events"."billing_company_id" AS t0_r17, "invoice_events"."receipt_report_id" AS t0_r18, "invoice_events"."status" AS t0_r19, "invoice_events"."status_updated_at" AS t0_r20, "invoice_events"."balance" AS t0_r21, "invoice_events"."description" AS t0_r22, "invoices"."id" AS t1_r0, "invoices"."patient_id" AS t1_r1, "invoices"."clinician_id" AS t1_r2, "invoices"."invoice_date" AS t1_r3, "invoices"."due_date" AS t1_r4, "invoices"."memo" AS t1_r5, "invoices"."diagnosis_code" AS t1_r6, "invoices"."pt_balance" AS t1_r7, "invoices"."ins_balance" AS t1_r8, "invoices"."inv_balance" AS t1_r9, "invoices"."created_at" AS t1_r10, "invoices"."updated_at" AS t1_r11, "invoices"."practice_id" AS t1_r12, "invoices"."terms" AS t1_r13, "invoices"."service_code_id" AS t1_r14, "invoices"."appointment_id" AS t1_r15, "invoices"."invoice_number" AS t1_r16, "invoices"."bill_address" AS t1_r17, "invoices"."total_patient_payments" AS t1_r18, "invoices"."total_insurance_payments" AS t1_r19, "invoices"."primary_diagnosis_code_id" AS t1_r20, "invoices"."secondary_diagnosis_code_id" AS t1_r21, "invoices"."dsm_version" AS t1_r22, "invoices"."contact_note_id" AS t1_r23, "invoices"."location_id" AS t1_r24 FROM "invoice_events" LEFT OUTER JOIN "invoices" ON "invoices"."id" = "invoice_events"."invoice_id" WHERE "invoice_events"."clinician_id" = $1 AND (invoice_events.created_at BETWEEN '2010-10-10' AND '2010-10-31 23:59:59.999999' AND payment_id IS NOT NULL) AND (invoices.location_id=602 AND (invoice_events.patient_amount < 0 OR invoice_events.insurance_amount < 0)) [["clinician_id", 426]]
=> #<ActiveRecord::AssociationRelation []>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment