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(attrs \\ %{}) do {:ok, code_vector} = attrs |> Enum.into(%{ code: "ABC", description: "My vector description", description_vector: Enum.to_list(1..384) }) |> Medicode.Coding.create_code_vector() code_vector end end