cqm-models 2.0.0 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.json +1 -1
- data/.github/workflows/gitleaks_github_actions.yml +28 -0
- data/.travis.yml +2 -2
- data/README.md +12 -9
- data/app/assets/javascripts/AdverseEvent.js +9 -3
- data/app/assets/javascripts/AllDataElements.js +18 -6
- data/app/assets/javascripts/AllergyIntolerance.js +8 -2
- data/app/assets/javascripts/AssessmentOrder.js +8 -2
- data/app/assets/javascripts/AssessmentPerformed.js +11 -3
- data/app/assets/javascripts/AssessmentRecommended.js +8 -2
- data/app/assets/javascripts/CareGoal.js +10 -3
- data/app/assets/javascripts/CommunicationPerformed.js +12 -6
- data/app/assets/javascripts/DeviceApplied.js +9 -2
- data/app/assets/javascripts/DeviceOrder.js +8 -2
- data/app/assets/javascripts/DeviceRecommended.js +8 -2
- data/app/assets/javascripts/Diagnosis.js +8 -2
- data/app/assets/javascripts/DiagnosticStudyOrder.js +8 -2
- data/app/assets/javascripts/DiagnosticStudyPerformed.js +9 -2
- data/app/assets/javascripts/DiagnosticStudyRecommended.js +8 -2
- data/app/assets/javascripts/EncounterOrder.js +9 -2
- data/app/assets/javascripts/EncounterPerformed.js +11 -5
- data/app/assets/javascripts/EncounterRecommended.js +8 -2
- data/app/assets/javascripts/FamilyHistory.js +8 -2
- data/app/assets/javascripts/ImmunizationAdministered.js +9 -2
- data/app/assets/javascripts/ImmunizationOrder.js +8 -2
- data/app/assets/javascripts/InterventionOrder.js +8 -2
- data/app/assets/javascripts/InterventionPerformed.js +9 -2
- data/app/assets/javascripts/InterventionRecommended.js +8 -2
- data/app/assets/javascripts/LaboratoryTestOrder.js +8 -2
- data/app/assets/javascripts/LaboratoryTestPerformed.js +9 -2
- data/app/assets/javascripts/LaboratoryTestRecommended.js +8 -2
- data/app/assets/javascripts/MedicationActive.js +9 -2
- data/app/assets/javascripts/MedicationAdministered.js +9 -2
- data/app/assets/javascripts/MedicationDischarge.js +9 -2
- data/app/assets/javascripts/MedicationDispensed.js +10 -4
- data/app/assets/javascripts/MedicationOrder.js +9 -4
- data/app/assets/javascripts/Participation.js +8 -2
- data/app/assets/javascripts/PatientCareExperience.js +8 -2
- data/app/assets/javascripts/PatientCharacteristic.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicBirthdate.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicClinicalTrialParticipant.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicEthnicity.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicExpired.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicPayer.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicRace.js +7 -2
- data/app/assets/javascripts/PatientCharacteristicSex.js +7 -2
- data/app/assets/javascripts/PhysicalExamOrder.js +8 -2
- data/app/assets/javascripts/PhysicalExamPerformed.js +9 -2
- data/app/assets/javascripts/PhysicalExamRecommended.js +8 -2
- data/app/assets/javascripts/ProcedureOrder.js +10 -3
- data/app/assets/javascripts/ProcedurePerformed.js +11 -3
- data/app/assets/javascripts/ProcedureRecommended.js +9 -3
- data/app/assets/javascripts/ProviderCareExperience.js +8 -2
- data/app/assets/javascripts/QDMPatient.js +25 -9
- data/app/assets/javascripts/RelatedPerson.js +42 -0
- data/app/assets/javascripts/SubstanceAdministered.js +9 -2
- data/app/assets/javascripts/SubstanceOrder.js +9 -2
- data/app/assets/javascripts/SubstanceRecommended.js +8 -2
- data/app/assets/javascripts/Symptom.js +8 -2
- data/app/assets/javascripts/attributes/CarePartner.js +33 -0
- data/app/assets/javascripts/attributes/Component.js +22 -1
- data/app/assets/javascripts/attributes/DiagnosisComponent.js +34 -0
- data/app/assets/javascripts/attributes/Entity.js +58 -0
- data/app/assets/javascripts/attributes/FacilityLocation.js +4 -1
- data/app/assets/javascripts/attributes/Identifier.js +23 -0
- data/app/assets/javascripts/attributes/Organization.js +33 -0
- data/app/assets/javascripts/attributes/PatientEntity.js +32 -0
- data/app/assets/javascripts/attributes/Practitioner.js +35 -0
- data/app/assets/javascripts/attributes/ResultComponent.js +31 -0
- data/app/assets/javascripts/basetypes/Any.js +24 -14
- data/app/assets/javascripts/basetypes/AnyEntity.js +44 -0
- data/app/assets/javascripts/basetypes/Code.js +8 -11
- data/app/assets/javascripts/basetypes/DataElement.js +17 -6
- data/app/assets/javascripts/basetypes/Interval.js +2 -2
- data/app/assets/javascripts/basetypes/QDMDate.js +36 -0
- data/app/assets/javascripts/basetypes/Quantity.js +1 -1
- data/app/assets/javascripts/basetypes/Ratio.js +1 -1
- data/app/assets/javascripts/cqm/Provider.js +0 -2
- data/app/models/cqm/individual_result.rb +2 -6
- data/app/models/cqm/provider.rb +4 -4
- data/app/models/hqmfOid_to_datatype_map.json +5 -1
- data/app/models/model_finder.rb +1 -0
- data/app/models/models.rb +12 -5
- data/app/models/qdm/adverse_event.rb +3 -2
- data/app/models/qdm/allergy_intolerance.rb +2 -1
- data/app/models/qdm/assessment_order.rb +2 -1
- data/app/models/qdm/assessment_performed.rb +5 -2
- data/app/models/qdm/assessment_recommended.rb +2 -1
- data/app/models/qdm/attributes/attribute.rb +1 -0
- data/app/models/qdm/attributes/care_partner.rb +10 -0
- data/app/models/qdm/attributes/component.rb +1 -1
- data/app/models/qdm/attributes/diagnosis_component.rb +10 -0
- data/app/models/qdm/attributes/entity.rb +15 -0
- data/app/models/qdm/attributes/facility_location.rb +1 -1
- data/app/models/qdm/{id.rb → attributes/identifier.rb} +3 -4
- data/app/models/qdm/attributes/organization.rb +10 -0
- data/app/models/qdm/attributes/patient_entity.rb +9 -0
- data/app/models/qdm/attributes/practitioner.rb +12 -0
- data/app/models/qdm/{result_component.rb → attributes/result_component.rb} +1 -3
- data/app/models/qdm/basetypes/code.rb +9 -10
- data/app/models/qdm/basetypes/data_element.rb +25 -18
- data/app/models/qdm/basetypes/date.rb +39 -0
- data/app/models/qdm/basetypes/interval.rb +8 -11
- data/app/models/qdm/basetypes/quantity.rb +1 -0
- data/app/models/qdm/basetypes/ratio.rb +1 -0
- data/app/models/qdm/care_goal.rb +4 -2
- data/app/models/qdm/communication_performed.rb +6 -5
- data/app/models/qdm/device_applied.rb +3 -1
- data/app/models/qdm/device_order.rb +2 -1
- data/app/models/qdm/device_recommended.rb +2 -1
- data/app/models/qdm/diagnosis.rb +2 -1
- data/app/models/qdm/diagnostic_study_order.rb +2 -1
- data/app/models/qdm/diagnostic_study_performed.rb +3 -1
- data/app/models/qdm/diagnostic_study_recommended.rb +2 -1
- data/app/models/qdm/encounter_order.rb +3 -1
- data/app/models/qdm/encounter_performed.rb +3 -2
- data/app/models/qdm/encounter_recommended.rb +2 -1
- data/app/models/qdm/family_history.rb +2 -1
- data/app/models/qdm/immunization_administered.rb +3 -1
- data/app/models/qdm/immunization_order.rb +2 -1
- data/app/models/qdm/intervention_order.rb +2 -1
- data/app/models/qdm/intervention_performed.rb +3 -1
- data/app/models/qdm/intervention_recommended.rb +2 -1
- data/app/models/qdm/laboratory_test_order.rb +2 -1
- data/app/models/qdm/laboratory_test_performed.rb +3 -1
- data/app/models/qdm/laboratory_test_recommended.rb +2 -1
- data/app/models/qdm/medication_active.rb +3 -1
- data/app/models/qdm/medication_administered.rb +3 -1
- data/app/models/qdm/medication_discharge.rb +3 -1
- data/app/models/qdm/medication_dispensed.rb +4 -3
- data/app/models/qdm/medication_order.rb +3 -3
- data/app/models/qdm/participation.rb +2 -1
- data/app/models/qdm/patient.rb +1 -1
- data/app/models/qdm/patient_care_experience.rb +2 -1
- data/app/models/qdm/patient_characteristic.rb +1 -1
- data/app/models/qdm/patient_characteristic_birthdate.rb +1 -1
- data/app/models/qdm/patient_characteristic_clinical_trial_participant.rb +1 -1
- data/app/models/qdm/patient_characteristic_ethnicity.rb +1 -1
- data/app/models/qdm/patient_characteristic_expired.rb +1 -1
- data/app/models/qdm/patient_characteristic_payer.rb +1 -1
- data/app/models/qdm/patient_characteristic_race.rb +1 -1
- data/app/models/qdm/patient_characteristic_sex.rb +1 -1
- data/app/models/qdm/physical_exam_order.rb +2 -1
- data/app/models/qdm/physical_exam_performed.rb +3 -1
- data/app/models/qdm/physical_exam_recommended.rb +2 -1
- data/app/models/qdm/procedure_order.rb +4 -2
- data/app/models/qdm/procedure_performed.rb +5 -2
- data/app/models/qdm/procedure_recommended.rb +3 -2
- data/app/models/qdm/provider_care_experience.rb +2 -1
- data/app/models/qdm/related_person.rb +13 -0
- data/app/models/qdm/substance_administered.rb +3 -1
- data/app/models/qdm/substance_order.rb +3 -1
- data/app/models/qdm/substance_recommended.rb +2 -1
- data/app/models/qdm/symptom.rb +2 -1
- data/bin/validate_generator.sh +1 -1
- data/cqm-models.gemspec +5 -5
- data/data/oids_qdm_5.5.json +337 -0
- data/dist/browser.js +12898 -6908
- data/dist/index.js +12897 -6907
- data/lib/generate_entities.rb +56 -0
- data/lib/generate_models.rb +77 -39
- data/lib/generate_patients.rb +20 -14
- data/lib/generate_types.rb +54 -14
- data/lib/generator_helpers.rb +14 -0
- data/modelinfo/qdm-modelinfo-5.5.xml +982 -0
- data/package.json +4 -4
- data/templates/entity_extension.rb.erb +6 -0
- data/templates/identifier_extension.rb.erb +58 -0
- data/templates/{id_template.js.erb → identifier_template.js.erb} +6 -5
- data/templates/models_template.rb.erb +19 -4
- data/templates/mongoose_template.js.erb +86 -12
- data/templates/patient_template.js.erb +0 -4
- data/yarn.lock +525 -392
- metadata +44 -22
- data/app/assets/javascripts/Id.js +0 -21
- data/app/assets/javascripts/ProviderCharacteristic.js +0 -36
- data/app/assets/javascripts/ResultComponent.js +0 -33
- 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 :
|
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.
|
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.
|
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.
|
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
|
-
|
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.
|
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.
|
14
|
+
field :qdmVersion, type: String, default: '5.5'
|
14
15
|
end
|
15
16
|
end
|
@@ -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
|
@@ -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
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module QDM
|
2
|
-
# app/models/qdm/
|
3
|
-
class
|
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.
|
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 <
|
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, :
|
4
|
+
attr_accessor :code, :display, :system, :version
|
5
5
|
|
6
6
|
# Code and code system are required (at minimum).
|
7
|
-
def initialize(code,
|
7
|
+
def initialize(code, sys, display = nil, version = nil)
|
8
8
|
@code = code
|
9
|
-
@
|
10
|
-
@
|
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,
|
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,
|
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[:
|
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
|
-
|
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
|
-
|
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 =
|
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.
|
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
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
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 &&
|
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
|
-
|
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 &&
|
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)
|