From 5b44497c90667537d290fffbb4353e93ed9d2e0f Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 10 Apr 2026 14:44:10 -0700 Subject: [PATCH 1/8] New query to resolve rerqeust for Discrepancy Report for R&L when Procedures are carged against an incorrect Alias --- .../onprc_ehr/GJ_BillingDescrepenciesR&.sql | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql new file mode 100644 index 000000000..854494058 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql @@ -0,0 +1,57 @@ +/* +===================================================================== + Query Name : GJ_BillingDescrepenciesR&L + Schema : onprc_ehr + Purpose : To provide the R&L team with a tool to idetofy when a procedure charges will be generated + Point to a alias that is not associcated witht eh Aniomals assigned project + Issue / Ticket : EHR Issue 11870 + Feature Branch: + Pull Request: + Development Status: In development FB posted to Test E + Business Context: + Resolution Logic: + Parameters : Non Defined + Output : Query Grid + Validation Notes: Thi + Author : jonesga + Created : 2026-04-10 + Last Modified : 2026-04-10 +===================================================================== +*/ + + +With procedureFees as ( + Select + pfr.id, + pfr.date, + pfr.project, + pfr.account, + pfr.chargetype, + pfr.assistingStaff, + pfr.procedureid, + pfr.chargeID, + pfr.serviceCenter, + pfr.item, + pfr.category, + pfr.sourceRecord, + pfr.unitcost, + pfr.NIHRate, + pfr.creditAccount, + pfr.matchesProject, + pfr.isAdjustment, + pfr.IsAcceptingCharges, + pfr.isExpiredAccount, + pfr.currentActiveAlias + from onprc_billing.procedurefeeRates pfr ) + +Select pf.* from procedureFees pf + +/*I want to add these are parameters on a webpart after we validate the query + +WHERE + (?matchesProject IS NULL OR pfr.matchesProject = ?matchesProject) + AND (?isAdjustment IS NULL OR pfr.isAdjustment = ?isAdjustment) + AND (?isAcceptingCharges IS NULL OR pfr.isAcceptingCharges = ?isAcceptingCharges) + AND (?isExpiredAccount IS NULL OR pfr.isExpiredAccount = ?isExpiredAccount) + AND (?currentActiveAlias IS NULL OR pfr.currentActiveAlias = ?currentActiveAlias) +*/ \ No newline at end of file From 68ea8712a884ec40befdc50bb77f8b124ab26823 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 10 Apr 2026 14:52:18 -0700 Subject: [PATCH 2/8] New query to resolve rerqeust for Discrepancy Report for R&L when Procedures are carged against an incorrect Alias --- .../resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql index 854494058..919858c7f 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql @@ -17,6 +17,7 @@ Created : 2026-04-10 Last Modified : 2026-04-10 ===================================================================== +2nd Try bad Github token */ From cc29d536d07055b4ea3ae5f66e995c746ca5fdb5 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Sat, 11 Apr 2026 05:11:51 -0700 Subject: [PATCH 3/8] New query to resolve rerqeust for Discrepancy Report for R&L when Procedures are carged against an incorrect Alias --- ...ngDescrepenciesR&.sql => GJ_BillingDescrepenciesRl.sql} | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) rename onprc_ehr/resources/queries/onprc_ehr/{GJ_BillingDescrepenciesR&.sql => GJ_BillingDescrepenciesRl.sql} (95%) diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql similarity index 95% rename from onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql rename to onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql index 919858c7f..4af8cbc29 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesR&.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql @@ -1,6 +1,6 @@ /* ===================================================================== - Query Name : GJ_BillingDescrepenciesR&L + Query Name : GJ_BillingDescrepenciesRL Schema : onprc_ehr Purpose : To provide the R&L team with a tool to idetofy when a procedure charges will be generated Point to a alias that is not associcated witht eh Aniomals assigned project @@ -16,11 +16,8 @@ Author : jonesga Created : 2026-04-10 Last Modified : 2026-04-10 -===================================================================== -2nd Try bad Github token +=====================================================================\ */ - - With procedureFees as ( Select pfr.id, From cf6bed4a22dfec4659486f06b10262738fb0350b Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Mon, 13 Apr 2026 14:26:18 -0700 Subject: [PATCH 4/8] Updared the CTGE adding a check of the Current Alis for the assigned Project --- .../onprc_ehr/GJ_BillingDescrepenciesRl.sql | 79 +++++++++++-------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql index 4af8cbc29..b0b4326c1 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql @@ -15,41 +15,56 @@ Validation Notes: Thi Author : jonesga Created : 2026-04-10 - Last Modified : 2026-04-10 -=====================================================================\ + Last Modified : 2026-04-13 +===================================================================== */ -With procedureFees as ( - Select +WITH procedureFees AS ( + SELECT pfr.id, pfr.date, pfr.project, - pfr.account, - pfr.chargetype, - pfr.assistingStaff, - pfr.procedureid, - pfr.chargeID, - pfr.serviceCenter, - pfr.item, - pfr.category, - pfr.sourceRecord, - pfr.unitcost, - pfr.NIHRate, - pfr.creditAccount, - pfr.matchesProject, - pfr.isAdjustment, - pfr.IsAcceptingCharges, - pfr.isExpiredAccount, - pfr.currentActiveAlias - from onprc_billing.procedurefeeRates pfr ) - -Select pf.* from procedureFees pf + pfr.account, + pfr.chargetype AS chargeType, + pfr.assistingStaff, + pfr.procedureid, + pfr.chargeID, + pfr.serviceCenter, + pfr.item, + pfr.category, + pfr.sourceRecord, + pfr.unitcost, + pfr.NIHRate, + pfr.creditAccount, + pfr.matchesProject, + pfr.isAdjustment, + pfr.IsAcceptingCharges, + pfr.isExpiredAccount, + pfr.currentActiveAlias + FROM onprc_billing.procedurefeeRates pfr +), -/*I want to add these are parameters on a webpart after we validate the query + ProjectAlias AS (SELECT pa.name, + pa.account + FROM ehr.project pa + where (pa.enddate > CurDate() + or pa.enddate is null) ) -WHERE - (?matchesProject IS NULL OR pfr.matchesProject = ?matchesProject) - AND (?isAdjustment IS NULL OR pfr.isAdjustment = ?isAdjustment) - AND (?isAcceptingCharges IS NULL OR pfr.isAcceptingCharges = ?isAcceptingCharges) - AND (?isExpiredAccount IS NULL OR pfr.isExpiredAccount = ?isExpiredAccount) - AND (?currentActiveAlias IS NULL OR pfr.currentActiveAlias = ?currentActiveAlias) -*/ \ No newline at end of file +SELECT + pf.id, + pf.date, + pf.project, + pf.account AS chargeToAlias, + pa.account AS projectAlias, + CASE When pf.account = pa.account then 'Billing is Correct' + ELSE 'Billing Needs Review' + end as ChargeReview, + pf.chargeType, + pf.procedureID, + pf.chargeID, + pf.unitcost, + pf.matchesProject +FROM procedureFees pf + LEFT JOIN ProjectAlias pa + ON pf.project.displayName = pa.name +/*WHERE + pf.account != pa.account*/ \ No newline at end of file From f145fce8175db9080dd76cba5380bc968298cf03 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 14 Apr 2026 19:57:00 -0700 Subject: [PATCH 5/8] This is an update of the original query with Enhancement that ned adjustment but wanted them in the Repository, Not available to the user yet as not added to the menu --- .../GJ_BillingDescrepenciesRl_enhanced.sql | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql new file mode 100644 index 000000000..30064e143 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql @@ -0,0 +1,114 @@ +/* +===================================================================== + Query Name : GJ_BillingDescrepenciesRL + Schema : onprc_ehr + Purpose : To provide the R&L team with a tool to identify when + procedure charges will be generated pointing to an + alias not associated with the animal's project + Issue / Ticket : EHR Issue 11870 + Development Status: In development FB posted to Test E + Author : jonesga + Created : 2026-04-10 + Last Modified : 2026-04-14 +Latest Changes: Added logic requested relating to date run but requires more review + Also added functionality to add a Red X where ther is a problem + THis is a new query based on the original with the enahncements +===================================================================== +*/ + +WITH RunContext AS ( + SELECT + CURDATE() AS runDate, + DAYOFWEEK(CURDATE()) AS runDayOfWeekNum, + CASE DAYOFWEEK(CURDATE()) + WHEN 1 THEN 'Sunday' + WHEN 2 THEN 'Monday' + WHEN 3 THEN 'Tuesday' + WHEN 4 THEN 'Wednesday' + WHEN 5 THEN 'Thursday' + WHEN 6 THEN 'Friday' + WHEN 7 THEN 'Saturday' + END AS runDayOfWeekName, + + -- If run on Monday, include Friday–Sunday; otherwise include yesterday + CASE + WHEN DAYOFWEEK(CURDATE()) = 2 THEN timestampadd('SQL_TSI_DAY', -3, CURDATE()) + ELSE timestampadd('SQL_TSI_DAY', -1, CURDATE()) + END AS changeStartDate, + + CURDATE() AS changeEndDate, + + CASE + WHEN DAYOFWEEK(CURDATE()) = 2 + THEN 'Monday run – includes Friday, Saturday, and Sunday changes' + ELSE 'Daily run – includes previous day changes' + END AS runLogicNote +), + + procedureFees AS ( + SELECT + pfr.id, + pfr.date, + pfr.project, + pfr.account, + pfr.chargetype AS chargeType, + pfr.assistingStaff, + pfr.procedureid, + pfr.chargeID, + pfr.serviceCenter, + pfr.item, + pfr.category, + pfr.sourceRecord, + pfr.unitcost, + pfr.NIHRate, + pfr.creditAccount, + pfr.matchesProject, + pfr.isAdjustment, + pfr.IsAcceptingCharges, + pfr.isExpiredAccount, + pfr.currentActiveAlias + FROM onprc_billing.procedurefeeRates pfr + ), + + ProjectAlias AS ( + SELECT + pa.name, + pa.account + FROM ehr.project pa + WHERE pa.enddate > CURDATE() + OR pa.enddate IS NULL + ) + +SELECT + pf.id, + pf.date, + pf.project, + pf.account AS chargeToAlias, + pa.account AS projectAlias, + + -- ✅ Status with symbols for conditional formatting + CASE + WHEN pf.account = pa.account + THEN '✅ Billing is Correct' + ELSE '❌ Billing Needs Review' + END AS ChargeReview, + + pf.chargeType, + pf.procedureID, + pf.chargeID, + pf.unitcost, + pf.matchesProject, + + -- ✅ Run context for transparency and auditability + --rc.runDate, + --rc.runDayOfWeekName, + --rc.runLogicNote + +FROM procedureFees pf + -- CROSS JOIN RunContext rc + LEFT JOIN ProjectAlias pa + ON pf.project.displayName = pa.name + +WHERE pf.project.displayName NOT LIKE '0492-%' + --AND pf.date >= rc.changeStartDate + --AND pf.date < rc.changeEndDate; \ No newline at end of file From f872a4b9073c1939e0dbb515c06513f0e9e0a521 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 17 Apr 2026 12:51:12 -0700 Subject: [PATCH 6/8] Update and REname to final naming for the Billing Discrepancy Report for R&L. Will be fginishing XML in the orning and uploading to teh Test E Instacne --- .../onprc_ehr/BillingDiscrepancyforR_L.sql | 66 ++++++++++ .../GJ_BillingDescrepenciesRl_enhanced.sql | 114 ---------------- .../gdj_BillingDiscrepancyforR_L.xml | 124 ++++++++++++++++++ 3 files changed, 190 insertions(+), 114 deletions(-) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql delete mode 100644 onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql create mode 100644 onprc_ehr/resources/queries/onprc_ehr/gdj_BillingDiscrepancyforR_L.xml 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..b08fc0b96 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql @@ -0,0 +1,66 @@ +/* +===================================================================== + 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 +===================================================================== +*/ + +WITH DateWindow AS ( + SELECT + CURDATE() AS runDate, + TIMESTAMPADD('SQL_TSI_DAY', -@DaysBack, CURDATE()) AS startDate +), + + ProcedureFees AS ( + SELECT + pfr.id, + pfr.date, + + -- Use project display names for user-facing review + pfr.project.displayName AS ProjectBilledTo, + pfr.currentProject.displayName AS CurrentProject, + + pfr.project AS billedProjectObj, + pfr.currentProject AS currentProjectObj, + + pfr.chargeType, + pfr.procedureId, + pfr.chargeId, + pfr.unitCost, + pfr.matchesProject + FROM onprc_billing.procedureFeeRates pfr + ) + +SELECT + pf.id, + pf.date, + + pf.ProjectBilledTo, + pf.CurrentProject, + + CASE + WHEN pf.ProjectBilledTo = pf.CurrentProject + THEN '✅ Billing is Correct' + ELSE '❌ Billing Needs Review' + END AS ChargeReview, + + pf.chargeType, + pf.procedureId, + pf.chargeId, + pf.unitCost, + pf.matchesProject + +FROM ProcedureFees pf + CROSS JOIN DateWindow dw + +WHERE pf.ProjectBilledTo NOT LIKE '0492-%' + AND pf.date >= dw.startDate + AND pf.date < dw.runDate +; \ No newline at end of file diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql deleted file mode 100644 index 30064e143..000000000 --- a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl_enhanced.sql +++ /dev/null @@ -1,114 +0,0 @@ -/* -===================================================================== - Query Name : GJ_BillingDescrepenciesRL - Schema : onprc_ehr - Purpose : To provide the R&L team with a tool to identify when - procedure charges will be generated pointing to an - alias not associated with the animal's project - Issue / Ticket : EHR Issue 11870 - Development Status: In development FB posted to Test E - Author : jonesga - Created : 2026-04-10 - Last Modified : 2026-04-14 -Latest Changes: Added logic requested relating to date run but requires more review - Also added functionality to add a Red X where ther is a problem - THis is a new query based on the original with the enahncements -===================================================================== -*/ - -WITH RunContext AS ( - SELECT - CURDATE() AS runDate, - DAYOFWEEK(CURDATE()) AS runDayOfWeekNum, - CASE DAYOFWEEK(CURDATE()) - WHEN 1 THEN 'Sunday' - WHEN 2 THEN 'Monday' - WHEN 3 THEN 'Tuesday' - WHEN 4 THEN 'Wednesday' - WHEN 5 THEN 'Thursday' - WHEN 6 THEN 'Friday' - WHEN 7 THEN 'Saturday' - END AS runDayOfWeekName, - - -- If run on Monday, include Friday–Sunday; otherwise include yesterday - CASE - WHEN DAYOFWEEK(CURDATE()) = 2 THEN timestampadd('SQL_TSI_DAY', -3, CURDATE()) - ELSE timestampadd('SQL_TSI_DAY', -1, CURDATE()) - END AS changeStartDate, - - CURDATE() AS changeEndDate, - - CASE - WHEN DAYOFWEEK(CURDATE()) = 2 - THEN 'Monday run – includes Friday, Saturday, and Sunday changes' - ELSE 'Daily run – includes previous day changes' - END AS runLogicNote -), - - procedureFees AS ( - SELECT - pfr.id, - pfr.date, - pfr.project, - pfr.account, - pfr.chargetype AS chargeType, - pfr.assistingStaff, - pfr.procedureid, - pfr.chargeID, - pfr.serviceCenter, - pfr.item, - pfr.category, - pfr.sourceRecord, - pfr.unitcost, - pfr.NIHRate, - pfr.creditAccount, - pfr.matchesProject, - pfr.isAdjustment, - pfr.IsAcceptingCharges, - pfr.isExpiredAccount, - pfr.currentActiveAlias - FROM onprc_billing.procedurefeeRates pfr - ), - - ProjectAlias AS ( - SELECT - pa.name, - pa.account - FROM ehr.project pa - WHERE pa.enddate > CURDATE() - OR pa.enddate IS NULL - ) - -SELECT - pf.id, - pf.date, - pf.project, - pf.account AS chargeToAlias, - pa.account AS projectAlias, - - -- ✅ Status with symbols for conditional formatting - CASE - WHEN pf.account = pa.account - THEN '✅ Billing is Correct' - ELSE '❌ Billing Needs Review' - END AS ChargeReview, - - pf.chargeType, - pf.procedureID, - pf.chargeID, - pf.unitcost, - pf.matchesProject, - - -- ✅ Run context for transparency and auditability - --rc.runDate, - --rc.runDayOfWeekName, - --rc.runLogicNote - -FROM procedureFees pf - -- CROSS JOIN RunContext rc - LEFT JOIN ProjectAlias pa - ON pf.project.displayName = pa.name - -WHERE pf.project.displayName NOT LIKE '0492-%' - --AND pf.date >= rc.changeStartDate - --AND pf.date < rc.changeEndDate; \ 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 From f9910bec26f804aea41deb5c4e38ec2bdd9c5c30 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 21 Apr 2026 09:34:05 -0700 Subject: [PATCH 7/8] Update with changes to handle dual assigned NHP, will post to Trest E and review with Jessica Stanley --- .../onprc_ehr/BillingDiscrepancyforR_L.sql | 106 +++++++++++++----- .../onprc_ehr/BillingDiscrepancyforR_L.xml | 79 +++++++++++++ 2 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.xml diff --git a/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql index b08fc0b96..51bb1f4c9 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/BillingDiscrepancyforR_L.sql @@ -11,56 +11,110 @@ 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 DateWindow AS ( +WITH ProcedureFees AS ( SELECT - CURDATE() AS runDate, - TIMESTAMPADD('SQL_TSI_DAY', -@DaysBack, CURDATE()) AS startDate + 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 ), - ProcedureFees AS ( +/*------------------------------------------------------------------- + Active assignment context +-------------------------------------------------------------------*/ + ActiveAssignments AS ( SELECT - pfr.id, - pfr.date, - - -- Use project display names for user-facing review - pfr.project.displayName AS ProjectBilledTo, - pfr.currentProject.displayName AS CurrentProject, + a.Id, + a.project, + a.project.displayName AS ProjectName + FROM study.assignment a + WHERE + a.enddate IS NULL + OR a.enddate >= CURDATE() + ), - pfr.project AS billedProjectObj, - pfr.currentProject AS currentProjectObj, + AssignmentCounts AS ( + SELECT + Id, + COUNT(DISTINCT project) AS AssignmentCount + FROM ActiveAssignments + GROUP BY Id + ), - pfr.chargeType, - pfr.procedureId, - pfr.chargeId, - pfr.unitCost, - pfr.matchesProject - FROM onprc_billing.procedureFeeRates pfr + 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, - pf.CurrentProject, + aas.CurrentProject, CASE - WHEN pf.ProjectBilledTo = pf.CurrentProject + 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.matchesProject, + pf.taskId FROM ProcedureFees pf - CROSS JOIN DateWindow dw + LEFT JOIN AnimalAssignmentStatus aas + ON pf.id = aas.Id + +WHERE + pf.ProjectBilledTo NOT LIKE '0492-%' + --or + --AND aas.IsDualAssigned = true) -WHERE pf.ProjectBilledTo NOT LIKE '0492-%' - AND pf.date >= dw.startDate - AND pf.date < dw.runDate -; \ No newline at end of file +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 From c4d6c14167fb41291f9376ee194edf8062a55f77 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Apr 2026 10:42:20 -0700 Subject: [PATCH 8/8] Remotved unwanted query from Discrepancy report --- .../onprc_ehr/GJ_BillingDescrepenciesRl.sql | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql b/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql deleted file mode 100644 index b0b4326c1..000000000 --- a/onprc_ehr/resources/queries/onprc_ehr/GJ_BillingDescrepenciesRl.sql +++ /dev/null @@ -1,70 +0,0 @@ -/* -===================================================================== - Query Name : GJ_BillingDescrepenciesRL - Schema : onprc_ehr - Purpose : To provide the R&L team with a tool to idetofy when a procedure charges will be generated - Point to a alias that is not associcated witht eh Aniomals assigned project - Issue / Ticket : EHR Issue 11870 - Feature Branch: - Pull Request: - Development Status: In development FB posted to Test E - Business Context: - Resolution Logic: - Parameters : Non Defined - Output : Query Grid - Validation Notes: Thi - Author : jonesga - Created : 2026-04-10 - Last Modified : 2026-04-13 -===================================================================== -*/ -WITH procedureFees AS ( - SELECT - pfr.id, - pfr.date, - pfr.project, - pfr.account, - pfr.chargetype AS chargeType, - pfr.assistingStaff, - pfr.procedureid, - pfr.chargeID, - pfr.serviceCenter, - pfr.item, - pfr.category, - pfr.sourceRecord, - pfr.unitcost, - pfr.NIHRate, - pfr.creditAccount, - pfr.matchesProject, - pfr.isAdjustment, - pfr.IsAcceptingCharges, - pfr.isExpiredAccount, - pfr.currentActiveAlias - FROM onprc_billing.procedurefeeRates pfr -), - - ProjectAlias AS (SELECT pa.name, - pa.account - FROM ehr.project pa - where (pa.enddate > CurDate() - or pa.enddate is null) ) - -SELECT - pf.id, - pf.date, - pf.project, - pf.account AS chargeToAlias, - pa.account AS projectAlias, - CASE When pf.account = pa.account then 'Billing is Correct' - ELSE 'Billing Needs Review' - end as ChargeReview, - pf.chargeType, - pf.procedureID, - pf.chargeID, - pf.unitcost, - pf.matchesProject -FROM procedureFees pf - LEFT JOIN ProjectAlias pa - ON pf.project.displayName = pa.name -/*WHERE - pf.account != pa.account*/ \ No newline at end of file