Indiana Birth Defects report

  • Thread starter Thread starter Ted
  • Start date Start date
T

Ted

Working on this report where I will be hitting 2 tables 16 times to
retrieve the ICD-9 diagnosis code. I need to retrieve up to 16 of
these codes per encounter. dxlistX is linked to dx_icdX where X is 1
thru 16. I need the dxlistX.line = X if and X line exists otherwise I
want it to return a null.
Currently my select statement only returns all nulls while there is up
to 4 lines of data available in our test environment.

Any help correcting this would be greatly appreciated.


Below is the sql statement that




/*Indiana Birth Defects*/
select distinct hsp_acct.prim_enc_csn_id,
pat_enc.age, pat.pat_first_name, pat.pat_middle_name,
pat.pat_last_name, pat.sex, pat.birth_date, pat.ssn,
pat.pat_mrn_id, pat.add_line_1, pat.add_line_2, pat.city,
zc_state.abbr, zc_county.name, hsp_acct.adm_date_time,
hsp_acct.disch_date_time, hsp_acct_admit_dx.line,
admit_dx_edg.diagnosis_code,
dxlist1.line, dx_icd1.diagnosis_code,
dxlist2.line, dx_icd2.diagnosis_code,
dxlist3.line, dx_icd3.diagnosis_code,
dxlist4.line, dx_icd4.diagnosis_code,
dxlist5.line, dx_icd5.diagnosis_code,
dxlist6.line, dx_icd6.diagnosis_code,
dxlist7.line, dx_icd7.diagnosis_code,
dxlist8.line, dx_icd8.diagnosis_code,
dxlist9.line, dx_icd9.diagnosis_code,
dxlist10.line, dx_icd10.diagnosis_code,
dxlist11.line, dx_icd11.diagnosis_code,
dxlist12.line, dx_icd12.diagnosis_code,
dxlist13.line, dx_icd13.diagnosis_code,
dxlist14.line, dx_icd14.diagnosis_code,
dxlist15.line, dx_icd15.diagnosis_code,
dxlist16.line, dx_icd16.diagnosis_code

from
hsp_account hsp_acct

left outer join pat_enc
on hsp_acct.prim_enc_csn_id = pat_enc.pat_enc_csn_id

left outer join patient pat
on hsp_acct.pat_id = pat.pat_id

left outer join zc_county
on pat.county_c = zc_county.county_c

left outer join zc_state
on pat.state_c = zc_state.state_c

left outer join hsp_acct_admit_dx
on hsp_acct.hsp_account_id = hsp_acct_admit_dx.hsp_account_id

left outer join clarity_edg admit_dx_edg
on hsp_acct_admit_dx.admit_dx_id = admit_dx_edg.dx_id

left outer join hsp_acct_dx_list dxlist1
on hsp_acct.hsp_account_id = dxlist1.hsp_account_id

left outer join clarity_edg dx_icd1
on dxlist1.dx_id = dx_icd1.dx_id

left outer join hsp_acct_dx_list dxlist2
on hsp_acct.hsp_account_id = dxlist2.hsp_account_id

left outer join clarity_edg dx_icd2
on dxlist2.dx_id = dx_icd2.dx_id

left outer join hsp_acct_dx_list dxlist3
on hsp_acct.hsp_account_id = dxlist3.hsp_account_id

left outer join clarity_edg dx_icd3
on dxlist3.dx_id = dx_icd3.dx_id

left outer join hsp_acct_dx_list dxlist4
on hsp_acct.hsp_account_id = dxlist4.hsp_account_id

left outer join clarity_edg dx_icd4
on dxlist4.dx_id = dx_icd4.dx_id

left outer join hsp_acct_dx_list dxlist5
on hsp_acct.hsp_account_id = dxlist5.hsp_account_id

left outer join clarity_edg dx_icd5
on dxlist5.dx_id = dx_icd5.dx_id

left outer join hsp_acct_dx_list dxlist6
on hsp_acct.hsp_account_id = dxlist6.hsp_account_id

left outer join clarity_edg dx_icd6
on dxlist6.dx_id = dx_icd6.dx_id

left outer join hsp_acct_dx_list dxlist7
on hsp_acct.hsp_account_id = dxlist7.hsp_account_id

left outer join clarity_edg dx_icd7
on dxlist7.dx_id = dx_icd7.dx_id

left outer join hsp_acct_dx_list dxlist8
on hsp_acct.hsp_account_id = dxlist8.hsp_account_id

left outer join clarity_edg dx_icd8
on dxlist8.dx_id = dx_icd8.dx_id

left outer join hsp_acct_dx_list dxlist9
on hsp_acct.hsp_account_id = dxlist7.hsp_account_id

left outer join clarity_edg dx_icd9
on dxlist9.dx_id = dx_icd9.dx_id

left outer join hsp_acct_dx_list dxlist10
on hsp_acct.hsp_account_id = dxlist10.hsp_account_id

left outer join clarity_edg dx_icd10
on dxlist10.dx_id = dx_icd10.dx_id

left outer join hsp_acct_dx_list dxlist11
on hsp_acct.hsp_account_id = dxlist11.hsp_account_id

left outer join clarity_edg dx_icd11
on dxlist11.dx_id = dx_icd11.dx_id

left outer join hsp_acct_dx_list dxlist12
on hsp_acct.hsp_account_id = dxlist12.hsp_account_id

left outer join clarity_edg dx_icd12
on dxlist12.dx_id = dx_icd12.dx_id


left outer join hsp_acct_dx_list dxlist13
on hsp_acct.hsp_account_id = dxlist13.hsp_account_id

left outer join clarity_edg dx_icd13
on dxlist13.dx_id = dx_icd13.dx_id


left outer join hsp_acct_dx_list dxlist14
on hsp_acct.hsp_account_id = dxlist14.hsp_account_id

left outer join clarity_edg dx_icd14
on dxlist14.dx_id = dx_icd14.dx_id

left outer join hsp_acct_dx_list dxlist15
on hsp_acct.hsp_account_id = dxlist15.hsp_account_id

left outer join clarity_edg dx_icd15
on dxlist15.dx_id = dx_icd15.dx_id


left outer join hsp_acct_dx_list dxlist16
on hsp_acct.hsp_account_id = dxlist16.hsp_account_id

left outer join clarity_edg dx_icd16
on dxlist16.dx_id = dx_icd16.dx_id


where

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line = 15 and dxlist16.line = 16
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line = 15 and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line is null and dxlist16.line is
null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line is null and dxlist15.line is null and dxlist16.line is
null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line is null
and dxlist14.line is null and dxlist15.line is null and dxlist16.line
is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line is null and dxlist13.line is null
and dxlist14.line is null and dxlist15.line is null and dxlist16.line
is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line is null and dxlist12.line is null and dxlist13.line is
null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line is null and
dxlist11.line is null and dxlist12.line is null and dxlist13.line is
null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line is null and dxlist10.line is null
and dxlist11.line is null and dxlist12.line is null and dxlist13.line
is null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line is null and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line is null and dxlist7.line is null and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line is null and dxlist6.line is null and dxlist7.line is null
and dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line is null and
dxlist5.line is null and dxlist6.line is null and dxlist7.line is null
and dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line is null and dxlist4.line is null
and dxlist5.line is null and dxlist6.line is null and dxlist7.line is
null and dxlist8.line is null and dxlist9.line is null and
dxlist10.line is null and dxlist11.line is null and dxlist12.line is
null and dxlist13.line is null and dxlist14.line is null and
dxlist15.line is null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line is null and dxlist3.line is null and dxlist4.line is
null and dxlist5.line is null and dxlist6.line is null and
dxlist7.line is null and dxlist8.line is null and dxlist9.line is null
and dxlist10.line is null and dxlist11.line is null and dxlist12.line
is null and dxlist13.line is null and dxlist14.line is null and
dxlist15.line is null and dxlist16.line is null
or
hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line is
null and dxlist2.line is null and dxlist3.line is null and
dxlist4.line is null and dxlist5.line is null and dxlist6.line is null
and dxlist7.line is null and dxlist8.line is null and dxlist9.line is
null and dxlist10.line is null and dxlist11.line is null and
dxlist12.line is null and dxlist13.line is null and dxlist14.line is
null and dxlist15.line is null and dxlist16.line is null
 
Here is the current part of the sql statement's selection

where

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line = 15 and dxlist16.line = 16

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line = 15 and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line = 14 and dxlist15.line is null and dxlist16.line is
null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line = 13 and
dxlist14.line is null and dxlist15.line is null and dxlist16.line is
null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line = 12 and dxlist13.line is null
and dxlist14.line is null and dxlist15.line is null and dxlist16.line
is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line = 11 and dxlist12.line is null and dxlist13.line is null
and dxlist14.line is null and dxlist15.line is null and dxlist16.line
is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line = 10 and
dxlist11.line is null and dxlist12.line is null and dxlist13.line is
null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line = 9 and dxlist10.line is null and
dxlist11.line is null and dxlist12.line is null and dxlist13.line is
null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line = 8 and dxlist9.line is null and dxlist10.line is null
and dxlist11.line is null and dxlist12.line is null and dxlist13.line
is null and dxlist14.line is null and dxlist15.line is null and
dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line = 7 and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line = 6 and dxlist7.line is null and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line = 5 and dxlist6.line is null and dxlist7.line is null and
dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line = 4 and
dxlist5.line is null and dxlist6.line is null and dxlist7.line is null
and dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line = 3 and dxlist4.line is null and
dxlist5.line is null and dxlist6.line is null and dxlist7.line is null
and dxlist8.line is null and dxlist9.line is null and dxlist10.line is
null and dxlist11.line is null and dxlist12.line is null and
dxlist13.line is null and dxlist14.line is null and dxlist15.line is
null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line = 2 and dxlist3.line is null and dxlist4.line is null
and dxlist5.line is null and dxlist6.line is null and dxlist7.line is
null and dxlist8.line is null and dxlist9.line is null and
dxlist10.line is null and dxlist11.line is null and dxlist12.line is
null and dxlist13.line is null and dxlist14.line is null and
dxlist15.line is null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line = 1
and dxlist2.line is null and dxlist3.line is null and dxlist4.line is
null and dxlist5.line is null and dxlist6.line is null and
dxlist7.line is null and dxlist8.line is null and dxlist9.line is null
and dxlist10.line is null and dxlist11.line is null and dxlist12.line
is null and dxlist13.line is null and dxlist14.line is null and
dxlist15.line is null and dxlist16.line is null

or

hsp_acct_admit_dx.line = 1 and pat_enc.age <= 5 and dxlist1.line is
null and dxlist2.line is null and dxlist3.line is null and
dxlist4.line is null and dxlist5.line is null and dxlist6.line is null
and dxlist7.line is null and dxlist8.line is null and dxlist9.line is
null and dxlist10.line is null and dxlist11.line is null and
dxlist12.line is null and dxlist13.line is null and dxlist14.line is
null and dxlist15.line is null and dxlist16.line is null
 
Back
Top