Sorry - I see what you wrote but I didn't understand where to get the '2Refer70' type. That is a group name I put in Crystal (it does not exist in the database) and it is based on conditions such as the referring doctor works here (as opposed to an outside doc) and a certain list of procedure codes.
This is a prepackaged database so I can't add any fields.
Here's how it's grouped in Crystal:
Dr. Name
1Rendering100%
Department
records here (where rendering gets 100%)
2Refer70
Department
records here (where referring gets 70%)
3Render30
Department
records here (where Rendering gets 30%)
4Referring
Department
records here (where referring gets 100%)
Here's the sp:
ALTER Procedure dch_MonthlyPmtsWithSIMandDept
As
SELECT
v.visit_id as Visit,
pm.desc_30 as Rendering,
(
SELECT [desc_30]
FROM [Provider_mstr]
WHERE [Provider_ID] = [V].[Refer_Phys_ID]
) AS [Referring],
ChargeSIM.Service_Item_ID as SIM,
ChargeSIM.Service_Item_Desc_40 as SIMDesc,
t.type as Type,
--t.trans_id as TranID,
td.paid_amt as PaidAmt,
td.adj_amt as AdjRef,
--chargesim.department,
mlist.desc_30 as department,
t.closing_date as TranClosingDT,
--fm.desc_40 as facility,
p.claim_type as ClaimType,
p.payer_name as PayerName
FROM
trans_detail td
inner join transactions t on td.trans_id = t.trans_id
left outer join visits v on t.source_id = v.visit_id
left outer join payer_mstr p on t.payer_id = p.payer_id
left outer join (
SELECT [Charges].[Charge_ID],
[Charges].[amt],
[Charges].[closing_date],
[Charges].[Rendering_ID],
[Charges].[Service_Item_ID],
Charges.Service_Item_Desc_40,
(
SELECT TOP 1 [Department] /*get Department the first time for any SIM - otherwise it is repeated for price changes */
FROM [Service_Item_mstr] AS [Services] /*subselect to get SIM only once - in there several times because price changes*/
WHERE [Charges].[Service_Item_Lib_ID] = [Services].[Service_Item_Lib_ID]
AND [Charges].[Service_Item_ID] = [Services].[Service_Item_ID]
) AS [Department]
FROM [dbo].[Charges])as chargeSIM on ChargeSIM.charge_id = td.charge_id
left outer join provider_mstr pm on ChargeSIM.rendering_id = pm.provider_id
left outer join mstr_lists mlist on chargeSIM.department = mlist.mstr_list_alias
left outer join facility_mstr fm on v.facility_id = fm.facility_id
where
t.closing_date between '20050402' and '20050502'
and t.type <> 'A'
--and (pm.desc_30 like @ProviderDescription)
Union ALL --I'm adding this 5-23-05 to get the render 30% records again because in Crystal you can only use
--each record once. I want to use one to calc 70% for referring and one to calc 30% for rendering. srb
SELECT
v.visit_id as Visit,
pm.desc_30 as Rendering,
(
SELECT [desc_30]
FROM [Provider_mstr]
WHERE [Provider_ID] = [V].[Refer_Phys_ID]
) AS [Referring],
ChargeSIM.Service_Item_ID as SIM,
ChargeSIM.Service_Item_Desc_40 as SIMDesc,
t.type as Type,
--t.trans_id as TranID,
td.paid_amt as PaidAmt,
td.adj_amt as AdjRef,
--chargesim.department,
mlist.desc_30 as department,
t.closing_date as TranClosingDT,
--fm.desc_40 as facility,
p.claim_type as ClaimType,
p.payer_name as PayerName
FROM
trans_detail td
inner join transactions t on td.trans_id = t.trans_id
left outer join visits v on t.source_id = v.visit_id
left outer join payer_mstr p on t.payer_id = p.payer_id
left outer join (
SELECT [Charges].[Charge_ID],
[Charges].[amt],
[Charges].[closing_date],
[Charges].[Rendering_ID],
[Charges].[Service_Item_ID],
Charges.Service_Item_Desc_40,
(
SELECT TOP 1 [Department] /*get Department the first time for any SIM - otherwise it is repeated for price changes */
FROM [Service_Item_mstr] AS [Services] /*subselect to get SIM only once - in there several times because price changes*/
WHERE [Charges].[Service_Item_Lib_ID] = [Services].[Service_Item_Lib_ID]
AND [Charges].[Service_Item_ID] = [Services].[Service_Item_ID]
) AS [Department]
FROM [dbo].[Charges])as chargeSIM on ChargeSIM.charge_id = td.charge_id
left outer join provider_mstr pm on ChargeSIM.rendering_id = pm.provider_id
left outer join mstr_lists mlist on chargeSIM.department = mlist.mstr_list_alias
left outer join facility_mstr fm on v.facility_id = fm.facility_id
where
t.closing_date between '20050402' and '20050502'
and t.type <> 'A'
and ChargeSIM.Service_Item_ID in ('93307', '93000', '93224', '95810', '95806', '95805', '95811', '94240', '94060', '94010')
and V.Refer_Phys_ID is not null and v.refer_phys_id in ('PH14K14SJT6J', 'PH14K14TQHOW', 'PH14K14V0S7Q', 'PH14K222MZC1', 'PH14K33MGV8O', 'PH14K33N1710', 'PH14K33NF901', 'PH14K33NMZ7Z', 'PH14K33O8FPY', 'PH14K341CH4K', 'PH14K3468F6T', 'PH14K346MHAU', 'PH14K347KY51', 'PH14K348BY2R', 'PH14K348NTQW', 'PH14K349B8H8', 'PH14K349N55K', 'PH14K34A8H0Z', 'PH14K34AJOAV', 'PH14K34B482B', 'PH14K34G1M24', 'PH14K34GF378', 'PH14M93W94IT', 'PH14M93X3WGE', 'PH14M93XKS4S', 'PH14M93WMVK1', 'PH14P92CJX9Z', 'PH14M93WNQ4P', 'PH150P3F9UQX', 'PH14P92CBQEI', 'PH14M93WMCFP', 'PH14M93WPHEZ', 'PH14M93WQ18V', 'PH14M93WJZKA', 'PH14M93YP6E2', 'PH14M93XKA3Q', 'PH14M93WGRN3', 'PH14M93WEJN3', 'PH14M93WF5BX', 'PH150P3FH5JC')
and pm.desc_30 is not null and pm.desc_30 in ('40 doctor names listed here')
Thank you -