Class: HQMF2::SpecificOccurrenceAndSource
- Inherits:
-
Object
- Object
- HQMF2::SpecificOccurrenceAndSource
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb
Overview
Handles various tasks that the Data Criteria needs performed to obtain and modify secific occurrences
Instance Method Summary collapse
-
#extract_specific_occurrences_and_source_data_criteria ⇒ Object
Retrieve the specific occurrence and source data criteria information (or just source if there is no specific).
-
#handle_occurrence_var(stripped_id, stripped_lvn, stripped_sdc, occurrence_id_compare, occurrence_lvn_compare, occ_index) ⇒ Object
If the occurrence is a variable, extract the occurrence identifier (if present).
-
#handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) ⇒ Object
Handle setting the specific and source instance variables with a given occurrence identifier.
-
#initialize(entry, id, local_variable_name, data_criteria_references, occurrences_map) ⇒ SpecificOccurrenceAndSource
constructor
A new instance of SpecificOccurrenceAndSource.
-
#obtain_occurrence_identifier(stripped_id, stripped_lvn, stripped_sdc, is_variable) ⇒ Object
Using the id, source data criteria id, and local variable name (and whether or not it’s a variable), extract the occurrence identifiter (if one exists).
Methods included from Utilities
#attr_val, attr_val, #strip_tokens, #to_xml
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(entry, id, local_variable_name, data_criteria_references, occurrences_map) ⇒ SpecificOccurrenceAndSource
Returns a new instance of SpecificOccurrenceAndSource.
7 8 9 10 11 12 13 14 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb', line 7 def initialize(entry, id, local_variable_name, data_criteria_references, occurrences_map) @entry = entry @id = id @local_variable_name = local_variable_name @occurrences_map = occurrences_map @is_variable = DataCriteriaMethods.extract_variable(@local_variable_name, @id) @data_criteria_references = data_criteria_references end |
Instance Method Details
#extract_specific_occurrences_and_source_data_criteria ⇒ Object
Retrieve the specific occurrence and source data criteria information (or just source if there is no specific)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb', line 17 def extract_specific_occurrences_and_source_data_criteria specific_def = @entry.at_xpath('./*/cda:outboundRelationship[@typeCode="OCCR"]', HQMF2::Document::NAMESPACES) source_def = @entry.at_xpath('./*/cda:outboundRelationship[cda:subsetCode/@code="SOURCE"]', HQMF2::Document::NAMESPACES) if specific_def source_data_criteria_extension = HQMF2::Utilities.attr_val(specific_def, './cda:criteriaReference/cda:id/@extension') source_data_criteria_root = HQMF2::Utilities.attr_val(specific_def, './cda:criteriaReference/cda:id/@root') occurrence_criteria = @data_criteria_references[strip_tokens("#{source_data_criteria_extension}_#{source_data_criteria_root}")] return if occurrence_criteria.nil? specific_occurrence_const = HQMF2::Utilities.attr_val(specific_def, './cda:localVariableName/@controlInformationRoot') specific_occurrence = HQMF2::Utilities.attr_val(specific_def, './cda:localVariableName/@controlInformationExtension') # FIXME: Remove debug statements after cleaning up occurrence handling # build regex for extracting alpha-index of specific occurrences occurrence_identifier = obtain_occurrence_identifier(strip_tokens(@id), strip_tokens(@local_variable_name) || '', strip_tokens(source_data_criteria_extension), @is_variable) handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) elsif source_def extension = HQMF2::Utilities.attr_val(source_def, './cda:criteriaReference/cda:id/@extension') root = HQMF2::Utilities.attr_val(source_def, './cda:criteriaReference/cda:id/@root') ["#{extension}_#{root}_source", root, extension] # return the soruce data criteria itself, the rest will be blank end end |
#handle_occurrence_var(stripped_id, stripped_lvn, stripped_sdc, occurrence_id_compare, occurrence_lvn_compare, occ_index) ⇒ Object
If the occurrence is a variable, extract the occurrence identifier (if present)
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb', line 106 def handle_occurrence_var(stripped_id, stripped_lvn, stripped_sdc, occurrence_id_compare, occurrence_lvn_compare, occ_index) # TODO: Handle specific occurrences of variables that don't self-reference? if stripped_id.match(/^#{occurrence_id_compare}/) return stripped_id[occ_index] elsif stripped_lvn.match(/^#{occurrence_lvn_compare}/) return stripped_lvn[occ_index] elsif stripped_sdc.match(/^#{occurrence_id_compare}/) return stripped_sdc[occ_index] end end |
#handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) ⇒ Object
Handle setting the specific and source instance variables with a given occurrence identifier
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb', line 52 def handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) source_data_criteria = "#{source_data_criteria_extension}_#{source_data_criteria_root}_source" if !occurrence_identifier.blank? # if it doesn't exist, add extracted occurrence to the map # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier specific_occurrence ||= occurrence_identifier specific_occurrence_const = "#{source_data_criteria}".upcase else # create variable occurrences that do not already exist if @is_variable # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier end occurrence = @occurrences_map.try(:[], strip_tokens(source_data_criteria)) unless occurrence fail "Could not find occurrence mapping for #{source_data_criteria}, #{source_data_criteria_root}" end # puts "\tUsing #{occurrence} for #{@id}" specific_occurrence ||= occurrence end specific_occurrence = 'A' unless specific_occurrence specific_occurrence_const = source_data_criteria.upcase unless specific_occurrence_const [source_data_criteria, source_data_criteria_root, source_data_criteria_extension, specific_occurrence, specific_occurrence_const] end |
#obtain_occurrence_identifier(stripped_id, stripped_lvn, stripped_sdc, is_variable) ⇒ Object
Using the id, source data criteria id, and local variable name (and whether or not it’s a variable),
extract the occurrence identifiter (if one exists).
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb', line 83 def obtain_occurrence_identifier(stripped_id, stripped_lvn, stripped_sdc, is_variable) if is_variable || (stripped_sdc.include? 'qdm_var') occurrence_lvn_regex = 'occ[A-Z]of_qdm_var' occurrence_id_regex = 'occ[A-Z]of_qdm_var' occ_index = 3 return handle_occurrence_var(stripped_id, stripped_lvn, stripped_sdc, occurrence_id_regex, occurrence_lvn_regex, occ_index) else occurrence_lvn_regex = 'Occurrence[A-Z]of' occurrence_id_regex = 'Occurrence[A-Z]_' occ_index = 10 occurrence_identifier = handle_occurrence_var( stripped_id, stripped_lvn, stripped_sdc, "#{occurrence_id_regex}#{stripped_sdc}", "#{occurrence_lvn_regex}#{stripped_sdc}", occ_index) return occurrence_identifier if occurrence_identifier.present? stripped_sdc[occ_index] if stripped_sdc.match( /(^#{occurrence_id_regex}| ^#{occurrence_id_regex}qdm_var_| ^#{occurrence_lvn_regex})| ^#{occurrence_lvn_regex}qdm_var_/) end end |