Skip to content

Instantly share code, notes, and snippets.

@philsmy
Created May 11, 2020 06:06
Show Gist options
  • Save philsmy/63c59d11e8af26836333de79ce00d969 to your computer and use it in GitHub Desktop.
Save philsmy/63c59d11e8af26836333de79ce00d969 to your computer and use it in GitHub Desktop.
Class to read in patient data
# frozen_string_literal: true
require 'csv'
class PatientDatum < ApplicationRecord
def self.import_from_csv
columns = %i[external_id episode_date age_group gender acquisition_info outcome reporter reporter_address reporter_city reporter_postal_code reporter_website reporter_latitude reporter_longitude country region]
upsert_columns = %i[episode_date age_group gender acquisition_info outcome reporter reporter_address reporter_city reporter_postal_code reporter_website reporter_latitude reporter_longitude]
values = CSV.read(Rails.root.join('data/conposcovidloc.csv'))[1..-1]
(0..(values.size - 1)).each do |i|
values[i] << 'CA'
values[i] << 'ON'
end
patients = PatientDatum.import columns, values, on_duplicate_key_update: {conflict_target: [:external_id, :country ,:region], columns: upsert_columns}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment