medicode / priv /repo /seeds.exs
timgremore's picture
chore: Rename app to Medicode
3f219b5
raw
history blame
1.11 kB
# Script for populating the database. You can run it as:
#
# mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
# Medicode.Repo.insert!(%Medicode.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
# Populate code_vectors with cached version of ICD-9 codes
code_vectors =
"../../code_vectors.csv"
|> Path.expand(__DIR__)
|> File.stream!()
|> CSV.decode(headers: true)
|> Enum.map(fn {:ok,
%{
"code" => code,
"description" => description,
"description_vector" => description_vector
}} ->
vector =
description_vector
|> String.replace_prefix("[", "")
|> String.replace_suffix("]", "")
|> String.split(",")
|> Enum.map(&String.to_float/1)
|> Pgvector.new()
%{code: code, description: description, description_vector: vector}
end)
Medicode.Repo.insert_all(
Medicode.Coding.CodeVector,
code_vectors
)