Skip to content

Instantly share code, notes, and snippets.

@juanandresnyc
Created December 6, 2019 14:33
Show Gist options
  • Save juanandresnyc/7dea13a3f3b61df086e8920f8e6e0d22 to your computer and use it in GitHub Desktop.
Save juanandresnyc/7dea13a3f3b61df086e8920f8e6e0d22 to your computer and use it in GitHub Desktop.
SELECT
"capsule_core_patientmedication"."id", "capsule_core_patientmedication"."should_process_refill", "capsule_core_patientmedication"."standard_fill_size", "capsule_core_patientmedication"."next_refill_date", "capsule_core_patientmedication"."medication_id", "capsule_core_medication"."primary_name", "capsule_core_medication"."secondary_name", "capsule_core_medication"."control_schedule", "capsule_core_medication"."mixing_type", "capsule_core_medication"."refrigeration_type", "capsule_core_medication"."strength", "capsule_core_medication"."unknown_status", "capsule_core_patientmedication"."last_delivered_fill_id", "capsule_core_prescriptionfulfillment"."price", "capsule_core_prescriptionfulfillment"."price_at_checkout", "capsule_core_prescriptionfulfillment"."should_waive_copay", "capsule_core_prescriptionfulfillment"."updated_at", "capsule_core_patientmedication"."upcoming_fill_id", T5."price", T5."price_at_checkout", T5."should_waive_copay", T5."updated_at", "capsule_core_patientmedication"."active_rx_id", "capsule_core_prescription"."control_schedule", "capsule_core_prescription"."quantity", "capsule_core_prescription"."quantity_remaining"
FROM
"capsule_core_patientmedication"
INNER JOIN "capsule_core_medication" ON ("capsule_core_patientmedication"."medication_id" = "capsule_core_medication"."id")
LEFT OUTER JOIN "capsule_core_prescriptionfulfillment" ON ("capsule_core_patientmedication"."last_delivered_fill_id" = "capsule_core_prescriptionfulfillment"."id")
LEFT OUTER JOIN "capsule_core_prescriptionfulfillment" T5 ON ("capsule_core_patientmedication"."upcoming_fill_id" = T5."id")
LEFT OUTER JOIN "capsule_core_prescription" ON ("capsule_core_patientmedication"."active_rx_id" = "capsule_core_prescription"."id")
WHERE (
"capsule_core_patientmedication"."deleted_at" IS NULL AND "capsule_core_patientmedication"."patient_id" = 59101
)
ORDER BY "capsule_core_patientmedication"."updated_at" DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment