Documentation Generator

Code Documentation Analysis

Retrieves distinct patient information along with prescription details from multiple tables using joins, conditions, and aggregations.


Empty image or helper icon

Prompt

SELECT distinct ep.pd_pat_nbr, ep.pd_pat_key, min_cp_upid, pd_creat_dt::DATE,pd_frst_nm as pat_frst_nm, pd_last_nm as pat_last_nm, ed.drug_ndc, ed.drug_lbl_nm, ef.FD_LGL_NM,
eprid.prscrbr_id as npi,
EPR.FRST_NM as prscrbr_frst_nm, EPR.MID_NM as prscrbr_mid_nm, EPR.LAST_NM as prscrbr_last_nm,t2.min_padr, pa.PRSCRBR_ADRS_LINE_1_TXT, pa.PRSCRBR_ADRS_LINE_2_TXT, pa.city_nm as prscrbr_city_nm, 
pa.st_cd as prscrbr_state_cd, pa.zip_cd as  prscrbr_zip_cd, nrs.referral_source,
pg.isr_grp_nm, pg.rcl_grp_nm, pg.connect_grp_nm, efs.FS_FILL_STTS_DESC
FROM cpdw_bz_pr_db.cpdw.ERX_FILL_WRKFLOW_FACT fwf

inner join (select pd_pat_key, min(fwfs_rx_nbr) as min_rx, max(FS_FILL_STTS_KEY) as max_fs_key, min(padr_key) as min_padr, min(drug_key) as min_drug_key from cpdw_bz_pr_db.cpdw.ERX_FILL_WRKFLOW_FACT where drug_key is not null and padr_key is not null and padr_key !=0 group by pd_pat_key) t2 on fwf.pd_pat_key = t2.pd_pat_key 
and fwf.fwfs_rx_nbr = t2.min_rx and fwf.FS_FILL_STTS_KEY = t2.max_fs_key and fwf.padr_key = t2.min_padr and fwf.drug_key = t2.min_drug_key

left join cpdw_bz_pr_db.cpdw.erx_pat ep on fwf.pd_pat_key = ep.pd_pat_key

inner join (select erx_pat_id, min(cp_upid) as min_cp_upid, cp_upid_trmntn_dt from cpdw_bz_pr_db.cpdw.pat_erx_cps_xwalk group by erx_pat_id, cp_upid_trmntn_dt) pecx on ep.pd_pat_nbr::TEXT =pecx.erx_pat_id and pecx.cp_upid_trmntn_dt > sysdate

left join cpdw_bz_pr_db.cpdw.ERX_PRSCRBR epr on fwf.PRS_PRSCRBR_KEY = EPR.PRSCRBR_KEY

left join cpdw_bz_pr_db.cpdw.ERX_PRSCRBR_ID eprid on eprid.prscrbr_key = fwf.PRS_PRSCRBR_KEY and prscrbr_id_type_key = 501

left join cpanalytics.prscrbr_groups pg on epr.prscrbr_nbr = pg.prscrbr_nbr

left join cpanalytics.npi_referral_source nrs on eprid.prscrbr_id = nrs.npi

left join cpdw_bz_pr_db.cpdw.ERX_DRUG ED on fwf.DRUG_KEY = ed.DRUG_KEY

left join cpdw_bz_pr_db.cpdw.ERX_FCLTY ef on fwf.FD_FCLTY_KEY = ef.FD_FCLTY_KEY

Answer

Code Documentation

Purpose

The purpose of this code is to retrieve distinct patient information along with their prescription details from multiple tables in the database. The code joins several tables and applies certain conditions to filter the data.

Class Signatures

There are no class signatures present in this code.

Method Signatures

There are no method signatures present in this code.

Inline Comments

There are no inline comments present in this code.

Code Blocks

SELECT distinct ep.pd_pat_nbr, ep.pd_pat_key, min_cp_upid, pd_creat_dt::DATE,pd_frst_nm as pat_frst_nm, pd_last_nm as pat_last_nm, ed.drug_ndc, ed.drug_lbl_nm, ef.FD_LGL_NM,
eprid.prscrbr_id as npi,
EPR.FRST_NM as prscrbr_frst_nm, EPR.MID_NM as prscrbr_mid_nm, EPR.LAST_NM as prscrbr_last_nm,t2.min_padr, pa.PRSCRBR_ADRS_LINE_1_TXT, pa.PRSCRBR_ADRS_LINE_2_TXT, pa.city_nm as prscrbr_city_nm, 
pa.st_cd as prscrbr_state_cd, pa.zip_cd as prscrbr_zip_cd, nrs.referral_source,
pg.isr_grp_nm, pg.rcl_grp_nm, pg.connect_grp_nm, efs.FS_FILL_STTS_DESC
FROM cpdw_bz_pr_db.cpdw.ERX_FILL_WRKFLOW_FACT fwf

inner join (select pd_pat_key, min(fwfs_rx_nbr) as min_rx, max(FS_FILL_STTS_KEY) as max_fs_key, min(padr_key) as min_padr, min(drug_key) as min_drug_key from cpdw_bz_pr_db.cpdw.ERX_FILL_WRKFLOW_FACT where drug_key is not null and padr_key is not null and padr_key !=0 group by pd_pat_key) t2 on fwf.pd_pat_key = t2.pd_pat_key 
and fwf.fwfs_rx_nbr = t2.min_rx and fwf.FS_FILL_STTS_KEY = t2.max_fs_key and fwf.padr_key = t2.min_padr and fwf.drug_key = t2.min_drug_key

left join cpdw_bz_pr_db.cpdw.erx_pat ep on fwf.pd_pat_key = ep.pd_pat_key

inner join (select erx_pat_id, min(cp_upid) as min_cp_upid, cp_upid_trmntn_dt from cpdw_bz_pr_db.cpdw.pat_erx_cps_xwalk group by erx_pat_id, cp_upid_trmntn_dt) pecx on ep.pd_pat_nbr::TEXT =pecx.erx_pat_id and pecx.cp_upid_trmntn_dt > sysdate

left join cpdw_bz_pr_db.cpdw.ERX_PRSCRBR epr on fwf.PRS_PRSCRBR_KEY = EPR.PRSCRBR_KEY

left join cpdw_bz_pr_db.cpdw.ERX_PRSCRBR_ID eprid on eprid.prscrbr_key = fwf.PRS_PRSCRBR_KEY and prscrbr_id_type_key = 501

left join cpanalytics.prscrbr_groups pg on epr.prscrbr_nbr = pg.prscrbr_nbr

left join cpanalytics.npi_referral_source nrs on eprid.prscrbr_id = nrs.npi

left join cpdw_bz_pr_db.cpdw.ERX_DRUG ED on fwf.DRUG_KEY = ed.DRUG_KEY

left join cpdw_bz_pr_db.cpdw.ERX_FCLTY ef on fwf.FD_FCLTY_KEY = ef.FD_FCLTY_KEY

Summary

This code retrieves distinct patient information along with their prescription details from multiple tables. It applies joins, conditions, and aggregations to filter the data. The retrieved information includes patient details, prescription details, drug information, facility information, and other related attributes.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This code documentation provides an analysis of code that retrieves distinct patient information and their prescription details from multiple tables in a database. The code uses various joins, conditions, and aggregations to filter the data. The retrieved information includes patient details such as patient number, key, first name, and last name, as well as prescription details such as drug NDC and label name. It also includes information about the prescribing physician, facility, address, referral source, and group affiliations. The code aims to gather comprehensive information related to patients and their prescriptions for further analysis and reporting purposes.