cqm-models 1.0.3 → 1.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/.eslintrc.json +10 -2
  3. data/.github/PULL_REQUEST_TEMPLATE.md +0 -4
  4. data/.rubocop.yml +3 -0
  5. data/.travis.yml +31 -1
  6. data/README.md +59 -2
  7. data/app/assets/javascripts/AdverseEvent.js +16 -7
  8. data/app/assets/javascripts/AllDataElements.js +6 -6
  9. data/app/assets/javascripts/AllergyIntolerance.js +16 -7
  10. data/app/assets/javascripts/AssessmentOrder.js +15 -6
  11. data/app/assets/javascripts/AssessmentPerformed.js +16 -7
  12. data/app/assets/javascripts/AssessmentRecommended.js +16 -7
  13. data/app/assets/javascripts/CareGoal.js +16 -7
  14. data/app/assets/javascripts/CommunicationPerformed.js +15 -6
  15. data/app/assets/javascripts/DeviceApplied.js +16 -7
  16. data/app/assets/javascripts/DeviceOrder.js +16 -7
  17. data/app/assets/javascripts/DeviceRecommended.js +16 -7
  18. data/app/assets/javascripts/Diagnosis.js +16 -7
  19. data/app/assets/javascripts/DiagnosticStudyOrder.js +16 -7
  20. data/app/assets/javascripts/DiagnosticStudyPerformed.js +16 -7
  21. data/app/assets/javascripts/DiagnosticStudyRecommended.js +16 -7
  22. data/app/assets/javascripts/EncounterOrder.js +16 -7
  23. data/app/assets/javascripts/EncounterPerformed.js +16 -7
  24. data/app/assets/javascripts/EncounterRecommended.js +16 -7
  25. data/app/assets/javascripts/FamilyHistory.js +16 -7
  26. data/app/assets/javascripts/Id.js +7 -3
  27. data/app/assets/javascripts/ImmunizationAdministered.js +16 -7
  28. data/app/assets/javascripts/ImmunizationOrder.js +16 -7
  29. data/app/assets/javascripts/IndividualResult.js +7 -2
  30. data/app/assets/javascripts/InterventionOrder.js +16 -7
  31. data/app/assets/javascripts/InterventionPerformed.js +16 -7
  32. data/app/assets/javascripts/InterventionRecommended.js +16 -7
  33. data/app/assets/javascripts/LaboratoryTestOrder.js +16 -7
  34. data/app/assets/javascripts/LaboratoryTestPerformed.js +16 -7
  35. data/app/assets/javascripts/LaboratoryTestRecommended.js +16 -7
  36. data/app/assets/javascripts/MedicationActive.js +16 -7
  37. data/app/assets/javascripts/MedicationAdministered.js +16 -7
  38. data/app/assets/javascripts/MedicationDischarge.js +16 -7
  39. data/app/assets/javascripts/MedicationDispensed.js +16 -7
  40. data/app/assets/javascripts/MedicationOrder.js +16 -7
  41. data/app/assets/javascripts/Participation.js +15 -6
  42. data/app/assets/javascripts/PatientCareExperience.js +16 -7
  43. data/app/assets/javascripts/PatientCharacteristic.js +16 -7
  44. data/app/assets/javascripts/PatientCharacteristicBirthdate.js +16 -7
  45. data/app/assets/javascripts/PatientCharacteristicClinicalTrialParticipant.js +16 -7
  46. data/app/assets/javascripts/PatientCharacteristicEthnicity.js +16 -7
  47. data/app/assets/javascripts/PatientCharacteristicExpired.js +16 -7
  48. data/app/assets/javascripts/PatientCharacteristicPayer.js +16 -7
  49. data/app/assets/javascripts/PatientCharacteristicRace.js +16 -7
  50. data/app/assets/javascripts/PatientCharacteristicSex.js +16 -7
  51. data/app/assets/javascripts/PhysicalExamOrder.js +16 -7
  52. data/app/assets/javascripts/PhysicalExamPerformed.js +16 -7
  53. data/app/assets/javascripts/PhysicalExamRecommended.js +16 -7
  54. data/app/assets/javascripts/ProcedureOrder.js +16 -7
  55. data/app/assets/javascripts/ProcedurePerformed.js +16 -7
  56. data/app/assets/javascripts/ProcedureRecommended.js +16 -7
  57. data/app/assets/javascripts/ProviderCareExperience.js +16 -7
  58. data/app/assets/javascripts/ProviderCharacteristic.js +16 -7
  59. data/app/assets/javascripts/QDMPatient.js +262 -0
  60. data/app/assets/javascripts/Result.js +7 -2
  61. data/app/assets/javascripts/ResultComponent.js +14 -6
  62. data/app/assets/javascripts/SubstanceAdministered.js +16 -7
  63. data/app/assets/javascripts/SubstanceOrder.js +16 -7
  64. data/app/assets/javascripts/SubstanceRecommended.js +16 -7
  65. data/app/assets/javascripts/Symptom.js +16 -7
  66. data/app/assets/javascripts/attributes/Component.js +30 -0
  67. data/app/assets/javascripts/attributes/FacilityLocation.js +30 -0
  68. data/app/assets/javascripts/basetypes/Any.js +1 -1
  69. data/app/assets/javascripts/basetypes/Code.js +1 -1
  70. data/app/assets/javascripts/basetypes/DataElement.js +2 -1
  71. data/app/assets/javascripts/basetypes/DateTime.js +5 -1
  72. data/app/assets/javascripts/basetypes/Interval.js +1 -1
  73. data/app/assets/javascripts/basetypes/Quantity.js +1 -1
  74. data/app/assets/javascripts/basetypes/Ratio.js +1 -1
  75. data/app/assets/javascripts/browser.js +3 -0
  76. data/app/assets/javascripts/cqm/AllCQMModels.js +24 -0
  77. data/app/assets/javascripts/cqm/CQLLibrary.js +32 -0
  78. data/app/assets/javascripts/cqm/CQLStatementDependency.js +28 -0
  79. data/app/assets/javascripts/cqm/Concept.js +17 -0
  80. data/app/assets/javascripts/cqm/Measure.js +108 -0
  81. data/app/assets/javascripts/{MeasurePackage.js → cqm/MeasurePackage.js} +9 -3
  82. data/app/assets/javascripts/cqm/Patient.js +38 -0
  83. data/app/assets/javascripts/cqm/PopulationSet.js +88 -0
  84. data/app/assets/javascripts/cqm/Provider.js +44 -0
  85. data/app/assets/javascripts/cqm/ValueSet.js +26 -0
  86. data/app/assets/javascripts/index.js +18 -8
  87. data/app/models/{qdm/tacoma → cqm}/concept.rb +4 -4
  88. data/app/models/cqm/cql_library.rb +22 -0
  89. data/app/models/cqm/cql_statement_dependency.rb +24 -0
  90. data/app/models/cqm/measure.rb +105 -0
  91. data/app/models/{qdm/tacoma → cqm}/measure_package.rb +2 -2
  92. data/app/models/cqm/patient.rb +20 -0
  93. data/app/models/cqm/population_set.rb +86 -0
  94. data/app/models/cqm/provider.rb +110 -0
  95. data/app/models/cqm/valueset.rb +15 -0
  96. data/app/models/hqmfOid_to_datatype_map.json +55 -0
  97. data/app/models/model_finder.rb +12 -0
  98. data/app/models/models.rb +18 -6
  99. data/app/models/qdm/adverse_event.rb +3 -2
  100. data/app/models/qdm/allergy_intolerance.rb +2 -1
  101. data/app/models/qdm/assessment_order.rb +1 -0
  102. data/app/models/qdm/assessment_performed.rb +2 -1
  103. data/app/models/qdm/assessment_recommended.rb +2 -1
  104. data/app/models/qdm/attributes/attribute.rb +63 -0
  105. data/app/models/qdm/{component.rb → attributes/component.rb} +1 -1
  106. data/app/models/qdm/{facility_location.rb → attributes/facility_location.rb} +1 -1
  107. data/app/models/qdm/basetypes/data_element.rb +21 -6
  108. data/app/models/qdm/basetypes/interval.rb +2 -1
  109. data/app/models/qdm/care_goal.rb +2 -1
  110. data/app/models/qdm/communication_performed.rb +1 -0
  111. data/app/models/qdm/device_applied.rb +2 -1
  112. data/app/models/qdm/device_order.rb +2 -1
  113. data/app/models/qdm/device_recommended.rb +2 -1
  114. data/app/models/qdm/diagnosis.rb +2 -1
  115. data/app/models/qdm/diagnostic_study_order.rb +2 -1
  116. data/app/models/qdm/diagnostic_study_performed.rb +3 -2
  117. data/app/models/qdm/diagnostic_study_recommended.rb +2 -1
  118. data/app/models/qdm/encounter_order.rb +3 -2
  119. data/app/models/qdm/encounter_performed.rb +2 -1
  120. data/app/models/qdm/encounter_recommended.rb +3 -2
  121. data/app/models/qdm/family_history.rb +2 -1
  122. data/app/models/qdm/immunization_administered.rb +2 -1
  123. data/app/models/qdm/immunization_order.rb +2 -1
  124. data/app/models/qdm/intervention_order.rb +2 -1
  125. data/app/models/qdm/intervention_performed.rb +2 -1
  126. data/app/models/qdm/intervention_recommended.rb +2 -1
  127. data/app/models/qdm/laboratory_test_order.rb +2 -1
  128. data/app/models/qdm/laboratory_test_performed.rb +2 -1
  129. data/app/models/qdm/laboratory_test_recommended.rb +2 -1
  130. data/app/models/qdm/medication_active.rb +2 -1
  131. data/app/models/qdm/medication_administered.rb +2 -1
  132. data/app/models/qdm/medication_discharge.rb +2 -1
  133. data/app/models/qdm/medication_dispensed.rb +4 -3
  134. data/app/models/qdm/medication_order.rb +3 -2
  135. data/app/models/qdm/participation.rb +1 -0
  136. data/app/models/qdm/patient.rb +7 -4
  137. data/app/models/qdm/patient_care_experience.rb +2 -1
  138. data/app/models/qdm/patient_characteristic.rb +2 -1
  139. data/app/models/qdm/patient_characteristic_birthdate.rb +2 -1
  140. data/app/models/qdm/patient_characteristic_clinical_trial_participant.rb +2 -1
  141. data/app/models/qdm/patient_characteristic_ethnicity.rb +2 -1
  142. data/app/models/qdm/patient_characteristic_expired.rb +2 -1
  143. data/app/models/qdm/patient_characteristic_payer.rb +2 -1
  144. data/app/models/qdm/patient_characteristic_race.rb +2 -1
  145. data/app/models/qdm/patient_characteristic_sex.rb +2 -1
  146. data/app/models/qdm/physical_exam_order.rb +2 -1
  147. data/app/models/qdm/physical_exam_performed.rb +2 -1
  148. data/app/models/qdm/physical_exam_recommended.rb +2 -1
  149. data/app/models/qdm/procedure_order.rb +2 -1
  150. data/app/models/qdm/procedure_performed.rb +2 -1
  151. data/app/models/qdm/procedure_recommended.rb +2 -1
  152. data/app/models/qdm/provider_care_experience.rb +2 -1
  153. data/app/models/qdm/provider_characteristic.rb +2 -1
  154. data/app/models/qdm/substance_administered.rb +2 -1
  155. data/app/models/qdm/substance_order.rb +2 -1
  156. data/app/models/qdm/substance_recommended.rb +2 -1
  157. data/app/models/qdm/symptom.rb +2 -1
  158. data/bin/build_cql_execution.sh +8 -0
  159. data/bin/validate_browser.sh +17 -0
  160. data/bin/validate_generator.sh +12 -0
  161. data/cqm-models.gemspec +5 -2
  162. data/data/oids_qdm_5.4.json +321 -0
  163. data/data/{oids.json → oids_unversioned.json} +0 -0
  164. data/dist/browser.js +102937 -0
  165. data/dist/index.js +36637 -36540
  166. data/lib/generate_models.rb +89 -93
  167. data/lib/generate_patients.rb +125 -0
  168. data/lib/generate_types.rb +64 -0
  169. data/lib/generators/custom_mongo/model.rb.tt +20 -0
  170. data/lib/generators/custom_mongo/model_generator.rb +34 -0
  171. data/notice.md +9 -0
  172. data/package.json +12 -6
  173. data/templates/id_template.js.erb +8 -3
  174. data/templates/index_template.js.erb +18 -8
  175. data/templates/models_template.rb.erb +20 -4
  176. data/templates/mongoose_template.js.erb +23 -15
  177. data/templates/patient_extension.rb.erb +7 -4
  178. data/templates/patient_template.js.erb +88 -87
  179. data/yarn.lock +552 -347
  180. metadata +86 -19
  181. data/app/assets/javascripts/Component.js +0 -26
  182. data/app/assets/javascripts/Concept.js +0 -14
  183. data/app/assets/javascripts/FacilityLocation.js +0 -26
  184. data/app/assets/javascripts/Measure.js +0 -78
  185. data/app/assets/javascripts/Patient.js +0 -262
  186. data/app/assets/javascripts/ValueSet.js +0 -30
  187. data/app/models/qdm/tacoma/measure.rb +0 -174
  188. data/app/models/qdm/tacoma/valueset.rb +0 -68
@@ -0,0 +1,20 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %><%= " < #{options[:parent].classify}" if options[:parent] %>
3
+ <% unless options[:parent] -%>
4
+ include Mongoid::Document
5
+ <% end -%>
6
+ <% if options[:timestamps] -%>
7
+ include Mongoid::Timestamps
8
+ <% end -%>
9
+ <% if options[:collection] -%>
10
+ store_in collection: "<%= options[:collection] %>"
11
+ <% end -%>
12
+ <% attributes.reject{|attr| attr.reference?}.each do |attribute| -%>
13
+ field :<%= attribute.name %>, type: <%= attribute.type_class %><% if attribute.default -%>, default: '<%= attribute.default %>'<% end -%>
14
+
15
+ <% end -%>
16
+ <% attributes.select{|attr| attr.reference? }.each do |attribute| -%>
17
+ embedded_in :<%= attribute.name%>
18
+ <% end -%>
19
+ end
20
+ <% end -%>
@@ -0,0 +1,34 @@
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/active_model'
3
+ require File.join(Gem::Specification.find_by_name('mongoid').gem_dir, 'lib/rails/generators/mongoid/model/model_generator.rb')
4
+
5
+ module Rails
6
+ module Generators
7
+ # Extend this class to add the "default" field used in the generator.
8
+ class GeneratedAttribute
9
+ attr_accessor :default
10
+ end
11
+ end
12
+ end
13
+
14
+ module CustomMongo
15
+ module Generators
16
+ # Extend this class to add the "default" field.
17
+ class ModelGenerator < ::Mongoid::Generators::ModelGenerator
18
+ def initialize(args, *options)
19
+ custom_attributes = args[1]
20
+ args = [args[0]] # "super" expects the name as arg[0], then we custom parse the attributes
21
+ super
22
+ self.attributes = custom_attributes.map do |attribute|
23
+ att = Rails::Generators::GeneratedAttribute.new(attribute[:name], attribute[:type].to_sym)
24
+ att.default = attribute[:default]
25
+ att
26
+ end
27
+ end
28
+
29
+ def create_model_file
30
+ template File.join(File.dirname(__FILE__), 'model.rb.tt'), File.join('app/models', class_path, "#{file_name}.rb")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ NOTICE
2
+ ======
3
+ This (software/technical data) was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
4
+
5
+ No other use other than that granted to the U. S. Government, or to those acting on behalf of the U. S. Government under that Clause is authorized without the express written permission of The MITRE Corporation.
6
+
7
+ To the extent necessary MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the Apache 2.0 license.
8
+
9
+ For further information, please contact The MITRE Corporation, Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539, (703) 983-6000.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cqm-models",
3
- "version": "1.0.2",
3
+ "version": "1.1.1.0",
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": {
@@ -11,24 +11,30 @@
11
11
  "contributors": [
12
12
  "Louis Ades <lades@mitre.org>",
13
13
  "Michael O'Keefe <mokeefe@mitre.org>",
14
- "Adam Holmes <aholmes@mitre.org>"
14
+ "Adam Holmes <aholmes@mitre.org>",
15
+ "Chris Hossenlopp <hossenlopp@mitre.org>"
15
16
  ],
16
17
  "license": "Apache-2.0",
17
18
  "dependencies": {
18
- "cql-execution": "1.3.3",
19
- "mongoose": "^5.0.7"
19
+ "cql-execution": "https://github.com/cqframework/cql-execution.git",
20
+ "mongoose": "^5.4.14"
20
21
  },
21
22
  "devDependencies": {
22
23
  "browserify": "^16.1.0",
23
24
  "eslint": "^4.17.0",
24
25
  "eslint-config-airbnb-base": "^12.1.0",
25
26
  "eslint-plugin-import": "^2.8.0",
27
+ "istanbul": "^0.4.5",
26
28
  "jasmine": "^2.9.0"
27
29
  },
28
30
  "scripts": {
29
- "test": "jasmine",
31
+ "prepublish": "./bin/build_cql_execution.sh",
32
+ "test": "istanbul cover jasmine -x 'spec/**/*'",
30
33
  "lint": "eslint 'app/assets/javascripts/**/*.js'",
31
34
  "dist": "yarn && browserify app/assets/javascripts/index.js > dist/index.js",
32
- "dist_test": "browserify app/assets/javascripts/index.js > tmp/dist/index.js"
35
+ "browser": "browserify app/assets/javascripts/browser.js > dist/browser.js",
36
+ "browser_test": "browserify app/assets/javascripts/browser.js > tmp/dist/browser.js",
37
+ "dist_test": "browserify app/assets/javascripts/index.js > tmp/dist/index.js",
38
+ "build-cql": "cd ./node_modules/cql-execution && yarn install && cd ../../"
33
39
  }
34
40
  }
@@ -1,4 +1,4 @@
1
- const mongoose = require('mongoose');
1
+ const mongoose = require('mongoose/browser');
2
2
 
3
3
  const [Number, String] = [
4
4
  mongoose.Schema.Types.Number,
@@ -7,9 +7,14 @@ const [Number, String] = [
7
7
 
8
8
  const IdSchema = mongoose.Schema({
9
9
  <%- for attribute in attrs_with_extras -%>
10
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
10
+ <% if attribute[:default] %><%= attribute[:name] %>: { type: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>, default: '<%= attribute[:default] %>' },<% else %><%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,<%- end %>
11
11
  <%- end %>
12
12
  }, { _id: false, id: false });
13
13
 
14
14
  module.exports.IdSchema = IdSchema;
15
- module.exports.Id = mongoose.model('Id', IdSchema);
15
+ class Id extends mongoose.Document {
16
+ constructor(object) {
17
+ super(object, IdSchema);
18
+ }
19
+ }
20
+ module.exports.Id = Id;
@@ -2,13 +2,23 @@ module.exports = require('./AllDataElements.js');
2
2
  module.exports.CQL = require('cql-execution');
3
3
  module.exports.Result = require('./Result.js').Result;
4
4
  module.exports.ResultSchema = require('./Result.js').ResultSchema;
5
- module.exports.Measure = require('./Measure.js').Measure;
6
- module.exports.MeasureSchema = require('./Measure.js').MeasureSchema;
7
- module.exports.MeasurePackage = require('./MeasurePackage.js').MeasurePackage;
8
- module.exports.MeasurePackageSchema = require('./MeasurePackage.js').MeasurePackageSchema;
9
- module.exports.ValueSet = require('./ValueSet.js').ValueSet;
10
- module.exports.ValueSetSchema = require('./ValueSet.js').ValueSetSchema;
11
- module.exports.Concept = require('./Concept.js').Concept;
12
- module.exports.ConceptSchema = require('./Concept.js').ConceptSchema;
5
+ module.exports.Measure = require('./cqm/Measure.js').Measure;
6
+ module.exports.MeasureSchema = require('./cqm/Measure.js').MeasureSchema;
7
+ module.exports.MeasurePackage = require('./cqm/MeasurePackage.js').MeasurePackage;
8
+ module.exports.MeasurePackageSchema = require('./cqm/MeasurePackage.js').MeasurePackageSchema;
9
+ module.exports.Patient = require('./cqm/Patient.js').Patient;
10
+ module.exports.PatientSchema = require('./cqm/Patient.js').PatientSchema;
11
+ module.exports.Provider = require('./cqm/Provider.js').Provider;
12
+ module.exports.ProviderSchema = require('./cqm/Provider.js').ProviderSchema;
13
+ module.exports.StatementDependency = require('./cqm/CQLStatementDependency.js').StatementDependency;
14
+ module.exports.StatementDependencySchema = require('./cqm/CQLStatementDependency.js').StatementDependencySchema;
15
+ module.exports.PopulationSet = require('./cqm/PopulationSet.js').PopulationSet;
16
+ module.exports.PopulationSetSchema = require('./cqm/PopulationSet.js').PopulationSetSchema;
17
+ module.exports.CQLLibrary = require('./cqm/CQLLibrary.js').CQLLibrary;
18
+ module.exports.CQLLibrarySchema = require('./cqm/CQLLibrary.js').CQLLibrarySchema;
19
+ module.exports.ValueSet = require('./cqm/ValueSet.js').ValueSet;
20
+ module.exports.ValueSetSchema = require('./cqm/ValueSet.js').ValueSetSchema;
21
+ module.exports.Concept = require('./cqm/Concept.js').Concept;
22
+ module.exports.ConceptSchema = require('./cqm/Concept.js').ConceptSchema;
13
23
  module.exports.IndividualResult = require('./IndividualResult').IndividualResult;
14
24
  module.exports.IndividualResultSchema = require('./IndividualResult').IndividualResultSchema;
@@ -3,6 +3,9 @@ module QDM
3
3
  end
4
4
  require 'mongoid'
5
5
 
6
+ # ModelFinder
7
+ require_relative 'model_finder'
8
+
6
9
  # Generated models that are dependencies for base types
7
10
  require_relative 'qdm/id'
8
11
 
@@ -12,16 +15,29 @@ require_relative 'qdm/basetypes/data_element'
12
15
  require_relative 'qdm/basetypes/interval'
13
16
  require_relative 'qdm/basetypes/quantity'
14
17
  require_relative 'qdm/basetypes/ratio'
18
+ require_relative 'qdm/attributes/attribute'
19
+ require_relative 'qdm/attributes/facility_location'
20
+ require_relative 'qdm/attributes/component'
15
21
 
16
22
  # Tacoma-specific models
17
- require_relative 'qdm/tacoma/measure'
18
- require_relative 'qdm/tacoma/measure_package'
19
- require_relative 'qdm/tacoma/valueset'
20
- require_relative 'qdm/tacoma/concept'
23
+ require_relative 'cqm/measure'
24
+ require_relative 'cqm/measure_package'
25
+ require_relative 'cqm/valueset'
26
+ require_relative 'cqm/concept'
27
+ require_relative 'cqm/cql_statement_dependency'
28
+ require_relative 'cqm/cql_library'
29
+ require_relative 'cqm/population_set'
30
+ require_relative 'cqm/patient'
31
+ require_relative 'cqm/provider'
21
32
  require_relative 'qdm/tacoma/individual_result'
22
33
 
34
+ # Make Patient Generation Available
35
+ require_relative '../../lib/generate_patients'
36
+
23
37
  # Generated models
24
38
  <%- datatypes.each_key do |datatype| -%>
25
39
  <%- next if datatype.underscore == 'id' -%>
40
+ <%- next if datatype.underscore == 'facility_location' -%>
41
+ <%- next if datatype.underscore == 'component' -%>
26
42
  require_relative 'qdm/<%= datatype.underscore %>'
27
43
  <%- end -%>
@@ -1,30 +1,38 @@
1
- const mongoose = require('mongoose');
1
+ const mongoose = require('mongoose/browser');
2
+ <% unless datatype.downcase == 'component' || datatype.downcase == 'facilitylocation' %>
3
+ <% unless datatype.downcase == 'id' %>const { IdSchema } = require('./Id');<% end %>
2
4
  const { DataElementSchema } = require('./basetypes/DataElement');
3
5
  const Code = require('./basetypes/Code');
4
6
  const Interval = require('./basetypes/Interval');
5
7
  const Quantity = require('./basetypes/Quantity');
6
8
  const DateTime = require('./basetypes/DateTime');
7
- <% unless datatype.downcase.include? 'component' %>const { ComponentSchema } = require('./Component');<% end %>
8
- <% unless datatype.downcase.include? 'facilitylocation' %>const { FacilityLocationSchema } = require('./FacilityLocation');<% end %>
9
- <% unless datatype.downcase == 'id' %>const { IdSchema } = require('./Id');<% end %>
10
9
  const Any = require('./basetypes/Any');
10
+ const { ComponentSchema } = require('./attributes/Component');
11
+ const { FacilityLocationSchema } = require('./attributes/FacilityLocation');
12
+ <% else %>
13
+ const Code = require('../basetypes/Code');
14
+ const Interval = require('../basetypes/Interval');
15
+ const Quantity = require('../basetypes/Quantity');
16
+ const DateTime = require('../basetypes/DateTime');
17
+ const Any = require('../basetypes/Any');
18
+ <% end %>
11
19
 
12
20
  const [Number, String] = [
13
21
  mongoose.Schema.Types.Number,
14
22
  mongoose.Schema.Types.String,
15
23
  ];
16
- <% unless datatype == 'Component' || datatype == 'FacilityLocation' %>
17
- const <%= datatype -%>Schema = DataElementSchema({
18
- <%- for attribute in attrs_with_extras -%>
19
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
20
- <%- end %>
21
- });
22
- <% else %>
23
- const <%= datatype -%>Schema = new mongoose.Schema({
24
+
25
+ const <%= datatype -%>Schema = <% unless datatype == 'Component' || datatype == 'FacilityLocation' %>DataElementSchema<% else %>new mongoose.Schema<%- end %>({
24
26
  <%- for attribute in attrs_with_extras -%>
25
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
27
+ <% if attribute[:default] %><%= attribute[:name] %>: { type: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>, default: '<%= attribute[:default] %>' },<% else %><%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,<%- end %>
26
28
  <%- end %>
27
29
  });
28
- <% end %>
30
+
29
31
  module.exports.<%= datatype %>Schema = <%= datatype %>Schema;
30
- module.exports.<%= datatype %> = mongoose.model('<%= datatype %>', <%= datatype %>Schema);
32
+ class <%= datatype %> extends mongoose.Document {
33
+ constructor(object) {
34
+ super(object, <%= datatype %>Schema);
35
+ this._type = 'QDM::<%= datatype %>';
36
+ }
37
+ }
38
+ module.exports.<%= datatype %> = <%= datatype %>;
@@ -1,6 +1,4 @@
1
- field :givenNames, type: Array
2
- field :familyName, type: String
3
- field :bundleId, type: String
1
+ embedded_in :tacomaPatient, class_name: 'CQM::Patient'
4
2
 
5
3
  # These are the "data criteria", or QDM datatype elements that exist on a
6
4
  # patient.
@@ -133,6 +131,11 @@
133
131
  get_data_elements('medication')
134
132
  end
135
133
 
134
+ # Helper method; returns patient_characteristic data element types on this patient.
135
+ def patient_characteristics
136
+ get_data_elements('patient_characteristic')
137
+ end
138
+
136
139
  # Helper method; returns physical_exam data element types on this patient.
137
140
  def physical_exams
138
141
  get_data_elements('physical_exam')
@@ -200,6 +203,6 @@
200
203
 
201
204
  # Include '_type' in any JSON output. This is necessary for deserialization.
202
205
  def to_json(options = nil)
203
- serializable_hash(methods: :_type).to_json(options)
206
+ serializable_hash(methods: :_type, include: :_type).to_json(options)
204
207
  end
205
208
  end
@@ -1,4 +1,4 @@
1
- const mongoose = require('mongoose');
1
+ const mongoose = require('mongoose/browser');
2
2
  const Code = require('./basetypes/Code');
3
3
  const Interval = require('./basetypes/Interval');
4
4
  const Quantity = require('./basetypes/Quantity');
@@ -12,13 +12,10 @@ const [Schema, Number, String, Mixed] = [
12
12
  mongoose.Schema.Types.Mixed,
13
13
  ];
14
14
 
15
- const PatientSchema = new Schema({
15
+ const QDMPatientSchema = new Schema({
16
16
  <%- for attribute in attrs_with_extras -%>
17
- <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
17
+ <% if attribute[:default] %><%= attribute[:name] %>: { type: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>, default: '<%= attribute[:default] %>' },<% else %><%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,<%- end %>
18
18
  <%- end %>
19
- givenNames: [String],
20
- familyName: String,
21
- bundleId: String,
22
19
  // These are the "data criteria", or QDM datatype elements that exist on a
23
20
  // patient.
24
21
  dataElements: [],
@@ -33,46 +30,40 @@ const PatientSchema = new Schema({
33
30
 
34
31
  // After initialization of a Patient model, initialize every individual data element
35
32
  // to its respective Mongoose Model
36
- PatientSchema.methods.initializeDataElements = function initializeDataElements() {
33
+ QDMPatientSchema.methods.initializeDataElements = function initializeDataElements() {
37
34
  let typeStripped;
38
35
  const dataElementsInit = [];
39
36
  this.dataElements.forEach((element) => {
40
37
  typeStripped = element._type.replace(/QDM::/, '');
41
- if (typeStripped in AllDataElements) {
42
- dataElementsInit.push(AllDataElements[typeStripped](element));
43
- } else {
44
- dataElementsInit.push(element);
45
- }
38
+ dataElementsInit.push(new AllDataElements[typeStripped](element));
46
39
  });
47
40
  this.set({ dataElements: dataElementsInit });
48
41
  };
49
42
 
50
- PatientSchema.queue('initializeDataElements');
51
-
52
- PatientSchema.methods.id = function id() {
43
+ QDMPatientSchema.methods.id = function id() {
53
44
  return this._id;
54
45
  };
55
46
 
56
47
  // Returns an array of elements that exist on this patient, that
57
48
  // match the given HQMF data criteria OID.
58
- PatientSchema.methods.getByHqmfOid = function getByHqmfOid(hqmfOid) {
49
+ QDMPatientSchema.methods.getByHqmfOid = function getByHqmfOid(hqmfOid) {
59
50
  return this.dataElements.filter(element => element.hqmfOid === hqmfOid);
60
51
  };
61
52
 
62
53
  // Returns an array of elements that exist on this patient, that
63
54
  // match the given QRDA data criteria OID.
64
- PatientSchema.methods.getByQrdaOid = function getByQrdaOid(qrdaOid) {
55
+ QDMPatientSchema.methods.getByQrdaOid = function getByQrdaOid(qrdaOid) {
65
56
  return this.dataElements.filter(element => element.qrdaOid === qrdaOid);
66
57
  };
67
58
 
68
59
  // Returns an array of elements that exist on this patient. Optionally
69
- // takes a category, which returns all elements of that QDM category.
70
- // Example: patient.getDataElements(category = 'encounters') will return
60
+ // takes a qdmCategory, which returns all elements of that QDM qdmCategory.
61
+ // Example: patient.getDataElements({qdmCategory: 'encounters'}) will return
71
62
  // all Encounter QDM data types active on the patient.
72
- PatientSchema.methods.getDataElements = function getDataElements(params) {
73
- if (params.qdmCategory && params.qdmStatus) {
63
+ QDMPatientSchema.methods.getDataElements = function getDataElements(params) {
64
+ if (params !== undefined && params.qdmCategory !== undefined && params.qdmStatus !== undefined) {
74
65
  return this.dataElements.filter(element => (element.qdmCategory === params.qdmCategory) && (element.qdmStatus === params.qdmStatus));
75
- } else if (params.category) {
66
+ } else if (params !== undefined && params.qdmCategory !== undefined) {
76
67
  return this.dataElements.filter(element => element.qdmCategory === params.qdmCategory);
77
68
  }
78
69
  return this.dataElements;
@@ -83,15 +74,15 @@ PatientSchema.methods.getDataElements = function getDataElements(params) {
83
74
  // @param {string} profile - the data criteria requested by the execution engine
84
75
  // @param {boolean} isNegated - whether dataElements should be returned based on their negation status
85
76
  // @returns {DataElement[]}
86
- PatientSchema.methods.getByProfile = function getByProfile(profile, isNegated = null) {
77
+ QDMPatientSchema.methods.getByProfile = function getByProfile(profile, isNegated = null) {
87
78
  // If isNegated == true, only return data elements with a negationRationale that is not null.
88
79
  // If isNegated == false, only return data elements with a null negationRationale.
89
80
  // If isNegated == null, return all matching data elements by type, regardless of negationRationale.
90
- const results = this.dataElements.filter(element => element._type === `QDM::${profile}` && (isNegated === null || !!element.negationRationale === isNegated));
81
+ const results = this.dataElements.filter(element => (element._type === `QDM::${profile}` || element._type === profile) && (isNegated === null || !!element.negationRationale === isNegated));
91
82
  return results.map((result) => {
92
- const removedMongooseItems = AllDataElements[profile](result).toObject();
83
+ const removedMongooseItems = new AllDataElements[profile](result).toObject({ virtuals: true });
93
84
  // toObject() will remove all mongoose functions but also remove the schema methods, so we add them back
94
- Object.entries(Object.getPrototypeOf(result).schema.methods).forEach(([method_name, method]) => {
85
+ Object.entries(result.schema.methods).forEach(([method_name, method]) => {
95
86
  removedMongooseItems[method_name] = method;
96
87
  });
97
88
  return removedMongooseItems;
@@ -105,7 +96,7 @@ PatientSchema.methods.getByProfile = function getByProfile(profile, isNegated =
105
96
  // in Bonnie patient builder).
106
97
  // @param {String} profile - the data criteria requested by the execution engine
107
98
  // @returns {Object}
108
- PatientSchema.methods.findRecords = function findRecords(profile) {
99
+ QDMPatientSchema.methods.findRecords = function findRecords(profile) {
109
100
  let profileStripped;
110
101
  if (profile === 'Patient') {
111
102
  // Requested generic patient info
@@ -141,121 +132,131 @@ PatientSchema.methods.findRecords = function findRecords(profile) {
141
132
  return [];
142
133
  };
143
134
 
144
- PatientSchema.methods.adverse_events = function adverse_events() {
145
- return this.getDataElements({ category: 'adverse_event' });
135
+ QDMPatientSchema.methods.adverse_events = function adverse_events() {
136
+ return this.getDataElements({ qdmCategory: 'adverse_event' });
146
137
  };
147
138
 
148
- PatientSchema.methods.allergies = function allergies() {
149
- return this.getDataElements({ category: 'allergy' });
139
+ QDMPatientSchema.methods.allergies = function allergies() {
140
+ return this.getDataElements({ qdmCategory: 'allergy' });
150
141
  };
151
142
 
152
- PatientSchema.methods.assessments = function assessments() {
153
- return this.getDataElements({ category: 'assessment' });
143
+ QDMPatientSchema.methods.assessments = function assessments() {
144
+ return this.getDataElements({ qdmCategory: 'assessment' });
154
145
  };
155
146
 
156
- PatientSchema.methods.care_experiences = function care_experiences() {
157
- return this.getDataElements({ category: 'care_experience' });
147
+ QDMPatientSchema.methods.care_experiences = function care_experiences() {
148
+ return this.getDataElements({ qdmCategory: 'care_experience' });
158
149
  };
159
150
 
160
- PatientSchema.methods.care_goals = function care_goals() {
161
- return this.getDataElements({ category: 'care_goal' });
151
+ QDMPatientSchema.methods.care_goals = function care_goals() {
152
+ return this.getDataElements({ qdmCategory: 'care_goal' });
162
153
  };
163
154
 
164
- PatientSchema.methods.communications = function communications() {
165
- return this.getDataElements({ category: 'communication' });
155
+ QDMPatientSchema.methods.communications = function communications() {
156
+ return this.getDataElements({ qdmCategory: 'communication' });
166
157
  };
167
158
 
168
- PatientSchema.methods.conditions = function conditions() {
169
- return this.getDataElements({ category: 'condition' });
159
+ QDMPatientSchema.methods.conditions = function conditions() {
160
+ return this.getDataElements({ qdmCategory: 'condition' });
170
161
  };
171
162
 
172
- PatientSchema.methods.devices = function devices() {
173
- return this.getDataElements({ category: 'device' });
163
+ QDMPatientSchema.methods.devices = function devices() {
164
+ return this.getDataElements({ qdmCategory: 'device' });
174
165
  };
175
166
 
176
- PatientSchema.methods.diagnostic_studies = function diagnostic_studies() {
177
- return this.getDataElements({ category: 'diagnostic_study' });
167
+ QDMPatientSchema.methods.diagnostic_studies = function diagnostic_studies() {
168
+ return this.getDataElements({ qdmCategory: 'diagnostic_study' });
178
169
  };
179
170
 
180
- PatientSchema.methods.encounters = function encounters() {
181
- return this.getDataElements({ category: 'encounter' });
171
+ QDMPatientSchema.methods.encounters = function encounters() {
172
+ return this.getDataElements({ qdmCategory: 'encounter' });
182
173
  };
183
174
 
184
- PatientSchema.methods.family_history = function family_history() {
185
- return this.getDataElements({ category: 'family_history' });
175
+ QDMPatientSchema.methods.family_history = function family_history() {
176
+ return this.getDataElements({ qdmCategory: 'family_history' });
186
177
  };
187
178
 
188
- PatientSchema.methods.functional_statuses = function functional_statuses() {
189
- return this.getDataElements({ category: 'functional_status' });
179
+ QDMPatientSchema.methods.functional_statuses = function functional_statuses() {
180
+ return this.getDataElements({ qdmCategory: 'functional_status' });
190
181
  };
191
182
 
192
- PatientSchema.methods.immunizations = function immunizations() {
193
- return this.getDataElements({ category: 'immunization' });
183
+ QDMPatientSchema.methods.immunizations = function immunizations() {
184
+ return this.getDataElements({ qdmCategory: 'immunization' });
194
185
  };
195
186
 
196
- PatientSchema.methods.interventions = function interventions() {
197
- return this.getDataElements({ category: 'intervention' });
187
+ QDMPatientSchema.methods.interventions = function interventions() {
188
+ return this.getDataElements({ qdmCategory: 'intervention' });
198
189
  };
199
190
 
200
- PatientSchema.methods.laboratory_tests = function laboratory_tests() {
201
- return this.getDataElements({ category: 'laboratory_test' });
191
+ QDMPatientSchema.methods.laboratory_tests = function laboratory_tests() {
192
+ return this.getDataElements({ qdmCategory: 'laboratory_test' });
202
193
  };
203
194
 
204
- PatientSchema.methods.medical_equipment = function medical_equipment() {
205
- return this.getDataElements({ category: 'medical_equipment' });
195
+ QDMPatientSchema.methods.medical_equipment = function medical_equipment() {
196
+ return this.getDataElements({ qdmCategory: 'medical_equipment' });
206
197
  };
207
198
 
208
- PatientSchema.methods.medications = function medications() {
209
- return this.getDataElements({ category: 'medication' });
199
+ QDMPatientSchema.methods.medications = function medications() {
200
+ return this.getDataElements({ qdmCategory: 'medication' });
210
201
  };
211
202
 
212
- PatientSchema.methods.physical_exams = function physical_exams() {
213
- return this.getDataElements({ category: 'physical_exam' });
203
+ QDMPatientSchema.methods.patient_characteristics = function patient_characteristics() {
204
+ return this.getDataElements({ qdmCategory: 'patient_characteristic' });
214
205
  };
215
206
 
216
- PatientSchema.methods.preferences = function preferences() {
217
- return this.getDataElements({ category: 'preference' });
207
+ QDMPatientSchema.methods.physical_exams = function physical_exams() {
208
+ return this.getDataElements({ qdmCategory: 'physical_exam' });
218
209
  };
219
210
 
220
- PatientSchema.methods.provider_characteristics = function provider_characteristics() {
221
- return this.getDataElements({ category: 'provider_characteristic' });
211
+ QDMPatientSchema.methods.preferences = function preferences() {
212
+ return this.getDataElements({ qdmCategory: 'preference' });
222
213
  };
223
214
 
224
- PatientSchema.methods.procedures = function procedures() {
225
- return this.getDataElements({ category: 'procedure' });
215
+ QDMPatientSchema.methods.provider_characteristics = function provider_characteristics() {
216
+ return this.getDataElements({ qdmCategory: 'provider_characteristic' });
226
217
  };
227
218
 
228
- PatientSchema.methods.results = function results() {
229
- return this.getDataElements({ category: 'result' });
219
+ QDMPatientSchema.methods.procedures = function procedures() {
220
+ return this.getDataElements({ qdmCategory: 'procedure' });
230
221
  };
231
222
 
232
- PatientSchema.methods.risk_category_assessments = function risk_category_assessments() {
233
- return this.getDataElements({ category: 'risk_category_assessment' });
223
+ QDMPatientSchema.methods.results = function results() {
224
+ return this.getDataElements({ qdmCategory: 'result' });
234
225
  };
235
226
 
236
- PatientSchema.methods.social_history = function social_history() {
237
- return this.getDataElements({ category: 'social_history' });
227
+ QDMPatientSchema.methods.risk_category_assessments = function risk_category_assessments() {
228
+ return this.getDataElements({ qdmCategory: 'risk_category_assessment' });
238
229
  };
239
230
 
240
- PatientSchema.methods.substances = function substances() {
241
- return this.getDataElements({ category: 'substance' });
231
+ QDMPatientSchema.methods.social_history = function social_history() {
232
+ return this.getDataElements({ qdmCategory: 'social_history' });
242
233
  };
243
234
 
244
- PatientSchema.methods.symptoms = function symptoms() {
245
- return this.getDataElements({ category: 'symptom' });
235
+ QDMPatientSchema.methods.substances = function substances() {
236
+ return this.getDataElements({ qdmCategory: 'substance' });
246
237
  };
247
238
 
248
- PatientSchema.methods.system_characteristics = function system_characteristics() {
249
- return this.getDataElements({ category: 'system_characteristic' });
239
+ QDMPatientSchema.methods.symptoms = function symptoms() {
240
+ return this.getDataElements({ qdmCategory: 'symptom' });
250
241
  };
251
242
 
252
- PatientSchema.methods.transfers = function transfers() {
253
- return this.getDataElements({ category: 'transfer' });
243
+ QDMPatientSchema.methods.system_characteristics = function system_characteristics() {
244
+ return this.getDataElements({ qdmCategory: 'system_characteristic' });
254
245
  };
255
246
 
256
- PatientSchema.methods.vital_signs = function vital_signs() {
257
- return this.getDataElements({ category: 'vital_sign' });
247
+ QDMPatientSchema.methods.transfers = function transfers() {
248
+ return this.getDataElements({ qdmCategory: 'transfer' });
258
249
  };
259
250
 
260
- module.exports.PatientSchema = PatientSchema;
261
- module.exports.Patient = mongoose.model('Patient', PatientSchema);
251
+ QDMPatientSchema.methods.vital_signs = function vital_signs() {
252
+ return this.getDataElements({ qdmCategory: 'vital_sign' });
253
+ };
254
+
255
+ module.exports.QDMPatientSchema = QDMPatientSchema;
256
+ class QDMPatient extends mongoose.Document {
257
+ constructor(object) {
258
+ super(object, QDMPatientSchema);
259
+ this.initializeDataElements();
260
+ }
261
+ }
262
+ module.exports.QDMPatient = QDMPatient;