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)
- 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:
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'
Case when c.service_item_id in ('9992','3302','3400','D33
'D3331') then 'Root Canal'
when c.service_item_id in ('2705','2702','2701','207
') Then 'Crown'
when c.service_item_id in ('2707','2708','6690','D62
when c.service_item_id in ('5001','5000','5003','500
5226') then 'Prosthetics'
when c.service_item_id in ('1062','D1510','D1515') then 'Space Maintainer'
end [Procedure_Type], c.amt [amount], isnull(td.paid_amt, 0) [amount_paid] --, c.*
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
order by p.last_name, pe.create_timestamp
Select * from #DenTmp1
drop table #DenTmp1