Commit ·
92f1e06
1
Parent(s): a3e56a7
chore: Move code_vectors state to parent component
Browse files
lib/medical_transcription_web/components/code_select.ex
CHANGED
|
@@ -23,7 +23,7 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 23 |
|
| 24 |
@impl Phoenix.LiveComponent
|
| 25 |
def update(
|
| 26 |
-
%{id: id, text: text, current_user: current_user,
|
| 27 |
socket
|
| 28 |
) do
|
| 29 |
form = to_form(%{"search_term" => ""}, as: id)
|
|
@@ -33,7 +33,7 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 33 |
|> assign(:form, form)
|
| 34 |
|> assign(:text, text)
|
| 35 |
|> assign(:current_user, current_user)
|
| 36 |
-
|> assign(:
|
| 37 |
|
| 38 |
{:ok, socket}
|
| 39 |
end
|
|
@@ -114,15 +114,14 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 114 |
Transcriptions.upsert_code_vector_for_transcription_chunk(%{
|
| 115 |
assigned_by_user_id: socket.assigns.current_user.id,
|
| 116 |
code_vector_id: selected_code.id,
|
| 117 |
-
transcription_chunk_id: socket.assigns.
|
| 118 |
cosine_similarity: 1.0
|
| 119 |
})
|
| 120 |
|
| 121 |
-
send_update(MedicalTranscriptionWeb.Components.
|
| 122 |
-
id: "transcription-chunk-#{socket.assigns.
|
| 123 |
-
|
| 124 |
-
current_user: socket.assigns.current_user
|
| 125 |
-
text: socket.assigns.text
|
| 126 |
)
|
| 127 |
|
| 128 |
socket =
|
|
|
|
| 23 |
|
| 24 |
@impl Phoenix.LiveComponent
|
| 25 |
def update(
|
| 26 |
+
%{id: id, text: text, current_user: current_user, chunk: chunk} = _assigns,
|
| 27 |
socket
|
| 28 |
) do
|
| 29 |
form = to_form(%{"search_term" => ""}, as: id)
|
|
|
|
| 33 |
|> assign(:form, form)
|
| 34 |
|> assign(:text, text)
|
| 35 |
|> assign(:current_user, current_user)
|
| 36 |
+
|> assign(:chunk, chunk)
|
| 37 |
|
| 38 |
{:ok, socket}
|
| 39 |
end
|
|
|
|
| 114 |
Transcriptions.upsert_code_vector_for_transcription_chunk(%{
|
| 115 |
assigned_by_user_id: socket.assigns.current_user.id,
|
| 116 |
code_vector_id: selected_code.id,
|
| 117 |
+
transcription_chunk_id: socket.assigns.chunk.id,
|
| 118 |
cosine_similarity: 1.0
|
| 119 |
})
|
| 120 |
|
| 121 |
+
send_update(MedicalTranscriptionWeb.Components.TranscriptionTextComponent,
|
| 122 |
+
id: "transcription-chunk-#{socket.assigns.chunk.id}",
|
| 123 |
+
chunk: socket.assigns.chunk,
|
| 124 |
+
current_user: socket.assigns.current_user
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
socket =
|
lib/medical_transcription_web/components/transcription_chunk_codings_component.ex
CHANGED
|
@@ -7,18 +7,6 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextCodingsComponent d
|
|
| 7 |
alias MedicalTranscription.Coding
|
| 8 |
alias MedicalTranscription.Feedback
|
| 9 |
|
| 10 |
-
@impl Phoenix.LiveComponent
|
| 11 |
-
def update(assigns, socket) do
|
| 12 |
-
socket =
|
| 13 |
-
socket
|
| 14 |
-
|> assign(:code_vectors, list_transcription_chunk_code_vectors(assigns.chunk_id))
|
| 15 |
-
|> assign(:chunk_id, assigns.chunk_id)
|
| 16 |
-
|> assign(:text, assigns.text)
|
| 17 |
-
|> assign(:current_user, assigns.current_user)
|
| 18 |
-
|
| 19 |
-
{:ok, socket}
|
| 20 |
-
end
|
| 21 |
-
|
| 22 |
@impl Phoenix.LiveComponent
|
| 23 |
def render(assigns) do
|
| 24 |
~H"""
|
|
@@ -55,8 +43,4 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextCodingsComponent d
|
|
| 55 |
|
| 56 |
{:noreply, socket}
|
| 57 |
end
|
| 58 |
-
|
| 59 |
-
defp list_transcription_chunk_code_vectors(chunk_id) do
|
| 60 |
-
MedicalTranscription.Transcriptions.list_transcription_chunk_code_vectors(chunk_id)
|
| 61 |
-
end
|
| 62 |
end
|
|
|
|
| 7 |
alias MedicalTranscription.Coding
|
| 8 |
alias MedicalTranscription.Feedback
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
@impl Phoenix.LiveComponent
|
| 11 |
def render(assigns) do
|
| 12 |
~H"""
|
|
|
|
| 43 |
|
| 44 |
{:noreply, socket}
|
| 45 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
end
|
lib/medical_transcription_web/components/transcription_text_component.ex
CHANGED
|
@@ -10,6 +10,11 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 10 |
alias MedicalTranscriptionWeb.Components.CodeSelect
|
| 11 |
alias MedicalTranscriptionWeb.Components.TranscriptionTextCodingsComponent
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@impl Phoenix.LiveComponent
|
| 14 |
def update_many(assigns_sockets) do
|
| 15 |
list_of_ids = Enum.map(assigns_sockets, fn {assigns, _sockets} -> assigns.chunk_id end)
|
|
@@ -20,10 +25,16 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 20 |
|> Map.new()
|
| 21 |
|
| 22 |
Enum.map(assigns_sockets, fn {assigns, socket} ->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
socket
|
| 24 |
|> assign(:id, assigns.id)
|
| 25 |
|> assign(:current_user, assigns.current_user)
|
| 26 |
|> assign(:chunk, chunks[assigns.chunk_id])
|
|
|
|
| 27 |
end)
|
| 28 |
end
|
| 29 |
|
|
@@ -83,6 +94,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 83 |
chunk_id={@chunk.id}
|
| 84 |
text={@chunk.text}
|
| 85 |
current_user={@current_user}
|
|
|
|
| 86 |
/>
|
| 87 |
<.live_component
|
| 88 |
:if={!@classification_loading}
|
|
@@ -90,7 +102,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 90 |
id={"#{@id}-code-select"}
|
| 91 |
text={@chunk.text}
|
| 92 |
current_user={@current_user}
|
| 93 |
-
|
| 94 |
/>
|
| 95 |
</div>
|
| 96 |
</div>
|
|
@@ -110,6 +122,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 110 |
})
|
| 111 |
|
| 112 |
MedicalTranscription.ClassificationSupervisor.start_classification(chunk)
|
|
|
|
| 113 |
|
| 114 |
{:noreply, assign(socket, :chunk, chunk)}
|
| 115 |
end
|
|
|
|
| 10 |
alias MedicalTranscriptionWeb.Components.CodeSelect
|
| 11 |
alias MedicalTranscriptionWeb.Components.TranscriptionTextCodingsComponent
|
| 12 |
|
| 13 |
+
@impl Phoenix.LiveComponent
|
| 14 |
+
def mount(socket) do
|
| 15 |
+
{:ok, assign(socket, :code_vectors, [])}
|
| 16 |
+
end
|
| 17 |
+
|
| 18 |
@impl Phoenix.LiveComponent
|
| 19 |
def update_many(assigns_sockets) do
|
| 20 |
list_of_ids = Enum.map(assigns_sockets, fn {assigns, _sockets} -> assigns.chunk_id end)
|
|
|
|
| 25 |
|> Map.new()
|
| 26 |
|
| 27 |
Enum.map(assigns_sockets, fn {assigns, socket} ->
|
| 28 |
+
code_vectors =
|
| 29 |
+
MedicalTranscription.Transcriptions.list_transcription_chunk_code_vectors(
|
| 30 |
+
assigns.chunk_id
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
socket
|
| 34 |
|> assign(:id, assigns.id)
|
| 35 |
|> assign(:current_user, assigns.current_user)
|
| 36 |
|> assign(:chunk, chunks[assigns.chunk_id])
|
| 37 |
+
|> assign(:code_vectors, code_vectors)
|
| 38 |
end)
|
| 39 |
end
|
| 40 |
|
|
|
|
| 94 |
chunk_id={@chunk.id}
|
| 95 |
text={@chunk.text}
|
| 96 |
current_user={@current_user}
|
| 97 |
+
code_vectors={@code_vectors}
|
| 98 |
/>
|
| 99 |
<.live_component
|
| 100 |
:if={!@classification_loading}
|
|
|
|
| 102 |
id={"#{@id}-code-select"}
|
| 103 |
text={@chunk.text}
|
| 104 |
current_user={@current_user}
|
| 105 |
+
chunk={@chunk}
|
| 106 |
/>
|
| 107 |
</div>
|
| 108 |
</div>
|
|
|
|
| 122 |
})
|
| 123 |
|
| 124 |
MedicalTranscription.ClassificationSupervisor.start_classification(chunk)
|
| 125 |
+
|> dbg()
|
| 126 |
|
| 127 |
{:noreply, assign(socket, :chunk, chunk)}
|
| 128 |
end
|