Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModelInfo issue with MedicationRequest #1146

Closed
chubert-sb opened this issue Mar 30, 2023 · 8 comments
Closed

ModelInfo issue with MedicationRequest #1146

chubert-sb opened this issue Mar 30, 2023 · 8 comments
Labels
bug md impact tracking The issue is impacting measure development
Milestone

Comments

@chubert-sb
Copy link

A issue occurs when a filter is used for a MedicationRequest profile retrieval in QI-Core. The MedicationRequest resource cannot be found even though the test case JSON contains the MedicationRequest resource, relevant meta.profile and uses the medication element either as a CodeableConcept or referenced Medication resource. For example, when provided the following CQL and correct test case JSON, the case passes:

CQL

define "Has ACEI or ARB or ARNI Ordered":
exists ( 
  [MedicationRequest] ACEIOrARBOrARNIOrdered
    where (
      ( ACEIOrARBOrARNIOrdered.medication as Concept ) in "ACE Inhibitor or ARB or ARNI"
        or ( ACEIOrARBOrARNIOrdered.medication as Reference ).reference.getId() in ( [Medication: "ACE Inhibitor or ARB or ARNI"] ACEIOrARBOrARNI return ACEIOrARBOrARNI.id )
         )
      and ACEIOrARBOrARNIOrdered.isOrderedDuringHeartFailureOutpatientEncounter()
           )

However, when the CQL is updated to use the primary code path for the MedicationRequest, the test case that was passing now fails:

updated CQL

define "Has ACEI or ARB or ARNI Ordered":
exists ( 
  [MedicationRequest: "ACE Inhibitor or ARB or ARNI"] ACEIOrARBOrARNIOrdered
    where ACEIOrARBOrARNIOrdered.isOrderedDuringHeartFailureOutpatientEncounter()
         ) 

Based on a brief review of the QI-Core 4.1.1 Model Info file, I'm speculating that the issue is stemming from it. The primary code path for MedicationRequest is provided as 'medication', but medication is a choice type:

<typeInfo xsi:type="ClassInfo" baseType="QICore.DomainResource" namespace="QICore" name="MedicationRequest" identifier="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest" label="MedicationRequest" retrievable="true" primaryCodePath="medication">
.....
  <element name="medication" target="FHIRHelpers.ToValue(%value)" description="..." mustSupport="true">
     <elementTypeSpecifier xsi:type="ChoiceTypeSpecifier">
        <choice namespace="System" name="Concept" xsi:type="NamedTypeSpecifier"/>
        <choice namespace="QICore" name="Reference" xsi:type="NamedTypeSpecifier"/>
     </elementTypeSpecifier>
     <binding description="Prescribable medications" strength="Extensible"/>
  </element> 
@brynrhodes brynrhodes added the bug label Apr 17, 2023
@brynrhodes brynrhodes added this to the Maintenance milestone Apr 17, 2023
@jenseeman jenseeman added the md impact tracking The issue is impacting measure development label Apr 26, 2023
@brynrhodes
Copy link
Member

The terminology target must be code-valued, so when it is used with the medication element, that resolves to the CodeableConcept choice, and there is no expectation that the retrieve would apply through the reference choice. In other words, when using the terminology target of the retrieve if the MedicationRequest.medication element is a reference, it would not be addressable through the retrieve. I've added a test to validate the MedicationRequest with a terminology target translates with the codeableconcept choice.

@JSRankins
Copy link
Contributor

@brynrhodes, I understand your explanation above. The patterns page for Medication ordered uses this same approach - asserting medication as a CodeableConcept. But this makes me wonder if that limitation should be forced at the profile level, since the current profile (for QI-Core 4.1.1 and 5.0.0) allows the medication to be either a medicationCodeableConcept OR a medicationReference. Based on the profile, a compliant instance of MedicationRequest could be provided with a medicationReference, but that creates an execution issue. Is the patterns page just a recommendation or a requirement? Should the patterns page be addressing medication as either a medicationCodeableConcept OR a medicationReference? Thoughts?

@brynrhodes
Copy link
Member

@JSRankins , it would make sense to address this in the patterns page, but I'm hesitant to enforce it at the profile level since it is still possible to address (and we'll need to be able to since there are systems that do both). I'll add this as an item to address in the patterns.

JPercival pushed a commit that referenced this issue Jul 11, 2023
* #1156: Added test cases for CMS143 and CMS149 to validate data requirements output

* #1147: Fixed invalid let ref during data requirements inference

* #1146: Added test for MedicationRequest to ensure expected ELM output

* #1109: Fixed newlines being stripped incorrectly in mixed single- and multi-line comments
brynrhodes added a commit that referenced this issue Jul 14, 2023
* #1156: Added test cases for CMS143 and CMS149 to validate data requirements output

* #1147: Fixed invalid let ref during data requirements inference

* #1146: Added test for MedicationRequest to ensure expected ELM output

* #1109: Fixed newlines being stripped incorrectly in mixed single- and multi-line comments
@jenseeman
Copy link
Collaborator

@brynrhodes
Copy link
Member

Proposed update to the patterns to address retrieving when medication requests are represented as references:

library MedicationRequestTest

using QICore version '4.1.1'

include FHIRHelpers version '4.2.000'
include QICoreCommon version '1.3.000'

valueset "Antithrombotic Therapy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.62'

context Patient

define "Antithrombotic Therapy at Discharge":
  ["MedicationRequest": medication in "Antithrombotic Therapy"] Antithrombotic
    where (Antithrombotic.isCommunity() or Antithrombotic.isDischarge())
      and Antithrombotic.status in { 'active', 'completed' }
      and Antithrombotic.intent = 'order'

// Proposed update to the pattern to address medications represented as references: https://github.com/cqframework/CQL-Formatting-and-Usage-Wiki/wiki/Authoring-Patterns---QICore-v4.1.1#medication-ordered-as-a-reference

define "Antithrombotic Therapy at Discharge (by Reference)":
  ["MedicationRequest"] Antithrombotic
    where Antithrombotic.medication().code in "Antithrombotic Therapy" 
      and (Antithrombotic.isCommunity() or Antithrombotic.isDischarge())
      and Antithrombotic.status in { 'active', 'completed' }
      and Antithrombotic.intent = 'order'

define fluent function medication(medicationRequest MedicationRequest):
  singleton from ([Medication: id = medicationRequest.medication.reference.getId()])

define fluent function medicationAlternate(medicationRequest MedicationRequest):
  singleton from ([Medication] M where M.id = medicationRequest.medication.reference.getId())

We should investigate whether it would make sense to support this more succinctly with the .resolve() function, and potentially as an implicit union by the translator when the terminology path is a choice of representations.

@brynrhodes
Copy link
Member

It is possible to support this in the translator, however, full support for this capability will require additional information about the reference to be captured in the ModelInfo. The initial exploratory implementation only supports the MedicationRequest scenario, full support is in development.

@brynrhodes
Copy link
Member

Included in release 3.2.0

@birick1
Copy link

birick1 commented Nov 2, 2023

Post 3.2.0 Issue

I tested Stan's example CQL by converting to ELM with translator version 3.4.0-SNAPSHOT. From there, I reproduced the reported error in the engine and worked to track down the root cause.

Root Cause (Translator version 3.4.0)

I believe the root cause is that the ELM being produced in version 3.4.0 is not correct.

The CQL at issue is:

image

When looking at the ELM, medication.reference needs to be converted to a CQL type (System.string) for the Split operator (red outline). In other words, there should be a .value and ToValue in the clause to handle the type conversion for the Split operator. Below is the ELM generated in 3.4.0 that results in an engine error:

image

Expected ELM

To get an expected version of the ELM, I created a CQL test case to replicate the operation sequence being performed.

image

Translating to ELM using v3.4.0, gives an expected form of ELM including a value and ToValue call. This output runs as expected in the engine.

image

Reference vs CodeableConcept choice

The CodeableConcept choice does not seem to be handled.

InValueSet Issue

Looking at the valueset part of the produced ELM, the code section does not have a scope or source property. The lack of scope is expected to lead to a engine error.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug md impact tracking The issue is impacting measure development
Projects
None yet
Development

No branches or pull requests

5 participants