diff --git a/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql new file mode 100644 index 000000000..51bb1f4c9 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql @@ -0,0 +1,120 @@ +/* +===================================================================== + Query Name : GJ_BillingDiscrepanciesRL + Schema : onprc_ehr + Purpose : Identify procedure charges where the billed project + does not match the animal’s current project, + using project.displayName for clarity + Parameters : @DaysBack (integer, 1–30) + Issue / Ticket : EHR Issue 11870 + Author : jonesga + Last Modified : 2026-04-17 +===================================================================== +*/ +/* +===================================================================== + Query Name : GJ_BillingDiscrepanciesRL + Schema : onprc_ehr + Purpose : Identify procedure charges where the billed project + does not match the animal’s current project and + highlight animals with dual active assignments. + Issue / Ticket : EHR Issue 11870 + Author : jonesga + Last Modified : 2026-04-21 +===================================================================== +*/ + +WITH ProcedureFees AS ( + SELECT + pfr.id, + pfr.date, + pfr.project.displayName AS ProjectBilledTo, + pfr.project AS billedProjectObj, + pfr.chargeType, + pfr.procedureId, + pfr.chargeId, + pfr.unitCost, + pfr.matchesProject, + pfr.taskId + FROM onprc_billing.procedureFeeRates pfr +), + +/*------------------------------------------------------------------- + Active assignment context +-------------------------------------------------------------------*/ + ActiveAssignments AS ( + SELECT + a.Id, + a.project, + a.project.displayName AS ProjectName + FROM study.assignment a + WHERE + a.enddate IS NULL + OR a.enddate >= CURDATE() + ), + + AssignmentCounts AS ( + SELECT + Id, + COUNT(DISTINCT project) AS AssignmentCount + FROM ActiveAssignments + GROUP BY Id + ), + + AnimalAssignmentStatus AS ( + SELECT + aa.Id, + aa.ProjectName AS CurrentProject, + ac.AssignmentCount, + CASE + WHEN ac.AssignmentCount > 1 THEN true + ELSE false + END AS IsDualAssigned + FROM ActiveAssignments aa + LEFT JOIN AssignmentCounts ac + ON aa.Id = ac.Id + ) + +/*------------------------------------------------------------------- + Final result +-------------------------------------------------------------------*/ +SELECT + pf.id, + pf.date, + + pf.ProjectBilledTo, + aas.CurrentProject, + + CASE + WHEN pf.ProjectBilledTo = aas.CurrentProject + THEN '✅ Billing is Correct' + ELSE '❌ Billing Needs Review' + END AS ChargeReview, + + CASE + WHEN aas.IsDualAssigned = true + THEN '⚠️ Dual Assigned' + ELSE 'Single Assignment' + END AS AssignmentStatus, + + aas.AssignmentCount, + + pf.chargeType, + pf.procedureId, + pf.chargeId, + pf.unitCost, + pf.matchesProject, + pf.taskId + +FROM ProcedureFees pf + LEFT JOIN AnimalAssignmentStatus aas + ON pf.id = aas.Id + +WHERE + pf.ProjectBilledTo NOT LIKE '0492-%' + --or + --AND aas.IsDualAssigned = true) + +ORDER BY + pf.date DESC, + pf.id; \ No newline at end of file diff --git a/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.xml b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.xml new file mode 100644 index 000000000..b44051b69 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.xml @@ -0,0 +1,79 @@ + + + + + + + + DaysBack + + int + true + 1 + + Number of prior days to include in the review window. + Valid values are 1 through 30. + + + + + + + + + + + ProjectBilledTo + + + The project to which the procedure charge was billed. + + + + + CurrentProject + + + The animal’s current active project at the time of review. + + + + + + ChargeReview + + + + + + + equals + Billing is Correct + #2E7D32 + #FFD700 + + + + + equals + Billing Needs Review + #C62828 + #FFFFFF + bold + + + + + + + + + + unitCost + + $#,##0.00 + + + + + \ No newline at end of file diff --git a/onprc_ehr/resources/queries/onprc_ehr/gdj_BillingDiscrepancyforR_L.xml b/onprc_ehr/resources/queries/onprc_ehr/gdj_BillingDiscrepancyforR_L.xml new file mode 100644 index 000000000..5ca9bae50 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/gdj_BillingDiscrepancyforR_L.xml @@ -0,0 +1,124 @@ + + + + + + + + DaysBack + + int + true + 1 + + Number of prior days to include in the review window. + Valid values are 1 through 30. + Example: 7 = review the last 7 days. + + + + + + + + + + ProjectBilledTo + + + The project to which the procedure charge will be billed. + + + + + CurrentProject + + + The animal’s current active project at the time of review. + + + + + ChargeReview + + + Indicates whether the billed project matches the animal’s + current project. Records marked with a red X require review. + + + + + DaysBackUsed + + + The actual number of days included in this run after + validation and bounds enforcement. + + + + + unitCost + + $#,##0.00 + + + + + + + + + + ChargeReview + equals + ❌ Billing Needs Review + #F8D7DA + #721C24 + + + + ChargeReview + equals + ✅ Billing is Correct + #D4EDDA + #155724 + + + + + + + + + + + + \ No newline at end of file