1
|
declare @TreatmentType varchar(10)= '02'
|
2
|
declare @EmployeeID varchar(10)= '00000219'
|
3
|
declare @StartDate varchar(10)= '20250115'
|
4
|
declare @CostType varchar(10)= '06'
|
5
|
declare @MedicalFamily varchar(10)= '0004'
|
6
|
|
7
|
select
|
8
|
distinct case when cover.TreatmentType = '03'
|
9
|
or cover.TreatmentType = '04' then (
|
10
|
select
|
11
|
count(pa42.TreatmentType) as CountTreatmentType
|
12
|
from
|
13
|
PHRPA0042 pa42
|
14
|
where
|
15
|
pa42.TreatmentType = @TreatmentType
|
16
|
and pa42.EmployeeID = @EmployeeID
|
17
|
and pa42.ClaimStatus in('01', '02')
|
18
|
and (
|
19
|
pa42.StartDate <= @StartDate
|
20
|
and pa42.StartDate >= (
|
21
|
select
|
22
|
dbo.fn_formatdatetime(
|
23
|
DATEADD(
|
24
|
DAY,
|
25
|
convert(
|
26
|
decimal,
|
27
|
'-' + convert(
|
28
|
varchar(50),
|
29
|
cover.TransactionPeriod
|
30
|
)
|
31
|
),
|
32
|
GETDATE()
|
33
|
),
|
34
|
'yyyymmdd'
|
35
|
) AS DateRange
|
36
|
)
|
37
|
)
|
38
|
) else '0' end as trxcount,
|
39
|
cover.TransactionFrequency,
|
40
|
cover.TransactionPeriod,
|
41
|
cover.CovCompanyInLimit,
|
42
|
case when cover.WagetypeBase <> '' then (
|
43
|
select
|
44
|
CAST(
|
45
|
REPLACE(
|
46
|
ISNULL(
|
47
|
dbo.GetPEN(pa04.Amount),
|
48
|
'0'
|
49
|
),
|
50
|
',',
|
51
|
'.'
|
52
|
) AS DECIMAL(22, 0)
|
53
|
)* 5 AS Amount
|
54
|
from
|
55
|
PHRBNMEDTREATCOVER cov
|
56
|
left outer join PHRPYCU0305 CU0305 on CU0305.WageTypeCum = cov.WagetypeBase
|
57
|
left outer join phrpa0004 pa04 on pa04.WageType = CU0305.WageType
|
58
|
where
|
59
|
cov.TreatmentType = @TreatmentType
|
60
|
and cov.CostType = @CostType
|
61
|
and cov.MedicalFamily = @MedicalFamily
|
62
|
and cov.EndDate = '99991231'
|
63
|
and pa04.EmployeeID = @EmployeeID
|
64
|
and pa04.EndDate = '99991231'
|
65
|
and CU0305.EndDate = '99991231'
|
66
|
) else '0' end as Amount,
|
67
|
case when cover.PayClass <> '*' then (
|
68
|
select
|
69
|
TCOVER.TransactionLimit
|
70
|
from
|
71
|
PHRBNMEDTREATCOVER TCOVER
|
72
|
left outer join PHRPA0003 pa03 on pa03.PayrollClass = TCOVER.PayClass
|
73
|
where
|
74
|
TCOVER.TreatmentType = @TreatmentType
|
75
|
and TCOVER.CostType = @CostType
|
76
|
and TCOVER.MedicalFamily = @MedicalFamily
|
77
|
and TCOVER.EndDate = '99991231'
|
78
|
and pa03.EmployeeID = @EmployeeID
|
79
|
and pa03.EndDate = '99991231'
|
80
|
) else cover.TransactionLimit end as TransactionLimit
|
81
|
from
|
82
|
PHRBNMEDTREATCOVER cover
|
83
|
where
|
84
|
cover.TreatmentType = @TreatmentType
|
85
|
and cover.CostType = @CostType
|
86
|
and cover.MedicalFamily = @MedicalFamily
|
87
|
and cover.EndDate = '99991231'
|