All files / src/elm external.coffee

100% Statements 18/18
62.5% Branches 5/8
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 337x 1x 1x   1x   1685x 1685x 1685x 1685x 1685x 1685x 1685x     80x 80x   9x   9x     3x 3x                
{ Expression } = require './expression'
{ build } = require './builder'
{ typeIsArray } = require '../util/util'
 
module.exports.Retrieve = class Retrieve extends Expression
  constructor: (json) ->
    super
    @datatype = json.dataType
    @templateId = json.templateId
    @codeProperty = json.codeProperty
    @codes = build json.codes
    @dateProperty = json.dateProperty
    @dateRange = build json.dateRange
 
  exec: (ctx) ->
    records = ctx.findRecords(@templateId ? @datatype)
    codes = @codes
    if @codes && typeof @codes.exec == 'function'
      codes = @codes.execute(ctx)
    if codes
      records = records.filter (r) => @recordMatchesCodesOrVS(r, codes)
    # TODO: Added @dateProperty check due to previous fix in cql4browsers in cql_qdm_patient_api hash: ddbc57
    if @dateRange && @dateProperty
      range = @dateRange.execute(ctx)
      records = (r for r in records when range.includes(r.getDateOrInterval(@dateProperty)))
 
    records
 
  recordMatchesCodesOrVS: (record, codes) ->
    if typeIsArray codes
      codes.some (c) => c.hasMatch(record.getCode(@codeProperty))
    else
      codes.hasMatch(record.getCode(@codeProperty))