thomasm1948
asked on
T-SQL Filter Groups
I am stuck on a query where we need to track in-process dental procedures. Below is an SQL script that is able to pull all of the dental procedures for the following processes:
- Root Canal (RCT)
- Bridges
- Crowns
- Dentures
- Space Maintainers
The issue that I have is that my script also pulls the final completed procedures instead of just the incomplete procedures. We have created local codes for each process in a procedure (service_item_id without a D in front of the number). When an in-process procedure is completed then a D-Code (ADA Code) is then completed for that procedure.
The idea is that we can track an in-process procedure and see what has been completed (local codes) and how much the patient has paid throughout the process.
Attached is test data dump from what my query selects. I dump everything into a temp table so that we can manipulate the data. From what I can see is that the teeth and quadrants can be considered unique. Quadrants can be used for dentures and the teeth for the rest. But bridges do span across multiple teeth but a D-Code will be associated with all of them when they are finally completed. That is what makes it hard to filter through.
The sql code will has case statement to show what codes associate to what procedure
Thank you for all of your help in advance. Here is the code:
select convert(varchar,pe.enc_tim estamp, 101)[Encounter_Date], l.location_name, p.last_name, p.first_name, p.person_nbr,
pe.enc_nbr [encounter_number],'Dr. ' + pr.last_name [provider], c.service_item_id, sm.description, c.tooth,c.surface,
Case when c.quadrant = '01' then 'UM'
when c.quadrant = '02' then 'LM'
end [Quandrant],
Case when c.service_item_id in ('9992','3302','3400','D33 30','D3310 ','D3320', 'D3331') then 'Root Canal'
when c.service_item_id in ('2705','2702','2701','207 1','2070', 'D2750','D 2751','D27 52','D2790 ','27500', 'D2931','D 2930','D27 40','D2962 ') Then 'Crown'
when c.service_item_id in ('2707','2708','6690','D62 40','D6241 ','D6242', 'D6250','D 6751','D67 52','D2750 ','D2790') then 'Bridge'
when c.service_item_id in ('5001','5000','5003','500 4','5007', '5011','50 14','5015' ,'5016','D 5110','D51 20','D5213 ','D5214', 'D5211','D 5212',
'D5750','D5751','D5225','D 5226') then 'Prosthetics'
when c.service_item_id in ('1062','D1510','D1515') then 'Space Maintainer'
else 'Unknown'
end [Procedure_Type], c.amt [amount], isnull(td.paid_amt, 0) [amount_paid] --, c.*
into #DenTmp1
from charges c
left outer join trans_detail td on c.charge_id = td.charge_id
inner join patient_encounter pe on c.source_id = pe.enc_id
inner join location_mstr l on pe.location_id = l.location_id
inner join provider_mstr pr on pe.rendering_provider_id = pr.provider_id
inner join person p on pe.person_id = p.person_id
inner join (select distinct service_item_id, description from service_item_mstr where time_to_perform is not null) sm on c.cpt4_code_id = sm.service_item_id
where p.last_name in ('test6','test24','test21' ,'test23', 'test22') and
pe.create_timestamp >= '12/1/2012' and
pe.create_timestamp < DATEADD(day, 1, '12/26/2013')
and c.service_item_id in ('9992','3302','3400','D33 30','D3310 ','D3320', 'D3331',
'2705','2702','2701','2071 ','2070',' D2750','D2 751','D275 2','D2790' ,'27500',' D2931','D2 930','D274 0','D2962' ,
'2707','2708','6690','D624 0','D6241' ,'D6242',' D6250','D6 751','D675 2','D2750' ,'D2790',
'5001','5000','5003','5004 ','5007',' 5011','501 4','5015', '5016','D5 110','D512 0','D5213' ,'D5214',' D5211','D5 212',
'D5750','D5751','D5225','D 5226',
'1062','D1510','D1515')
order by p.last_name, pe.create_timestamp
Select * from #DenTmp1
drop table #DenTmp1
Dental-Charges.xls
- Root Canal (RCT)
- Bridges
- Crowns
- Dentures
- Space Maintainers
The issue that I have is that my script also pulls the final completed procedures instead of just the incomplete procedures. We have created local codes for each process in a procedure (service_item_id without a D in front of the number). When an in-process procedure is completed then a D-Code (ADA Code) is then completed for that procedure.
The idea is that we can track an in-process procedure and see what has been completed (local codes) and how much the patient has paid throughout the process.
Attached is test data dump from what my query selects. I dump everything into a temp table so that we can manipulate the data. From what I can see is that the teeth and quadrants can be considered unique. Quadrants can be used for dentures and the teeth for the rest. But bridges do span across multiple teeth but a D-Code will be associated with all of them when they are finally completed. That is what makes it hard to filter through.
The sql code will has case statement to show what codes associate to what procedure
Thank you for all of your help in advance. Here is the code:
select convert(varchar,pe.enc_tim
pe.enc_nbr [encounter_number],'Dr. ' + pr.last_name [provider], c.service_item_id, sm.description, c.tooth,c.surface,
Case when c.quadrant = '01' then 'UM'
when c.quadrant = '02' then 'LM'
end [Quandrant],
Case when c.service_item_id in ('9992','3302','3400','D33
when c.service_item_id in ('2705','2702','2701','207
when c.service_item_id in ('2707','2708','6690','D62
when c.service_item_id in ('5001','5000','5003','500
'D5750','D5751','D5225','D
when c.service_item_id in ('1062','D1510','D1515') then 'Space Maintainer'
else 'Unknown'
end [Procedure_Type], c.amt [amount], isnull(td.paid_amt, 0) [amount_paid] --, c.*
into #DenTmp1
from charges c
left outer join trans_detail td on c.charge_id = td.charge_id
inner join patient_encounter pe on c.source_id = pe.enc_id
inner join location_mstr l on pe.location_id = l.location_id
inner join provider_mstr pr on pe.rendering_provider_id = pr.provider_id
inner join person p on pe.person_id = p.person_id
inner join (select distinct service_item_id, description from service_item_mstr where time_to_perform is not null) sm on c.cpt4_code_id = sm.service_item_id
where p.last_name in ('test6','test24','test21'
pe.create_timestamp >= '12/1/2012' and
pe.create_timestamp < DATEADD(day, 1, '12/26/2013')
and c.service_item_id in ('9992','3302','3400','D33
'2705','2702','2701','2071
'2707','2708','6690','D624
'5001','5000','5003','5004
'D5750','D5751','D5225','D
'1062','D1510','D1515')
order by p.last_name, pe.create_timestamp
Select * from #DenTmp1
drop table #DenTmp1
Dental-Charges.xls
Just as an aside: It looks like you are in urgent need of some sort of normalization. You need to create a couple of tables that include service items and service items types ("Root Canal", "'Crown", "Bridge", etc.)
ASKER
If I do not like 'D%' then I will still get the final completed procedures. What I need to do is remove all of the completed items that are related to the one with a D-code. For Example, the following codes show an in-process procedure for Dentures. The patient will come in several times before the dentures (For Quadrant UM) is finaly completed:
5011 Denture Bite Registration
5015 Denture Wax In
5015 Denture Wax In
D5110 Complete Denture, Maxillary
5003 Denture Complete Final Impressions
5011 Denture Bite Registration
5000 Denture Complete Initial Impressions
In the above example all of the procedures should not be on the report. The report should show only the procedures that are still in process and show what stage they have completed (local codes). For Example, for a root canal still in process the report should show only:
3400 RCT Start
9992 PREPAYMENT
3302 Endo Continued Care
5011 Denture Bite Registration
5015 Denture Wax In
5015 Denture Wax In
D5110 Complete Denture, Maxillary
5003 Denture Complete Final Impressions
5011 Denture Bite Registration
5000 Denture Complete Initial Impressions
In the above example all of the procedures should not be on the report. The report should show only the procedures that are still in process and show what stage they have completed (local codes). For Example, for a root canal still in process the report should show only:
3400 RCT Start
9992 PREPAYMENT
3302 Endo Continued Care
Does your data contain that relationship somehow? I mean, how can you know what other items are related to the "D"-item? Once you've figured that out, we can try to solve it. Perhaps through that encounter_number field? Once an "encounter" contains a "D"-record, none of the records related to the encounter should appear? Or is that not how it works?
If you'd had a table that contains all procedures and related actions, I think that should help as well.
As acperkins already mentioned, some remodeling should make your queries a lot easier!
If you'd had a table that contains all procedures and related actions, I think that should help as well.
As acperkins already mentioned, some remodeling should make your queries a lot easier!
ASKER
Is it possible to use group filters in reporting services? I managed to create the report and made my groups but I am having a hard time to filter out the groups.
ASKER
So what I am now trying to do is filter out a group that has a D-Code in SSRS. Does anyone know how to do it
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That made since. Thank you so much. The following is my code. I decided to create a identifier as the quadrant
select convert(varchar,pe.create_ timestamp, 101)[Encounter_Date], replace(l.location_name,'C DCR ','')[location_name], p.last_name, p.first_name, p.person_nbr,
pe.enc_nbr [encounter_number],'Dr. ' + pr.last_name [provider], c.service_item_id, sm.description, c.tooth,c.surface,
Case when c.quadrant = '01' then 'UM'
when c.quadrant = '02' then 'LM'
when c.quadrant is null and c.service_item_id in ('9992','3302','3400','D33 30','D3310 ','D3320', 'D3331') then 'RCT' + c.tooth
when c.quadrant is null and c.service_item_id in ('2705','2702','2701','207 1','2070', 'D2750','D 2751','D27 52','D2790 ','27500', 'D2931','D 2930','D27 40','D2962 ')then 'CRN' + c.tooth
when c.quadrant is null and c.service_item_id in ('2707','2708','6690','D62 40','D6241 ','D6242', 'D6250','D 6751','D67 52','D2750 ','D2790') then 'BR'
when c.quadrant is null and c.service_item_id in ('1062','D1510','D1515') then 'SP' + c.tooth
end [Quadrant],
Case when c.service_item_id in ('9992','3302','3400','D33 30','D3310 ','D3320', 'D3331') then 'Root Canal'
when c.service_item_id in ('2705','2702','2701','207 1','2070', 'D2750','D 2751','D27 52','D2790 ','27500', 'D2931','D 2930','D27 40','D2962 ') Then 'Crown'
when c.service_item_id in ('2707','2708','6690','D62 40','D6241 ','D6242', 'D6250','D 6751','D67 52','D2750 ','D2790') then 'Bridge'
when c.service_item_id in ('5001','5000','5003','500 4','5007', '5011','50 14','5015' ,'5016','D 5110','D51 20','D5213 ','D5214', 'D5211','D 5212',
'D5750','D5751','D5225','D 5226') then 'Prosthetics'
when c.service_item_id in ('1062','D1510','D1515') then 'Space Maintainer'
else 'Unknown'
end [Procedure_Type], c.amt [amount], isnull(td.paid_amt, 0) [amount_paid] --, c.*
into #DenTmp1
from charges c
left outer join trans_detail td on c.charge_id = td.charge_id
inner join patient_encounter pe on c.source_id = pe.enc_id
inner join location_mstr l on pe.location_id = l.location_id
inner join provider_mstr pr on pe.rendering_provider_id = pr.provider_id
inner join person p on pe.person_id = p.person_id
inner join (select distinct service_item_id, description from service_item_mstr where time_to_perform is not null) sm on c.cpt4_code_id = sm.service_item_id
where p.last_name in ('test7','test6','test24', 'test21',' test23','t est22') and
pe.create_timestamp >= '12/1/2012' and
pe.create_timestamp < DATEADD(day, 1, '12/26/2013')
and c.service_item_id in ('9992','3302','3400','D33 30','D3310 ','D3320', 'D3331',
'2705','2702','2701','2071 ','2070',' D2750','D2 751','D275 2','D2790' ,'27500',' D2931','D2 930','D274 0','D2962' ,
'2707','2708','6690','D624 0','D6241' ,'D6242',' D6250','D6 751','D675 2','D2750' ,'D2790',
'5001','5000','5003','5004 ','5007',' 5011','501 4','5015', '5016','D5 110','D512 0','D5213' ,'D5214',' D5211','D5 212',
'D5750','D5751','D5225','D 5226',
'1062','D1510','D1515')
order by p.last_name, pe.create_timestamp
Select * from #DenTmp1
where Quadrant NOT IN (select Quadrant from #DenTmp1 where service_item_id like 'D%')
drop table #DenTmp1
select convert(varchar,pe.create_
pe.enc_nbr [encounter_number],'Dr. ' + pr.last_name [provider], c.service_item_id, sm.description, c.tooth,c.surface,
Case when c.quadrant = '01' then 'UM'
when c.quadrant = '02' then 'LM'
when c.quadrant is null and c.service_item_id in ('9992','3302','3400','D33
when c.quadrant is null and c.service_item_id in ('2705','2702','2701','207
when c.quadrant is null and c.service_item_id in ('2707','2708','6690','D62
when c.quadrant is null and c.service_item_id in ('1062','D1510','D1515') then 'SP' + c.tooth
end [Quadrant],
Case when c.service_item_id in ('9992','3302','3400','D33
when c.service_item_id in ('2705','2702','2701','207
when c.service_item_id in ('2707','2708','6690','D62
when c.service_item_id in ('5001','5000','5003','500
'D5750','D5751','D5225','D
when c.service_item_id in ('1062','D1510','D1515') then 'Space Maintainer'
else 'Unknown'
end [Procedure_Type], c.amt [amount], isnull(td.paid_amt, 0) [amount_paid] --, c.*
into #DenTmp1
from charges c
left outer join trans_detail td on c.charge_id = td.charge_id
inner join patient_encounter pe on c.source_id = pe.enc_id
inner join location_mstr l on pe.location_id = l.location_id
inner join provider_mstr pr on pe.rendering_provider_id = pr.provider_id
inner join person p on pe.person_id = p.person_id
inner join (select distinct service_item_id, description from service_item_mstr where time_to_perform is not null) sm on c.cpt4_code_id = sm.service_item_id
where p.last_name in ('test7','test6','test24',
pe.create_timestamp >= '12/1/2012' and
pe.create_timestamp < DATEADD(day, 1, '12/26/2013')
and c.service_item_id in ('9992','3302','3400','D33
'2705','2702','2701','2071
'2707','2708','6690','D624
'5001','5000','5003','5004
'D5750','D5751','D5225','D
'1062','D1510','D1515')
order by p.last_name, pe.create_timestamp
Select * from #DenTmp1
where Quadrant NOT IN (select Quadrant from #DenTmp1 where service_item_id like 'D%')
drop table #DenTmp1
Open in new window
If you don't want to get those Dxxxx codes, just remove them from that list.To avoid hardcoding codes, you could do something like this:
Open in new window
Doing that would give you only codes that don't start with a D.