Skip to content

MedicationRequest - Unable to extract codes from fhirType Reference #1604

@jbyrdevans

Description

@jbyrdevans

The following error is encountered when attempting to filter a QICore6 MedicationRequest by valueset. It occurs when a MedicationRequest.medication code is defined using a reference to a Medication resource. Encountered in the https://github.com/cqframework/dqm-content-qicore-2025 repo while testing at Connectathon 40.

org.opencds.cqf.cql.engine.exception.CqlException: Unable to extract codes from fhirType Reference
	at org.opencds.cqf.cql.engine.execution.EvaluationVisitor.visitExpression(EvaluationVisitor.java:28)
	...
Caused by: java.lang.IllegalArgumentException: Unable to extract codes from fhirType Reference
	at org.opencds.cqf.fhir.cql.engine.utility.CodeExtractor.getCodesFromBase(CodeExtractor.java:86)
	...

CQL minimal repro

library Repro version '1.0.000'

using QICore version '6.0.0'

include FHIRHelpers version '4.4.000' called FHIRHelpers

valueset "ACE Inhibitor or ARB or ARNI": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1139'

context Patient

define "CqlException: Unable to extract codes from fhirType Reference":
    [MedicationRequest: "ACE Inhibitor or ARB or ARNI"]

Patient

{
  "resourceType": "Patient",
  "id": "c095195c-8893-4bf1-aa7d-ad2bfd9bafa5",
  "meta": {
    "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-patient" ]
  },
  "name": [ {
    "family": "DENOMFail",
    "given": [ "EFLT40Obsv1MinAfterEncEdge" ]
  } ],
  "gender": "female",
  "birthDate": "1958-12-21"
}

MedicationRequest

{
  "resourceType": "MedicationRequest",
  "id": "07d579bf-dbf5-4122-82c4-40fccb1922dd",
  "meta": {
    "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest" ]
  },
  "status": "completed",
  "intent": "order",
  "medicationReference": {
    "reference": "Medication/5256de90-9f37-4c32-a9db-c45b3383d841"
  },
  "subject": {
    "reference": "Patient/c095195c-8893-4bf1-aa7d-ad2bfd9bafa5"
  },
  "authoredOn": "2026-04-15T10:30:00.000+00:00"
}

Medication

{
  "resourceType": "Medication",
  "id": "5256de90-9f37-4c32-a9db-c45b3383d841",
  "meta": {
    "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medication" ]
  },
  "code": {
    "coding": [ {
      "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
      "version": "06052023",
      "code": "1000001",
      "display": "amlodipine 5 MG / hydrochlorothiazide 25 MG / olmesartan medoxomil 40 MG Oral Tablet"
    } ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions