Skip to content

Instantly share code, notes, and snippets.

@zerokarmaleft
Forked from laod/medicat.rb
Last active December 14, 2015 06:39
Show Gist options
  • Save zerokarmaleft/5044335 to your computer and use it in GitHub Desktop.
Save zerokarmaleft/5044335 to your computer and use it in GitHub Desktop.
map = [
#general
{name: "Patient Control ID", value: nil},
{name: "SSN", value: nil},
{name: "Other ID", source: :ldap, source_name: "datatelid"},
{name: "Last Name", source: :ldap, source_name: "sn"},
{name: "First Name", source: :ldap, source_name: "givenName"},
{name: "Middle Initial", source: :ldap, source_name: "initials", mapper: Proc.new {|v| v[0]}},
{name: "Sex", source_name: "gender", source: :ods},
{name: "Address", source: :ods, source_name: ["home_address_line_1","home_address_line_2"], mapper: Proc.new{|v| v.join " "}},
{name: "City", source_name: "home_address_city", source: :ods},
{name: "State", source_name: "home_address_state", source: :ods},
{name: "Zip Code", source_name: "home_address_zip", source: :ods, mapper: Proc.new{|v| v.delete '-'}},
{name: "Home Phone", value: nil},
{name: "Work Phone", value: nil},
{name: "Cell Phone", source_name: "cell_phone", source: :ods},
{name: "Date of Birth", source_name: "birthday", source: :ods, mapper: Proc.new {|v| [1,2,0].map{|i| v.split('-')[i]}.join('/')}},
{name: "Marital Status", value: 7},
{name: "Employment", value: 1},
{name: "Employer Code", value: 1},
{name: "Email Address", source: :ldap, source_name: "primaryMail"},
{name: "Eligibility", value: 1},
# students
{name: "Campus Address", source_name: "local_address_line_1", source: :ods},
{name: "Permanent Address", source: :ods, source_name: "home_address_line_1"},
{name: "Permanent City", source_name: "home_address_city", source: :ods},
{name: "Permanent State", source_name: "home_address_state", source: :ods},
{name: "Permanent Zip Code", source_name: "home_address_zip", source: :ods},
{name: "Permanent Country", source_name: "home_address_country", source: :ods},
{name: "Permanent Phone", value: nil},
{name: "Foreign Student", value: 1},
{name: "Visa Type", value: nil},
{name: "Major", source: :ods, source_name: "major1"},
{name: "Standing", source_name: "academic_level", source: :ods},
{name: "Class", value: nil},
{name: "Enrollment Date", value: nil},
{name: "Student Status", value: nil},
{name: "School", source_name: "academic_program", source: :ods},
{name: "Residency", value: 1},
# misc
{name: "Race", value: 8},
{name: "Ethnicity", value: nil},
{name: "EmerName", value: nil},
{name: "EmerPhone1", value: nil},
{name: "EmerRelationship", value: nil},
]
@attrs = map.select{|f| f[:source] == :ldap}
.map{|f| f.include?(:source_name) ? f[:source_name] : f[:name]}
# SOME TOP SECRET LDAP AND MSSQL STUFF WAS HERE
def lookup(uid)
#builds hash[source][name] = value from the various sources by uid
end
CSV.open("medicat.psv", "wb", {col_sep: "|", headers: true}) do |csv|
csv << map.map {|f| f[:name]}
ARGF.each do |uid|
uid.strip!
p uid
r = lookup uid
csv << map.map do |field|
if field.include? :value
field[:value]
else
# TODO: make this more functional: maybe wrap/unwrap if needed before/after
names = [] << field[:source_name] ||= field[:name]
values = names.map {|f| r[field[:source]][f] || ''}
mapped = field.include?(:mapper) ? field[:mapper].call(values) : values
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment