Skip to content

Commit 16dc45a

Browse files
authored
Merge pull request openimis#132 from openimis/feature/capitation-based-on-period
use the period G or O or I
2 parents 2f86ca0 + c669221 commit 16dc45a

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

sql/stored_procedures/uspCreateCapitationPaymentReportData.sql

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,56 @@ BEGIN
3131
@WeightInsuredPopulation DECIMAL(5, 2),
3232
@WeightNumberInsuredFamilies DECIMAL(5, 2),
3333
@WeightNumberVisits DECIMAL(5, 2),
34-
@WeightAdjustedAmount DECIMAL(5, 2)
34+
@WeightAdjustedAmount DECIMAL(5, 2),
35+
@RP Char(1),
36+
@TargetQuarter INT,
37+
@startDateQuarter DATE,
38+
@startDateYear DATE,
39+
@startDateMonth DATE,
40+
@FirstDay DATE,
41+
@LastDay DATE
3542

3643

37-
DECLARE @FirstDay DATE = CAST(@Year AS VARCHAR(4)) + '-' + CAST(@Month AS VARCHAR(2)) + '-01'
38-
DECLARE @LastDay DATE = EOMONTH(@FirstDay, 0)
39-
DECLARE @DaysInMonth INT = DATEDIFF(DAY,@FirstDay,DATEADD(MONTH,1,@FirstDay))
44+
-- get the product data
45+
SELECT @Level1 = Level1,
46+
@Sublevel1 = Sublevel1,
47+
@Level2 = Level2,
48+
@Sublevel2 = Sublevel2,
49+
@Level3 = Level3,
50+
@Sublevel3 = Sublevel3,
51+
@Level4 = Level4,
52+
@Sublevel4 = Sublevel4,
53+
@ShareContribution = ISNULL(ShareContribution, 0),
54+
@WeightPopulation = ISNULL(WeightPopulation, 0),
55+
@WeightNumberFamilies = ISNULL(WeightNumberFamilies, 0),
56+
@WeightInsuredPopulation = ISNULL(WeightInsuredPopulation, 0),
57+
@WeightNumberInsuredFamilies = ISNULL(WeightNumberInsuredFamilies, 0),
58+
@WeightNumberVisits = ISNULL(WeightNumberVisits, 0),
59+
@WeightAdjustedAmount = ISNULL(WeightAdjustedAmount, 0),
60+
@RP =( CASE WHEN PeriodRelPrices is not NULL then PeriodRelPrices
61+
WHEN PeriodRelPricesOP is not NULL THEN PeriodRelPricesOP
62+
WHEN PeriodRelPricesIP is not NULL THEN PeriodRelPricesIP ELSE 'M' END)
63+
FROM tblProduct Prod
64+
WHERE ProdId = @ProdId
65+
66+
set @startDateMonth = DATEFROMPARTS(@Year, @Month ,'01')
67+
set @startDateYear = DATEFROMPARTS(@Year, '01' ,'01')
68+
IF @Month = 3 or @Month = 6 OR @Month = 9 OR @Month = 12
69+
BEGIN
70+
SET @TargetQuarter = @Month / 3
71+
SET @startDateQuarter = DATEFROMPARTS(@Year, (@TargetQuarter -1)*3+1 ,'01')
72+
END
73+
ELSE
74+
SET @startDateQuarter = NULL
75+
76+
77+
set @LastDay = EOMONTH(@startDateMonth, 0)
78+
SELECT @FirstDay = CASE @RP WHEN 'M' THEN @FirstDay
79+
WHEN 'Q' THEN @startDateQuarter
80+
WHEN 'Y' THEN @startDateYear END
81+
82+
if @FirstDay IS NULL
83+
RETURN
4084

4185
set @DistrictId = CASE @DistrictId WHEN 0 THEN NULL ELSE @DistrictId END
4286

@@ -84,24 +128,7 @@ BEGIN
84128

85129
declare @listOfHF table (id int)
86130

87-
-- get the product data
88-
SELECT @Level1 = Level1,
89-
@Sublevel1 = Sublevel1,
90-
@Level2 = Level2,
91-
@Sublevel2 = Sublevel2,
92-
@Level3 = Level3,
93-
@Sublevel3 = Sublevel3,
94-
@Level4 = Level4,
95-
@Sublevel4 = Sublevel4,
96-
@ShareContribution = ISNULL(ShareContribution, 0),
97-
@WeightPopulation = ISNULL(WeightPopulation, 0),
98-
@WeightNumberFamilies = ISNULL(WeightNumberFamilies, 0),
99-
@WeightInsuredPopulation = ISNULL(WeightInsuredPopulation, 0),
100-
@WeightNumberInsuredFamilies = ISNULL(WeightNumberInsuredFamilies, 0),
101-
@WeightNumberVisits = ISNULL(WeightNumberVisits, 0),
102-
@WeightAdjustedAmount = ISNULL(WeightAdjustedAmount, 0)
103-
FROM tblProduct Prod
104-
WHERE ProdId = @ProdId
131+
105132

106133
-- get the list of Hf part of the covered regions and config
107134
IF (@RegionId IS NULL or @RegionId =0) AND (@DistrictId is NULL or @DistrictId =0)

0 commit comments

Comments
 (0)