Noah Settersten commited on
Commit ·
f296c58
1
Parent(s): 278333f
feat: Record code feedback when user manually enters code
Browse files
lib/medical_transcription/feedback.ex
CHANGED
|
@@ -19,6 +19,22 @@ defmodule MedicalTranscription.Feedback do
|
|
| 19 |
end
|
| 20 |
end
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
defp message_for_response(params) do
|
| 23 |
action = if params["response"] == "true", do: "upvoted", else: "downvoted"
|
| 24 |
|
|
|
|
| 19 |
end
|
| 20 |
end
|
| 21 |
|
| 22 |
+
def insert_and_return(params) do
|
| 23 |
+
changeset = CodeFeedback.changeset(%CodeFeedback{}, params)
|
| 24 |
+
|
| 25 |
+
case Repo.insert(changeset) do
|
| 26 |
+
{:ok, code_feedback} -> code_feedback
|
| 27 |
+
{:error, _changeset} -> nil
|
| 28 |
+
end
|
| 29 |
+
end
|
| 30 |
+
|
| 31 |
+
def delete(id) do
|
| 32 |
+
case Repo.delete(id) do
|
| 33 |
+
{:ok, _code_feedback} -> {:ok, "Deleted code feedback."}
|
| 34 |
+
{:error, changeset} -> {:error, Repo.collect_errors(changeset)}
|
| 35 |
+
end
|
| 36 |
+
end
|
| 37 |
+
|
| 38 |
defp message_for_response(params) do
|
| 39 |
action = if params["response"] == "true", do: "upvoted", else: "downvoted"
|
| 40 |
|
lib/medical_transcription_web/components/code_select.ex
CHANGED
|
@@ -3,6 +3,8 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 3 |
An auto-complete select field that allows users to search for codes to add by either `code` or `description`.
|
| 4 |
"""
|
| 5 |
|
|
|
|
|
|
|
| 6 |
use MedicalTranscriptionWeb, :live_component
|
| 7 |
import MedicalTranscriptionWeb.Components, only: [tag_result: 1]
|
| 8 |
|
|
@@ -13,10 +15,16 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 13 |
|> assign(:form, to_form(%{"search_term" => ""}))
|
| 14 |
|> assign(:codes, [])
|
| 15 |
|> assign(:selected_code, nil)
|
|
|
|
| 16 |
|
| 17 |
{:ok, socket}
|
| 18 |
end
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@impl Phoenix.LiveComponent
|
| 21 |
def render(assigns) do
|
| 22 |
~H"""
|
|
@@ -81,16 +89,42 @@ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
|
|
| 81 |
@impl Phoenix.LiveComponent
|
| 82 |
def handle_event("choose-code", %{"code" => code}, socket) do
|
| 83 |
selected_code = Enum.find(socket.assigns.codes, &(&1.code == code))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
end
|
| 87 |
|
| 88 |
@impl Phoenix.LiveComponent
|
| 89 |
-
def handle_event(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
socket =
|
| 91 |
socket
|
| 92 |
|> assign(:codes, [])
|
| 93 |
|> assign(:selected_code, nil)
|
|
|
|
| 94 |
|
| 95 |
{:noreply, socket}
|
| 96 |
end
|
|
|
|
| 3 |
An auto-complete select field that allows users to search for codes to add by either `code` or `description`.
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
alias MedicalTranscription.Feedback.CodeFeedback
|
| 7 |
+
alias MedicalTranscription.Feedback
|
| 8 |
use MedicalTranscriptionWeb, :live_component
|
| 9 |
import MedicalTranscriptionWeb.Components, only: [tag_result: 1]
|
| 10 |
|
|
|
|
| 15 |
|> assign(:form, to_form(%{"search_term" => ""}))
|
| 16 |
|> assign(:codes, [])
|
| 17 |
|> assign(:selected_code, nil)
|
| 18 |
+
|> assign(:submitted_code_feedback, nil)
|
| 19 |
|
| 20 |
{:ok, socket}
|
| 21 |
end
|
| 22 |
|
| 23 |
+
@impl Phoenix.LiveComponent
|
| 24 |
+
def update(%{text: text} = _assigns, socket) do
|
| 25 |
+
{:ok, assign(socket, :text, text)}
|
| 26 |
+
end
|
| 27 |
+
|
| 28 |
@impl Phoenix.LiveComponent
|
| 29 |
def render(assigns) do
|
| 30 |
~H"""
|
|
|
|
| 89 |
@impl Phoenix.LiveComponent
|
| 90 |
def handle_event("choose-code", %{"code" => code}, socket) do
|
| 91 |
selected_code = Enum.find(socket.assigns.codes, &(&1.code == code))
|
| 92 |
+
text_vector = MedicalTranscription.Coding.compute_vector_as_list(socket.assigns.text)
|
| 93 |
+
|
| 94 |
+
code_feedback =
|
| 95 |
+
Feedback.insert_and_return(%{
|
| 96 |
+
text: socket.assigns.text,
|
| 97 |
+
text_vector: text_vector,
|
| 98 |
+
response: true,
|
| 99 |
+
code_vector_id: selected_code.id
|
| 100 |
+
})
|
| 101 |
|
| 102 |
+
socket =
|
| 103 |
+
if !is_nil(code_feedback) do
|
| 104 |
+
socket
|
| 105 |
+
|> assign(:selected_code, selected_code)
|
| 106 |
+
|> assign(:submitted_code_feedback, code_feedback)
|
| 107 |
+
else
|
| 108 |
+
put_flash(socket, :error, "Failed to record feedback")
|
| 109 |
+
end
|
| 110 |
+
|
| 111 |
+
{:noreply, socket}
|
| 112 |
end
|
| 113 |
|
| 114 |
@impl Phoenix.LiveComponent
|
| 115 |
+
def handle_event(
|
| 116 |
+
"clear-code",
|
| 117 |
+
_params,
|
| 118 |
+
%{assigns: %{submitted_code_feedback: submitted_code_feedback}} = socket
|
| 119 |
+
) do
|
| 120 |
+
# Delete previous code feedback
|
| 121 |
+
Feedback.delete(submitted_code_feedback)
|
| 122 |
+
|
| 123 |
socket =
|
| 124 |
socket
|
| 125 |
|> assign(:codes, [])
|
| 126 |
|> assign(:selected_code, nil)
|
| 127 |
+
|> assign(:submitted_code_feedback, nil)
|
| 128 |
|
| 129 |
{:noreply, socket}
|
| 130 |
end
|
lib/medical_transcription_web/components/transcription_text_component.ex
CHANGED
|
@@ -93,7 +93,8 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
| 93 |
weighting={weighting}
|
| 94 |
/>
|
| 95 |
<% end %>
|
| 96 |
-
|
|
|
|
| 97 |
</.async_result>
|
| 98 |
</div>
|
| 99 |
</div>
|
|
|
|
| 93 |
weighting={weighting}
|
| 94 |
/>
|
| 95 |
<% end %>
|
| 96 |
+
|
| 97 |
+
<.live_component module={CodeSelect} id={"#{@id}-code-select"} text={@text} />
|
| 98 |
</.async_result>
|
| 99 |
</div>
|
| 100 |
</div>
|