defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do @moduledoc """ Represents a portion of transcribed text. Once rendered, starts tasks to find relevant codes and keywords for the text. """ use MedicalTranscriptionWeb, :live_component import MedicalTranscriptionWeb.Components import MedicalTranscriptionWeb.Components.KeywordHighlighter alias AudioTagger.KeywordFinder alias MedicalTranscription.Coding alias MedicalTranscription.Coding.CodeVectorMatch @impl Phoenix.LiveComponent def update(assigns, socket) do socket = assign_initial_state(assigns, socket) {:ok, socket} end defp assign_initial_state(%{start_mark: start_mark, end_mark: end_mark, text: text}, socket) do self_pid = self() initial_state = %{ start_mark: start_mark, end_mark: end_mark, text: text, editing: false } socket |> assign(initial_state) |> assign_async(:tags, fn -> classify_text(text) end) |> assign_async(:keywords, fn -> find_keywords(self_pid, text) end) end defp assign_initial_state(_assigns, socket), do: socket @impl Phoenix.LiveComponent def render(assigns) do ~H"""
<%= if !is_nil(@start_mark) && !is_nil(@end_mark) do %> <%= @start_mark %> - <%= @end_mark %> <% end %>
<.async_result :let={keywords} assign={@keywords}> <:loading><%= @text %> <%= if @editing do %> <% else %>