Sha256: cc739ce4ee35d0250f96ae14b8c1c694ea6f06ed34981b084145638d274c68e8

Contents?: true

Size: 1.5 KB

Versions: 36

Compression:

Stored size: 1.5 KB

Contents

module HQMF1
  module Utilities
    
    include HQMF::Conversion::Utilities
    
    # Utility function to handle optional attributes
    # @param xpath an XPath that identifies an XML attribute
    # @return the value of the attribute or nil if the attribute is missing
    def attr_val(xpath)
      attr = @entry.at_xpath(xpath)
      if attr
        attr.value
      else
        nil
      end
    end
    
    def clean_json(json)
      json.reject!{|k,v| v.nil? || (v.respond_to?(:empty?) && v.empty?)}
    end
    
    def clean_json_recursive(json)
      json.each do |k,v|
        if v.is_a? Hash
          clean_json_recursive(v)
          clean_json(v)
        elsif v.is_a? Array
          v.each do |e|
            if e.is_a? Hash
              clean_json_recursive(e)
              clean_json(e)
            end
          end
        end
        
      end
      clean_json(json)
    end

    # Preconditions can have nil conjunctions as part of a DATEDIFF, we want to remove these and warn
    def check_nil_conjunction_on_child
      if (@preconditions.length == 1 && @preconditions.first.conjunction.nil?)
        bad_precondition = @preconditions.first
        if (bad_precondition.restrictions.empty? && bad_precondition.subset.nil? && bad_precondition.expression.nil?)
          @preconditions = @preconditions.first.preconditions
          #puts "\t FIXED PRECONDITION WITHOUT CONJUNCTION"
        else
          puts "\t PRECONDITION WITHOUT CONJUNCTION: Cannot be fixed"
        end
      end
    end

    
  end
end  

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
cqm-parsers-4.1.1.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-4.1.0.2 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-4.1.0.1 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-4.1.0.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-4.0.0.1 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.2.0.2 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-4.0.0.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.2.0.1 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.2.0.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.1.1.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.1.0.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-3.0.0.0 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-2.0.1 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-0.2.4 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-2.0.0 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-4.3.5 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-0.2.3 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-4.3.4 lib/hqmf-parser/1.0/utilities.rb
cqm-parsers-0.2.2 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-4.3.3 lib/hqmf-parser/1.0/utilities.rb