cqm-models 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.json +1 -1
  3. data/app/assets/javascripts/AdverseEvent.js +1 -0
  4. data/app/assets/javascripts/AllergyIntolerance.js +1 -0
  5. data/app/assets/javascripts/AssessmentPerformed.js +2 -1
  6. data/app/assets/javascripts/AssessmentRecommended.js +1 -0
  7. data/app/assets/javascripts/CareGoal.js +2 -1
  8. data/app/assets/javascripts/CommunicationFromPatientToProvider.js +2 -1
  9. data/app/assets/javascripts/CommunicationFromProviderToPatient.js +2 -1
  10. data/app/assets/javascripts/CommunicationFromProviderToProvider.js +2 -1
  11. data/app/assets/javascripts/Component.js +1 -0
  12. data/app/assets/javascripts/DeviceApplied.js +1 -0
  13. data/app/assets/javascripts/DeviceOrder.js +1 -0
  14. data/app/assets/javascripts/DeviceRecommended.js +1 -0
  15. data/app/assets/javascripts/Diagnosis.js +1 -0
  16. data/app/assets/javascripts/DiagnosticStudyOrder.js +1 -0
  17. data/app/assets/javascripts/DiagnosticStudyPerformed.js +1 -0
  18. data/app/assets/javascripts/DiagnosticStudyRecommended.js +1 -0
  19. data/app/assets/javascripts/EncounterOrder.js +1 -0
  20. data/app/assets/javascripts/EncounterPerformed.js +1 -0
  21. data/app/assets/javascripts/EncounterRecommended.js +1 -0
  22. data/app/assets/javascripts/FacilityLocation.js +1 -0
  23. data/app/assets/javascripts/FamilyHistory.js +1 -0
  24. data/app/assets/javascripts/Id.js +2 -10
  25. data/app/assets/javascripts/ImmunizationAdministered.js +1 -0
  26. data/app/assets/javascripts/ImmunizationOrder.js +1 -0
  27. data/app/assets/javascripts/InterventionOrder.js +1 -0
  28. data/app/assets/javascripts/InterventionPerformed.js +1 -0
  29. data/app/assets/javascripts/InterventionRecommended.js +1 -0
  30. data/app/assets/javascripts/LaboratoryTestOrder.js +1 -0
  31. data/app/assets/javascripts/LaboratoryTestPerformed.js +1 -0
  32. data/app/assets/javascripts/LaboratoryTestRecommended.js +1 -0
  33. data/app/assets/javascripts/MedicationActive.js +1 -0
  34. data/app/assets/javascripts/MedicationAdministered.js +1 -0
  35. data/app/assets/javascripts/MedicationDischarge.js +1 -0
  36. data/app/assets/javascripts/MedicationDispensed.js +1 -0
  37. data/app/assets/javascripts/MedicationOrder.js +1 -0
  38. data/app/assets/javascripts/Participation.js +1 -0
  39. data/app/assets/javascripts/Patient.js +4 -8
  40. data/app/assets/javascripts/PatientCareExperience.js +1 -0
  41. data/app/assets/javascripts/PatientCharacteristic.js +1 -0
  42. data/app/assets/javascripts/PatientCharacteristicBirthdate.js +1 -0
  43. data/app/assets/javascripts/PatientCharacteristicClinicalTrialParticipant.js +1 -0
  44. data/app/assets/javascripts/PatientCharacteristicEthnicity.js +1 -0
  45. data/app/assets/javascripts/PatientCharacteristicExpired.js +1 -0
  46. data/app/assets/javascripts/PatientCharacteristicPayer.js +1 -0
  47. data/app/assets/javascripts/PatientCharacteristicRace.js +1 -0
  48. data/app/assets/javascripts/PatientCharacteristicSex.js +1 -0
  49. data/app/assets/javascripts/PhysicalExamOrder.js +1 -0
  50. data/app/assets/javascripts/PhysicalExamPerformed.js +1 -0
  51. data/app/assets/javascripts/PhysicalExamRecommended.js +1 -0
  52. data/app/assets/javascripts/ProcedureOrder.js +1 -0
  53. data/app/assets/javascripts/ProcedurePerformed.js +1 -0
  54. data/app/assets/javascripts/ProcedureRecommended.js +1 -0
  55. data/app/assets/javascripts/ProviderCareExperience.js +1 -0
  56. data/app/assets/javascripts/ProviderCharacteristic.js +1 -0
  57. data/app/assets/javascripts/Ratio.js +1 -0
  58. data/app/assets/javascripts/ResultComponent.js +1 -0
  59. data/app/assets/javascripts/SubstanceAdministered.js +1 -0
  60. data/app/assets/javascripts/SubstanceOrder.js +1 -0
  61. data/app/assets/javascripts/SubstanceRecommended.js +1 -0
  62. data/app/assets/javascripts/Symptom.js +1 -0
  63. data/app/assets/javascripts/basetypes/Any.js +1 -1
  64. data/app/assets/javascripts/basetypes/DataElement.js +7 -0
  65. data/app/models/models.rb +3 -1
  66. data/app/models/qdm/assessment_performed.rb +1 -1
  67. data/app/models/qdm/basetypes/data_element.rb +8 -5
  68. data/app/models/qdm/care_goal.rb +1 -1
  69. data/app/models/qdm/communication_from_patient_to_provider.rb +1 -1
  70. data/app/models/qdm/communication_from_provider_to_patient.rb +1 -1
  71. data/app/models/qdm/communication_from_provider_to_provider.rb +1 -1
  72. data/app/models/qdm/component.rb +0 -1
  73. data/app/models/qdm/facility_location.rb +0 -1
  74. data/app/models/qdm/id.rb +2 -2
  75. data/cqm-models.gemspec +1 -1
  76. data/dist/index.js +137 -84
  77. data/lib/generate_models.rb +27 -19
  78. data/package.json +1 -1
  79. data/templates/id_template.js.erb +15 -0
  80. data/templates/models_template.rb.erb +4 -0
  81. data/templates/mongoose_template.js.erb +1 -0
  82. data/templates/patient_template.js.erb +4 -8
  83. metadata +4 -3
@@ -25,7 +25,6 @@ TYPE_LOOKUP_RB = {
25
25
  'list<QDM.ResultComponent>': 'Array',
26
26
  'list<QDM.FacilityLocation>': 'Array',
27
27
  'list<System.Code>': 'Array',
28
- 'QDM.Id': 'String',
29
28
  'System.Decimal': 'Float',
30
29
  'System.Time': 'Time',
31
30
  'System.Concept': 'Any'
@@ -42,11 +41,10 @@ TYPE_LOOKUP_JS = {
42
41
  'interval<System.Quantity>': 'Interval',
43
42
  'list<QDM.Component>': '[]',
44
43
  'System.String': 'String',
45
- 'list<QDM.Id>': '[String]',
44
+ 'list<QDM.Id>': '[]',
46
45
  'list<QDM.ResultComponent>': '[]',
47
46
  'list<QDM.FacilityLocation>': '[]',
48
47
  'list<System.Code>': '[Code]',
49
- 'QDM.Id': 'String',
50
48
  'System.Decimal': 'Number',
51
49
  'System.Time': 'DateTime',
52
50
  'System.Concept': '{}'
@@ -151,7 +149,7 @@ puts 'Generating JavaScript models...'
151
149
 
152
150
  # Create JavaScript models
153
151
  template = File.read('templates/mongoose_template.js.erb')
154
- renderer = ERB.new(template, nil, '-')
152
+ default_renderer = ERB.new(template, nil, '-')
155
153
  file_path = 'app/assets/javascripts/'
156
154
  file_path = 'tmp/' if IS_TEST
157
155
  extra_fields_js = [
@@ -162,19 +160,19 @@ extra_fields_js = [
162
160
  { name: 'qdmVersion', type: 'System.String' },
163
161
  { name: '_type', type: 'System.String' }
164
162
  ]
163
+ datatype_custom_templates = {
164
+ Patient: 'templates/patient_template.js.erb',
165
+ Id: 'templates/id_template.js.erb'
166
+ }
165
167
  datatypes.each do |datatype, attributes|
166
- if datatype == 'Patient'
167
- # Handle Patient as its own special case, with its own template.
168
- patient_template = File.read('templates/patient_template.js.erb')
169
- patient_renderer = ERB.new(patient_template, nil, '-')
170
- attrs_with_extras = attributes + extra_fields_js
171
- puts ' ' + file_path + datatype + '.js'
172
- File.open(file_path + datatype + '.js', 'w') { |file| file.puts patient_renderer.result(binding) }
173
- else
174
- attrs_with_extras = attributes + extra_fields_js
175
- puts ' ' + file_path + datatype + '.js'
176
- File.open(file_path + datatype + '.js', 'w') { |file| file.puts renderer.result(binding) }
168
+ renderer = default_renderer
169
+ if datatype_custom_templates.key?(datatype.to_sym)
170
+ puts "using custom template for #{datatype}"
171
+ renderer = ERB.new(File.read(datatype_custom_templates[datatype.to_sym]), nil, '-')
177
172
  end
173
+ attrs_with_extras = attributes + extra_fields_js # this field gets used in the template
174
+ puts ' ' + file_path + datatype + '.js'
175
+ File.open(file_path + datatype + '.js', 'w') { |file| file.puts renderer.result(binding) }
178
176
  end
179
177
 
180
178
  # Create require file (if not in test mode)
@@ -240,6 +238,9 @@ Dir.glob(ruby_models_path + '*.rb').each do |file_name|
240
238
  contents.gsub!(/ field :qdmStatus, type: String\n/, '') # Don't include this field
241
239
  end
242
240
 
241
+ # Make relatedTo embeds_many instead of field
242
+ contents.gsub!(/ field :relatedTo, type: Array\n/, " embeds_many :relatedTo, class_name: 'QDM::Id'\n")
243
+
243
244
  File.open(file_name, 'w') { |file| file.puts contents }
244
245
  end
245
246
 
@@ -287,11 +288,12 @@ files = Dir.glob(js_models_path + '*.js').each do |file_name|
287
288
  # Add class
288
289
  contents.gsub!(/ _type: String,\n/, " _type: { type: String, default: '#{dc_name.camelize}' },\n")
289
290
 
290
- # Component and Facility types
291
+ # Component, Facility, and Id types
291
292
  contents.gsub!(/facilityLocations: \[\]/, 'facilityLocations: [FacilityLocationSchema]')
292
293
  contents.gsub!(/facilityLocation: Code/, 'facilityLocation: FacilityLocationSchema')
293
294
  contents.gsub!(/components: \[\]/, 'components: [ComponentSchema]')
294
295
  contents.gsub!(/component: Code/, 'component: ComponentSchema')
296
+ contents.gsub!(/relatedTo: \[\]/, 'relatedTo: [IdSchema]')
295
297
 
296
298
  File.open(file_name, 'w') { |file| file.puts contents }
297
299
  end
@@ -318,8 +320,14 @@ end
318
320
  # Set embedded in for datatypes
319
321
  Dir.glob(ruby_models_path + '*.rb').each do |file_name|
320
322
  contents = File.read(file_name)
321
- next if File.basename(file_name) == 'patient.rb'
322
- contents.gsub!(/ include Mongoid::Document\n/, " include Mongoid::Document\n embedded_in :patient\n")
323
+ # TODO: Might be able to make this list by finding baseType="System.Any" in model info file instead of hard-coding.
324
+ if File.basename(file_name) == 'id.rb'
325
+ contents.gsub!(/ include Mongoid::Document\n/, " include Mongoid::Document\n embedded_in :data_element\n")
326
+ else
327
+ not_embedded_in_patient_files = ['patient.rb', 'component.rb', 'facility_location.rb']
328
+ next if not_embedded_in_patient_files.include?(File.basename(file_name))
329
+ contents.gsub!(/ include Mongoid::Document\n/, " include Mongoid::Document\n embedded_in :patient\n")
330
+ end
323
331
  File.open(file_name, 'w') { |file| file.puts contents }
324
332
  end
325
333
 
@@ -327,7 +335,7 @@ end
327
335
  Dir.glob(ruby_models_path + '*.rb').each do |file_name|
328
336
  contents = ''
329
337
  File.open(file_name).each_line.with_index do |line, index|
330
- line.gsub!("\n", " < DataElement\n") if index.zero? && !file_name.include?('/patient.rb')
338
+ line.gsub!("\n", " < DataElement\n") if index.zero? && !file_name.include?('/patient.rb') && !file_name.include?('/id.rb')
331
339
  contents += "module QDM\n # #{file_name}\n #{line.gsub('QDM::', '')}" if index.zero?
332
340
  contents += ' ' unless index.zero? || line.blank?
333
341
  contents += line unless index.zero?
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cqm-models",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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": {
@@ -0,0 +1,15 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const [Number, String] = [
4
+ mongoose.Schema.Types.Number,
5
+ mongoose.Schema.Types.String,
6
+ ];
7
+
8
+ const IdSchema = mongoose.Schema({
9
+ <%- for attribute in attrs_with_extras -%>
10
+ <%= attribute[:name] %>: <%= TYPE_LOOKUP_JS[attribute[:type]] -%>,
11
+ <%- end %>
12
+ }, { _id: false, id: false });
13
+
14
+ module.exports.IdSchema = IdSchema;
15
+ module.exports.Id = mongoose.model('Id', IdSchema);
@@ -3,6 +3,9 @@ module QDM
3
3
  end
4
4
  require 'mongoid'
5
5
 
6
+ # Generated models that are dependencies for base types
7
+ require_relative 'qdm/id'
8
+
6
9
  # base types
7
10
  require_relative 'qdm/basetypes/code'
8
11
  require_relative 'qdm/basetypes/interval'
@@ -18,5 +21,6 @@ require_relative 'qdm/tacoma/individual_result'
18
21
 
19
22
  # Generated models
20
23
  <%- datatypes.each_key do |datatype| -%>
24
+ <%- next if datatype.underscore == 'id' -%>
21
25
  require_relative 'qdm/<%= datatype.underscore %>'
22
26
  <%- end -%>
@@ -6,6 +6,7 @@ const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
7
  <% unless datatype.downcase.include? 'component' %>const { ComponentSchema } = require('./Component');<% end %>
8
8
  <% unless datatype.downcase.include? 'facilitylocation' %>const { FacilityLocationSchema } = require('./FacilityLocation');<% end %>
9
+ <% unless datatype.downcase == 'id' %>const { IdSchema } = require('./Id');<% end %>
9
10
  const Any = require('./basetypes/Any');
10
11
 
11
12
  const [Number, String] = [
@@ -89,15 +89,11 @@ PatientSchema.methods.getByProfile = function getByProfile(profile, isNegated =
89
89
  // If isNegated == null, return all matching data elements by type, regardless of negationRationale.
90
90
  const results = this.dataElements.filter(element => element._type === `QDM::${profile}` && (isNegated === null || !!element.negationRationale === isNegated));
91
91
  return results.map((result) => {
92
- const getCodeFunction = Object.getPrototypeOf(result).getCode;
93
- const codeFunction = Object.getPrototypeOf(result).code;
94
- const idField = result.id;
95
92
  const removedMongooseItems = AllDataElements[profile](result).toObject();
96
- // toObject() will remove all mongoose functions but also removed the getCode and code functions
97
- // the execution engine requires the code and getCode functions so we have to add them back
98
- removedMongooseItems.getCode = getCodeFunction;
99
- removedMongooseItems.code = codeFunction;
100
- removedMongooseItems.id = idField;
93
+ // 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]) => {
95
+ removedMongooseItems[method_name] = method;
96
+ });
101
97
  return removedMongooseItems;
102
98
  });
103
99
  };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cqm-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - aholmes@mitre.org
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-08-03 00:00:00.000000000 Z
13
+ date: 2018-08-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -289,6 +289,7 @@ files:
289
289
  - modelinfo/qdm-modelinfo-5.3.xml
290
290
  - package.json
291
291
  - templates/all_data_elements_template.js.erb
292
+ - templates/id_template.js.erb
292
293
  - templates/index_template.js.erb
293
294
  - templates/models_template.rb.erb
294
295
  - templates/mongoose_template.js.erb
@@ -316,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
317
  version: '0'
317
318
  requirements: []
318
319
  rubyforge_project:
319
- rubygems_version: 2.6.12
320
+ rubygems_version: 2.6.14
320
321
  signing_key:
321
322
  specification_version: 4
322
323
  summary: Mongo models that correspond to the QDM specification.