SELECT
c.rendering_id AS prov_number,
c.begin_date_of_service AS date_of_service,
c.practice_id AS group_number,
v.enc_nbr AS invoice,
p.person_nbr AS patient,
v.enc_nbr AS invoice_number,
c.charge_id AS transaction_number,
t.med_rec_nbr AS primary_mrn,
p.last_name,
p.first_name,
z.payer_id AS orig_fsc_number,
z.payer_id AS curr_fsc_number,
c.location_id AS location_number,
c.closing_date AS posting_date,
c.quantity AS service_units,
c.amt AS charge_amount,
c.cpt4_code_id AS procedure_code,
r.description AS procedure_name,
x.tran_code_id AS pay_code_number,
ISNULL([modifier_1],'')AS modifier_code_1,
ISNULL([modifier_2],'') AS modifier_code_2,
ISNULL([modifier_3],'') AS modifier_code_3,
ISNULL([icd9cm_code_id],'') AS dx_code_1,
ISNULL([icd9cm_code_id_2],'') AS dx_code_2,
ISNULL([icd9cm_code_id_3],'') AS dx_code_3,
ISNULL([icd9cm_code_id_4],'') AS dx_code_4
FROM charges c
INNER JOIN person p ON c.person_id = p.person_id
INNER JOIN patient t ON c.person_id = t.person_id
INNER JOIN patient_encounter v ON c.person_id = v.person_id
INNER JOIN encounter_payer z ON c.person_id = z.person_id
INNER JOIN cpt4_code_mstr r ON c.cpt4_code_id = r.cpt4_code_id
INNER JOIN transactions x ON c.person_id = x.person_id
WHERE c.practice_id ='0001'
AND c.closing_date >= GetDate() - 7