defmodule Medicode.ClassificationServerTest do @moduledoc """ Tests for Medicode.ClassificationServer """ use Medicode.DataCase import Medicode.TranscriptionsFixtures import Medicode.TranscriptionChunksFixtures import Medicode.CodeVectorsFixtures alias Medicode.Transcriptions alias Medicode.ClassificationServer setup do transcription = transcription_fixture() chunk = transcription_chunk_fixture(%{ transcription_id: transcription.id, text: "patient is suffering Typhoid fever" }) insert_code_vector_fixtures() %{chunk: chunk, transcription: transcription} end test "extract keywords and assign medical codes", %{chunk: chunk, transcription: transcription} do spec = {ClassificationServer, {:chunk, chunk}} {:ok, pid} = start_supervised(spec, restart: :transient) ref = Process.monitor(pid) assert_receive({:DOWN, ^ref, :process, _object, _pid}, 5_000) chunks = transcription.id |> Transcriptions.get_transcription!(true) |> Map.fetch!(:chunks) keywords = Enum.flat_map(chunks, & &1.keywords) code_vectors = Enum.flat_map(chunks, & &1.code_vectors) assert 2 == Enum.count(keywords) assert 2 == Enum.count(code_vectors) end end