Skip to content

Commit

Permalink
Better type support
Browse files Browse the repository at this point in the history
* Rename types files
* Add strict typing to executor and context args
* Update example to use typescript import with comment
  • Loading branch information
mgramigna committed Feb 16, 2022
1 parent bdb31d7 commit ea8e9e8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/typescript/exec-age.ts
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-var-requires */
import cql from '../../src/cql';
const measure = require('./age.json');
import * as measure from './age.json'; // Ensure "resolveJsonModule" is set to true in tsconfig.json

const lib = new cql.Library(measure);
const executor = new cql.Executor(lib);
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/context.ts
@@ -1,10 +1,10 @@
import { Exception } from '../datatypes/exception';
import { typeIsArray } from '../util/util';
import * as dt from '../datatypes/datatypes';
import { CodeService } from '../cql-code-service';
import { MessageListener, NullMessageListener } from './messageListeners';
import { Patient } from '../cql-patient';
import { Parameter } from '../types/runtime-types';
import { TerminologyProvider } from '../types';

export class Context {
// Public Construcor args
Expand All @@ -13,7 +13,7 @@ export class Context {
public messageListener?: MessageListener;

// Private Construcor args
private _codeService?: CodeService | null;
private _codeService?: TerminologyProvider | null;
private _parameters?: Parameter;

// Auto-initialized properties
Expand All @@ -24,7 +24,7 @@ export class Context {

constructor(
parent: Context,
_codeService?: CodeService | null,
_codeService?: TerminologyProvider | null,
_parameters?: Parameter,
executionDateTime?: dt.DateTime,
messageListener?: MessageListener
Expand All @@ -51,7 +51,7 @@ export class Context {
this._parameters = params;
}

get codeService(): CodeService {
get codeService(): TerminologyProvider {
return this._codeService || (this.parent && this.parent.codeService);
}

Expand All @@ -64,7 +64,7 @@ export class Context {
return this;
}

withCodeService(cs: CodeService) {
withCodeService(cs: TerminologyProvider) {
this.codeService = cs;
return this;
}
Expand Down Expand Up @@ -423,7 +423,7 @@ export class PatientContext extends Context {
constructor(
public library: any,
public patient?: Patient | null,
codeService?: CodeService | null,
codeService?: TerminologyProvider | null,
parameters?: Parameter,
executionDateTime: dt.DateTime = dt.DateTime.fromJSDate(new Date()),
messageListener: MessageListener = new NullMessageListener()
Expand Down Expand Up @@ -472,7 +472,7 @@ export class UnfilteredContext extends Context {
constructor(
public library: any,
public results: any,
codeService?: CodeService | null,
codeService?: TerminologyProvider | null,
parameters?: Parameter,
executionDateTime: dt.DateTime = dt.DateTime.fromJSDate(new Date()),
messageListener: MessageListener = new NullMessageListener()
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/executor.ts
@@ -1,14 +1,14 @@
import { MessageListener, NullMessageListener } from './messageListeners';
import { Results } from './results';
import { UnfilteredContext, PatientContext } from './context';
import { CodeService } from '../cql-code-service';
import { DateTime } from '../datatypes/datetime';
import { Parameter } from '../types/runtime-types';
import { DataProvider, TerminologyProvider } from '../types';

export class Executor {
constructor(
public library: any,
public codeService?: CodeService,
public codeService?: TerminologyProvider,
public parameters?: Parameter,
public messageListener: MessageListener = new NullMessageListener()
) {
Expand All @@ -28,7 +28,7 @@ export class Executor {
return this;
}

withCodeService(cs: CodeService) {
withCodeService(cs: TerminologyProvider) {
this.codeService = cs;
return this;
}
Expand All @@ -38,7 +38,7 @@ export class Executor {
return this;
}

exec_expression(expression: any, patientSource: any, executionDateTime: DateTime) {
exec_expression(expression: any, patientSource: DataProvider, executionDateTime: DateTime) {
const r = new Results();
const expr = this.library.expressions[expression];
if (expr != null) {
Expand All @@ -58,7 +58,7 @@ export class Executor {
return r;
}

exec(patientSource: any, executionDateTime?: DateTime) {
exec(patientSource: DataProvider, executionDateTime?: DateTime) {
const r = this.exec_patient_context(patientSource, executionDateTime);
const unfilteredContext = new UnfilteredContext(
this.library,
Expand All @@ -79,7 +79,7 @@ export class Executor {
return r;
}

exec_patient_context(patientSource: any, executionDateTime?: DateTime) {
exec_patient_context(patientSource: DataProvider, executionDateTime?: DateTime) {
const r = new Results();
while (patientSource.currentPatient()) {
const patient_ctx = new PatientContext(
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/types/index.ts
@@ -1,3 +1,3 @@
export * from './runtime-types';
export * from './cql-code-service-types';
export * from './cql-patient-types';
export * from './cql-code-service.interfaces';
export * from './cql-patient.interfaces';

0 comments on commit ea8e9e8

Please sign in to comment.