From 7f59591b7fed77ed66bcfac72c6895e083bf5621 Mon Sep 17 00:00:00 2001 From: Dylan Hall Date: Mon, 2 Nov 2026 17:08:44 -0500 Subject: [PATCH 1/2] Initial DataModelProvider support --- src/cql-patient.ts | 13 +- src/elm/instance.ts | 14 +-- src/runtime/context.ts | 60 +++++++-- src/runtime/executor.ts | 29 ++++- src/runtime/systemDataModelProvider.ts | 22 ++++ src/types/cql-patient.interfaces.ts | 5 + src/util/elmTypes.ts | 5 + test/elm/instance/data.cql | 5 +- test/elm/instance/data.js | 162 ++++++++++++++++++++++++- test/elm/instance/instance-test.ts | 6 + test/runtime/context-test.ts | 40 +++++- 11 files changed, 328 insertions(+), 33 deletions(-) create mode 100644 src/runtime/systemDataModelProvider.ts diff --git a/src/cql-patient.ts b/src/cql-patient.ts index 181ed253f..ba786b6f3 100644 --- a/src/cql-patient.ts +++ b/src/cql-patient.ts @@ -1,5 +1,12 @@ import * as DT from './datatypes/datatypes'; -import { DataProvider, NamedTypeSpecifier, PatientObject, RecordObject } from './types'; +import { SystemDataModelProvider } from './runtime/systemDataModelProvider'; +import { + DataModelProvider, + DataProvider, + NamedTypeSpecifier, + PatientObject, + RecordObject +} from './types'; import { ELM_ANY_TYPE, ELM_NAMED_TYPE_SPECIFIER } from './util/elmTypes'; export class Record implements RecordObject { @@ -159,4 +166,8 @@ export class PatientSource implements DataProvider { this.current = currentJSON ? new Patient(currentJSON) : undefined; return this.current; } + + getDataModelProvider(): DataModelProvider { + return new SystemDataModelProvider(); + } } diff --git a/src/elm/instance.ts b/src/elm/instance.ts index 07fd9c369..19e86e154 100644 --- a/src/elm/instance.ts +++ b/src/elm/instance.ts @@ -1,9 +1,6 @@ import { Expression } from './expression'; -import { Quantity } from '../datatypes/quantity'; -import { Code, Concept } from '../datatypes/datatypes'; import { Context } from '../runtime/context'; import { build } from './builder'; -import { ELM_QUANTITY_TYPE, ELM_CONCEPT_TYPE } from '../util/elmTypes'; class Element { name: string; @@ -33,15 +30,6 @@ export class Instance extends Expression { for (const el of this.element) { obj[el.name] = await el.exec(ctx); } - switch (this.classType) { - case ELM_QUANTITY_TYPE: - return new Quantity(obj.value, obj.unit); - case '{urn:hl7-org:elm-types:r1}Code': - return new Code(obj.code, obj.system, obj.version, obj.display); - case ELM_CONCEPT_TYPE: - return new Concept(obj.codes, obj.display); - default: - return obj; - } + return ctx.createInstance(this.classType, obj); } } diff --git a/src/runtime/context.ts b/src/runtime/context.ts index d72ba99f5..ed7f359d0 100644 --- a/src/runtime/context.ts +++ b/src/runtime/context.ts @@ -1,7 +1,7 @@ import * as dt from '../datatypes/datatypes'; import { Exception } from '../datatypes/exception'; import { Library } from '../elm/library'; -import { PatientObject, RetrieveDetails, TerminologyProvider } from '../types'; +import { DataModelProvider, PatientObject, RetrieveDetails, TerminologyProvider } from '../types'; import { Parameter } from '../types/runtime.types'; import { ELM_NAMED_TYPE_SPECIFIER, @@ -18,16 +18,20 @@ import { ELM_DATETIME_TYPE, ELM_DATE_TYPE, ELM_QUANTITY_TYPE, - ELM_TIME_TYPE + ELM_TIME_TYPE, + ELM_CODE_TYPE, + ELM_ANY_TYPE } from '../util/elmTypes'; import { typeIsArray } from '../util/util'; import { MessageListener, NullMessageListener } from './messageListeners'; +import { SystemDataModelProvider } from './systemDataModelProvider'; export class Context { // Public Constructor args parent: any; executionDateTime?: dt.DateTime; messageListener?: MessageListener; + dataModelProviders?: DataModelProvider[]; // Private Constructor args private _codeService?: TerminologyProvider; @@ -44,7 +48,8 @@ export class Context { _codeService?: TerminologyProvider, _parameters?: Parameter, executionDateTime?: dt.DateTime, - messageListener?: MessageListener + messageListener?: MessageListener, + dataModelProviders?: DataModelProvider[] ) { this.parent = parent; this._codeService = _codeService; @@ -57,6 +62,7 @@ export class Context { this._parameters = _parameters || {}; this.executionDateTime = executionDateTime; this.messageListener = messageListener; + this.dataModelProviders = dataModelProviders; } get parameters(): any { @@ -156,6 +162,17 @@ export class Context { } } + getDataModelProviders(): DataModelProvider[] { + if (this.dataModelProviders == null) { + if (this.parent instanceof Context) { + this.dataModelProviders = this.parent.getDataModelProviders(); + } else { + this.dataModelProviders = [new SystemDataModelProvider()]; + } + } + return this.dataModelProviders; + } + getValueSet(name: string, library: any) { return this.parent && this.parent.getValueSet(name, library); } @@ -350,7 +367,7 @@ export class Context { return typeof val === 'string'; case ELM_CONCEPT_TYPE: return val && val.isConcept; - case '{urn:hl7-org:elm-types:r1}Code': + case ELM_CODE_TYPE: return val && val.isCode; case ELM_DATETIME_TYPE: return val && val.isDateTime; @@ -442,6 +459,25 @@ export class Context { (val.high == null || this.matchesInstanceType(val.high, pointType)) ); } + + createInstance(classType: string, obj: any) { + for (const dataModel of this.getDataModelProviders()) { + const instance = dataModel.createInstance(classType, obj); + if (instance != null) { + return instance; + } + } + + // None of the DataModelProviders know how to instantiate this as anything better, so return the plain object. + // Tag it with an _is method that lets us identify what it is. + // TODO / KNOWN LIMITATION: we have no way of knowing what the full type hierarchy of this type is here, + // so `Is` expressions with a supertype will incorrectly return false. + // `defineProperty` means it will still be callable but won’t appear in enumeration or object spread. + Object.defineProperty(obj, '_is', { + value: (spec: any) => spec.name === classType || spec.name === ELM_ANY_TYPE + }); + return obj; + } } export class PatientContext extends Context { @@ -451,9 +487,10 @@ export class PatientContext extends Context { codeService?: TerminologyProvider, parameters?: Parameter, executionDateTime: dt.DateTime = dt.DateTime.fromJSDate(new Date()), - messageListener: MessageListener = new NullMessageListener() + messageListener: MessageListener = new NullMessageListener(), + dataModelProviders?: DataModelProvider[] ) { - super(library, codeService, parameters, executionDateTime, messageListener); + super(library, codeService, parameters, executionDateTime, messageListener, dataModelProviders); } rootContext() { @@ -468,7 +505,8 @@ export class PatientContext extends Context { this.codeService, this.parameters, this.executionDateTime, - this.messageListener + this.messageListener, + this.getDataModelProviders() ); } return this.library_context[library]; @@ -482,7 +520,8 @@ export class PatientContext extends Context { this.codeService, this.parameters, this.executionDateTime, - this.messageListener + this.messageListener, + this.getDataModelProviders() ); } return this.localId_context[localId]; @@ -500,9 +539,10 @@ export class UnfilteredContext extends Context { codeService?: TerminologyProvider, parameters?: Parameter, executionDateTime: dt.DateTime = dt.DateTime.fromJSDate(new Date()), - messageListener: MessageListener = new NullMessageListener() + messageListener: MessageListener = new NullMessageListener(), + dataModelProviders?: DataModelProvider[] ) { - super(library, codeService, parameters, executionDateTime, messageListener); + super(library, codeService, parameters, executionDateTime, messageListener, dataModelProviders); } rootContext() { diff --git a/src/runtime/executor.ts b/src/runtime/executor.ts index 0fb278f08..a2d6f074c 100644 --- a/src/runtime/executor.ts +++ b/src/runtime/executor.ts @@ -3,14 +3,16 @@ import { Results } from './results'; import { UnfilteredContext, PatientContext } from './context'; import { DateTime } from '../datatypes/datetime'; import { Parameter } from '../types/runtime.types'; -import { DataProvider, TerminologyProvider } from '../types'; +import { DataModelProvider, DataProvider, TerminologyProvider } from '../types'; +import { SystemDataModelProvider } from './systemDataModelProvider'; export class Executor { constructor( public library: any, public codeService?: TerminologyProvider, public parameters?: Parameter, - public messageListener: MessageListener = new NullMessageListener() + public messageListener: MessageListener = new NullMessageListener(), + public dataModelProviders: DataModelProvider[] = [] ) {} withLibrary(lib: any) { @@ -33,6 +35,11 @@ export class Executor { return this; } + withDataModelProviders(dmps: DataModelProvider[]) { + this.dataModelProviders = dmps; + return this; + } + async exec_expression(expression: any, patientSource: DataProvider, executionDateTime: DateTime) { const r = new Results(); const expr = this.library.expressions[expression]; @@ -47,7 +54,8 @@ export class Executor { this.codeService, this.parameters, executionDateTime, - this.messageListener + this.messageListener, + this.getDataModelProviders(patientSource) ); r.recordPatientResults(patient_ctx, { [expression]: await expr.execute(patient_ctx) }); currentPatient = await patientSource.nextPatient(); @@ -64,7 +72,8 @@ export class Executor { this.codeService, this.parameters, executionDateTime, - this.messageListener + this.messageListener, + this.getDataModelProviders(patientSource) ); const resultMap: any = {}; for (const key in this.library.expressions) { @@ -90,7 +99,8 @@ export class Executor { this.codeService, this.parameters, executionDateTime, - this.messageListener + this.messageListener, + this.getDataModelProviders(patientSource) ); const resultMap: any = {}; for (const key in this.library.expressions) { @@ -104,4 +114,13 @@ export class Executor { } return r; } + + private getDataModelProviders(patientSource: DataProvider) { + const dataModelProviders = new Set(this.dataModelProviders); + dataModelProviders.add(new SystemDataModelProvider()); + if (typeof patientSource.getDataModelProvider === 'function') { + dataModelProviders.add(patientSource.getDataModelProvider()); + } + return Array.from(dataModelProviders); + } } diff --git a/src/runtime/systemDataModelProvider.ts b/src/runtime/systemDataModelProvider.ts new file mode 100644 index 000000000..40bd34796 --- /dev/null +++ b/src/runtime/systemDataModelProvider.ts @@ -0,0 +1,22 @@ +import { Code, Concept, Quantity } from '../datatypes/datatypes'; +import { DataModelProvider } from '../types/cql-patient.interfaces'; +import { ELM_QUANTITY_TYPE, ELM_CODE_TYPE, ELM_CONCEPT_TYPE } from '../util/elmTypes'; + +export class SystemDataModelProvider implements DataModelProvider { + createInstance(classType: string, obj: any) { + if (!classType.startsWith('{urn:hl7-org:elm-types:r1}')) { + return null; + } + switch (classType) { + case ELM_QUANTITY_TYPE: + return new Quantity(obj.value, obj.unit); + case ELM_CODE_TYPE: + return new Code(obj.code, obj.system, obj.version, obj.display); + case ELM_CONCEPT_TYPE: + return new Concept(obj.codes, obj.display); + default: + // TODO: consider implementing other types here, such as ValueSet and CodeSystem + return obj; + } + } +} diff --git a/src/types/cql-patient.interfaces.ts b/src/types/cql-patient.interfaces.ts index 75cb6281e..fabdfe3f1 100644 --- a/src/types/cql-patient.interfaces.ts +++ b/src/types/cql-patient.interfaces.ts @@ -8,6 +8,11 @@ import { AnyTypeSpecifier } from './type-specifiers.interfaces'; export interface DataProvider { currentPatient(): PatientObject | undefined | Promise; nextPatient(): PatientObject | undefined | Promise; + getDataModelProvider?(): DataModelProvider; +} + +export interface DataModelProvider { + createInstance(classType: string, obj: any): any; } /* diff --git a/src/util/elmTypes.ts b/src/util/elmTypes.ts index e61798868..5ef1afcc5 100644 --- a/src/util/elmTypes.ts +++ b/src/util/elmTypes.ts @@ -1,6 +1,8 @@ // Simple Types export const ELM_ANY_TYPE = '{urn:hl7-org:elm-types:r1}Any'; export const ELM_BOOLEAN_TYPE = '{urn:hl7-org:elm-types:r1}Boolean'; +export const ELM_CODE_TYPE = '{urn:hl7-org:elm-types:r1}Code'; +export const ELM_CODESYSTEM_TYPE = '{urn:hl7-org:elm-types:r1}CodeSystem'; export const ELM_CONCEPT_TYPE = '{urn:hl7-org:elm-types:r1}Concept'; export const ELM_DATE_TYPE = '{urn:hl7-org:elm-types:r1}Date'; export const ELM_DATETIME_TYPE = '{urn:hl7-org:elm-types:r1}DateTime'; @@ -8,8 +10,11 @@ export const ELM_DECIMAL_TYPE = '{urn:hl7-org:elm-types:r1}Decimal'; export const ELM_INTEGER_TYPE = '{urn:hl7-org:elm-types:r1}Integer'; export const ELM_LONG_TYPE = '{urn:hl7-org:elm-types:r1}Long'; export const ELM_QUANTITY_TYPE = '{urn:hl7-org:elm-types:r1}Quantity'; +export const ELM_RATIO_TYPE = '{urn:hl7-org:elm-types:r1}Ratio'; export const ELM_STRING_TYPE = '{urn:hl7-org:elm-types:r1}String'; export const ELM_TIME_TYPE = '{urn:hl7-org:elm-types:r1}Time'; +export const ELM_VALUESET_TYPE = '{urn:hl7-org:elm-types:r1}ValueSet'; +export const ELM_VOCABULARY_TYPE = '{urn:hl7-org:elm-types:r1}Vocabulary'; // Type Specifiers export const ELM_NAMED_TYPE_SPECIFIER = 'NamedTypeSpecifier'; diff --git a/test/elm/instance/data.cql b/test/elm/instance/data.cql index 86e93d9ea..32e3165d0 100644 --- a/test/elm/instance/data.cql +++ b/test/elm/instance/data.cql @@ -29,5 +29,6 @@ define Pharyngitis : Condition { define val: QuantityA.value - - +define PharyngitisIsCondition: Pharyngitis is Condition +define PharyngitisIsEncounter: Pharyngitis is Encounter +define PharyngitisIsAny: Pharyngitis is Any diff --git a/test/elm/instance/data.js b/test/elm/instance/data.js index 096357c1c..d3dc95b97 100644 --- a/test/elm/instance/data.js +++ b/test/elm/instance/data.js @@ -40,6 +40,10 @@ define Pharyngitis : Condition { } define val: QuantityA.value + +define PharyngitisIsCondition: Pharyngitis is Condition +define PharyngitisIsEncounter: Pharyngitis is Encounter +define PharyngitisIsAny: Pharyngitis is Any */ module.exports['Instance'] = { @@ -54,7 +58,7 @@ module.exports['Instance'] = { "type" : "Annotation", "t" : [ ], "s" : { - "r" : "266", + "r" : "283", "s" : [ { "value" : [ "", "library TestSnippet version '1'" ] } ] @@ -622,6 +626,162 @@ module.exports['Instance'] = { "annotation" : [ ] } } + }, { + "localId" : "271", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "PharyngitisIsCondition", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "271", + "s" : [ { + "value" : [ "", "define ", "PharyngitisIsCondition", ": " ] + }, { + "r" : "272", + "s" : [ { + "r" : "273", + "s" : [ { + "value" : [ "Pharyngitis" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "274", + "s" : [ { + "value" : [ "Condition" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "272", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ExpressionRef", + "localId" : "273", + "resultTypeName" : "{https://github.com/cqframework/cql-execution/simple}Condition", + "name" : "Pharyngitis", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "274", + "resultTypeName" : "{https://github.com/cqframework/cql-execution/simple}Condition", + "name" : "{https://github.com/cqframework/cql-execution/simple}Condition", + "annotation" : [ ] + } + } + }, { + "localId" : "277", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "PharyngitisIsEncounter", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "277", + "s" : [ { + "value" : [ "", "define ", "PharyngitisIsEncounter", ": " ] + }, { + "r" : "278", + "s" : [ { + "r" : "279", + "s" : [ { + "value" : [ "Pharyngitis" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "280", + "s" : [ { + "value" : [ "Encounter" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "278", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ExpressionRef", + "localId" : "279", + "resultTypeName" : "{https://github.com/cqframework/cql-execution/simple}Condition", + "name" : "Pharyngitis", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "280", + "resultTypeName" : "{https://github.com/cqframework/cql-execution/simple}Encounter", + "name" : "{https://github.com/cqframework/cql-execution/simple}Encounter", + "annotation" : [ ] + } + } + }, { + "localId" : "283", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "PharyngitisIsAny", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "283", + "s" : [ { + "value" : [ "", "define ", "PharyngitisIsAny", ": " ] + }, { + "r" : "284", + "s" : [ { + "r" : "285", + "s" : [ { + "value" : [ "Pharyngitis" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "286", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "284", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ExpressionRef", + "localId" : "285", + "resultTypeName" : "{https://github.com/cqframework/cql-execution/simple}Condition", + "name" : "Pharyngitis", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "286", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } } ] } } diff --git a/test/elm/instance/instance-test.ts b/test/elm/instance/instance-test.ts index 7197a395e..cee4962e7 100644 --- a/test/elm/instance/instance-test.ts +++ b/test/elm/instance/instance-test.ts @@ -44,4 +44,10 @@ describe('Instance', () => { (await this.pharyngitis.exec(this.ctx)).status.code.should.eql('active'); (await this.pharyngitis.exec(this.ctx)).code.display.should.eql('Viral pharyngitis (disorder)'); }); + + it(`should evaluate an instance Is its defined type and Any`, async function () { + should(await this.pharyngitisIsCondition.exec(this.ctx)).be.true(); + should(await this.pharyngitisIsAny.exec(this.ctx)).be.true(); + should(await this.pharyngitisIsEncounter.exec(this.ctx)).be.false(); + }); }); diff --git a/test/runtime/context-test.ts b/test/runtime/context-test.ts index 2b8ddb362..abdb6f91a 100644 --- a/test/runtime/context-test.ts +++ b/test/runtime/context-test.ts @@ -1,5 +1,6 @@ import should from 'should'; -import { Context, Library } from '../../src/cql'; +import { Context, Decimal, Library, Quantity } from '../../src/cql'; +import { ELM_QUANTITY_TYPE } from '../../src/util/elmTypes'; const simpleELMWithVersion = require('./fixtures/SimpleLibraryWithVersion.json'); describe('Context', () => { @@ -32,5 +33,42 @@ describe('Context', () => { const child = context.childContext(null); should(child.context_values).eql({}); }); + + it('should inherit data model providers from its parent', () => { + const provider = { createInstance: () => ({ fromProvider: true }) }; + const parent = new Context(library, undefined, undefined, undefined, undefined, [provider]); + const child = parent.childContext(); + + should(child.getDataModelProviders()).containEql(provider); + should(child.createInstance('{urn:test}Record', {})).eql({ fromProvider: true }); + }); + }); + + describe('#createInstance', () => { + let library: Library; + let context: Context; + + beforeEach(() => { + library = new Library(simpleELMWithVersion); + context = new Context(library); + }); + it('should construct System types', () => { + const quantity = context.createInstance(ELM_QUANTITY_TYPE, { + value: Decimal.from(5), + unit: 'mg' + }); + + should(quantity).be.instanceof(Quantity); + should(quantity.value).equalDecimal(5); + should(quantity.unit).equal('mg'); + }); + + it('should keep instances as plain objects for unrecognized types', () => { + const fields = { value: 'test', nested: { code: '123' }, missing: null as null }; + const instance = context.createInstance('{urn:test}Record', fields); + + should(instance).equal(fields); + should(instance._is).be.a.Function(); + }); }); }); From ec4037de303530b52bfd536c5f066de7bfc6582e Mon Sep 17 00:00:00 2001 From: Dylan Hall Date: Mon, 2 Nov 2026 17:41:31 -0500 Subject: [PATCH 2/2] Add remaining system datatypes to SystemDataModelProvider --- src/datatypes/clinical.ts | 4 + src/runtime/context.ts | 34 +- src/runtime/systemDataModelProvider.ts | 18 +- test/elm/type/data.cql | 45 + test/elm/type/data.js | 2240 ++++++++++++++++++ test/elm/type/type-test.ts | 139 ++ test/runtime/systemDataModelProvider-test.ts | 116 + 7 files changed, 2579 insertions(+), 17 deletions(-) create mode 100644 test/runtime/systemDataModelProvider-test.ts diff --git a/src/datatypes/clinical.ts b/src/datatypes/clinical.ts index 6ce62ea6a..c54b4fb88 100644 --- a/src/datatypes/clinical.ts +++ b/src/datatypes/clinical.ts @@ -56,6 +56,10 @@ export class CodeSystem extends Vocabulary { super(id, version, name); } + get isCodeSystem() { + return true; + } + hasMatch(_code: any) { throw new Error('In CodeSystem operation not yet supported.'); } diff --git a/src/runtime/context.ts b/src/runtime/context.ts index ed7f359d0..a6432a337 100644 --- a/src/runtime/context.ts +++ b/src/runtime/context.ts @@ -20,7 +20,11 @@ import { ELM_QUANTITY_TYPE, ELM_TIME_TYPE, ELM_CODE_TYPE, - ELM_ANY_TYPE + ELM_CODESYSTEM_TYPE, + ELM_VALUESET_TYPE, + ELM_RATIO_TYPE, + ELM_ANY_TYPE, + ELM_VOCABULARY_TYPE } from '../util/elmTypes'; import { typeIsArray } from '../util/util'; import { MessageListener, NullMessageListener } from './messageListeners'; @@ -358,7 +362,7 @@ export class Context { case ELM_BOOLEAN_TYPE: return typeof val === 'boolean'; case ELM_DECIMAL_TYPE: - return val && val.isDecimal; + return val.isDecimal; case ELM_INTEGER_TYPE: return typeof val === 'number' && Number.isInteger(val); case ELM_LONG_TYPE: @@ -366,17 +370,25 @@ export class Context { case ELM_STRING_TYPE: return typeof val === 'string'; case ELM_CONCEPT_TYPE: - return val && val.isConcept; + return val.isConcept; case ELM_CODE_TYPE: - return val && val.isCode; + return val.isCode; + case ELM_CODESYSTEM_TYPE: + return val.isCodeSystem; + case ELM_VALUESET_TYPE: + return val.isValueSet; + case ELM_VOCABULARY_TYPE: + return val.isCodeSystem ?? val.isValueSet; + case ELM_RATIO_TYPE: + return val.isRatio; case ELM_DATETIME_TYPE: - return val && val.isDateTime; + return val.isDateTime; case ELM_DATE_TYPE: - return val && val.isDate; + return val.isDate; case ELM_QUANTITY_TYPE: - return val && val.isQuantity; + return val.isQuantity; case ELM_TIME_TYPE: - return val && val.isTime && val.isTime(); + return val.isTime && val.isTime(); default: // Use the data model's implementation of _is, if it is available if (typeof val._is === 'function') { @@ -391,12 +403,6 @@ export class Context { return false; } // Otherwise just default to true to match legacy behavior. - // - // NOTE: This is also where arbitrary tuples land because they will not have - // an "is" function and we don't encode the type information into the runtime - // objects so we can't easily determine their type. We can't reject them, - // else things like `Encounter{ id: "1" } is Encounter` would return false. - // So for now we allow false positives in order to avoid false negatives. return true; } } diff --git a/src/runtime/systemDataModelProvider.ts b/src/runtime/systemDataModelProvider.ts index 40bd34796..9a6e0e192 100644 --- a/src/runtime/systemDataModelProvider.ts +++ b/src/runtime/systemDataModelProvider.ts @@ -1,6 +1,13 @@ -import { Code, Concept, Quantity } from '../datatypes/datatypes'; +import { Code, CodeSystem, Concept, CQLValueSet, Quantity, Ratio } from '../datatypes/datatypes'; import { DataModelProvider } from '../types/cql-patient.interfaces'; -import { ELM_QUANTITY_TYPE, ELM_CODE_TYPE, ELM_CONCEPT_TYPE } from '../util/elmTypes'; +import { + ELM_QUANTITY_TYPE, + ELM_CODE_TYPE, + ELM_CONCEPT_TYPE, + ELM_CODESYSTEM_TYPE, + ELM_VALUESET_TYPE, + ELM_RATIO_TYPE +} from '../util/elmTypes'; export class SystemDataModelProvider implements DataModelProvider { createInstance(classType: string, obj: any) { @@ -14,8 +21,13 @@ export class SystemDataModelProvider implements DataModelProvider { return new Code(obj.code, obj.system, obj.version, obj.display); case ELM_CONCEPT_TYPE: return new Concept(obj.codes, obj.display); + case ELM_CODESYSTEM_TYPE: + return new CodeSystem(obj.id, obj.version, obj.name); + case ELM_VALUESET_TYPE: + return new CQLValueSet(obj.id, obj.version, obj.name, obj.codesystems); + case ELM_RATIO_TYPE: + return new Ratio(obj.numerator, obj.denominator); default: - // TODO: consider implementing other types here, such as ValueSet and CodeSystem return obj; } } diff --git a/test/elm/type/data.cql b/test/elm/type/data.cql index 0a3fbc9d8..82f45dc40 100644 --- a/test/elm/type/data.cql +++ b/test/elm/type/data.cql @@ -4,6 +4,51 @@ define FiveIsString: 5 is String define StringFiveIsInteger: '5' is Integer define StringFiveIsString: '5' is String +// @Test: IsCodeSystemType +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +define CodeSystemIsCodeSystem: "TestCodeSystem" is CodeSystem +define ValueSetIsCodeSystem: "TestValueSet" is CodeSystem +define RatioIsCodeSystem: Ratio { numerator: 1 '1', denominator: 2 '1' } is CodeSystem +define TupleIsCodeSystem: Tuple { : } is CodeSystem +define StringIsCodeSystem: 'test' is CodeSystem +define IntegerIsCodeSystem: 1 is CodeSystem +define BooleanIsCodeSystem: false is CodeSystem +define ExpansionIsCodeSystem: Expansion is CodeSystem +define NullIsCodeSystem: null is CodeSystem +define CodeSystemIsAny: "TestCodeSystem" is Any + +// @Test: IsValueSetType +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +define CodeSystemIsValueSet: "TestCodeSystem" is ValueSet +define ValueSetIsValueSet: "TestValueSet" is ValueSet +define RatioIsValueSet: Ratio { numerator: 1 '1', denominator: 2 '1' } is ValueSet +define TupleIsValueSet: Tuple { : } is ValueSet +define StringIsValueSet: 'test' is ValueSet +define IntegerIsValueSet: 1 is ValueSet +define BooleanIsValueSet: false is ValueSet +define ExpansionIsValueSet: Expansion is ValueSet +define NullIsValueSet: null is ValueSet +define ValueSetIsAny: "TestValueSet" is Any + +// @Test: IsRatioType +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +define CodeSystemIsRatio: "TestCodeSystem" is Ratio +define ValueSetIsRatio: "TestValueSet" is Ratio +define RatioIsRatio: Ratio { numerator: 1 '1', denominator: 2 '1' } is Ratio +define TupleIsRatio: Tuple { : } is Ratio +define StringIsRatio: 'test' is Ratio +define IntegerIsRatio: 1 is Ratio +define BooleanIsRatio: false is Ratio +define ExpansionIsRatio: Expansion is Ratio +define NullIsRatio: null is Ratio +define RatioIsAny: Ratio { numerator: 1 '1', denominator: 2 '1' } is Any + // @Test: IsListType define ListOfIntegersIsListOfIntegers: {1, 2, 3, 4, 5} is List define ListOfDecimalsIsListOfIntegers: {1.5, 2.5, 3.5, 4.5, 5.5} is List diff --git a/test/elm/type/data.js b/test/elm/type/data.js index cb56d6331..342338d94 100644 --- a/test/elm/type/data.js +++ b/test/elm/type/data.js @@ -311,6 +311,2246 @@ module.exports['IsSystemType'] = { } } +/* IsCodeSystemType +library TestSnippet version '1' +using Simple version '1.0.0' +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +context Patient +define CodeSystemIsCodeSystem: "TestCodeSystem" is CodeSystem +define ValueSetIsCodeSystem: "TestValueSet" is CodeSystem +define RatioIsCodeSystem: Ratio { numerator: 1 '1', denominator: 2 '1' } is CodeSystem +define TupleIsCodeSystem: Tuple { : } is CodeSystem +define StringIsCodeSystem: 'test' is CodeSystem +define IntegerIsCodeSystem: 1 is CodeSystem +define BooleanIsCodeSystem: false is CodeSystem +define ExpansionIsCodeSystem: Expansion is CodeSystem +define NullIsCodeSystem: null is CodeSystem +define CodeSystemIsAny: "TestCodeSystem" is Any +*/ + +module.exports['IsCodeSystemType'] = { + "library" : { + "localId" : "0", + "annotation" : [ { + "type" : "CqlToElmInfo", + "translatorVersion" : "4.2.0", + "translatorOptions" : "EnableDateRangeOptimization,EnableAnnotations,EnableResultTypes", + "signatureLevel" : "All" + }, { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "library TestSnippet version '1'" ] + } ] + } + } ], + "identifier" : { + "id" : "TestSnippet", + "version" : "1" + }, + "schemaIdentifier" : { + "id" : "urn:hl7-org:elm", + "version" : "r1" + }, + "usings" : { + "def" : [ { + "localId" : "1", + "localIdentifier" : "System", + "uri" : "urn:hl7-org:elm-types:r1", + "annotation" : [ ] + }, { + "localId" : "206", + "localIdentifier" : "Simple", + "uri" : "https://github.com/cqframework/cql-execution/simple", + "version" : "1.0.0", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "206", + "s" : [ { + "value" : [ "", "using " ] + }, { + "s" : [ { + "value" : [ "Simple" ] + } ] + }, { + "value" : [ " version '1.0.0'" ] + } ] + } + } ] + } ] + }, + "parameters" : { + "def" : [ { + "localId" : "212", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "212", + "s" : [ { + "value" : [ "", "parameter ", "Expansion", " " ] + }, { + "r" : "213", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } + } ], + "parameterTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "213", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } ] + }, + "codeSystems" : { + "def" : [ { + "localId" : "208", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "id" : "urn:test:system", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "208", + "s" : [ { + "value" : [ "", "codesystem ", "\"TestCodeSystem\"", ": ", "'urn:test:system'" ] + } ] + } + } ] + } ] + }, + "valueSets" : { + "def" : [ { + "localId" : "210", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "id" : "urn:test:valueset", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "210", + "s" : [ { + "value" : [ "", "valueset ", "\"TestValueSet\"", ": ", "'urn:test:valueset'" ] + } ] + } + } ], + "codeSystem" : [ ] + } ] + }, + "contexts" : { + "def" : [ { + "localId" : "218", + "name" : "Patient", + "annotation" : [ ] + } ] + }, + "statements" : { + "def" : [ { + "localId" : "216", + "name" : "Patient", + "context" : "Patient", + "annotation" : [ ], + "expression" : { + "type" : "SingletonFrom", + "localId" : "217", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Retrieve", + "localId" : "215", + "dataType" : "{https://github.com/cqframework/cql-execution/simple}Patient", + "annotation" : [ ], + "include" : [ ], + "codeFilter" : [ ], + "dateFilter" : [ ], + "otherFilter" : [ ] + } + } + }, { + "localId" : "221", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "CodeSystemIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "221", + "s" : [ { + "value" : [ "", "define ", "CodeSystemIsCodeSystem", ": " ] + }, { + "r" : "222", + "s" : [ { + "r" : "223", + "s" : [ { + "value" : [ "\"TestCodeSystem\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "224", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "222", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "CodeSystemRef", + "localId" : "223", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "224", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "227", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ValueSetIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "227", + "s" : [ { + "value" : [ "", "define ", "ValueSetIsCodeSystem", ": " ] + }, { + "r" : "228", + "s" : [ { + "r" : "229", + "s" : [ { + "value" : [ "\"TestValueSet\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "230", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "228", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ValueSetRef", + "localId" : "229", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "preserve" : true, + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "230", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "233", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "RatioIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "233", + "s" : [ { + "value" : [ "", "define ", "RatioIsCodeSystem", ": " ] + }, { + "r" : "234", + "s" : [ { + "r" : "235", + "s" : [ { + "value" : [ "Ratio", " { " ] + }, { + "s" : [ { + "value" : [ "numerator", ": " ] + }, { + "r" : "237", + "s" : [ { + "value" : [ "1 ", "'1'" ] + } ] + } ] + }, { + "value" : [ ", " ] + }, { + "s" : [ { + "value" : [ "denominator", ": " ] + }, { + "r" : "238", + "s" : [ { + "value" : [ "2 ", "'1'" ] + } ] + } ] + }, { + "value" : [ " }" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "239", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "234", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Instance", + "localId" : "235", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "classType" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ], + "element" : [ { + "name" : "numerator", + "value" : { + "type" : "Quantity", + "localId" : "237", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 1, + "unit" : "1", + "annotation" : [ ] + } + }, { + "name" : "denominator", + "value" : { + "type" : "Quantity", + "localId" : "238", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 2, + "unit" : "1", + "annotation" : [ ] + } + } ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "239", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "242", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "TupleIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "242", + "s" : [ { + "value" : [ "", "define ", "TupleIsCodeSystem", ": " ] + }, { + "r" : "243", + "s" : [ { + "r" : "244", + "value" : [ "Tuple { : }", " is " ] + }, { + "r" : "246", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "243", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Tuple", + "localId" : "244", + "annotation" : [ ], + "resultTypeSpecifier" : { + "type" : "TupleTypeSpecifier", + "localId" : "245", + "annotation" : [ ], + "element" : [ ] + }, + "element" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "246", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "249", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "StringIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "249", + "s" : [ { + "value" : [ "", "define ", "StringIsCodeSystem", ": " ] + }, { + "r" : "250", + "s" : [ { + "r" : "251", + "s" : [ { + "value" : [ "'test'" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "253", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "250", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "251", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}String", + "valueType" : "{urn:hl7-org:elm-types:r1}String", + "value" : "test", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "253", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "256", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "IntegerIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "256", + "s" : [ { + "value" : [ "", "define ", "IntegerIsCodeSystem", ": " ] + }, { + "r" : "257", + "s" : [ { + "r" : "258", + "value" : [ "1", " is " ] + }, { + "r" : "259", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "257", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "258", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Integer", + "valueType" : "{urn:hl7-org:elm-types:r1}Integer", + "value" : "1", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "259", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "262", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "BooleanIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "262", + "s" : [ { + "value" : [ "", "define ", "BooleanIsCodeSystem", ": " ] + }, { + "r" : "263", + "s" : [ { + "r" : "264", + "value" : [ "false", " is " ] + }, { + "r" : "265", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "263", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "264", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "valueType" : "{urn:hl7-org:elm-types:r1}Boolean", + "value" : "false", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "265", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "268", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ExpansionIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "268", + "s" : [ { + "value" : [ "", "define ", "ExpansionIsCodeSystem", ": " ] + }, { + "r" : "269", + "s" : [ { + "r" : "270", + "s" : [ { + "value" : [ "Expansion" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "271", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "269", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ParameterRef", + "localId" : "270", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "271", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "274", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "NullIsCodeSystem", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "274", + "s" : [ { + "value" : [ "", "define ", "NullIsCodeSystem", ": " ] + }, { + "r" : "275", + "s" : [ { + "r" : "276", + "value" : [ "null", " is " ] + }, { + "r" : "277", + "s" : [ { + "value" : [ "CodeSystem" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "275", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Null", + "localId" : "276", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "277", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "annotation" : [ ] + } + } + }, { + "localId" : "280", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "CodeSystemIsAny", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "define ", "CodeSystemIsAny", ": " ] + }, { + "r" : "281", + "s" : [ { + "r" : "282", + "s" : [ { + "value" : [ "\"TestCodeSystem\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "283", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "281", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "CodeSystemRef", + "localId" : "282", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "283", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } + } ] + } + } +} + +/* IsValueSetType +library TestSnippet version '1' +using Simple version '1.0.0' +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +context Patient +define CodeSystemIsValueSet: "TestCodeSystem" is ValueSet +define ValueSetIsValueSet: "TestValueSet" is ValueSet +define RatioIsValueSet: Ratio { numerator: 1 '1', denominator: 2 '1' } is ValueSet +define TupleIsValueSet: Tuple { : } is ValueSet +define StringIsValueSet: 'test' is ValueSet +define IntegerIsValueSet: 1 is ValueSet +define BooleanIsValueSet: false is ValueSet +define ExpansionIsValueSet: Expansion is ValueSet +define NullIsValueSet: null is ValueSet +define ValueSetIsAny: "TestValueSet" is Any +*/ + +module.exports['IsValueSetType'] = { + "library" : { + "localId" : "0", + "annotation" : [ { + "type" : "CqlToElmInfo", + "translatorVersion" : "4.2.0", + "translatorOptions" : "EnableDateRangeOptimization,EnableAnnotations,EnableResultTypes", + "signatureLevel" : "All" + }, { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "library TestSnippet version '1'" ] + } ] + } + } ], + "identifier" : { + "id" : "TestSnippet", + "version" : "1" + }, + "schemaIdentifier" : { + "id" : "urn:hl7-org:elm", + "version" : "r1" + }, + "usings" : { + "def" : [ { + "localId" : "1", + "localIdentifier" : "System", + "uri" : "urn:hl7-org:elm-types:r1", + "annotation" : [ ] + }, { + "localId" : "206", + "localIdentifier" : "Simple", + "uri" : "https://github.com/cqframework/cql-execution/simple", + "version" : "1.0.0", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "206", + "s" : [ { + "value" : [ "", "using " ] + }, { + "s" : [ { + "value" : [ "Simple" ] + } ] + }, { + "value" : [ " version '1.0.0'" ] + } ] + } + } ] + } ] + }, + "parameters" : { + "def" : [ { + "localId" : "212", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "212", + "s" : [ { + "value" : [ "", "parameter ", "Expansion", " " ] + }, { + "r" : "213", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } + } ], + "parameterTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "213", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } ] + }, + "codeSystems" : { + "def" : [ { + "localId" : "208", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "id" : "urn:test:system", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "208", + "s" : [ { + "value" : [ "", "codesystem ", "\"TestCodeSystem\"", ": ", "'urn:test:system'" ] + } ] + } + } ] + } ] + }, + "valueSets" : { + "def" : [ { + "localId" : "210", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "id" : "urn:test:valueset", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "210", + "s" : [ { + "value" : [ "", "valueset ", "\"TestValueSet\"", ": ", "'urn:test:valueset'" ] + } ] + } + } ], + "codeSystem" : [ ] + } ] + }, + "contexts" : { + "def" : [ { + "localId" : "218", + "name" : "Patient", + "annotation" : [ ] + } ] + }, + "statements" : { + "def" : [ { + "localId" : "216", + "name" : "Patient", + "context" : "Patient", + "annotation" : [ ], + "expression" : { + "type" : "SingletonFrom", + "localId" : "217", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Retrieve", + "localId" : "215", + "dataType" : "{https://github.com/cqframework/cql-execution/simple}Patient", + "annotation" : [ ], + "include" : [ ], + "codeFilter" : [ ], + "dateFilter" : [ ], + "otherFilter" : [ ] + } + } + }, { + "localId" : "221", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "CodeSystemIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "221", + "s" : [ { + "value" : [ "", "define ", "CodeSystemIsValueSet", ": " ] + }, { + "r" : "222", + "s" : [ { + "r" : "223", + "s" : [ { + "value" : [ "\"TestCodeSystem\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "224", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "222", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "CodeSystemRef", + "localId" : "223", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "224", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "227", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ValueSetIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "227", + "s" : [ { + "value" : [ "", "define ", "ValueSetIsValueSet", ": " ] + }, { + "r" : "228", + "s" : [ { + "r" : "229", + "s" : [ { + "value" : [ "\"TestValueSet\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "230", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "228", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ValueSetRef", + "localId" : "229", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "preserve" : true, + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "230", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "233", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "RatioIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "233", + "s" : [ { + "value" : [ "", "define ", "RatioIsValueSet", ": " ] + }, { + "r" : "234", + "s" : [ { + "r" : "235", + "s" : [ { + "value" : [ "Ratio", " { " ] + }, { + "s" : [ { + "value" : [ "numerator", ": " ] + }, { + "r" : "237", + "s" : [ { + "value" : [ "1 ", "'1'" ] + } ] + } ] + }, { + "value" : [ ", " ] + }, { + "s" : [ { + "value" : [ "denominator", ": " ] + }, { + "r" : "238", + "s" : [ { + "value" : [ "2 ", "'1'" ] + } ] + } ] + }, { + "value" : [ " }" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "239", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "234", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Instance", + "localId" : "235", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "classType" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ], + "element" : [ { + "name" : "numerator", + "value" : { + "type" : "Quantity", + "localId" : "237", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 1, + "unit" : "1", + "annotation" : [ ] + } + }, { + "name" : "denominator", + "value" : { + "type" : "Quantity", + "localId" : "238", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 2, + "unit" : "1", + "annotation" : [ ] + } + } ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "239", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "242", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "TupleIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "242", + "s" : [ { + "value" : [ "", "define ", "TupleIsValueSet", ": " ] + }, { + "r" : "243", + "s" : [ { + "r" : "244", + "value" : [ "Tuple { : }", " is " ] + }, { + "r" : "246", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "243", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Tuple", + "localId" : "244", + "annotation" : [ ], + "resultTypeSpecifier" : { + "type" : "TupleTypeSpecifier", + "localId" : "245", + "annotation" : [ ], + "element" : [ ] + }, + "element" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "246", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "249", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "StringIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "249", + "s" : [ { + "value" : [ "", "define ", "StringIsValueSet", ": " ] + }, { + "r" : "250", + "s" : [ { + "r" : "251", + "s" : [ { + "value" : [ "'test'" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "253", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "250", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "251", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}String", + "valueType" : "{urn:hl7-org:elm-types:r1}String", + "value" : "test", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "253", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "256", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "IntegerIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "256", + "s" : [ { + "value" : [ "", "define ", "IntegerIsValueSet", ": " ] + }, { + "r" : "257", + "s" : [ { + "r" : "258", + "value" : [ "1", " is " ] + }, { + "r" : "259", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "257", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "258", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Integer", + "valueType" : "{urn:hl7-org:elm-types:r1}Integer", + "value" : "1", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "259", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "262", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "BooleanIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "262", + "s" : [ { + "value" : [ "", "define ", "BooleanIsValueSet", ": " ] + }, { + "r" : "263", + "s" : [ { + "r" : "264", + "value" : [ "false", " is " ] + }, { + "r" : "265", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "263", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "264", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "valueType" : "{urn:hl7-org:elm-types:r1}Boolean", + "value" : "false", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "265", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "268", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ExpansionIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "268", + "s" : [ { + "value" : [ "", "define ", "ExpansionIsValueSet", ": " ] + }, { + "r" : "269", + "s" : [ { + "r" : "270", + "s" : [ { + "value" : [ "Expansion" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "271", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "269", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ParameterRef", + "localId" : "270", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "271", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "274", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "NullIsValueSet", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "274", + "s" : [ { + "value" : [ "", "define ", "NullIsValueSet", ": " ] + }, { + "r" : "275", + "s" : [ { + "r" : "276", + "value" : [ "null", " is " ] + }, { + "r" : "277", + "s" : [ { + "value" : [ "ValueSet" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "275", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Null", + "localId" : "276", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "277", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "{urn:hl7-org:elm-types:r1}ValueSet", + "annotation" : [ ] + } + } + }, { + "localId" : "280", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ValueSetIsAny", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "define ", "ValueSetIsAny", ": " ] + }, { + "r" : "281", + "s" : [ { + "r" : "282", + "s" : [ { + "value" : [ "\"TestValueSet\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "283", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "281", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ValueSetRef", + "localId" : "282", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "preserve" : true, + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "283", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } + } ] + } + } +} + +/* IsRatioType +library TestSnippet version '1' +using Simple version '1.0.0' +codesystem "TestCodeSystem": 'urn:test:system' +valueset "TestValueSet": 'urn:test:valueset' +parameter Expansion Any +context Patient +define CodeSystemIsRatio: "TestCodeSystem" is Ratio +define ValueSetIsRatio: "TestValueSet" is Ratio +define RatioIsRatio: Ratio { numerator: 1 '1', denominator: 2 '1' } is Ratio +define TupleIsRatio: Tuple { : } is Ratio +define StringIsRatio: 'test' is Ratio +define IntegerIsRatio: 1 is Ratio +define BooleanIsRatio: false is Ratio +define ExpansionIsRatio: Expansion is Ratio +define NullIsRatio: null is Ratio +define RatioIsAny: Ratio { numerator: 1 '1', denominator: 2 '1' } is Any +*/ + +module.exports['IsRatioType'] = { + "library" : { + "localId" : "0", + "annotation" : [ { + "type" : "CqlToElmInfo", + "translatorVersion" : "4.2.0", + "translatorOptions" : "EnableDateRangeOptimization,EnableAnnotations,EnableResultTypes", + "signatureLevel" : "All" + }, { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "library TestSnippet version '1'" ] + } ] + } + } ], + "identifier" : { + "id" : "TestSnippet", + "version" : "1" + }, + "schemaIdentifier" : { + "id" : "urn:hl7-org:elm", + "version" : "r1" + }, + "usings" : { + "def" : [ { + "localId" : "1", + "localIdentifier" : "System", + "uri" : "urn:hl7-org:elm-types:r1", + "annotation" : [ ] + }, { + "localId" : "206", + "localIdentifier" : "Simple", + "uri" : "https://github.com/cqframework/cql-execution/simple", + "version" : "1.0.0", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "206", + "s" : [ { + "value" : [ "", "using " ] + }, { + "s" : [ { + "value" : [ "Simple" ] + } ] + }, { + "value" : [ " version '1.0.0'" ] + } ] + } + } ] + } ] + }, + "parameters" : { + "def" : [ { + "localId" : "212", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "212", + "s" : [ { + "value" : [ "", "parameter ", "Expansion", " " ] + }, { + "r" : "213", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } + } ], + "parameterTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "213", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } ] + }, + "codeSystems" : { + "def" : [ { + "localId" : "208", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "id" : "urn:test:system", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "208", + "s" : [ { + "value" : [ "", "codesystem ", "\"TestCodeSystem\"", ": ", "'urn:test:system'" ] + } ] + } + } ] + } ] + }, + "valueSets" : { + "def" : [ { + "localId" : "210", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "id" : "urn:test:valueset", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "210", + "s" : [ { + "value" : [ "", "valueset ", "\"TestValueSet\"", ": ", "'urn:test:valueset'" ] + } ] + } + } ], + "codeSystem" : [ ] + } ] + }, + "contexts" : { + "def" : [ { + "localId" : "218", + "name" : "Patient", + "annotation" : [ ] + } ] + }, + "statements" : { + "def" : [ { + "localId" : "216", + "name" : "Patient", + "context" : "Patient", + "annotation" : [ ], + "expression" : { + "type" : "SingletonFrom", + "localId" : "217", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Retrieve", + "localId" : "215", + "dataType" : "{https://github.com/cqframework/cql-execution/simple}Patient", + "annotation" : [ ], + "include" : [ ], + "codeFilter" : [ ], + "dateFilter" : [ ], + "otherFilter" : [ ] + } + } + }, { + "localId" : "221", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "CodeSystemIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "221", + "s" : [ { + "value" : [ "", "define ", "CodeSystemIsRatio", ": " ] + }, { + "r" : "222", + "s" : [ { + "r" : "223", + "s" : [ { + "value" : [ "\"TestCodeSystem\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "224", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "222", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "CodeSystemRef", + "localId" : "223", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}CodeSystem", + "name" : "TestCodeSystem", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "224", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "227", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ValueSetIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "227", + "s" : [ { + "value" : [ "", "define ", "ValueSetIsRatio", ": " ] + }, { + "r" : "228", + "s" : [ { + "r" : "229", + "s" : [ { + "value" : [ "\"TestValueSet\"" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "230", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "228", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ValueSetRef", + "localId" : "229", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet", + "name" : "TestValueSet", + "preserve" : true, + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "230", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "233", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "RatioIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "233", + "s" : [ { + "value" : [ "", "define ", "RatioIsRatio", ": " ] + }, { + "r" : "234", + "s" : [ { + "r" : "235", + "s" : [ { + "value" : [ "Ratio", " { " ] + }, { + "s" : [ { + "value" : [ "numerator", ": " ] + }, { + "r" : "237", + "s" : [ { + "value" : [ "1 ", "'1'" ] + } ] + } ] + }, { + "value" : [ ", " ] + }, { + "s" : [ { + "value" : [ "denominator", ": " ] + }, { + "r" : "238", + "s" : [ { + "value" : [ "2 ", "'1'" ] + } ] + } ] + }, { + "value" : [ " }" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "239", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "234", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Instance", + "localId" : "235", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "classType" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ], + "element" : [ { + "name" : "numerator", + "value" : { + "type" : "Quantity", + "localId" : "237", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 1, + "unit" : "1", + "annotation" : [ ] + } + }, { + "name" : "denominator", + "value" : { + "type" : "Quantity", + "localId" : "238", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 2, + "unit" : "1", + "annotation" : [ ] + } + } ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "239", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "242", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "TupleIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "242", + "s" : [ { + "value" : [ "", "define ", "TupleIsRatio", ": " ] + }, { + "r" : "243", + "s" : [ { + "r" : "244", + "value" : [ "Tuple { : }", " is " ] + }, { + "r" : "246", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "243", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Tuple", + "localId" : "244", + "annotation" : [ ], + "resultTypeSpecifier" : { + "type" : "TupleTypeSpecifier", + "localId" : "245", + "annotation" : [ ], + "element" : [ ] + }, + "element" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "246", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "249", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "StringIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "249", + "s" : [ { + "value" : [ "", "define ", "StringIsRatio", ": " ] + }, { + "r" : "250", + "s" : [ { + "r" : "251", + "s" : [ { + "value" : [ "'test'" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "253", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "250", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "251", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}String", + "valueType" : "{urn:hl7-org:elm-types:r1}String", + "value" : "test", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "253", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "256", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "IntegerIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "256", + "s" : [ { + "value" : [ "", "define ", "IntegerIsRatio", ": " ] + }, { + "r" : "257", + "s" : [ { + "r" : "258", + "value" : [ "1", " is " ] + }, { + "r" : "259", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "257", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "258", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Integer", + "valueType" : "{urn:hl7-org:elm-types:r1}Integer", + "value" : "1", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "259", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "262", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "BooleanIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "262", + "s" : [ { + "value" : [ "", "define ", "BooleanIsRatio", ": " ] + }, { + "r" : "263", + "s" : [ { + "r" : "264", + "value" : [ "false", " is " ] + }, { + "r" : "265", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "263", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Literal", + "localId" : "264", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "valueType" : "{urn:hl7-org:elm-types:r1}Boolean", + "value" : "false", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "265", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "268", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "ExpansionIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "268", + "s" : [ { + "value" : [ "", "define ", "ExpansionIsRatio", ": " ] + }, { + "r" : "269", + "s" : [ { + "r" : "270", + "s" : [ { + "value" : [ "Expansion" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "271", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "269", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "ParameterRef", + "localId" : "270", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "Expansion", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "271", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "274", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "NullIsRatio", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "274", + "s" : [ { + "value" : [ "", "define ", "NullIsRatio", ": " ] + }, { + "r" : "275", + "s" : [ { + "r" : "276", + "value" : [ "null", " is " ] + }, { + "r" : "277", + "s" : [ { + "value" : [ "Ratio" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "275", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Null", + "localId" : "276", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "277", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "name" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ] + } + } + }, { + "localId" : "280", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "name" : "RatioIsAny", + "context" : "Patient", + "accessLevel" : "Public", + "annotation" : [ { + "type" : "Annotation", + "t" : [ ], + "s" : { + "r" : "280", + "s" : [ { + "value" : [ "", "define ", "RatioIsAny", ": " ] + }, { + "r" : "281", + "s" : [ { + "r" : "282", + "s" : [ { + "value" : [ "Ratio", " { " ] + }, { + "s" : [ { + "value" : [ "numerator", ": " ] + }, { + "r" : "284", + "s" : [ { + "value" : [ "1 ", "'1'" ] + } ] + } ] + }, { + "value" : [ ", " ] + }, { + "s" : [ { + "value" : [ "denominator", ": " ] + }, { + "r" : "285", + "s" : [ { + "value" : [ "2 ", "'1'" ] + } ] + } ] + }, { + "value" : [ " }" ] + } ] + }, { + "value" : [ " is " ] + }, { + "r" : "286", + "s" : [ { + "value" : [ "Any" ] + } ] + } ] + } ] + } + } ], + "expression" : { + "type" : "Is", + "localId" : "281", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean", + "annotation" : [ ], + "signature" : [ ], + "operand" : { + "type" : "Instance", + "localId" : "282", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Ratio", + "classType" : "{urn:hl7-org:elm-types:r1}Ratio", + "annotation" : [ ], + "element" : [ { + "name" : "numerator", + "value" : { + "type" : "Quantity", + "localId" : "284", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 1, + "unit" : "1", + "annotation" : [ ] + } + }, { + "name" : "denominator", + "value" : { + "type" : "Quantity", + "localId" : "285", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Quantity", + "value" : 2, + "unit" : "1", + "annotation" : [ ] + } + } ] + }, + "isTypeSpecifier" : { + "type" : "NamedTypeSpecifier", + "localId" : "286", + "resultTypeName" : "{urn:hl7-org:elm-types:r1}Any", + "name" : "{urn:hl7-org:elm-types:r1}Any", + "annotation" : [ ] + } + } + } ] + } + } +} + /* IsListType library TestSnippet version '1' using Simple version '1.0.0' diff --git a/test/elm/type/type-test.ts b/test/elm/type/type-test.ts index 47a769a8c..17d309b93 100644 --- a/test/elm/type/type-test.ts +++ b/test/elm/type/type-test.ts @@ -1,5 +1,6 @@ import should from 'should'; import { Interval } from '../../../src/datatypes/interval'; +import { ValueSet } from '../../../src/datatypes/clinical'; import setup from '../../setup'; const data = require('./data'); const { p1 } = require('./patients'); @@ -20,6 +21,144 @@ describe('IsSystemType', () => { }); }); +describe('IsCodeSystemType', () => { + beforeEach(function () { + setup(this, data, [], {}, { Expansion: new ValueSet('urn:test:valueset') }); + }); + + it('should accept CodeSystem', async function () { + should(await this.codeSystemIsCodeSystem.exec(this.ctx)).be.true(); + }); + + it('should reject CQLValueSet', async function () { + should(await this.valueSetIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject Ratio', async function () { + should(await this.ratioIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a tuple', async function () { + should(await this.tupleIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a string', async function () { + should(await this.stringIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject an integer', async function () { + should(await this.integerIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a boolean', async function () { + should(await this.booleanIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a value set expansion', async function () { + should(await this.expansionIsCodeSystem.exec(this.ctx)).not.be.ok(); + }); + + it('should reject null', async function () { + should(await this.nullIsCodeSystem.exec(this.ctx)).be.false(); + }); + + it('should match CodeSystem as Any', async function () { + should(await this.codeSystemIsAny.exec(this.ctx)).be.true(); + }); +}); + +describe('IsValueSetType', () => { + beforeEach(function () { + setup(this, data, [], {}, { Expansion: new ValueSet('urn:test:valueset') }); + }); + + it('should reject CodeSystem', async function () { + should(await this.codeSystemIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should accept CQLValueSet', async function () { + should(await this.valueSetIsValueSet.exec(this.ctx)).be.true(); + }); + + it('should reject Ratio', async function () { + should(await this.ratioIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a tuple', async function () { + should(await this.tupleIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a string', async function () { + should(await this.stringIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject an integer', async function () { + should(await this.integerIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a boolean', async function () { + should(await this.booleanIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a value set expansion', async function () { + should(await this.expansionIsValueSet.exec(this.ctx)).not.be.ok(); + }); + + it('should reject null', async function () { + should(await this.nullIsValueSet.exec(this.ctx)).be.false(); + }); + + it('should match ValueSet as Any', async function () { + should(await this.valueSetIsAny.exec(this.ctx)).be.true(); + }); +}); + +describe('IsRatioType', () => { + beforeEach(function () { + setup(this, data, [], {}, { Expansion: new ValueSet('urn:test:valueset') }); + }); + + it('should reject CodeSystem', async function () { + should(await this.codeSystemIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject CQLValueSet', async function () { + should(await this.valueSetIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should accept Ratio', async function () { + should(await this.ratioIsRatio.exec(this.ctx)).be.true(); + }); + + it('should reject a tuple', async function () { + should(await this.tupleIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a string', async function () { + should(await this.stringIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject an integer', async function () { + should(await this.integerIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a boolean', async function () { + should(await this.booleanIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject a value set expansion', async function () { + should(await this.expansionIsRatio.exec(this.ctx)).not.be.ok(); + }); + + it('should reject null', async function () { + should(await this.nullIsRatio.exec(this.ctx)).be.false(); + }); + + it('should match Ratio as Any', async function () { + should(await this.ratioIsAny.exec(this.ctx)).be.true(); + }); +}); + describe('IsListType', () => { beforeEach(function () { setup(this, data); diff --git a/test/runtime/systemDataModelProvider-test.ts b/test/runtime/systemDataModelProvider-test.ts new file mode 100644 index 000000000..f326f97f5 --- /dev/null +++ b/test/runtime/systemDataModelProvider-test.ts @@ -0,0 +1,116 @@ +import should from 'should'; +import { + Code, + CodeSystem, + CQLValueSet, + Quantity, + Ratio, + ValueSet +} from '../../src/datatypes/datatypes'; +import { ExpandValueSet, InValueSet } from '../../src/elm/clinical'; +import { Library } from '../../src/elm/library'; +import { Context } from '../../src/runtime/context'; +import { SystemDataModelProvider } from '../../src/runtime/systemDataModelProvider'; +import { ELM_CODESYSTEM_TYPE, ELM_VALUESET_TYPE, ELM_RATIO_TYPE } from '../../src/util/elmTypes'; +const simpleELMWithVersion = require('./fixtures/SimpleLibraryWithVersion.json'); + +describe('SystemDataModelProvider', () => { + const provider = new SystemDataModelProvider(); + + it('should construct a CodeSystem with its metadata', () => { + const system = provider.createInstance(ELM_CODESYSTEM_TYPE, { + id: 'http://loinc.org', + version: '1', + name: 'LOINC' + }); + should(system).be.instanceof(CodeSystem); + should(system.id).equal('http://loinc.org'); + should(system.version).equal('1'); + should(system.name).equal('LOINC'); + should(system.isCodeSystem).be.true(); + }); + + it('should construct a CQLValueSet and preserve its code systems', () => { + const codesystems = [new CodeSystem('http://loinc.org')]; + const valueset = provider.createInstance(ELM_VALUESET_TYPE, { + id: 'urn:test:valueset', + version: '1', + name: 'Test value set', + codesystems + }); + should(valueset).be.instanceof(CQLValueSet); + should(valueset.id).equal('urn:test:valueset'); + should(valueset.version).equal('1'); + should(valueset.name).equal('Test value set'); + should(valueset.codesystems).equal(codesystems); + }); + + it('should allow omitted optional metadata for CodeSystem', () => { + const instance = provider.createInstance(ELM_CODESYSTEM_TYPE, { id: 'urn:test' }); + should(instance.id).equal('urn:test'); + should(instance.version).be.undefined(); + should(instance.name).be.undefined(); + }); + + it('should allow omitted optional metadata for ValueSet', () => { + const instance = provider.createInstance(ELM_VALUESET_TYPE, { id: 'urn:test' }); + should(instance.id).equal('urn:test'); + should(instance.version).be.undefined(); + should(instance.name).be.undefined(); + should(instance.codesystems).be.undefined(); + }); + + it('should construct a Ratio with working quantity operations', () => { + const numerator = new Quantity(1, 'mg'); + const denominator = new Quantity(2, 'mL'); + const ratio = provider.createInstance(ELM_RATIO_TYPE, { numerator, denominator }); + should(ratio).be.instanceof(Ratio); + should(ratio.numerator).equal(numerator); + should(ratio.denominator).equal(denominator); + should(ratio.equals(new Ratio(new Quantity(2, 'mg'), new Quantity(4, 'mL')))).be.true(); + }); + + it('should reject ratios missing either quantity', () => { + should(() => provider.createInstance(ELM_RATIO_TYPE, { denominator: new Quantity(1) })).throw( + 'Cannot create a ratio with an undefined numerator' + ); + should(() => provider.createInstance(ELM_RATIO_TYPE, { numerator: new Quantity(1) })).throw( + 'Cannot create a ratio with an undefined denominator' + ); + }); + + it('should decline other namespaces and preserve unknown System types', () => { + const fields = { id: 'test' }; + should(provider.createInstance('{urn:test}CodeSystem', fields)).be.null(); + should(provider.createInstance('{urn:hl7-org:elm-types:r1}Unknown', fields)).equal(fields); + }); + + it('should support terminology operations on constructed value sets', async () => { + const code = new Code('12345', 'http://loinc.org'); + const expansion = new ValueSet('urn:test:valueset', '1', [code]); + const context = new Context(new Library(simpleELMWithVersion)); + context.codeService = { + findValueSetsByOid: () => [expansion], + findValueSet: (id, version) => { + should(id).equal('urn:test:valueset'); + should(version).equal('1'); + return expansion; + } + }; + context.set( + 'valueset', + context.createInstance(ELM_VALUESET_TYPE, { + id: 'urn:test:valueset', + version: '1' + }) + ); + context.set('code', code); + const valuesetExpression = { type: 'ExpressionRef', name: 'valueset' }; + const contains = new InValueSet({ + code: { type: 'ExpressionRef', name: 'code' }, + valuesetExpression + }); + should(await contains.exec(context)).be.true(); + should(await new ExpandValueSet({ operand: valuesetExpression }).exec(context)).eql([code]); + }); +});