File size: 4,167 Bytes
3f219b5 cb8dc08 3748deb 3f219b5 3748deb 3f219b5 3748deb 3f219b5 d93863b 92f1e06 71b9dff 89a368d 71b9dff 95b5634 5a90f65 71b9dff d93863b 71b9dff dc3c63a 34b4725 71b9dff a55bd7a dc3c63a c016b89 8ba1194 71b9dff 34b4725 aaa724e d93863b 496c5dc ef2aac1 496c5dc 6ee6b5e 496c5dc 0311a5a 496c5dc c770ab7 d93863b ec4c8b2 59c36fe cf5a59c 8548275 cf5a59c 8548275 d93863b 5bbeb93 9d78425 d8ed8f8 8548275 a0c1c94 0fc3ad2 8548275 0fc3ad2 8548275 83bf488 d93863b 43645d7 7e6cf75 43645d7 0311a5a b16857b 8548275 0311a5a dc3c63a c016b89 8ba1194 8548275 5f7f244 54601b7 5f7f244 92f1e06 5f7f244 d93863b 5505ef0 8f56351 e7215af 5505ef0 e7215af 50d1bef e7215af 5505ef0 3f219b5 e7215af 5505ef0 d93863b |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
defmodule MedicodeWeb.Components.TranscriptionTextComponent do
@moduledoc """
Represents a portion of transcribed text.
"""
use MedicodeWeb, :live_component
import MedicodeWeb.Components.KeywordHighlighter
alias Medicode.Transcriptions
alias MedicodeWeb.Components.CodeSelect
alias MedicodeWeb.Components.TranscriptionTextCodingsComponent
@impl Phoenix.LiveComponent
def mount(socket) do
{:ok, assign(socket, :code_vectors, [])}
end
@impl Phoenix.LiveComponent
def update_many(assigns_sockets) do
list_of_ids = Enum.map(assigns_sockets, fn {assigns, _sockets} -> assigns.chunk_id end)
chunks =
list_of_ids
|> Transcriptions.list_transcription_chunks()
|> Map.new()
Enum.map(assigns_sockets, fn {assigns, socket} ->
chunk = chunks[assigns.chunk_id]
socket
|> assign(:id, assigns.id)
|> assign(:current_user, assigns.current_user)
|> assign(:chunk, chunk)
|> assign(:on_feedback, assigns.on_feedback)
|> assign(:on_remove_code, assigns.on_remove_code)
|> assign(:on_finalize_code, assigns.on_finalize_code)
end)
end
@impl Phoenix.LiveComponent
def render(assigns) do
assigns =
assigns
|> assign_new(:classification_loading, fn ->
# NOTE: This assumes that if a process matches by transcription chunk ID that
# the chunk is in the process of loading. Specific state inspection could happen
# with the :sys module (ie :sys.get_state/1)
# case Registry.lookup({:via, :gproc, {:n, :l, {:transcription, transcription_id}}}) do
case [] do
[] -> false
[{_pid, _}] -> true
end
end)
# TODO: Adjust the blue border when editing
~H"""
<div id={@id} class="flex gap-12 py-12 border-b border-[#444444]/20">
<div class="flex-1 flex flex-col gap-4 w-1/2">
<p
:if={!is_nil(@chunk.start_mark) && !is_nil(@chunk.end_mark)}
class="px-2 text-[32px] leading-normal font-semibold"
>
<%= @chunk.start_mark %> - <%= @chunk.end_mark %>
</p>
<div class="flex-1 w-full text-[28px] leading-normal text-type-black-tertiary">
<!-- <p class="h-full min-h-full rounded p-2"><%= @chunk.text %></p> -->
<p
id={"#{@id}-transcription-text"}
contenteditable
role="textbox"
class="rounded p-2"
phx-hook="ContentEditor"
phx-target={@myself}
phx-event-name="reclassify_transcription"
>
<.highlight text={@chunk.text} keywords={@chunk.keywords} />
</p>
</div>
</div>
<div class="flex-1 flex flex-col items-stretch gap-3">
<img
:if={@classification_loading}
src={~p"/images/loading.svg"}
width="36"
class="m-4 animate-spin"
/>
<.live_component
module={TranscriptionTextCodingsComponent}
id={"#{@id}-codings"}
chunk_id={@chunk.id}
text={@chunk.text}
current_user={@current_user}
on_feedback={@on_feedback}
on_remove_code={@on_remove_code}
on_finalize_code={@on_finalize_code}
/>
<.live_component
:if={!@classification_loading}
module={CodeSelect}
id={"#{@id}-code-select"}
text={@chunk.text}
current_user={@current_user}
chunk={@chunk}
/>
</div>
</div>
"""
end
@impl Phoenix.LiveComponent
def handle_event("reclassify_transcription", %{"value" => new_chunk_text} = _params, socket) do
new_chunk_text_trimmed = String.trim(new_chunk_text)
if socket.assigns.chunk.text == new_chunk_text_trimmed do
{:noreply, socket}
else
{:ok, chunk} =
Transcriptions.update_transcription_chunk(socket.assigns.chunk, %{
text: new_chunk_text_trimmed,
text_vector: Medicode.Coding.compute_vector_as_list(new_chunk_text_trimmed)
})
Medicode.ClassificationSupervisor.start_classification(chunk)
{:noreply, assign(socket, :chunk, chunk)}
end
end
end
|