All files / src/elm instance.coffee

100% Statements 15/15
57.14% Branches 4/7
100% Functions 5/5
100% Lines 14/14

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 287x 1x 1x 1x     856x 856x         1x   388x 388x 776x     36x 72x 85x 36x          
{ Expression } = require './expression'
{ build } = require './builder'
{ Quantity } = require('./quantity')
{ Code, Concept } = require('../datatypes/datatypes')
class Element
  constructor: (json) ->
    @name = json.name
    @value = build json.value
  exec: (ctx) ->
    @value?.execute(ctx)
 
 
module.exports.Instance = class Instance extends Expression
  constructor: (json) ->
    super
    @classType = json.classType
    @element = ( new Element(child) for child in json.element)
 
  exec: (ctx) ->
    obj = {}
    for el in @element
      obj[el.name] = el.exec(ctx)
    switch @classType
      when "{urn:hl7-org:elm-types:r1}Quantity" then new Quantity(obj)
      when "{urn:hl7-org:elm-types:r1}Code" then new Code(obj.code, obj.system, obj.version, obj.display)
      when "{urn:hl7-org:elm-types:r1}Concept" then new Concept(obj.codes, obj.display)
      else obj