0% found this document useful (0 votes)
8 views3 pages

1 ICMS RPT - dbo.DW Case Data Fields Initial Load

The document contains a SQL script that truncates the table 'DW_Case_Data_Fields' and inserts new data into it from various sources, including demographic and hospital information. It includes multiple case-related fields such as case status, newborn details, mother information, and emergency contact data. The script utilizes various functions to retrieve and format data for insertion into the specified table.

Uploaded by

Mahir Kaljanac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

1 ICMS RPT - dbo.DW Case Data Fields Initial Load

The document contains a SQL script that truncates the table 'DW_Case_Data_Fields' and inserts new data into it from various sources, including demographic and hospital information. It includes multiple case-related fields such as case status, newborn details, mother information, and emergency contact data. The script utilizes various functions to retrieve and format data for insertion into the specified table.

Uploaded by

Mahir Kaljanac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

truncate table iCMS_RPT.dbo.

DW_Case_Data_Fields
INSERT INTO iCMS_RPT.dbo.DW_Case_Data_Fields
select
CASE
WHEN CDV.LINK is null THEN 'No'
else 'Yes'
END
as "Case",
CASE
WHEN CDV.LINK is null THEN PA_ICMS.dbo.GETCASESTATUS ('Z')
else
PA_ICMS.dbo.GETCASESTATUS (CDV.SIDE)
END

AS "Case Status",
a.Newborn_ID as "Newborn ID",
a.LABID as "Filter Paper",
PA_ICMS.dbo.GETUSERNAME( CDV.DBS_CHNID ) as "DBS CHN",
PA_ICMS.dbo.GETUSERNAME( CDV.POC_HEARING_CHNID ) as "POC-Hearing CHN",
PA_ICMS.dbo.GETUSERNAME( CDV.POC_CHD_CHNID ) as "PPOC-CHD CHN",
PA_ICMS.dbo.getsubmittername(CDV.submid) as "Current Hospital",

a.INIT_PA_LABNO as "Accession #",


CDV.MEDRECNO as "Med Rec No",
CDV.LNAME as "Last Name",
CDV.FNAME as "First Name",
CDV.AKALAST as "AKA Last Name",
CDV.AKA as "AKA First Name",
CDV.LNAME_DISCHARGE as "Last Name at Discharge",
CDV.FNAME_DISCHARGE as "First Name at Discharge",
PA_ICMS.DBO.GetSexType(cdv.SEX) as "Gender",

PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(418, cdv.ethnicity) as "Newborn Hispanic",


PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(53, cdv.twin) as "Birth Order",
cdv.BIRTHDT as "Birth Date",
cdv.birthtm as "Birth Time",
cdv.birthwt as "Birth Weight",
CDV.CURRWT as "Current Weight",
CDV.GESTATION_AGE as "Gestation Age",

PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(419, CDV.Medical_Assistance)
as "Medical Assistance",

CASE
WHEN cdv.TRANSFUS = '0' THEN 'No'
WHEN cdv.TRANSFUS = '2' THEN 'No'
WHEN cdv.TRANSFUS = 'N' THEN 'No'
WHEN cdv.TRANSFUS = '1' THEN 'Yes'
WHEN cdv.TRANSFUS = 'Y' THEN 'Yes'
WHEN cdv.TRANSFUS = '' THEN ''
WHEN cdv.TRANSFUS is null THEN ''
else cdv.TRANSFUS
END as "Transfused",
cdv.DTXFUS "Transfusion Date/Time",
cdv.LABNO,
cdv.LABNO as "NHSP",

BH.DESCR1 as "Birth Hospital",


BH.DESCR1 as "Hospital Name",
BH.Street1 as "Hospital Address",
BH.City as "Hospital City",
BH.State as "Hospital State",
BH.zipcode as "Hospital Zip Code",

cdv.MLNAME as "Mother Last",


cdv.MFNAME as "Mother First",
cdv.RegionID as "Region",
cdv.MSTREET as "Mother Address",
cdv.MCITY as "Mother City",
cdv.MSTATE as "Mother State",
cdv.MZIPCODE as "Mother Zip Code",
PA_ICMS.dbo.GETCOUNTYNAME(cdv.MCOUNTY) as "Mother County",
cdv.MPHONE as "Mother Phone Number",
cdv.MBIRTHDT as "Mother DOB",
CDV.MCELL as "Mother Cell Phone",
cdv.mfax as "Mother Work Phone",

CDV.MEXT as "Mother Work Extension",


CDV.MEMAIL as "Mother Email Address",

cdv.ECONTACT as "Emergency Contact",


cdv.EPHONE as "Emergency Contact#",

a.DTCOLL as "Specimen Collection Date",


a.TMCOLL as "Collection Time",

a.AGECOLL as "Age at Collection",


PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(201, a.SPECTYPE)
as "Specimen Type",
cdv.CCHD_REASON,
cdv.MAT_STEROIDS,

PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(8963, CDV.HYPERAL)
as "TPN",

PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(8963, CDV.CARNITINE_SUPPL)
as "Carnitine supplement",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(8900, cdv.NICU_INDICATOR)
as "Acuity",
PA_ICMS.dbo.GETUSERNAME(LG.ORIG_USER_ID) as "AC
Entered by",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(62, LG.CNTCT_FUTYPE)
as "AC Follow-up Type",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(60, LG.CNTCT_GUARDIAN)
as "Legal Guardian",

LG.CNTCT_LNAME as "AC Last Name",


LG.CNTCT_FNAME as "AC First Name",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(38, LG.CNTCT_PCONTACT)
as "AC Relationship",
LG.CNTCT_STREET as "AC Street Address",
LG.CNTCT_ZIPCODE as "AC Zip Code",
LG.CNTCT_CITY as "AC City",
LG.CNTCT_STATE as "AC State",
PA_ICMS.dbo.GETCOUNTYNAME(LG.CNTCT_COUNTY) as "AC County of Residence",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(50, LG.CNTCT_COUNTRY) as "AC Country Of
Residence",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(36,LG.CNTCT_PRIMARY_LANGUAGE)
as "AC Primary Language",
LG.CNTCT_PHONE as "AC Home Phone",
LG.CNTCT_CELL as "AC Cell Phone",
LG.CNTCT_WPHONE as "AC Work Phone",
LG.CNTCT_WRK_EXT as "AC Work Extension",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(64, LG.CNTCT_ADOPTED) as "Adopted",
PA_ICMS.dbo.GET_RDE_VALIDS_DESCR(64,LG.CNTCT_FOSTERCR)
as "Foster Care",
cdv.BIRTHHOSP as "BirthHosp_ID",
CDV.submid as "Current_Hosp_ID",
CDV.MIDDLE_INIAL as "Mother Initial",
CDV.EMERGENCY_CONTACT_INFO as "Emergency Contact Info",
CDV.PATNO,
CDV.LASTMOD

from PA_ICMS.dbo.CASE_DEMOG_VIEW CDV (NOLOCK)


left outer Join iCMS_RPT.dbo.SAMPLE_DEMOG_VIEW a (NOLOCK) on a.LABNO = CDV.PATNO
left outer Join PA_MSDS.dbo.REF_PROVIDER_ADDRESS BH (NOLOCK) on BH.PROVIDERID =
cdv.BIRTHHOSP
left outer Join PA_ICMS.dbo.CASE_CONTACTS LG (NOLOCK) on LG.CNTCT_PATNO = a.LINK
and LG.CC_REC_ID = (Select Min(CC_REC_ID) from PA_ICMS.dbo.CASE_CONTACTS
where CNTCT_PATNO = LG.CNTCT_PATNO)
WHERE CDV.LINK IS NOT NULL

You might also like