Sha256: a542edc0be33b11aaf6296697e1f4fb19e33de0d4931c281e9cddaa114a765bf

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 KB

Contents

const mongoose = require('mongoose/browser');
const cql = require('cql-execution');

function Code(key, options) {
  mongoose.SchemaType.call(this, key, options, 'Code');
}
Code.prototype = Object.create(mongoose.SchemaType.prototype);

Code.prototype.cast = (code) => {
  if (code != null) {
    // return code if it doesn't even need casting
    if (code.isCode) {
      return code;
    }
    // handles codes that have not yet been cast to a code and those that have already been cast to a code
    if (code.code && code.system) {
      const val = { code: code.code, system: code.system };
      val.display = (typeof code.display !== 'undefined') ? code.display : null;
      val.version = (typeof code.version !== 'undefined') ? code.version : null;

      return new cql.Code(val.code, val.system, val.version, val.display);
    }
    throw new Error(`Expected a code. Received ${code}.`);
  } else {
    // returns a null or undefined if what is passed in is null or undefined
    return code;
  }
};

mongoose.Schema.Types.Code = Code;
module.exports = Code;

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cqm-models-4.2.0 app/assets/javascripts/basetypes/Code.js
cqm-models-3.1.2 app/assets/javascripts/basetypes/Code.js
cqm-models-4.1.1 app/assets/javascripts/basetypes/Code.js
cqm-models-4.1.0 app/assets/javascripts/basetypes/Code.js
cqm-models-4.0.2 app/assets/javascripts/basetypes/Code.js
cqm-models-4.0.1 app/assets/javascripts/basetypes/Code.js
cqm-models-4.0.0 app/assets/javascripts/basetypes/Code.js
cqm-models-3.1.1 app/assets/javascripts/basetypes/Code.js
cqm-models-3.1.0 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.6 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.5 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.4 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.3 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.2 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.1 app/assets/javascripts/basetypes/Code.js
cqm-models-3.0.0 app/assets/javascripts/basetypes/Code.js