[CQLIT-325] Invalid unit calculation error assistance Created: 07/26/22  Updated: 07/06/23  Resolved: 09/27/22

Status: Resolved
Project: CQL Issue Tracker
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Blocker
Reporter: Dorothy Lee Assignee: eCQM Standards Team
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive CMS136-v12-0-011-QDM-5-6.zip     Zip Archive CMS136-v12-0-012-QDM-5-6.zip     Zip Archive CMS136-v12-0-013-QDM-5-6.zip     PNG File measure calculation error.png     Zip Archive patients_703CC49B-B653-4885-80E8-245A057F5AE9_QDM_56_1659643952.zip     Zip Archive patients_703CC49B-B653-4885-80E8-245A057F5AE9_QDM_56_1659986570.zip    
Impact: This impacts the upcoming publication for the measure.

 Description   

Hi Bonnie team,

Would you kindly assist with troubleshooting this error message "Invalid unit 1"?

This is in relation to but a separate issue from https://oncprojectracking.healthit.gov/support/browse/BONNIEMAT-1207 where there is a logic issue identified for “CumulativeDuration” function to handle null inputs from “RolloutIntervals” function.

"CumulativeDuration" function has been removed and I am now only testing “RolloutIntervals” to make sure there are no errors in execution for that function first. "RolloutIntervals" is referenced/nested in these definitions: "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days" and "Initial Population 2". The error message (see screenshot) was displayed when uploading the draft MAT package (see attached) to Bonnie v5.1.2.

It appears that the function "RolloutIntervals" is causing this error. Any insights you can provide to help narrow down the issue would be appreciated. Thank you!

define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max({ 
          end of Last(R)+ 1 day, start of X }
        ),
        E: S + duration in days of X
        return Interval[S, E]}
    ) 

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
  "RolloutIntervals"("ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase")

define "Initial Population 2":
  AgeInYearsAt(date from start of "Intake Period")>= 6
    and AgeInYearsAt(date from 
      end of "Intake Period"
    )<= 12
    and exists "Qualifying Encounter"
    and "First ADHD Medication Prescribed During Intake Period" is not null
    and exists "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days"...


 Comments   
Comment by eCQM Standards Team [ 09/27/22 ]

Bryn has updated the CumulativeMedicationDuration libraries in MAT and ecqm-content-r4-2022

a) return all

define function "CumulativeDuration"(Intervals List<Interval<Date>> ):
  Sum((collapse Intervals per day) X return all (difference in days between start of X and end of X)+1)

b) Quantity { value: Coalesce(duration in days of X, 0), unit: 'day' }

define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate all R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max(

{            end of Last(R)+ 1 day, start of X }

        ),
        E: S + Quantity { value: Coalesce(duration in days of X, 0), unit: 'day' }
        return Interval[S, E]}
    )

 

This ticket will be closed.  Thank you. 

PMuir MD   ICF/ESAC Standards Team.

Comment by eCQM Standards Team [ 09/08/22 ]

Bryn discussed updates to the Cumulative Medication Duration shared libraries on the FHIR CQM call 2022-08-16.   Changes have been applied to MAT library. 

The ToDaily() functions are aligned for maximum daily amount calculation across MAT as well as r4-2022 and qicore-2022 in github; however the Rollout Interval and CumulativeDuration edits are only been applied to MAT for Bonnie issue.

Will keep this ticket open as tracker for now.
PMuir MD   ICF/ESAC Standards Team.

Comment by eCQM Standards Team [ 08/17/22 ]

Bryn discussed updates to the Cumulative Medication Duration shared libraries on the FHIR CQM call 2022-08-16.

PMuir MD   ICF/ESAC Standards Team.

Comment by Dorothy Lee [ 08/12/22 ]

Hello! Sharing additional updates to the CQL for the QDM version of CMD.“RolloutInterval” function and CMD.“CumulativeDuration” function. It looks like the following updates to the QDM/CQL CMD functions would be necessary, for the current AU, to fully address the Bonnie QDM errors identified in both this ticket and in BONNIEMAT-1207.

CMD.”RolloutIntervals”

  • Update “duration in days of X” to “Quantity { value: duration in days of X, unit: ‘day’ }” – This is to resolve Bonnie error message ‘invalid unit 1’
  • Update “aggregate” to “aggregate all” – This is an enhancement
  • Update “Quantity { value: duration in days of X, unit: ‘day’ }” to “Quantity { value: Coalesce(duration in days of X, 0), unit: ‘day’ }” – This is to resolve Bonnie error message ‘cannot create quantity with an unidentified value’

CMD.”CumulativeDuration”

  • Add ‘if Intervals is not null then… else null” for null handling – This is to resolve Bonnie error message ‘object null is not iterable (cannot read property Symbol(Symbol.iterator))’
//Before

define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I
    aggregate R starting (null as List<Interval<Date>>):
      R union ({
        I X
          let
            S: Max({ end of Last(R) + 1 day, start of X }),
            E: S + duration in days of X
          return Interval[S, E]
      })define 

function "CumulativeDuration"(Intervals List<Interval<Date>> ):
  Sum((collapse Intervals per day) X return all (difference in days between start of X and end of X)+1) 

//After

define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate all R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max({ 
          end of Last(R)+ 1 day, start of X }
        ),
        E: S + Quantity { value: Coalesce(duration in days of X, 0), unit: 'day' }
        return Interval[S, E]}
    )

define function "CumulativeDuration"(Intervals List<Interval<Date>> ):
  if Intervals is not null then ( Sum((collapse Intervals per day)X
        return all(difference in days between start of X and 
          end of X
        )+ 1
    )
  ) 
    else null
Comment by eCQM Standards Team [ 08/12/22 ]

Hi Dorothy.  Just to confirm that

define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate all R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max(

{            end of Last(R)+ 1 day, start of X }

        ),
  //        E: S + duration in days of X
        E: S + Quantity { value: duration in days of X, unit: 'days' }
        return Interval[S, E]}
    )

.....
 
define "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase";
[INTERVAL: 2012-01-01 - 2012-01-30, INTERVAL: 2012-01-29 - 2012-02-29, INTERVAL: 2012-02-25 - 2012-07-23]

define "CumulativeDays":
CMD."CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase"
205

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days TEST":
Coalesce("CumulativeDays TEST", 0)>= 210
No result calculated

define "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase TEST":
"RolloutIntervals"("ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase")
[INTERVAL: 2012-01-01 - 2012-01-30, INTERVAL: 2012-01-31 - 2012-03-02, INTERVAL: 2012-03-03 - 2012-07-30]

 define "CumulativeDays TEST":
CMD."CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase TEST" )
212

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days TEST":
Coalesce("CumulativeDays TEST", 0)>= 210
true

Thank you.  Will flag for Bryn re shared libraries.

PMuir MD   ICF/ESAC Standards Team

Comment by eCQM Standards Team [ 08/12/22 ]

Hi Dorothy.  Thank you for your update.  Since your quantity and aggregate comments impact the Cumulative Medication Duration libraries for QDM, FHIR and QI-Core, let us leave this ticket open for now.

PMuir MD   ICF/ESAC Standards Team

Comment by Dorothy Lee [ 08/11/22 ]

Thanks for the update! I may have a solution now. It looks like “duration in days of X” would need to be updated to “Quantity { value: duration in days of X, unit: ‘day’ }”. Making this adjustment would resolve the “Invalid unit 1” error message in Bonnie. This appears to be a similar issue to BONNIEMAT-986 where there is a mismatch of units in the logic and the resolution is to ensure “duration in days of X” has days in units to work correctly. Additionally, unrelated to this issue, it looks like “aggregate” would need to be updated to “aggregate all” to ensure all intervals can be properly iterated. This solution should also resolve the issue identified in BONNIEMAT-1207 when nothing results from the RolloutIntervals function. As this issue has been resolved, please feel free to close the ticket accordingly. Thank you very much to all the teams for your assistance!

//Before
define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max({ 
          end of Last(R)+ 1 day, start of X }
        ),
        E: S + duration in days of X
        return Interval[S, E]}
    )  

//After
define function "RolloutIntervals"(intervals List<Interval<Date>> ):
  intervals I aggregate all R starting ( null as List<Interval<Date>>): R
    union ( { I X
        let S: Max({ 
          end of Last(R)+ 1 day, start of X }
        ),
        E: S + Quantity { value: duration in days of X, unit: 'day' }
        return Interval[S, E]}
    ) 

 

 

Comment by eCQM Standards Team [ 08/10/22 ]

Update.  I have created a test measure that confirmed the issue re  RollOutIntervals() and contains modified definitions to display the data at different stages.  In progress, although delayed due to other tickets.

PMuir MD   ICF/ESAC Standards Team

Comment by Dorothy Lee [ 08/08/22 ]

Thank you for investigating this issue! Clarifying that the Bonnie error message referenced in this ticket is in relation to the implementation of “RolloutIntervals”. I have included new materials (i.e., two MAT packages and test cases export) for easier replication of the error message in Bonnie v5.1.2. The only difference between MAT packages #1 and #2 is the usage of "RolloutIntervals”. They produce different results when executed against the same test cases in #3.

1. Attachment “CMS136-v12-0-012-QDM-5-6” – No implementation of “RolloutIntervals”

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
  ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" )
  //   "RolloutIntervals"("ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase") 

2. Attachment “CMS136-v12-0-013-QDM-5-6” – Implementation of “RolloutIntervals”

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
  //   ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" )
  "RolloutIntervals"("ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase") 

3. Attachment “patients_703CC49B-B653-4885-80E8-245A057F5AE9_QDM_56_1659986570” – 3 test cases

a) One interval – No issues when executed against #1 and #2 MAT packages

b) Two nonoverlapping intervals – No issues when executed against #1 MAT package but generated Bonnie "invalid unit error" when executed against #2 MAT package

c) Two overlapping intervals – No issues when executed against #1 MAT package but generated Bonnie "invalid unit error" when executed against #2 MAT package

Comment by eCQM Standards Team [ 08/01/22 ]

Hi Dorothy.  I still have some further testing CMD and Rollout with additional test cases, but this Coalesce revision to the CQL logic of v12.0.011 seems to avoid the error message so am providing this in the interim to avoid delay:

  /*PJM original  
  define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
     CMD."CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" ) >= 210*/
     
  // PJM the two following definitions could be combined into one but done separately to show result of CumulativeDuration calculation in days rather than boolean in Bonnie.

define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
  Coalesce("CumulativeDays", 0)>= 210

define "CumulativeDays":
  CMD."CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" )

/*PJM not utilized
  define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days":
  "RolloutIntervals"("ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase")*/

 

The above revision passes 91/91 for Population 1 and Population 2 using February patient export from Round 2.

Please let me know if the above works for you. (TestPJMCQLIT325 in MAT).

PMuir MD   ICF/ESAC Standards Team CQLIT-325

Comment by eCQM Standards Team [ 07/28/22 ]

Thank you for submitting your question. We will review your ticket and provide a response as soon as possible.

PMuir MD  ICF/ESAC Standards Team

Comment by Heather Frideres [ 07/28/22 ]

Moving ticket to the CQL Issue Tracker per discussion with Mathematica. 

As some fields are removed when moving to that project, documenting the information here.

This ticket is regarding the QDM measure CMS 136, FollowUpCareforChildrenPrescribedADHDMedicationADD

Comment by Heather Frideres [ 07/27/22 ]

Hello Dorothy,

We discussed this ticket with the Bonnie team and also with Mathematica. We are going to transfer this ticket to the CQL Issue Tracker, and will reach out to meeting organizers to request this be included as an agenda item on an upcoming Cooking with CQL or eCQM Working Group call. 

You indicated this issue impacts publication for CMS136 - is there a deadline we should be mindful of?

Thank you

Comment by MADiE Team [ 07/26/22 ]

Thank you for submitting your question/issue. We will assign this to a team member and respond in one business day. If your question/issue is related to a particular measure, please upload the corresponding measure package.

Generated at Sun Aug 31 08:12:14 UTC 2025 using Jira 10.3.8#10030008-sha1:cdaed80cecc964184c5b19b002388d56f96e274e.