From f3297914db6d6d02a43538b4fd0ab248bb56dccd Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Wed, 21 Jan 2026 08:02:09 -0700 Subject: [PATCH] Change to filtering on labfees to handle lacking dateFinailized. --- .../queries/onprc_billing/labworkFees.sql | 75 +++++++++++-------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/onprc_billing/resources/queries/onprc_billing/labworkFees.sql b/onprc_billing/resources/queries/onprc_billing/labworkFees.sql index b1c222f8a..8ffb2f6b5 100644 --- a/onprc_billing/resources/queries/onprc_billing/labworkFees.sql +++ b/onprc_billing/resources/queries/onprc_billing/labworkFees.sql @@ -1,40 +1,51 @@ -PARAMETERS(StartDate TIMESTAMP, EndDate TIMESTAMP) -SELECT - e.Id, - e.date, - e.billingDate, - e.project, - e.servicerequested, - p.chargeId, - e.sourceRecord, - null as chargeCategory, - e.taskid +PARAMETERS (StartDate TIMESTAMP, EndDate TIMESTAMP) +-- Direct charges (internal labwork) by evaluation date +SELECT + e.Id, + e.date, + e.billingDate, + e.project, + e.serviceRequested, + p.chargeId, + e.sourceRecord, + NULL AS chargeCategory, + e.taskId FROM onprc_billing.clinPathRun_ExemptCharges e -JOIN onprc_billing.labworkFeeDefinition p ON (p.servicename = e.servicerequested AND p.active = true) - -WHERE CAST(e.billingdate as date) >= CAST(StartDate as date) AND CAST(e.billingdate as date) <= CAST(EndDate as date) -AND (e.chargetype not in ('Not Billable', 'No Charge', 'Research Staff') or e.chargetype is null) -AND e.qcstate.publicdata = true + JOIN onprc_billing.labworkFeeDefinition p + ON p.serviceName = e.serviceRequested + AND p.active = TRUE +WHERE CAST(e.date AS DATE) BETWEEN CAST(StartDate AS DATE) AND CAST(EndDate AS DATE) + AND e.qcState = 18 + AND (e.chargeType NOT IN ('Not Billable', 'No Charge', 'Research Staff') OR e.chargeType IS NULL) UNION ALL ---for any service sent to an outside lab, we have 1 processing charge per distinct sample +-- Processing fee: 1 per distinct sample sent to outside labs SELECT - e.Id, - e.date, - e.billingDate, - e.project, - group_concat(e.servicerequested) as servicerequested, - (SELECT c.rowid FROM onprc_billing_public.chargeableItems c WHERE c.name = 'Lab Processing Fee') as chargeId, - null as sourceRecord, - null as chargeCategory, - e.taskid - + e.Id, + e.date, + e.billingDate, + e.project, + GROUP_CONCAT(DISTINCT e.serviceRequested) AS serviceRequested, + ( + SELECT c.rowId + FROM onprc_billing_public.chargeableItems c + WHERE c.name = 'Lab Processing Fee' + ) AS chargeId, + NULL AS sourceRecord, + NULL AS chargeCategory, + e.taskId FROM onprc_billing.clinPathRun_ExemptCharges e -WHERE CAST(e.billingDate as date) >= CAST(StartDate as date) AND CAST(e.billingDate as date) <= CAST(EndDate as date) -AND e.qcstate.publicdata = true -AND (e.chargetype not in ('Not Billable', 'No Charge', 'Research Staff') or e.chargetype is null) -AND e.servicerequested.outsidelab = true -GROUP BY e.Id, e.date, e.billingdate, e.project, e.tissue, e.taskid \ No newline at end of file +WHERE CAST(e.date AS DATE) BETWEEN CAST(StartDate AS DATE) AND CAST(EndDate AS DATE) + AND e.qcState = 18 + AND (e.chargeType NOT IN ('Not Billable', 'No Charge', 'Research Staff') OR e.chargeType IS NULL) + AND e.serviceRequested.outsideLab = TRUE +GROUP BY + e.Id, + e.date, + e.billingDate, + e.project, + e.tissue, + e.taskId;