cqm-models 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.json +2 -2
  3. data/.github/PULL_REQUEST_TEMPLATE.md +3 -0
  4. data/app/assets/javascripts/AdverseEvent.js +3 -1
  5. data/app/assets/javascripts/AllergyIntolerance.js +2 -0
  6. data/app/assets/javascripts/AssessmentPerformed.js +1 -0
  7. data/app/assets/javascripts/AssessmentRecommended.js +2 -0
  8. data/app/assets/javascripts/CareGoal.js +2 -0
  9. data/app/assets/javascripts/CommunicationFromPatientToProvider.js +2 -0
  10. data/app/assets/javascripts/CommunicationFromProviderToPatient.js +2 -0
  11. data/app/assets/javascripts/CommunicationFromProviderToProvider.js +2 -0
  12. data/app/assets/javascripts/Component.js +3 -1
  13. data/app/assets/javascripts/DeviceApplied.js +2 -0
  14. data/app/assets/javascripts/DeviceOrder.js +2 -0
  15. data/app/assets/javascripts/DeviceRecommended.js +2 -0
  16. data/app/assets/javascripts/Diagnosis.js +2 -0
  17. data/app/assets/javascripts/DiagnosticStudyOrder.js +2 -0
  18. data/app/assets/javascripts/DiagnosticStudyPerformed.js +2 -1
  19. data/app/assets/javascripts/DiagnosticStudyRecommended.js +2 -0
  20. data/app/assets/javascripts/EncounterOrder.js +3 -1
  21. data/app/assets/javascripts/EncounterPerformed.js +1 -0
  22. data/app/assets/javascripts/EncounterRecommended.js +3 -1
  23. data/app/assets/javascripts/FacilityLocation.js +3 -1
  24. data/app/assets/javascripts/FamilyHistory.js +2 -0
  25. data/app/assets/javascripts/Id.js +2 -0
  26. data/app/assets/javascripts/ImmunizationAdministered.js +2 -0
  27. data/app/assets/javascripts/ImmunizationOrder.js +2 -0
  28. data/app/assets/javascripts/IndividualResult.js +4 -1
  29. data/app/assets/javascripts/InterventionOrder.js +2 -0
  30. data/app/assets/javascripts/InterventionPerformed.js +2 -0
  31. data/app/assets/javascripts/InterventionRecommended.js +2 -0
  32. data/app/assets/javascripts/LaboratoryTestOrder.js +2 -0
  33. data/app/assets/javascripts/LaboratoryTestPerformed.js +1 -0
  34. data/app/assets/javascripts/LaboratoryTestRecommended.js +2 -0
  35. data/app/assets/javascripts/MedicationActive.js +2 -0
  36. data/app/assets/javascripts/MedicationAdministered.js +2 -0
  37. data/app/assets/javascripts/MedicationDischarge.js +2 -0
  38. data/app/assets/javascripts/MedicationDispensed.js +2 -0
  39. data/app/assets/javascripts/MedicationOrder.js +2 -0
  40. data/app/assets/javascripts/Participation.js +2 -0
  41. data/app/assets/javascripts/Patient.js +22 -10
  42. data/app/assets/javascripts/PatientCareExperience.js +2 -0
  43. data/app/assets/javascripts/PatientCharacteristic.js +2 -0
  44. data/app/assets/javascripts/PatientCharacteristicBirthdate.js +2 -0
  45. data/app/assets/javascripts/PatientCharacteristicClinicalTrialParticipant.js +2 -0
  46. data/app/assets/javascripts/PatientCharacteristicEthnicity.js +2 -0
  47. data/app/assets/javascripts/PatientCharacteristicExpired.js +2 -0
  48. data/app/assets/javascripts/PatientCharacteristicPayer.js +2 -0
  49. data/app/assets/javascripts/PatientCharacteristicRace.js +2 -0
  50. data/app/assets/javascripts/PatientCharacteristicSex.js +2 -0
  51. data/app/assets/javascripts/PhysicalExamOrder.js +2 -0
  52. data/app/assets/javascripts/PhysicalExamPerformed.js +1 -0
  53. data/app/assets/javascripts/PhysicalExamRecommended.js +2 -0
  54. data/app/assets/javascripts/ProcedureOrder.js +2 -0
  55. data/app/assets/javascripts/ProcedurePerformed.js +2 -2
  56. data/app/assets/javascripts/ProcedureRecommended.js +2 -0
  57. data/app/assets/javascripts/ProviderCareExperience.js +2 -0
  58. data/app/assets/javascripts/ProviderCharacteristic.js +2 -0
  59. data/app/assets/javascripts/Ratio.js +2 -0
  60. data/app/assets/javascripts/ResultComponent.js +2 -0
  61. data/app/assets/javascripts/SubstanceAdministered.js +2 -0
  62. data/app/assets/javascripts/SubstanceOrder.js +2 -0
  63. data/app/assets/javascripts/SubstanceRecommended.js +2 -0
  64. data/app/assets/javascripts/Symptom.js +2 -0
  65. data/app/assets/javascripts/basetypes/Any.js +15 -0
  66. data/app/assets/javascripts/basetypes/Code.js +20 -10
  67. data/app/assets/javascripts/basetypes/DataElement.js +13 -13
  68. data/app/models/qdm/patient.rb +1 -1
  69. data/cqm-models.gemspec +1 -1
  70. data/dist/index.js +527 -231
  71. data/lib/generate_models.rb +6 -0
  72. data/package.json +3 -3
  73. data/templates/models_template.rb.erb +1 -0
  74. data/templates/mongoose_template.js.erb +10 -2
  75. data/templates/patient_extension.rb.erb +12 -1
  76. data/templates/patient_template.js.erb +24 -11
  77. data/yarn.lock +3 -3
  78. metadata +3 -3
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -5,6 +5,7 @@ const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
7
  const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
8
9
  const Any = require('./basetypes/Any');
9
10
 
10
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,9 +4,9 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
- const Any = require('./basetypes/Any');
8
-
9
7
  const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
9
+ const Any = require('./basetypes/Any');
10
10
 
11
11
  const [Number, String] = [
12
12
  mongoose.Schema.Types.Number,
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -4,6 +4,8 @@ const Code = require('./basetypes/Code');
4
4
  const Interval = require('./basetypes/Interval');
5
5
  const Quantity = require('./basetypes/Quantity');
6
6
  const DateTime = require('./basetypes/DateTime');
7
+ const { ComponentSchema } = require('./Component');
8
+ const { FacilityLocationSchema } = require('./FacilityLocation');
7
9
  const Any = require('./basetypes/Any');
8
10
 
9
11
  const [Number, String] = [
@@ -10,6 +10,21 @@ function RecursiveCast(any) {
10
10
  if (any && any.value && any.unit) {
11
11
  return new cql.Quantity(any);
12
12
  }
13
+ if (any && any.code && any.codeSystem) {
14
+ if (typeof any.code === 'undefined') {
15
+ throw new Error(`Code: ${any} does not have a code`);
16
+ } else if (typeof any.codeSystem === 'undefined') {
17
+ throw new Error(`Code: ${any} does not have a codeSystem`);
18
+ }
19
+
20
+ const val = { code: any.code, codeSystem: any.codeSystem };
21
+
22
+ val.descriptor = (typeof any.descriptor !== 'undefined') ? any.descriptor : null;
23
+ val.codeSystemOid = (typeof any.codeSystemOid !== 'undefined') ? any.codeSystemOid : null;
24
+ val.version = (typeof any.version !== 'undefined') ? any.version : null;
25
+
26
+ return new cql.Code(val.code, val.codeSystem, val.version, val.descriptor);
27
+ }
13
28
  if (any && any.low) {
14
29
  const casted = new cql.Interval(any.low, any.high, any.lowClosed, any.highClosed);
15
30
 
@@ -1,4 +1,5 @@
1
1
  const mongoose = require('mongoose');
2
+ const cql = require('cql-execution');
2
3
 
3
4
  function Code(key, options) {
4
5
  mongoose.SchemaType.call(this, key, options, 'Code');
@@ -6,19 +7,28 @@ function Code(key, options) {
6
7
  Code.prototype = Object.create(mongoose.SchemaType.prototype);
7
8
 
8
9
  Code.prototype.cast = (code) => {
9
- if (typeof code.code === 'undefined') {
10
- throw new Error(`Code: ${code} does not have a code`);
11
- } else if (typeof code.codeSystem === 'undefined') {
12
- throw new Error(`Code: ${code} does not have a codeSystem`);
13
- }
10
+ if (code != null) {
11
+ // handles codes that have not yet been cast to a code and those that have already been cast to a code
12
+ if (code.code && (code.codeSystem || code.system)) {
13
+ if (typeof code.code === 'undefined') {
14
+ throw new Error(`Code: ${code} does not have a code`);
15
+ } else if (typeof code.codeSystem === 'undefined' && typeof code.system === 'undefined') {
16
+ throw new Error(`Code: ${code} does not have a system`);
17
+ }
14
18
 
15
- const val = { code: code.code, codeSystem: code.codeSystem };
19
+ const val = { code: code.code, codeSystem: code.codeSystem || code.system };
16
20
 
17
- val.descriptor = (typeof code.descriptor !== 'undefined') ? code.descriptor : null;
18
- val.codeSystemOid = (typeof code.codeSystemOid !== 'undefined') ? code.codeSystemOid : null;
19
- val.version = (typeof code.version !== 'undefined') ? code.version : null;
21
+ val.descriptor = (typeof code.descriptor !== 'undefined') ? code.descriptor : null;
22
+ val.codeSystemOid = (typeof code.codeSystemOid !== 'undefined') ? code.codeSystemOid : null;
23
+ val.version = (typeof code.version !== 'undefined') ? code.version : null;
20
24
 
21
- return val;
25
+ return new cql.Code(val.code, val.codeSystem, val.version, val.descriptor);
26
+ }
27
+ throw new Error(`Expected a code. Received ${code}.`);
28
+ } else {
29
+ // returns a null or undefined if what is passed in is null or undefined
30
+ return code;
31
+ }
22
32
  };
23
33
 
24
34
  mongoose.Schema.Types.Code = Code;
@@ -1,11 +1,12 @@
1
1
  const mongoose = require('mongoose');
2
2
  const Code = require('./Code.js');
3
+ const cql = require('cql-execution');
3
4
 
4
5
  const [Schema] = [mongoose.Schema];
5
6
 
6
7
  function DataElementSchema(add, options) {
7
8
  const extended = new Schema({
8
- dataElementCodes: { type: [Code] },
9
+ dataElementCodes: { type: [] },
9
10
  description: { type: String },
10
11
  }, options);
11
12
 
@@ -13,21 +14,20 @@ function DataElementSchema(add, options) {
13
14
  extended.add(add);
14
15
  }
15
16
 
16
- // Returns all of the codes on this data element
17
- // in a format usable by the cql-execution framework
17
+ // Returns all of the codes on this data element in a format usable by
18
+ // the cql-execution framework.
18
19
  extended.methods.getCode = function getCode() {
19
- return this.dataElementCodes.map((code) => {
20
- const result = {};
21
- result.code = code.code;
22
- result.system = code.code_system;
23
- return result;
24
- });
20
+ return this.dataElementCodes.map(code => new cql.Code(code.code, code.codeSystem, code.version, code.descriptor));
25
21
  };
26
22
 
27
- // Returns all of the codes on this data element
28
- // in their normal form.
29
- extended.methods.codes = function getCodes() {
30
- return this.dataElementCodes;
23
+ // Return the first code on this data element in a format usable by
24
+ // the cql-execution framework.
25
+ extended.methods.code = function code() {
26
+ if (this.dataElementCodes && this.dataElementCodes[0]) {
27
+ const qdmCode = this.dataElementCodes[0];
28
+ return new cql.Code(qdmCode.code, qdmCode.codeSystem, qdmCode.version, qdmCode.descriptor);
29
+ }
30
+ return null;
31
31
  };
32
32
 
33
33
  return extended;
@@ -36,7 +36,7 @@ module QDM
36
36
  # Note: This will shift dates of the birthdate and
37
37
  # dates on the data elements that exist on the patient.
38
38
  def shift_dates(seconds)
39
- self.birthDatetime = (birthDatetime.utc.to_time + seconds.seconds).to_datetime.new_offset(0)
39
+ self.birthDatetime = (birthDatetime.utc.to_time + seconds.seconds).to_datetime
40
40
  dataElements.each { |element| element.shift_dates(seconds) }
41
41
  end
42
42
 
data/cqm-models.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'cqm-models'
7
- spec.version = '0.8.0'
7
+ spec.version = '0.8.1'
8
8
  spec.authors = ['aholmes@mitre.org', 'mokeefe@mitre.org', 'lades@mitre.org']
9
9
 
10
10
  spec.summary = 'Mongo models that correspond to the QDM specification.'