cqm-models 2.0.1 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.json +1 -1
  3. data/.github/workflows/gitleaks_github_actions.yml +28 -0
  4. data/.travis.yml +2 -2
  5. data/README.md +12 -9
  6. data/app/assets/javascripts/AdverseEvent.js +9 -3
  7. data/app/assets/javascripts/AllDataElements.js +18 -6
  8. data/app/assets/javascripts/AllergyIntolerance.js +8 -2
  9. data/app/assets/javascripts/AssessmentOrder.js +8 -2
  10. data/app/assets/javascripts/AssessmentPerformed.js +11 -3
  11. data/app/assets/javascripts/AssessmentRecommended.js +8 -2
  12. data/app/assets/javascripts/CareGoal.js +10 -3
  13. data/app/assets/javascripts/CommunicationPerformed.js +12 -6
  14. data/app/assets/javascripts/DeviceApplied.js +9 -2
  15. data/app/assets/javascripts/DeviceOrder.js +8 -2
  16. data/app/assets/javascripts/DeviceRecommended.js +8 -2
  17. data/app/assets/javascripts/Diagnosis.js +8 -2
  18. data/app/assets/javascripts/DiagnosticStudyOrder.js +8 -2
  19. data/app/assets/javascripts/DiagnosticStudyPerformed.js +9 -2
  20. data/app/assets/javascripts/DiagnosticStudyRecommended.js +8 -2
  21. data/app/assets/javascripts/EncounterOrder.js +9 -2
  22. data/app/assets/javascripts/EncounterPerformed.js +11 -5
  23. data/app/assets/javascripts/EncounterRecommended.js +8 -2
  24. data/app/assets/javascripts/FamilyHistory.js +8 -2
  25. data/app/assets/javascripts/ImmunizationAdministered.js +9 -2
  26. data/app/assets/javascripts/ImmunizationOrder.js +8 -2
  27. data/app/assets/javascripts/InterventionOrder.js +8 -2
  28. data/app/assets/javascripts/InterventionPerformed.js +9 -2
  29. data/app/assets/javascripts/InterventionRecommended.js +8 -2
  30. data/app/assets/javascripts/LaboratoryTestOrder.js +8 -2
  31. data/app/assets/javascripts/LaboratoryTestPerformed.js +9 -2
  32. data/app/assets/javascripts/LaboratoryTestRecommended.js +8 -2
  33. data/app/assets/javascripts/MedicationActive.js +9 -2
  34. data/app/assets/javascripts/MedicationAdministered.js +9 -2
  35. data/app/assets/javascripts/MedicationDischarge.js +9 -2
  36. data/app/assets/javascripts/MedicationDispensed.js +10 -4
  37. data/app/assets/javascripts/MedicationOrder.js +9 -4
  38. data/app/assets/javascripts/Participation.js +8 -2
  39. data/app/assets/javascripts/PatientCareExperience.js +8 -2
  40. data/app/assets/javascripts/PatientCharacteristic.js +7 -2
  41. data/app/assets/javascripts/PatientCharacteristicBirthdate.js +7 -2
  42. data/app/assets/javascripts/PatientCharacteristicClinicalTrialParticipant.js +7 -2
  43. data/app/assets/javascripts/PatientCharacteristicEthnicity.js +7 -2
  44. data/app/assets/javascripts/PatientCharacteristicExpired.js +7 -2
  45. data/app/assets/javascripts/PatientCharacteristicPayer.js +7 -2
  46. data/app/assets/javascripts/PatientCharacteristicRace.js +7 -2
  47. data/app/assets/javascripts/PatientCharacteristicSex.js +7 -2
  48. data/app/assets/javascripts/PhysicalExamOrder.js +8 -2
  49. data/app/assets/javascripts/PhysicalExamPerformed.js +9 -2
  50. data/app/assets/javascripts/PhysicalExamRecommended.js +8 -2
  51. data/app/assets/javascripts/ProcedureOrder.js +10 -3
  52. data/app/assets/javascripts/ProcedurePerformed.js +11 -3
  53. data/app/assets/javascripts/ProcedureRecommended.js +9 -3
  54. data/app/assets/javascripts/ProviderCareExperience.js +8 -2
  55. data/app/assets/javascripts/QDMPatient.js +25 -9
  56. data/app/assets/javascripts/RelatedPerson.js +42 -0
  57. data/app/assets/javascripts/SubstanceAdministered.js +9 -2
  58. data/app/assets/javascripts/SubstanceOrder.js +9 -2
  59. data/app/assets/javascripts/SubstanceRecommended.js +8 -2
  60. data/app/assets/javascripts/Symptom.js +8 -2
  61. data/app/assets/javascripts/attributes/CarePartner.js +33 -0
  62. data/app/assets/javascripts/attributes/Component.js +22 -1
  63. data/app/assets/javascripts/attributes/DiagnosisComponent.js +34 -0
  64. data/app/assets/javascripts/attributes/Entity.js +58 -0
  65. data/app/assets/javascripts/attributes/FacilityLocation.js +4 -1
  66. data/app/assets/javascripts/attributes/Identifier.js +23 -0
  67. data/app/assets/javascripts/attributes/Organization.js +33 -0
  68. data/app/assets/javascripts/attributes/PatientEntity.js +32 -0
  69. data/app/assets/javascripts/attributes/Practitioner.js +35 -0
  70. data/app/assets/javascripts/attributes/ResultComponent.js +31 -0
  71. data/app/assets/javascripts/basetypes/Any.js +24 -14
  72. data/app/assets/javascripts/basetypes/AnyEntity.js +44 -0
  73. data/app/assets/javascripts/basetypes/Code.js +8 -11
  74. data/app/assets/javascripts/basetypes/DataElement.js +17 -6
  75. data/app/assets/javascripts/basetypes/Interval.js +2 -2
  76. data/app/assets/javascripts/basetypes/QDMDate.js +36 -0
  77. data/app/assets/javascripts/basetypes/Quantity.js +1 -1
  78. data/app/assets/javascripts/basetypes/Ratio.js +1 -1
  79. data/app/assets/javascripts/cqm/Provider.js +0 -2
  80. data/app/models/cqm/individual_result.rb +2 -6
  81. data/app/models/cqm/provider.rb +4 -4
  82. data/app/models/hqmfOid_to_datatype_map.json +5 -1
  83. data/app/models/model_finder.rb +1 -0
  84. data/app/models/models.rb +12 -5
  85. data/app/models/qdm/adverse_event.rb +3 -2
  86. data/app/models/qdm/allergy_intolerance.rb +2 -1
  87. data/app/models/qdm/assessment_order.rb +2 -1
  88. data/app/models/qdm/assessment_performed.rb +5 -2
  89. data/app/models/qdm/assessment_recommended.rb +2 -1
  90. data/app/models/qdm/attributes/attribute.rb +1 -0
  91. data/app/models/qdm/attributes/care_partner.rb +10 -0
  92. data/app/models/qdm/attributes/component.rb +1 -1
  93. data/app/models/qdm/attributes/diagnosis_component.rb +10 -0
  94. data/app/models/qdm/attributes/entity.rb +15 -0
  95. data/app/models/qdm/attributes/facility_location.rb +1 -1
  96. data/app/models/qdm/{id.rb → attributes/identifier.rb} +3 -4
  97. data/app/models/qdm/attributes/organization.rb +10 -0
  98. data/app/models/qdm/attributes/patient_entity.rb +9 -0
  99. data/app/models/qdm/attributes/practitioner.rb +12 -0
  100. data/app/models/qdm/{result_component.rb → attributes/result_component.rb} +1 -3
  101. data/app/models/qdm/basetypes/code.rb +9 -10
  102. data/app/models/qdm/basetypes/data_element.rb +25 -18
  103. data/app/models/qdm/basetypes/date.rb +39 -0
  104. data/app/models/qdm/basetypes/interval.rb +8 -11
  105. data/app/models/qdm/basetypes/quantity.rb +1 -0
  106. data/app/models/qdm/basetypes/ratio.rb +1 -0
  107. data/app/models/qdm/care_goal.rb +4 -2
  108. data/app/models/qdm/communication_performed.rb +6 -5
  109. data/app/models/qdm/device_applied.rb +3 -1
  110. data/app/models/qdm/device_order.rb +2 -1
  111. data/app/models/qdm/device_recommended.rb +2 -1
  112. data/app/models/qdm/diagnosis.rb +2 -1
  113. data/app/models/qdm/diagnostic_study_order.rb +2 -1
  114. data/app/models/qdm/diagnostic_study_performed.rb +3 -1
  115. data/app/models/qdm/diagnostic_study_recommended.rb +2 -1
  116. data/app/models/qdm/encounter_order.rb +3 -1
  117. data/app/models/qdm/encounter_performed.rb +3 -2
  118. data/app/models/qdm/encounter_recommended.rb +2 -1
  119. data/app/models/qdm/family_history.rb +2 -1
  120. data/app/models/qdm/immunization_administered.rb +3 -1
  121. data/app/models/qdm/immunization_order.rb +2 -1
  122. data/app/models/qdm/intervention_order.rb +2 -1
  123. data/app/models/qdm/intervention_performed.rb +3 -1
  124. data/app/models/qdm/intervention_recommended.rb +2 -1
  125. data/app/models/qdm/laboratory_test_order.rb +2 -1
  126. data/app/models/qdm/laboratory_test_performed.rb +3 -1
  127. data/app/models/qdm/laboratory_test_recommended.rb +2 -1
  128. data/app/models/qdm/medication_active.rb +3 -1
  129. data/app/models/qdm/medication_administered.rb +3 -1
  130. data/app/models/qdm/medication_discharge.rb +3 -1
  131. data/app/models/qdm/medication_dispensed.rb +4 -3
  132. data/app/models/qdm/medication_order.rb +3 -3
  133. data/app/models/qdm/participation.rb +2 -1
  134. data/app/models/qdm/patient.rb +1 -1
  135. data/app/models/qdm/patient_care_experience.rb +2 -1
  136. data/app/models/qdm/patient_characteristic.rb +1 -1
  137. data/app/models/qdm/patient_characteristic_birthdate.rb +1 -1
  138. data/app/models/qdm/patient_characteristic_clinical_trial_participant.rb +1 -1
  139. data/app/models/qdm/patient_characteristic_ethnicity.rb +1 -1
  140. data/app/models/qdm/patient_characteristic_expired.rb +1 -1
  141. data/app/models/qdm/patient_characteristic_payer.rb +1 -1
  142. data/app/models/qdm/patient_characteristic_race.rb +1 -1
  143. data/app/models/qdm/patient_characteristic_sex.rb +1 -1
  144. data/app/models/qdm/physical_exam_order.rb +2 -1
  145. data/app/models/qdm/physical_exam_performed.rb +3 -1
  146. data/app/models/qdm/physical_exam_recommended.rb +2 -1
  147. data/app/models/qdm/procedure_order.rb +4 -2
  148. data/app/models/qdm/procedure_performed.rb +5 -2
  149. data/app/models/qdm/procedure_recommended.rb +3 -2
  150. data/app/models/qdm/provider_care_experience.rb +2 -1
  151. data/app/models/qdm/related_person.rb +13 -0
  152. data/app/models/qdm/substance_administered.rb +3 -1
  153. data/app/models/qdm/substance_order.rb +3 -1
  154. data/app/models/qdm/substance_recommended.rb +2 -1
  155. data/app/models/qdm/symptom.rb +2 -1
  156. data/bin/validate_generator.sh +1 -1
  157. data/cqm-models.gemspec +5 -5
  158. data/data/oids_qdm_5.5.json +337 -0
  159. data/dist/browser.js +8819 -4882
  160. data/dist/index.js +8818 -4881
  161. data/lib/generate_entities.rb +56 -0
  162. data/lib/generate_models.rb +77 -39
  163. data/lib/generate_patients.rb +20 -14
  164. data/lib/generate_types.rb +54 -14
  165. data/lib/generator_helpers.rb +14 -0
  166. data/modelinfo/qdm-modelinfo-5.5.xml +982 -0
  167. data/package.json +4 -4
  168. data/templates/entity_extension.rb.erb +6 -0
  169. data/templates/identifier_extension.rb.erb +58 -0
  170. data/templates/{id_template.js.erb → identifier_template.js.erb} +6 -5
  171. data/templates/models_template.rb.erb +19 -4
  172. data/templates/mongoose_template.js.erb +86 -12
  173. data/templates/patient_template.js.erb +0 -4
  174. data/yarn.lock +396 -320
  175. metadata +40 -19
  176. data/app/assets/javascripts/Id.js +0 -21
  177. data/app/assets/javascripts/ProviderCharacteristic.js +0 -36
  178. data/app/assets/javascripts/ResultComponent.js +0 -33
  179. data/app/models/qdm/provider_characteristic.rb +0 -12
@@ -4,13 +4,14 @@ module QDM
4
4
  include Mongoid::Document
5
5
  embedded_in :patient
6
6
  field :authorDatetime, type: DateTime
7
- field :relevantPeriod, type: QDM::Interval
7
+ field :relevantDatetime, type: DateTime
8
8
  field :severity, type: QDM::Code
9
9
  field :facilityLocation, type: QDM::FacilityLocation
10
10
  field :type, type: QDM::Code
11
+ embeds_one :recorder, class_name: 'QDM::Entity'
11
12
  field :qdmTitle, type: String, default: 'Adverse Event'
12
13
  field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.120'
13
14
  field :qdmCategory, type: String, default: 'adverse_event'
14
- field :qdmVersion, type: String, default: '5.4'
15
+ field :qdmVersion, type: String, default: '5.5'
15
16
  end
16
17
  end
@@ -7,10 +7,11 @@ module QDM
7
7
  field :prevalencePeriod, type: QDM::Interval
8
8
  field :type, type: QDM::Code
9
9
  field :severity, type: QDM::Code
10
+ embeds_one :recorder, class_name: 'QDM::Entity'
10
11
  field :qdmTitle, type: String, default: 'Allergy/Intolerance'
11
12
  field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.119'
12
13
  field :qdmCategory, type: String, default: 'allergy'
13
14
  field :qdmStatus, type: String, default: 'intolerance'
14
- field :qdmVersion, type: String, default: '5.4'
15
+ field :qdmVersion, type: String, default: '5.5'
15
16
  end
16
17
  end
@@ -6,10 +6,11 @@ module QDM
6
6
  field :authorDatetime, type: DateTime
7
7
  field :negationRationale, type: QDM::Code
8
8
  field :reason, type: QDM::Code
9
+ embeds_one :requester, class_name: 'QDM::Entity'
9
10
  field :qdmTitle, type: String, default: 'Assessment, Order'
10
11
  field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.131'
11
12
  field :qdmCategory, type: String, default: 'assessment'
12
13
  field :qdmStatus, type: String, default: 'order'
13
- field :qdmVersion, type: String, default: '5.4'
14
+ field :qdmVersion, type: String, default: '5.5'
14
15
  end
15
16
  end
@@ -4,16 +4,19 @@ module QDM
4
4
  include Mongoid::Document
5
5
  embedded_in :patient
6
6
  field :authorDatetime, type: DateTime
7
+ field :relevantDatetime, type: DateTime
8
+ field :relevantPeriod, type: QDM::Interval
7
9
  field :negationRationale, type: QDM::Code
8
10
  field :reason, type: QDM::Code
9
11
  field :method, type: QDM::Code
10
12
  field :result
11
13
  field :components, type: Array
12
- embeds_many :relatedTo, class_name: 'QDM::Id'
14
+ field :relatedTo, type: Array
15
+ embeds_one :performer, class_name: 'QDM::Entity'
13
16
  field :qdmTitle, type: String, default: 'Assessment, Performed'
14
17
  field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.117'
15
18
  field :qdmCategory, type: String, default: 'assessment'
16
19
  field :qdmStatus, type: String, default: 'performed'
17
- field :qdmVersion, type: String, default: '5.4'
20
+ field :qdmVersion, type: String, default: '5.5'
18
21
  end
19
22
  end
@@ -6,10 +6,11 @@ module QDM
6
6
  field :authorDatetime, type: DateTime
7
7
  field :negationRationale, type: QDM::Code
8
8
  field :reason, type: QDM::Code
9
+ embeds_one :requester, class_name: 'QDM::Entity'
9
10
  field :qdmTitle, type: String, default: 'Assessment, Recommended'
10
11
  field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.118'
11
12
  field :qdmCategory, type: String, default: 'assessment'
12
13
  field :qdmStatus, type: String, default: 'recommended'
13
- field :qdmVersion, type: String, default: '5.4'
14
+ field :qdmVersion, type: String, default: '5.5'
14
15
  end
15
16
  end
@@ -30,6 +30,7 @@ module QDM
30
30
  # this custom class from it.
31
31
  def demongoize(object)
32
32
  return nil unless object
33
+
33
34
  object = object.symbolize_keys
34
35
  if object.is_a?(Hash)
35
36
  # This will turn the object into the concrete type eg: facilityLocation
@@ -0,0 +1,10 @@
1
+ module QDM
2
+ # app/models/qdm/care_partner.rb
3
+ class CarePartner < Entity
4
+ include Mongoid::Document
5
+ embedded_in :data_element
6
+ field :relationship, type: QDM::Code
7
+ field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.134'
8
+ field :qrdaOid, type: String, default: '2.16.840.1.113883.10.20.24.3.160'
9
+ end
10
+ end
@@ -4,6 +4,6 @@ module QDM
4
4
  include Mongoid::Document
5
5
  field :code, type: QDM::Code
6
6
  field :result
7
- field :qdmVersion, type: String, default: '5.4'
7
+ field :qdmVersion, type: String, default: '5.5'
8
8
  end
9
9
  end
@@ -0,0 +1,10 @@
1
+ module QDM
2
+ # app/models/qdm/diagnosis_component.rb
3
+ class DiagnosisComponent < Attribute
4
+ include Mongoid::Document
5
+ field :code, type: QDM::Code
6
+ field :presentOnAdmissionIndicator, type: QDM::Code
7
+ field :rank, type: Integer
8
+ field :qdmVersion, type: String, default: '5.5'
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module QDM
2
+ # app/models/qdm/entity.rb
3
+ class Entity < Attribute
4
+ include Mongoid::Document
5
+ embedded_in :data_element
6
+ field :id, type: String
7
+ embeds_one :identifier, class_name: 'QDM::Identifier'
8
+ field :qdmVersion, type: String, default: '5.5'
9
+ def initialize(options = {})
10
+ super(options)
11
+ # default id to the mongo ObjectId for this DataElement if it isnt already defined
12
+ self.id = _id.to_s unless id?
13
+ end
14
+ end
15
+ end
@@ -4,6 +4,6 @@ module QDM
4
4
  include Mongoid::Document
5
5
  field :code, type: QDM::Code
6
6
  field :locationPeriod, type: QDM::Interval
7
- field :qdmVersion, type: String, default: '5.4'
7
+ field :qdmVersion, type: String, default: '5.5'
8
8
  end
9
9
  end
@@ -1,10 +1,9 @@
1
1
  module QDM
2
- # app/models/qdm/id.rb
3
- class Id
2
+ # app/models/qdm/identifier.rb
3
+ class Identifier < Attribute
4
4
  include Mongoid::Document
5
- embedded_in :data_element
6
5
  field :namingSystem, type: String
7
6
  field :value, type: String
8
- field :qdmVersion, type: String, default: '5.4'
7
+ field :qdmVersion, type: String, default: '5.5'
9
8
  end
10
9
  end
@@ -0,0 +1,10 @@
1
+ module QDM
2
+ # app/models/qdm/organization.rb
3
+ class Organization < Entity
4
+ include Mongoid::Document
5
+ embedded_in :data_element
6
+ field :type, type: QDM::Code
7
+ field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.135'
8
+ field :qrdaOid, type: String, default: '2.16.840.1.113883.10.20.24.3.163'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module QDM
2
+ # app/models/qdm/patient_entity.rb
3
+ class PatientEntity < Entity
4
+ include Mongoid::Document
5
+ embedded_in :data_element
6
+ field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.136'
7
+ field :qrdaOid, type: String, default: '2.16.840.1.113883.10.20.24.3.161'
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module QDM
2
+ # app/models/qdm/practitioner.rb
3
+ class Practitioner < Entity
4
+ include Mongoid::Document
5
+ embedded_in :data_element
6
+ field :role, type: QDM::Code
7
+ field :specialty, type: QDM::Code
8
+ field :qualification, type: QDM::Code
9
+ field :hqmfOid, type: String, default: '2.16.840.1.113883.10.20.28.4.137'
10
+ field :qrdaOid, type: String, default: '2.16.840.1.113883.10.20.24.3.162'
11
+ end
12
+ end
@@ -1,9 +1,7 @@
1
1
  module QDM
2
2
  # app/models/qdm/result_component.rb
3
- class ResultComponent < DataElement
3
+ class ResultComponent < Component
4
4
  include Mongoid::Document
5
- embedded_in :patient
6
5
  field :referenceRange, type: QDM::Interval
7
- field :qdmVersion, type: String, default: '5.4'
8
6
  end
9
7
  end
@@ -1,20 +1,19 @@
1
1
  module QDM
2
2
  # Represents a Code
3
3
  class Code
4
- attr_accessor :code, :codeSystem, :descriptor, :codeSystemOid, :version
4
+ attr_accessor :code, :display, :system, :version
5
5
 
6
6
  # Code and code system are required (at minimum).
7
- def initialize(code, codeSystemOid, descriptor = nil, codeSystem = nil, version = nil)
7
+ def initialize(code, sys, display = nil, version = nil)
8
8
  @code = code
9
- @codeSystem = codeSystem
10
- @descriptor = descriptor
11
- @codeSystemOid = codeSystemOid
9
+ @system = sys
10
+ @display = display
12
11
  @version = version
13
12
  end
14
13
 
15
14
  # Converts an object of this instance into a database friendly value.
16
15
  def mongoize
17
- { code: @code, codeSystemOid: @codeSystemOid, descriptor: @descriptor, codeSystem: @codeSystem, version: @version, _type: 'QDM::Code' }
16
+ { code: @code, system: @system, display: @display, version: @version, _type: 'QDM::Code' }
18
17
  end
19
18
 
20
19
  class << self
@@ -22,11 +21,12 @@ module QDM
22
21
  # this custom class from it.
23
22
  #
24
23
  # The array elements in demongoize are the same 5 elements used in mongoize, i.e.
25
- # [ code, codeSystem, descriptor, codeSystemOid, version ].
24
+ # [ code, system, display, version ].
26
25
  def demongoize(object)
27
26
  return nil unless object
27
+
28
28
  object = object.symbolize_keys
29
- QDM::Code.new(object[:code], object[:codeSystemOid], object[:descriptor], object[:codeSystem], object[:version])
29
+ QDM::Code.new(object[:code], object[:system], object[:display], object[:version])
30
30
  end
31
31
 
32
32
  # Takes any possible object and converts it to how it would be
@@ -37,8 +37,7 @@ module QDM
37
37
  when QDM::Code then object.mongoize
38
38
  when Hash
39
39
  object = object.symbolize_keys
40
- codeSystemOid = object[:system] ? object[:system] : object[:codeSystemOid]
41
- QDM::Code.new(object[:code], codeSystemOid, object[:descriptor], object[:codeSystem], object[:version]).mongoize
40
+ QDM::Code.new(object[:code], object[:system], object[:display], object[:version]).mongoize
42
41
  else object
43
42
  end
44
43
  end
@@ -14,12 +14,12 @@ module QDM
14
14
  # Valueset oid of the specific type.
15
15
  field :codeListId, type: String
16
16
 
17
- embeds_one :id, class_name: 'QDM::Id'
17
+ field :id, type: String
18
18
 
19
19
  def initialize(options = {})
20
20
  super(options)
21
21
  # default id to the mongo ObjectId for this DataElement if it isnt already defined
22
- self.id = QDM::Id.new(value: _id.to_s) unless id?
22
+ self.id = _id.to_s unless id?
23
23
  end
24
24
 
25
25
  # Returns the attribute requested on the datatype.
@@ -31,7 +31,7 @@ module QDM
31
31
  # to the CQL execution engine.
32
32
  def code_system_pairs
33
33
  codes.collect do |code|
34
- { code: code.code, system: code.codeSystemOid }
34
+ { code: code.code, system: code.system }
35
35
  end
36
36
  end
37
37
 
@@ -59,12 +59,8 @@ module QDM
59
59
  # values shift backwards.
60
60
  def shift_dates(seconds)
61
61
  fields.keys.each do |field|
62
- if send(field).is_a? DateTime
63
- send(field + '=', (send(field).to_time + seconds.seconds).to_datetime)
64
- end
65
- if (send(field).is_a? Interval) || (send(field).is_a? DataElement)
66
- send(field + '=', send(field).shift_dates(seconds))
67
- end
62
+ send(field + '=', (send(field).to_time + seconds.seconds).to_datetime) if send(field).is_a? DateTime
63
+ send(field + '=', send(field).shift_dates(seconds)) if (send(field).is_a? Interval) || (send(field).is_a? DataElement)
68
64
 
69
65
  # Special case for facility locations
70
66
  if field == 'facilityLocations'
@@ -91,12 +87,24 @@ module QDM
91
87
  # back to the 28th in non leap years
92
88
  def shift_years(year_shift)
93
89
  fields.keys.each do |field|
94
- if send(field).is_a? DateTime
95
- if send(field).year + year_shift > 9999 || send(field).year + year_shift < 1
96
- raise RangeError, 'Year was shifted after 9999 or before 0001'
97
- end
98
- if send(field).month == 2 && send(field).day == 29 && !Date.leap?(year_shift + send(field).year)
99
- send(field + '=', send(field).change(year: year_shift + send(field).year, day: 28))
90
+ if send(field).is_a?(QDM::Date) || send(field).is_a?(DateTime)
91
+ # Do not shift Time values. They are stored as DateTimes with year 0.
92
+ next if send(field).year.zero?
93
+ raise RangeError, 'Year was shifted after 9999 or before 0001' if send(field).year + year_shift > 9999 || send(field).year + year_shift < 1
94
+
95
+ if send(field).month == 2 && send(field).day == 29 && !::Date.leap?(year_shift + send(field).year)
96
+ if send(field).is_a?(QDM::Date)
97
+ shifted_date = send(field)
98
+ shifted_date.year = shifted_date.year + year_shift
99
+ shifted_date.day = 28
100
+ send(field + '=', shifted_date)
101
+ else
102
+ send(field + '=', send(field).change(year: year_shift + send(field).year, day: 28))
103
+ end
104
+ elsif send(field).is_a?(QDM::Date)
105
+ shifted_date = send(field)
106
+ shifted_date.year = shifted_date.year + year_shift
107
+ send(field + '=', shifted_date)
100
108
  else
101
109
  send(field + '=', send(field).change(year: year_shift + send(field).year))
102
110
  end
@@ -124,9 +132,7 @@ module QDM
124
132
  end
125
133
  end
126
134
 
127
- if (send(field).is_a? Interval) || (send(field).is_a? DataElement)
128
- send(field + '=', send(field).shift_years(year_shift))
129
- end
135
+ send(field + '=', send(field).shift_years(year_shift)) if (send(field).is_a? Interval) || (send(field).is_a? DataElement)
130
136
  end
131
137
  end
132
138
 
@@ -140,6 +146,7 @@ module QDM
140
146
  #
141
147
  def demongoize(object)
142
148
  return nil unless object
149
+
143
150
  object = object.symbolize_keys
144
151
  if object.is_a?(Hash)
145
152
  data_element = QDM.const_get(object[:_type])
@@ -0,0 +1,39 @@
1
+ module QDM
2
+ # Represents a QDM/CQL Date
3
+ class Date
4
+ attr_accessor :year, :month, :day
5
+
6
+ def initialize(year = nil, month = nil, day = nil)
7
+ @year = year
8
+ @month = month
9
+ @day = day
10
+ end
11
+
12
+ # Converts an object of this instance into a database friendly value.
13
+ def mongoize
14
+ "#{format('%04d', year)}-#{format('%02d', month)}-#{format('%02d', day)}"
15
+ end
16
+
17
+ class << self
18
+ # Get the string as it was stored in the database, and instantiate
19
+ # this custom class from it.
20
+ def demongoize(date_str)
21
+ return nil unless date_str
22
+
23
+ year = date_str[0..3].to_i
24
+ month = date_str[5..6].to_i
25
+ day = date_str[8..10].to_i
26
+ QDM::Date.new(year, month, day)
27
+ end
28
+
29
+ # Converts the object that was supplied to a criteria and converts it
30
+ # into a database friendly form.
31
+ def evolve(object)
32
+ case object
33
+ when QDM::Date then object.mongoize
34
+ else object
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -22,9 +22,7 @@ module QDM
22
22
  #
23
23
  # NOTE: This will only shift if @high and @low are DateTimes.
24
24
  def shift_dates(seconds)
25
- if (@low.is_a? DateTime) || (@low.is_a? Time)
26
- @low = (@low.utc.to_time + seconds.seconds).to_datetime.new_offset(0)
27
- end
25
+ @low = (@low.utc.to_time + seconds.seconds).to_datetime.new_offset(0) if (@low.is_a? DateTime) || (@low.is_a? Time)
28
26
  if (@high.is_a? DateTime) || (@high.is_a? Time)
29
27
  @high = (@high.utc.to_time + seconds.seconds).to_datetime.new_offset(0)
30
28
  @high = @high.year > 9999 ? @high.change(year: 9999) : @high
@@ -34,22 +32,20 @@ module QDM
34
32
 
35
33
  def shift_years(year_shift)
36
34
  if (@low.is_a? DateTime) || (@low.is_a? Time)
37
- if @low.year + year_shift < 1 || @low.year + year_shift > 9999
38
- raise RangeError, 'Year was shifted after 9999 or before 0001'
39
- end
35
+ raise RangeError, 'Year was shifted after 9999 or before 0001' if @low.year + year_shift < 1 || @low.year + year_shift > 9999
36
+
40
37
  low_shift = @low.year + year_shift
41
- @low = if @low.month == 2 && @low.day == 29 && !Date.leap?(low_shift)
38
+ @low = if @low.month == 2 && @low.day == 29 && !::Date.leap?(low_shift)
42
39
  @low.change(year: low_shift, day: 28)
43
40
  else
44
41
  @low.change(year: low_shift)
45
42
  end
46
43
  end
47
44
  if (@high.is_a? DateTime) || (@high.is_a? Time)
48
- if @high.year + year_shift < 1 || @high.year + year_shift > 9999
49
- raise RangeError, 'Year was shifted after 9999 or before 0001'
50
- end
45
+ raise RangeError, 'Year was shifted after 9999 or before 0001' if @high.year + year_shift < 1 || @high.year + year_shift > 9999
46
+
51
47
  high_shift = @high.year + year_shift
52
- @high = if @high.month == 2 && @high.day == 29 && !Date.leap?(high_shift)
48
+ @high = if @high.month == 2 && @high.day == 29 && !::Date.leap?(high_shift)
53
49
  @high.change(year: high_shift, day: 28)
54
50
  else
55
51
  @high.change(year: high_shift)
@@ -66,6 +62,7 @@ module QDM
66
62
  # [ low, high ].
67
63
  def demongoize(object)
68
64
  return nil unless object
65
+
69
66
  object = object.symbolize_keys
70
67
  fix_datetime(object)
71
68
  QDM::Interval.new(object[:low], object[:high], object[:lowClosed], object[:highClosed]) if object.is_a?(Hash)
@@ -22,6 +22,7 @@ module QDM
22
22
  # [ value, unit ].
23
23
  def demongoize(object)
24
24
  return nil unless object
25
+
25
26
  object = object.symbolize_keys
26
27
  QDM::Quantity.new(object[:value], object[:unit]) if object.is_a?(Hash)
27
28
  end
@@ -22,6 +22,7 @@ module QDM
22
22
  # [ numerator, denominator ].
23
23
  def demongoize(object)
24
24
  return nil unless object
25
+
25
26
  object = object.symbolize_keys
26
27
  QDM::Ratio.new(object[:numerator], object[:denominator]) if object.is_a?(Hash)
27
28
  end