lib/hqmf-model/data_criteria.rb in health-data-standards-3.4.6 vs lib/hqmf-model/data_criteria.rb in health-data-standards-3.5.0
- old
+ new
@@ -7,11 +7,16 @@
SOURCE_DATA_CRITERIA_TEMPLATE_ID = '2.16.840.1.113883.3.100.1.1'
SOURCE_DATA_CRITERIA_TEMPLATE_TITLE = 'Source data criteria'
XPRODUCT = 'XPRODUCT'
UNION = 'UNION'
+ INTERSECT = 'INTERSECT'
+ SATISFIES_ALL = 'satisfies_all'
+ SATISFIES_ANY = 'satisfies_any'
+ VARIABLE = 'variable'
+
FIELDS = {'SEVERITY' => {title:'Severity', coded_entry_method: :severity, code: 'SEV', code_system:'2.16.840.1.113883.5.4', template_id: '2.16.840.1.113883.3.560.1.1021.2', field_type: :value},
'ORDINAL' => {title:'Ordinal', coded_entry_method: :ordinality, code: '117363000', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1012.2', field_type: :value},
'REASON' => {title:'Reason', coded_entry_method: :reason, code: '410666004', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1017.2', field_type: :value},
'SOURCE' => {title:'Source', coded_entry_method: :source, code: '260753009', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.2001.2', field_type: :value},
'CUMULATIVE_MEDICATION_DURATION' => {title:'Cumulative Medication Duration', coded_entry_method: :cumulative_medication_duration, code: '363819003', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1001.3', field_type: :value},
@@ -29,11 +34,11 @@
'ANATOMICAL_STRUCTURE' => {title:'Anatomical Structure', coded_entry_method: :anatomical_structure, code: '91723000', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1000.2', field_type: :value},
'STOP_DATETIME' => {title:'Stop Date/Time', coded_entry_method: :end_date, code: '397898000', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1026.1', field_type: :timestamp},
'INCISION_DATETIME' => {title:'Incision Date/Time', coded_entry_method: :incision_time, code: '34896006', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1007.1', field_type: :timestamp},
'REMOVAL_DATETIME' => {title:'Removal Date/Time', coded_entry_method: :removal_time, code: '118292001', code_system:'2.16.840.1.113883.6.96', template_id: '2.16.840.1.113883.3.560.1.1032.1', field_type: :timestamp},
'TRANSFER_TO' => {title:'Transfer To', coded_entry_method: :transfer_to, code: 'TRANSFER_TO', template_id: '2.16.840.1.113883.3.560.1.72', field_type: :value},
- 'TRANSFER_FROM' => {title:'Transfer From', coded_entry_method: :transfer_from, code: 'TRANSFER_FROM', template_id: '2.16.840.1.113883.3.560.1.71', field_type: :value}
+ 'TRANSFER_FROM' => {title:'Transfer From', coded_entry_method: :transfer_from, code: 'TRANSFER_FROM', template_id: '2.16.840.1.113883.3.560.1.71', field_type: :value},
}
VALUE_FIELDS = {'SEV' => 'SEVERITY',
'117363000' => 'ORDINAL',
'410666004' => 'REASON',
@@ -49,16 +54,18 @@
'398201009' => 'START_DATETIME',
'260864003' =>'FREQUENCY',
'91723000' => 'ANATOMICAL_STRUCTURE',
'397898000' => 'STOP_DATETIME',
'34896006' => 'INCISION_DATETIME',
- '118292001' =>'REMOVAL_DATETIME'
+ '118292001' =>'REMOVAL_DATETIME',
+ 'SDLOC_ARRIVAL' => 'FACILITY_LOCATION_ARRIVAL_DATETIME',
+ 'SDLOC_DEPARTURE' => 'FACILITY_LOCATION_DEPARTURE_DATETIME'
}
- attr_reader :title, :description, :code_list_id, :children_criteria, :derivation_operator , :specific_occurrence, :specific_occurrence_const, :source_data_criteria
- attr_accessor :id, :value, :field_values, :effective_time, :status, :temporal_references, :subset_operators, :definition, :inline_code_list, :negation_code_list_id, :negation, :display_name
+ attr_reader :title, :description, :code_list_id, :derivation_operator , :specific_occurrence, :specific_occurrence_const, :source_data_criteria, :variable
+ attr_accessor :id, :value, :field_values, :children_criteria, :effective_time, :status, :temporal_references, :subset_operators, :definition, :inline_code_list, :negation_code_list_id, :negation, :display_name, :comments
# Create a new data criteria instance
# @param [String] id
# @param [String] title
# @param [String] display_name
@@ -78,11 +85,13 @@
# @param [List<TemporalReference>] temporal_references
# @param [List<SubsetOperator>] subset_operators
# @param [String] specific_occurrence
# @param [String] specific_occurrence_const
# @param [String] source_data_criteria (id for the source data criteria, important for specific occurrences)
- def initialize(id, title, display_name, description, code_list_id, children_criteria, derivation_operator, definition, status, value, field_values, effective_time, inline_code_list, negation, negation_code_list_id, temporal_references, subset_operators, specific_occurrence, specific_occurrence_const, source_data_criteria=nil)
+ # @param [String] user comments for the criteria
+ # @param [Boolean] variable defines if the element is a QDM variable
+ def initialize(id, title, display_name, description, code_list_id, children_criteria, derivation_operator, definition, status, value, field_values, effective_time, inline_code_list, negation, negation_code_list_id, temporal_references, subset_operators, specific_occurrence, specific_occurrence_const, source_data_criteria=nil, comments=nil, variable=false)
status = normalize_status(definition, status)
@settings = HQMF::DataCriteria.get_settings_for_definition(definition, status)
@id = id
@@ -103,24 +112,19 @@
@temporal_references = temporal_references
@subset_operators = subset_operators
@specific_occurrence = specific_occurrence
@specific_occurrence_const = specific_occurrence_const
@source_data_criteria = source_data_criteria || id
+ @comments = comments
+ @variable = variable
end
# create a new data criteria given a category and sub_category. A sub category can either be a status or a sub category
def self.create_from_category(id, title, description, code_list_id, category, sub_category=nil, negation=false, negation_code_list_id=nil)
settings = HQMF::DataCriteria.get_settings_for_definition(category, sub_category)
HQMF::DataCriteria.new(id, title, nil, description, code_list_id, nil, nil, settings['definition'], settings['status'], nil, nil, nil, nil, negation, negation_code_list_id, nil, nil, nil,nil)
end
-
- def standard_category
- @settings['standard_category']
- end
- def qds_data_type
- @settings['qds_data_type']
- end
def type
@settings['category'].to_sym
end
def property
@settings['property'].to_sym unless @settings['property'].nil?
@@ -129,11 +133,17 @@
@settings['patient_api_function'].to_sym unless @settings['patient_api_function'].empty?
end
def hard_status
@settings['hard_status']
end
-
+ def update_copy(hard_status, title, description, derivation_operator, definition)
+ @settings['hard_status'] = hard_status
+ @title = title
+ @description = description
+ @derivation_operator = derivation_operator
+ @definition = definition
+ end
def definition=(definition)
@definition = definition
@settings = HQMF::DataCriteria.get_settings_for_definition(@definition, @status)
end
def status=(status)
@@ -161,30 +171,38 @@
temporal_references = json["temporal_references"].map {|reference| HQMF::TemporalReference.from_json(reference)} if json["temporal_references"]
subset_operators = json["subset_operators"].map {|operator| HQMF::SubsetOperator.from_json(operator)} if json["subset_operators"]
specific_occurrence = json['specific_occurrence'] if json['specific_occurrence']
specific_occurrence_const = json['specific_occurrence_const'] if json['specific_occurrence_const']
source_data_criteria = json['source_data_criteria'] if json['source_data_criteria']
+ comments = json['comments'] if json['comments']
+ variable = json['variable'] || false
HQMF::DataCriteria.new(id, title, display_name, description, code_list_id, children_criteria, derivation_operator, definition, status, value, field_values,
- effective_time, inline_code_list, negation, negation_code_list_id, temporal_references, subset_operators,specific_occurrence,specific_occurrence_const,source_data_criteria)
+ effective_time, inline_code_list, negation, negation_code_list_id, temporal_references, subset_operators,specific_occurrence,specific_occurrence_const,source_data_criteria, comments, variable)
end
+ def is_same_type?(criteria)
+ return @definition == criteria.definition && @hard_status == criteria.hard_status &&
+ @negation == criteria.negation && all_code_set_oids.sort == criteria.all_code_set_oids.sort
+ end
+
def to_json
json = base_json
{self.id.to_s.to_sym => json}
end
def base_json
x = nil
- json = build_hash(self, [:title,:display_name,:description,:standard_category,:qds_data_type,:code_list_id,:children_criteria, :derivation_operator, :property, :type, :definition, :status, :hard_status, :negation, :negation_code_list_id,:specific_occurrence,:specific_occurrence_const,:source_data_criteria])
+ json = build_hash(self, [:title,:display_name,:description,:code_list_id,:children_criteria, :derivation_operator, :property, :type, :definition, :status, :hard_status, :negation, :negation_code_list_id,:specific_occurrence,:specific_occurrence_const,:source_data_criteria,:variable])
json[:children_criteria] = @children_criteria unless @children_criteria.nil? || @children_criteria.empty?
json[:value] = ((@value.is_a? String) ? @value : @value.to_json) if @value
json[:field_values] = @field_values.inject({}) {|memo,(k,v)| memo[k] = (!v.nil? ? v.to_json : nil); memo} if @field_values
json[:effective_time] = @effective_time.to_json if @effective_time
json[:inline_code_list] = @inline_code_list if @inline_code_list
json[:temporal_references] = x if x = json_array(@temporal_references)
json[:subset_operators] = x if x = json_array(@subset_operators)
+ json[:comments] = @comments if @comments
json
end
def has_temporal(temporal_reference)
@temporal_references.reduce(false) {|found, item| found ||= item == temporal_reference }
@@ -257,12 +275,18 @@
referenced_oids
end
+ def self.get_settings_map
+ return @settings_map if @settings_map
+ settings_file = File.expand_path('../data_criteria.json', __FILE__)
+ @settings_map = JSON.parse(File.read(settings_file))
+ end
+
def self.get_settings_for_definition(definition, status)
settings_file = File.expand_path('../data_criteria.json', __FILE__)
- settings_map = JSON.parse(File.read(settings_file))
+ settings_map = get_settings_map
key = definition + ((status.nil? || status.empty?) ? '' : "_#{status}")
settings = settings_map[key]
raise "data criteria is not supported #{key}" if settings.nil? || settings["not_supported"]