cqm-models 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cqm-models",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "This library contains auto generated Mongo (Mongoose.js) models that correspond to the QDM (Quality Data Model) specification.",
5
5
  "main": "app/assets/javascripts/index.js",
6
6
  "browser": {
@@ -17,20 +17,24 @@
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
19
  "cql-execution": "2.4.1",
20
- "mongoose": "^5.13.12"
20
+ "mongoose": "^5.13.20"
21
21
  },
22
22
  "devDependencies": {
23
- "browserify": "^16.1.0",
24
- "eslint": "^7.0.0",
25
- "eslint-config-airbnb-base": "^14.2.1",
26
- "eslint-plugin-import": "^2.8.0",
27
- "jasmine": "^2.9.0",
28
- "nyc": "^15.1.0"
23
+ "browserify": "^17.0.0",
24
+ "eslint": "^8.53.0",
25
+ "eslint-config-airbnb-base": "^15.0.0",
26
+ "eslint-plugin-import": "^2.29.0",
27
+ "jest": "^29.7.0"
28
+ },
29
+ "resolutions": {
30
+ "browserify-sign": "^4.2.2",
31
+ "semver": "^7.5.4",
32
+ "@babel/traverse": "^7.23.3"
29
33
  },
30
34
  "scripts": {
31
35
  "prepublish": "./bin/build_cql_execution.sh",
32
- "test": "jasmine",
33
- "coverage": "nyc npm run test",
36
+ "test": "npx jest",
37
+ "coverage": "npx jest --coverage",
34
38
  "lint": "eslint 'app/assets/javascripts/**/*.js'",
35
39
  "dist": "yarn && browserify app/assets/javascripts/index.js > dist/index.js",
36
40
  "browser": "browserify app/assets/javascripts/browser.js > dist/browser.js",
@@ -112,6 +112,23 @@ function <%= datatype %>SchemaFunction(add, options) {
112
112
  extended.add(add);
113
113
  }
114
114
 
115
+ /* eslint no-underscore-dangle: 0 */
116
+ extended.methods._is = function _is(typeSpecifier) {
117
+ return this._typeHierarchy().some(
118
+ t => t.type === typeSpecifier.type && t.name === typeSpecifier.name
119
+ );
120
+ };
121
+
122
+ extended.methods._typeHierarchy = function _typeHierarchy() {
123
+ const typeName = this._type.replace(/QDM::/, '');
124
+ const ver = this.qdmVersion.replace('.', '_');
125
+ return [
126
+ {
127
+ name: `{urn:healthit-gov:qdm:v${ver}}${typeName}`,
128
+ type: 'NamedTypeSpecifier',
129
+ },
130
+ ];
131
+ };
115
132
  return extended;
116
133
  }
117
134
  <% end %>
@@ -3,6 +3,7 @@ const Code = require('./basetypes/Code');
3
3
  const Interval = require('./basetypes/Interval');
4
4
  const Quantity = require('./basetypes/Quantity');
5
5
  const DateTime = require('./basetypes/DateTime');
6
+ const AnyEntity = require('./basetypes/AnyEntity');
6
7
  const AllDataElements = require('./AllDataElements');
7
8
 
8
9
  const [Schema, Number, String, Mixed] = [
@@ -94,6 +95,12 @@ QDMPatientSchema.methods.getDataElements = function getDataElements(params) {
94
95
  return this.dataElements;
95
96
  };
96
97
 
98
+ QDMPatientSchema.methods.addMethodsTo = function addMethodsTo(obj, methods) {
99
+ Object.entries(methods).forEach(([method_name, method]) => {
100
+ obj[method_name] = method;
101
+ });
102
+ };
103
+
97
104
  // Returns an array of dataElements that exist on the patient, queried by
98
105
  // QDM profile
99
106
  // @param {string} profile - the data criteria requested by the execution engine
@@ -105,10 +112,26 @@ QDMPatientSchema.methods.getByProfile = function getByProfile(profile, isNegated
105
112
  // If isNegated == null, return all matching data elements by type, regardless of negationRationale.
106
113
  const results = this.dataElements.filter(element => (element._type === `QDM::${profile}` || element._type === profile) && (isNegated === null || !!element.negationRationale === isNegated));
107
114
  return results.map((result) => {
115
+ // we need to convert mongoose document to an object.
116
+ // This is required for comparing the two objects(in cql-execution) as we can't compare two mongoose documents.
108
117
  const removedMongooseItems = new AllDataElements[profile](result).toObject({ virtuals: true });
109
118
  // toObject() will remove all mongoose functions but also remove the schema methods, so we add them back
110
- Object.entries(result.schema.methods).forEach(([method_name, method]) => {
111
- removedMongooseItems[method_name] = method;
119
+ this.addMethodsTo(removedMongooseItems, result.schema.methods);
120
+ // add methods to entities
121
+ Object.entries(result).forEach(([key, values]) => {
122
+ // entities are always an array
123
+ if (Array.isArray(values)) {
124
+ try {
125
+ // check if the attribute is of Entity
126
+ if (AnyEntity.prototype.cast(values[0])) {
127
+ values.forEach((value, index) => {
128
+ const entity = removedMongooseItems[key][index];
129
+ this.addMethodsTo(entity, value.schema.methods);
130
+ });
131
+ }
132
+ // eslint-disable-next-line no-empty
133
+ } catch (e) {}
134
+ }
112
135
  });
113
136
  return removedMongooseItems;
114
137
  });