medicode / test /support /fixtures /code_vectors_fixtures.ex
timgremore's picture
chore: Rename app to Medicode
3f219b5
raw
history blame
1.37 kB
defmodule Medicode.CodeVectorsFixtures do
@moduledoc """
This module defines test helpers for creating %CodeVector{}
entities via the `Medicode.Coding` context.
"""
@doc """
Insert code vectors from cached csv file.
"""
def insert_code_vector_fixtures() do
code_vectors =
"../../../code_vectors.csv"
|> Path.expand(__DIR__)
|> File.stream!()
|> CSV.decode(headers: true)
|> Enum.take(5)
|> 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
)
end
def code_vector_fixture() do
{:ok, code_vector} =
%Medicode.Coding.CodeVector{
code: "ABC",
description: "My vector description",
description_vector: Enum.to_list(1..384)
}
|> Medicode.Repo.insert()
code_vector
end
end