Skip to content

Commit

Permalink
Merge pull request #19 from cqframework/starts_ends_with
Browse files Browse the repository at this point in the history
Starts ends with
  • Loading branch information
cmoesel authored May 4, 2018
2 parents 8286916 + 1ca7045 commit 43944a1
Show file tree
Hide file tree
Showing 7 changed files with 1,061 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cql-execution",
"version": "1.2.0",
"version": "1.2.1",
"description": "An execution framework for the Clinical Quality Language (CQL)",
"keywords": [
"CQL",
Expand Down
16 changes: 16 additions & 0 deletions src/elm/string.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,19 @@ module.exports.Substring = class Substring extends Expression
stringToSub.substr(startIndex, length)
else
stringToSub.substr(startIndex)

module.exports.StartsWith = class StartsWith extends Expression
constructor: (json) ->
super

exec: (ctx) ->
args = @execArgs ctx
if (args.some (x) -> not x?) then null else args[0].slice(0, args[1].length) == args[1]

module.exports.EndsWith = class EndsWith extends Expression
constructor: (json) ->
super

exec: (ctx) ->
args = @execArgs ctx
if (args.some (x) -> not x?) then null else args[1] is '' or args[0].slice(-args[1].length) == args[1]
53 changes: 50 additions & 3 deletions src/example/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6495,7 +6495,7 @@
},{"./builder":14,"./expression":20}],35:[function(require,module,exports){
// Generated by CoffeeScript 1.12.7
(function() {
var Combine, Concatenate, Expression, Lower, PositionOf, Split, Substring, Upper, build,
var Combine, Concatenate, EndsWith, Expression, Lower, PositionOf, Split, StartsWith, Substring, Upper, build,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

Expand Down Expand Up @@ -6672,6 +6672,52 @@

})(Expression);

module.exports.StartsWith = StartsWith = (function(superClass) {
extend(StartsWith, superClass);

function StartsWith(json) {
StartsWith.__super__.constructor.apply(this, arguments);
}

StartsWith.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if (args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args[0].slice(0, args[1].length) === args[1];
}
};

return StartsWith;

})(Expression);

module.exports.EndsWith = EndsWith = (function(superClass) {
extend(EndsWith, superClass);

function EndsWith(json) {
EndsWith.__super__.constructor.apply(this, arguments);
}

EndsWith.prototype.exec = function(ctx) {
var args;
args = this.execArgs(ctx);
if (args.some(function(x) {
return x == null;
})) {
return null;
} else {
return args[1] === '' || args[0].slice(-args[1].length) === args[1];
}
};

return EndsWith;

})(Expression);

}).call(this);


Expand Down Expand Up @@ -43785,8 +43831,9 @@
}

Results.prototype.recordPatientResult = function(patient_ctx, resultName, result) {
var base, patientId;
patientId = patient_ctx.patient.id();
var base, p, patientId;
p = patient_ctx.patient;
patientId = typeof p.getId === 'function' ? p.getId() : p.id();
if ((base = this.patientResults)[patientId] == null) {
base[patientId] = {};
}
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/results.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module.exports.Results = class Results
@localIdPatientResultsMap = {}

recordPatientResult: (patient_ctx, resultName, result) ->
patientId = patient_ctx.patient.id()
p = patient_ctx.patient
# NOTE: From now on prefer getId() over id() because some data models may have an id property
# that is not a string (e.g., FHIR) -- so reserve getId() for the API (and expect a string
# representation) but leave id() for data-model specific formats.
patientId = if typeof p.getId == 'function' then p.getId() else p.id()
@patientResults[patientId] ?= {}
@patientResults[patientId][resultName] = result
@localIdPatientResultsMap[patientId] = patient_ctx.getAllLocalIds()
Expand Down
Loading

0 comments on commit 43944a1

Please sign in to comment.