Sha256: bd885c7d5531cc7bdcbdef5113eb4b22f7de44f9d8d442016195bb4b423e8696

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

module ProviderImportUtils
  
  def extract_provider(performer, element_name="assignedEntity")
    provider_data = extract_provider_data(performer, false, "./cda:#{element_name}")
    find_or_create_provider(provider_data)
  end
  
  def find_or_create_provider(provider_hash)
    provider = Provider.by_npi(provider_hash[:npi]).first if provider_hash[:npi] && !provider_hash[:npi].empty?
    unless provider
      if provider_hash[:npi]
        provider = Provider.create(provider_hash)
        provider.npi = provider_hash[:npi]
      else
        provider ||= Provider.resolve_provider(provider_hash) if Provider.respond_to? :resolve_provider

        ident_roots = provider_hash[:cda_identifiers].map {|ident| ident.root}
        ident_extensions = provider_hash[:cda_identifiers].map {|ident| ident.extension}
        unless ident_roots.size == 0
          provider ||= Provider.in("cda_identifiers.root" => ident_roots).and.in("cda_identifiers.extension" => ident_extensions).first
        end
        provider_query = {:title => provider_hash[:title],            
                            :given_name => provider_hash[:given_name],  
                            :family_name=> provider_hash[:family_name],
                            :specialty => provider_hash[:specialty]}
        provider ||= Provider.where(provider_query).first
        provider ||= Provider.create(provider_hash)
      end
    end
    provider 
  end

  # Returns nil if result is an empty string, block allows text munging of result if there is one
  def extract_data(subject, query)
    result = subject.at_xpath(query)
    if result.nil? || result.content.empty?
      nil
    else
      result.content
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
health-data-standards-3.4.4 lib/health-data-standards/import/provider_import_utils.rb
health-data-standards-3.4.3 lib/health-data-standards/import/provider_import_utils.rb
health-data-standards-3.4.2 lib/health-data-standards/import/provider_import_utils.rb