Class: HQMF::Coded

Inherits:
Object
  • Object
show all
Defined in:
lib/tpg/ext/coded.rb

Class Method Summary collapse

Class Method Details

.select_code(oid, value_sets) ⇒ Object

Select the relevant value set that matches the given OID and generate a hash that can be stored on a Record. The hash will be of this format: { “codeSystem” => “code_set_identified”, “code” => code }

Parameters:

  • oid (String)

    The target value set.

  • value_sets (Hash)

    Value sets that might contain the OID for which we’re searching.

Returns:

  • A Hash including a code and code system containing one randomly selected code.



36
37
38
39
40
41
42
43
44
# File 'lib/tpg/ext/coded.rb', line 36

def self.select_code(oid, value_sets)
  codes = select_codes(oid, value_sets)
  code_system = codes.keys()[0]
  return nil if code_system.nil?
  {
    'code_system' => code_system,
    'code' => codes[code_system][0]
  }
end

.select_codes(oid, value_sets) ⇒ Object

Select the relevant value set that matches the given OID and generate a hash that can be stored on a Record. The hash will be of this format: { “code_set_identified” => [code] }

Parameters:

  • oid (String)

    The target value set.

  • value_sets (Hash)

    Value sets that might contain the OID for which we’re searching.

Returns:

  • A Hash of code sets corresponding to the given oid, each containing one randomly selected code.



9
10
11
12
13
14
15
16
# File 'lib/tpg/ext/coded.rb', line 9

def self.select_codes(oid, value_sets)
  value_sets = HQMF::Coded.select_value_sets(oid, value_sets)
  code_sets = {}
  value_sets["concepts"].each do |concept|
    code_sets[concept["code_system_name"]] ||= [concept["code"]]
  end
  code_sets
end

.select_value_sets(oid, value_sets) ⇒ Object

Filter through a list of value sets and choose only the ones marked with a given OID.

Parameters:

  • oid (String)

    The OID being used for filtering.

  • value_sets (Array)

    A pool of available value sets

Returns:

  • The value set from the list with the requested OID.



23
24
25
26
27
28
# File 'lib/tpg/ext/coded.rb', line 23

def self.select_value_sets(oid, value_sets)
  # Pick the value set for this DataCriteria. If it can't be found, it is an error from the value set source. We'll add the entry without codes for now.
  index = value_sets.index{|value_set| value_set["oid"] == oid}
  value_sets = index.nil? ? { "concepts" => [] } : value_sets[index]
  value_sets
end