Sha256: cf6cdd6a7ddd08f8dc2f8266ccc80480328ea699388ef113b2a2309df6aa1bd6

Contents?: true

Size: 851 Bytes

Versions: 7

Compression:

Stored size: 851 Bytes

Contents

const mongoose = require('mongoose');

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

Code.prototype.cast = (code) => {
  if (typeof code.code === 'undefined') {
    throw new Error(`Code: ${code} does not have a code`);
  } else if (typeof code.codeSystem === 'undefined') {
    throw new Error(`Code: ${code} does not have a codeSystem`);
  }

  const val = { code: code.code, codeSystem: code.codeSystem };

  val.descriptor = (typeof code.descriptor !== 'undefined') ? code.descriptor : null;
  val.codeSystemOid = (typeof code.codeSystemOid !== 'undefined') ? code.codeSystemOid : null;
  val.version = (typeof code.version !== 'undefined') ? code.version : null;

  return val;
};

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cqm-models-0.8.0 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.7 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.6 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.5 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.4 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.3 app/assets/javascripts/basetypes/Code.js
cqm-models-0.7.2 app/assets/javascripts/basetypes/Code.js