Prompt
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.
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.
More Documentation Generators
![Apache Flink Documentation Generator](https://fs.enterprisedna.co/library/icons/flink.png)
![Apache Pig Documentation Generator](https://fs.enterprisedna.co/library/icons/apache_pig.png)
![Azure Data Factory Documentation Generator](https://fs.enterprisedna.co/library/icons/azure-data-factory.png)
![C/C++ Documentation Generator](https://fs.enterprisedna.co/library/icons/c_c_plus.png)
![CouchDB Documentation Generator](https://fs.enterprisedna.co/library/icons/couchdb.png)
![DAX Documentation Generator](https://fs.enterprisedna.co/library/icons/power-bi.png)
![Excel Documentation Generator](https://fs.enterprisedna.co/library/icons/excel.png)
![Firebase Documentation Generator](https://fs.enterprisedna.co/library/icons/firebase.png)
![Google BigQuery Documentation Generator](https://fs.enterprisedna.co/library/icons/google_bigquery.png)
![Google Sheets Documentation Generator](https://fs.enterprisedna.co/library/icons/google_sheets.png)
![GraphQL Documentation Generator](https://fs.enterprisedna.co/library/icons/graphql.png)
![Hive Documentation Generator](https://fs.enterprisedna.co/library/icons/hive.png)
![Java Documentation Generator](https://fs.enterprisedna.co/library/icons/java.png)
![JavaScript Documentation Generator](https://fs.enterprisedna.co/library/icons/javascript.png)
![Julia Documentation Generator](https://fs.enterprisedna.co/library/icons/julia.png)
![Lua Documentation Generator](https://fs.enterprisedna.co/library/icons/lua.png)
![M (Power Query) Documentation Generator](https://fs.enterprisedna.co/library/icons/m.png)
![MATLAB Documentation Generator](https://fs.enterprisedna.co/library/icons/matlab.png)
![MongoDB Documentation Generator](https://fs.enterprisedna.co/library/icons/mongodb.png)
![Oracle Documentation Generator](https://fs.enterprisedna.co/library/icons/oracle.png)
![PostgreSQL Documentation Generator](https://fs.enterprisedna.co/library/icons/postgresql.png)
![Power BI Documentation Generator](https://fs.enterprisedna.co/library/icons/power-bi.png)
![Python Documentation Generator](https://fs.enterprisedna.co/library/icons/python.png)
![R Documentation Generator](https://fs.enterprisedna.co/library/icons/r.png)
![Redis Documentation Generator](https://fs.enterprisedna.co/library/icons/redis.png)
![Regex Documentation Generator](https://fs.enterprisedna.co/library/icons/regex.png)
![Ruby Documentation Generator](https://fs.enterprisedna.co/library/icons/ruby.png)
![SAS Documentation Generator](https://fs.enterprisedna.co/library/icons/sas.png)
![Scala Documentation Generator](https://fs.enterprisedna.co/library/icons/scala.png)
![Shell Documentation Generator](https://fs.enterprisedna.co/library/icons/shell.png)
![SPSS Documentation Generator](https://fs.enterprisedna.co/library/icons/spss.png)
![SQL Documentation Generator](https://fs.enterprisedna.co/library/icons/sql.png)
![SQLite Documentation Generator](https://fs.enterprisedna.co/library/icons/sqlite.png)
![Stata Documentation Generator](https://fs.enterprisedna.co/library/icons/stata.png)
![Tableau Documentation Generator](https://fs.enterprisedna.co/library/icons/tableau.png)
![VBA Documentation Generator](https://fs.enterprisedna.co/library/icons/vba.png)