File size: 1,110 Bytes
d77a9fd
 
 
 
 
 
 
3f219b5
d77a9fd
 
 
5579301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f219b5
 
5579301
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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
)