You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: onprc_billing/resources/queries/onprc_billing/leaseFees.sql
+29-21Lines changed: 29 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -56,8 +56,7 @@ When a5.id is not Null
56
56
then (Selectc.rowidfrom Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer')}.onprc_billing.chargeableItems c wherec.itemCode='ONR41')
57
57
When (a4.idis not nulland (TIMESTAMPDIFF('SQL_TSI_Day',a.date,a.projectedRelease)) <=14anda.endDate is nullanda.ageAtTime.AgeAtTimeYearsRounded <1)
58
58
then (Selectc.rowidfrom Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer')}.onprc_billing.chargeableItems c wherec.itemCode='ONR44')
59
-
WHEN (a.duration<= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') asINTEGER) ANDa.enddateIS NOT NULLANDa.assignCondition=a.releaseCondition) THEN (SELECT rowid FROMonprc_billing_public.chargeableItems ci WHEREci.active= true ANDci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME'))
60
-
WHEN (a.duration<= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') asINTEGER) ANDa.enddateIS NOT NULLANDa.assignCondition=a.releaseCondition) THEN (SELECT rowid FROMonprc_billing_public.chargeableItems ci WHEREci.active= true ANDci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME'))
59
+
WHEN (a.duration<= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') asINTEGER) ANDa.enddateIS NOT NULLANDa.assignCondition=a.releaseCondition) THEN (SELECT rowid FROMonprc_billing_public.chargeableItems ci WHEREci.active= true ANDci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME'))
61
60
WHEN a2.idIS NOT NULL THEN (SELECT rowid FROMonprc_billing_public.chargeableItems ci WHERE (ci.startDate<=a.dateandci.endDate>=a.date) ANDci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.TMB_LEASE_NAME'))
62
61
ELSE lf.chargeId
63
62
END as chargeId,
@@ -81,7 +80,8 @@ CASE
81
80
whereb.id=a.idanda1.project.protocol =a2.project.protocol) >0 THEN 0
82
81
83
82
WHEN (a.duration=0ANDa.enddateIS NOT NULLANDa.assignCondition=a.releaseCondition) THEN 1
84
-
WHEN (fl.idIs Not Null) THEN 0
83
+
-- Exempt PI-purchased NHPs from lease fees
84
+
WHEN (fl.idIS NOT NULL) THEN 0
85
85
--This will check for infants born to resource moms and will not charge
86
86
87
87
WHEN (a.duration<= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') asINTEGER) ANDa.enddateIS NOT NULLANDa.assignCondition=a.releaseCondition) THEN a.duration
@@ -139,21 +139,20 @@ LEFT JOIN onprc_billing.leaseFeeDefinition lf ON (
139
139
ANDlf.active= true
140
140
)
141
141
142
-
143
-
144
-
--adds the reasearch owned animal exemption
145
-
LEFT JOINstudy.flags fl on
146
-
(a.id=fl.id
147
-
andfl.flag.code =4034
148
-
and (a.date>=fl.dateanda.date<=COALESCE(fl.enddate,Now()) ))
149
-
142
+
-- Add PI-purchased NHP flag data
143
+
LEFT JOINstudy.flags fl
144
+
ON (a.id=fl.id
145
+
ANDfl.flag.code =4034
146
+
ANDa.date BETWEEN CAST(fl.dateASDATE) AND COALESCE(fl.enddate, now())
147
+
)
150
148
151
149
WHERE CAST(a.datefinalizedASDATE) >= CAST(STARTDATE asDATE) AND CAST(a.datefinalizedASDATE) <= CAST(ENDDATE asDATE)
152
150
ANDa.qcstate.publicdata = true --and a.participantID.demographics.species.common not in ('Rabbit','Guinea Pigs')
153
151
154
152
155
-
--add setup fees for all starts, except day leases aznd sla
153
+
-- Add lease setup fees for all lease starts, except day leases, PI-purchased NHPs, and sla
156
154
UNION ALL
155
+
157
156
SELECT
158
157
a.id,
159
158
a.date,
@@ -168,7 +167,7 @@ SELECT
168
167
''as ESPFAnimal,
169
168
'Lease Setup Fees'as category,
170
169
(SELECT rowid FROMonprc_billing_public.chargeableItems ci WHEREci.active= true ANDci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.LEASE_SETUP_FEES')) as chargeId,
171
-
1as quantity,
170
+
1AS quantity,
172
171
cast(nullasinteger) as leaseCharge1,
173
172
cast(nullasinteger) as leaseCharge2,
174
173
a.objectidas sourceRecord,
@@ -179,11 +178,19 @@ SELECT
179
178
180
179
FROMstudy.assignment a
181
180
181
+
-- Add PI-purchased NHP flag data
182
+
LEFT JOINstudy.flags fl
183
+
ON (a.id=fl.id
184
+
ANDfl.flag.code =4034
185
+
ANDa.date BETWEEN CAST(fl.dateASDATE) AND COALESCE(fl.enddate, now())
186
+
)
187
+
182
188
WHERE CAST(a.datefinalizedASDATE) >= CAST(STARTDATE asDATE) AND CAST(a.datefinalizedASDATE) <= CAST(ENDDATE asDATE)
183
189
ANDa.qcstate.publicdata = true
184
190
--only charge setup fee for leases >24H. note: duration assumes today as end, so exclude null enddates
185
191
AND ((a.duration> CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') asINTEGER)) OR ( a.assignCondition!=a.releaseConditionANDa.enddate IS NULL))
186
192
anda.id.demographics.species Not IN ('Rabbit','Guinea Pigs')
193
+
ANDfl.id IS NULL-- Exempt PI-purchased NHPs from lease setup fees
187
194
188
195
--add released animals that need adjustments
189
196
UNION ALL
@@ -208,9 +215,9 @@ a5.id as ESPFAnimal,
208
215
--////This selectes the charge ID to be used
209
216
(SELECTmax(rowid) as rowid FROMonprc_billing_public.chargeableItems ci WHEREci.name= javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.LEASE_FEE_ADJUSTMENT') andci.active= true) as chargeId,
210
217
CASE
211
-
when (fl.idIs Not Null) then 0
212
-
else1
213
-
end as quantity,
218
+
WHEN (fl.idIS NOT NULL) THEN 0-- Exempt PI-purchased NHPs from lease fees
219
+
ELSE1
220
+
END AS quantity,
214
221
lf2.chargeIdas leaseCharge1,
215
222
lf.chargeIdas leaseCharge2,
216
223
a.objectidas sourceRecord,
@@ -248,11 +255,12 @@ LEFT join assignment_U42ESPF a5 on
248
255
anda5.dateonly<=a.dateOnly
249
256
ANDa5.endDateCoalesced>=a.dateOnly)
250
257
251
-
--adds the reasearch owned animal exemption
252
-
LEFT JOINstudy.flags fl on
253
-
(a.id=fl.id
254
-
andfl.flag.code =4034
255
-
and (a.date>=fl.dateanda.date<=COALESCE(fl.enddate,Now()) ))
258
+
-- Add PI-purchased NHP flag data
259
+
LEFT JOINstudy.flags fl
260
+
ON (a.id=fl.id
261
+
ANDfl.flag.code =4034
262
+
ANDa.date BETWEEN CAST(fl.dateASDATE) AND COALESCE(fl.enddate, now())
0 commit comments