Skip to content

Commit

Permalink
Add more proper typing
Browse files Browse the repository at this point in the history
* Require _is and _typeHierarchy
* Add interfaces for TypeSpecifier structures
  • Loading branch information
mgramigna committed Feb 17, 2022
1 parent a221bd6 commit c139c09
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 42 deletions.
82 changes: 44 additions & 38 deletions examples/browser/cql4browsers.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cql-patient.ts
@@ -1,5 +1,5 @@
import * as DT from './datatypes/datatypes';
import { DataProvider, PatientObject, RecordObject } from './types';
import { DataProvider, NamedTypeSpecifier, PatientObject, RecordObject } from './types';

export class Record implements RecordObject {
json: any;
Expand All @@ -16,7 +16,7 @@ export class Record implements RecordObject {
);
}

_typeHierarchy() {
_typeHierarchy(): NamedTypeSpecifier[] {
return [
{
name: `{https://github.com/cqframework/cql-execution/simple}${this.json.recordType}`,
Expand Down
6 changes: 5 additions & 1 deletion src/types/cql-patient.interfaces.ts
@@ -1,3 +1,5 @@
import { AnyTypeSpecifier } from './type-specifiers.interfaces';

/*
* Iterator for the patients provided to the execution engine
*/
Expand All @@ -15,11 +17,13 @@ export interface RecordObject {
getCode(field: any): any;
getDate(field: any): any;
getDateOrInterval(field: any): any;
_is?(typeSpecifier: any): boolean;
_typeHierarchy?(): AnyTypeSpecifier[];
}

/*
* Patient data object that implements logic for searching for records based on the Patient
*/
export interface PatientObject {
export interface PatientObject extends RecordObject {
findRecords(profile: string | null): RecordObject[];
}
3 changes: 2 additions & 1 deletion src/types/index.ts
@@ -1,3 +1,4 @@
export * from './runtime.types';
export * from './cql-code-service.interfaces';
export * from './cql-patient.interfaces';
export * from './runtime.types';
export * from './type-specifiers.interfaces';
50 changes: 50 additions & 0 deletions src/types/type-specifiers.interfaces.ts
@@ -0,0 +1,50 @@
// Types derived from http://cql.hl7.org/04-logicalspecification.html#typespecifier

/*
* Utility type for any possible TypeSpecifier
*/
export type AnyTypeSpecifier =
| NamedTypeSpecifier
| IntervalTypeSpecifier
| ListTypeSpecifier
| TupleTypeSpecifier
| ChoiceTypeSpecifier;

/*
* Base interface for other TypeSpecifiers to extend from
*/
export interface TypeSpecifier {
type: string;
localId?: string;
}

export interface NamedTypeSpecifier extends TypeSpecifier {
type: 'NamedTypeSpecifier';
name: string;
}

export interface IntervalTypeSpecifier extends TypeSpecifier {
type: 'IntervalTypeSpecifier';
pointType: AnyTypeSpecifier;
}

export interface ListTypeSpecifier extends TypeSpecifier {
type: 'ListTypeSpecifier';
elementType: AnyTypeSpecifier;
}

export interface TupleElementDefinition {
localId?: string;
name: string;
elementType: AnyTypeSpecifier;
}

export interface TupleTypeSpecifier extends TypeSpecifier {
type: 'TupleTypeSpecifier';
element?: TupleElementDefinition[];
}

export interface ChoiceTypeSpecifier extends TypeSpecifier {
type: 'ChoiceTypeSpecifier';
choice?: AnyTypeSpecifier[];
}

0 comments on commit c139c09

Please sign in to comment.