Class: HQMF::ValueSet::Parser
- Inherits:
-
Object
- Object
- HQMF::ValueSet::Parser
- Defined in:
- lib/hqmf-parser/value_sets/value_set_parser.rb
Constant Summary collapse
- GROUP_CODE_SET =
"GROUPING"
- ORGANIZATION_TITLE =
"Value Set Developer"
- OID_TITLE =
"Value Set OID"
- CONCEPT_TITLE =
"Value Set Name"
- CATEGORY_TITLE =
"QDM Category"
- CODE_SET_TITLE =
"Code System"
- VERSION_TITLE =
"Code System Version"
- CODE_TITLE =
"Code"
- DESCRIPTION_TITLE =
"Descriptor"
- CODE_SYSTEM_NORMALIZER =
{ 'ICD-9'=>'ICD-9-CM', 'ICD-10'=>'ICD-10-CM', 'HL7 (2.16.840.1.113883.5.1)'=>'HL7' }
- IGNORED_CODE_SYSTEM_NAMES =
['Grouping', 'GROUPING' ,'HL7', "Administrative Sex"]
Class Method Summary collapse
Instance Method Summary collapse
- #adopt_orphan(orphan) ⇒ Object
-
#cells_to_hashs_by_oid(array) ⇒ Object
take an excel matrix array and turn it into an array of db models.
- #collapse_groups(by_oid_ungrouped) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse(file, options = {}) ⇒ Object
import an excel matrix array into mongo.
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
29 30 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 29 def initialize() end |
Class Method Details
.get_format(file_path) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 108 def self.get_format(file_path) if file_path =~ /xls$/ :xls elsif file_path =~ /xlsx$/ :xlsx end end |
Instance Method Details
#adopt_orphan(orphan) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 78 def adopt_orphan(orphan) parent = orphan.dup parent["code_sets"] = [orphan] parent.delete("codes") parent.delete("code_set") parent end |
#cells_to_hashs_by_oid(array) ⇒ Object
take an excel matrix array and turn it into an array of db models
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 87 def cells_to_hashs_by_oid(array) a = Array.new(array) # new variable for reentrant headers = a.shift.map {|i| i.to_s } # because of this shift string_data = a.map {|row| row.map {|cell| cell.to_s } } array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] } by_oid = {} array_of_hashes.each do |row| entry = convert_row(row) existing = by_oid[entry["oid"]] if (existing) existing["codes"].concat(entry["codes"]) else by_oid[entry["oid"]] = entry end end by_oid end |
#collapse_groups(by_oid_ungrouped) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 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 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 39 def collapse_groups(by_oid_ungrouped) final = [] # select the grouped code sets and fill in the children... also remove the children that are a # member of a group. We remove the children so that we can create parent groups for the orphans (by_oid_ungrouped.select {|key,value| value["code_set"].upcase == GROUP_CODE_SET}).each do |key, value| # remove the group so that it is not in the orphan list by_oid_ungrouped.delete(value["oid"]) codes = [] value["codes"].each do |child_oid| # codes << by_oid_ungrouped.delete(child_oid) # do not delete the children of a group. These may be referenced by other groups or directly by the measure code = by_oid_ungrouped[child_oid] puts "\tcode could not be found: #{child_oid}" unless code codes << code if code # for hierarchies we need to probably have codes be a hash that we select from if we don't find the # element in by_oid_ungrouped we may need to look for it in final end value["code_sets"] = codes value.delete("codes") value.delete("code_set") final << value end # fill out the orphans by_oid_ungrouped.each do |key, orphan| final << adopt_orphan(orphan) end deleted = [] final.delete_if {|x| to_delete = x['code_sets'].nil? || x['code_sets'].empty?; deleted << x if to_delete; to_delete } deleted.each do |value| puts "\tDeleted value set with no code sets: #{value['oid']}" end final end |
#parse(file, options = {}) ⇒ Object
import an excel matrix array into mongo
33 34 35 36 37 |
# File 'lib/hqmf-parser/value_sets/value_set_parser.rb', line 33 def parse(file, ={}) sheet_array = file_to_array(file, ) by_oid_ungrouped = cells_to_hashs_by_oid(sheet_array) collapse_groups(by_oid_ungrouped) end |