Sha256: 60ef4d7b1e5d63c1c14ceb1bcad772b395be20411b68ceb9488120a14e6a4d01

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

const mongoose = require('mongoose/browser');
const Code = require('./Code.js');
const cql = require('cql-execution');
const Identifier = require('../attributes/Identifier');

const [Schema] = [mongoose.Schema];

function DataElementSchema(add, options) {
  const extended = new Schema({
    dataElementCodes: { type: [Code] },
    description: { type: String },
    codeListId: { type: String },
    id: {
      type: String,
      default() {
        return this._id ? this._id.toString() : mongoose.Types.ObjectId().toString();
      },
    },
  }, options);

  if (add) {
    extended.add(add);
  }

  // Returns all of the codes on this data element in a format usable by
  // the cql-execution framework.
  extended.methods.getCode = function getCode() {
    if (this.dataElementCodes) {
      return this.dataElementCodes.map((code) => {
        if (code.isCode) {
          return code;
        }
        return new cql.Code(code.code, code.system, code.version, code.display);
      });
    }
    return null;
  };

  // Return the first code on this data element in a format usable by
  // the cql-execution framework.
  extended.methods.code = function code() {
    if (this.dataElementCodes && this.dataElementCodes[0]) {
      const qdmCode = this.dataElementCodes[0];
      if (qdmCode.isCode) {
        return qdmCode;
      }
      return new cql.Code(qdmCode.code, qdmCode.system, qdmCode.version, qdmCode.display);
    }
    return null;
  };

  return extended;
}

module.exports.DataElementSchema = DataElementSchema;

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cqm-models-3.1.2 app/assets/javascripts/basetypes/DataElement.js
cqm-models-4.0.0 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.1.1 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.1.0 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.0.6 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.0.5 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.0.4 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.0.3 app/assets/javascripts/basetypes/DataElement.js
cqm-models-3.0.2 app/assets/javascripts/basetypes/DataElement.js