noahsettersten
commited on
Commit
•
712bb74
1
Parent(s):
165b349
feat: Record user feedback on given code
Browse files
lib/medical_transcription/code_feedback.ex
CHANGED
@@ -14,8 +14,23 @@ defmodule MedicalTranscription.CodeFeedback do
|
|
14 |
end
|
15 |
|
16 |
def track_response(params) do
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
end
|
21 |
end
|
|
|
14 |
end
|
15 |
|
16 |
def track_response(params) do
|
17 |
+
changeset =
|
18 |
+
%MedicalTranscription.CodeFeedback{}
|
19 |
+
|> changeset(params)
|
20 |
+
|
21 |
+
case MedicalTranscription.Repo.insert(changeset) do
|
22 |
+
{:ok, _code_feedback} ->
|
23 |
+
{:ok, "Success!"}
|
24 |
+
|
25 |
+
{:error, changeset} ->
|
26 |
+
messages =
|
27 |
+
Ecto.Changeset.traverse_errors(changeset, fn {msg, opts} ->
|
28 |
+
Enum.reduce(opts, msg, fn {key, value}, acc ->
|
29 |
+
String.replace(acc, "%{#{key}}", to_string(value))
|
30 |
+
end)
|
31 |
+
end)
|
32 |
+
|
33 |
+
{:error, messages}
|
34 |
+
end
|
35 |
end
|
36 |
end
|
lib/medical_transcription_web/components/components.ex
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
defmodule MedicalTranscriptionWeb.Components do
|
2 |
use Phoenix.Component
|
3 |
import MedicalTranscriptionWeb.CoreComponents
|
|
|
4 |
|
5 |
def tag_result_chip(assigns) do
|
6 |
~H"""
|
@@ -12,19 +13,38 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
12 |
<strong><%= @code %>:</strong> <%= @label %>
|
13 |
</div>
|
14 |
|
15 |
-
<div class="w-fit flex items-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
</div>
|
27 |
</div>
|
28 |
"""
|
29 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
end
|
|
|
1 |
defmodule MedicalTranscriptionWeb.Components do
|
2 |
use Phoenix.Component
|
3 |
import MedicalTranscriptionWeb.CoreComponents
|
4 |
+
alias Phoenix.LiveView.JS
|
5 |
|
6 |
def tag_result_chip(assigns) do
|
7 |
~H"""
|
|
|
13 |
<strong><%= @code %>:</strong> <%= @label %>
|
14 |
</div>
|
15 |
|
16 |
+
<div class="w-fit flex items-stretch border border-slate-300 rounded overflow-hidden">
|
17 |
+
<.feedback_button
|
18 |
+
code={@code}
|
19 |
+
text={@text}
|
20 |
+
response="true"
|
21 |
+
icon_name="hero-check-circle"
|
22 |
+
class="border-r border-slate-300"
|
23 |
+
/>
|
24 |
+
<.feedback_button
|
25 |
+
code={@code}
|
26 |
+
text={@text}
|
27 |
+
response="false"
|
28 |
+
icon_name="hero-x-circle"
|
29 |
+
class=""
|
30 |
+
/>
|
31 |
</div>
|
32 |
</div>
|
33 |
"""
|
34 |
end
|
35 |
+
|
36 |
+
defp feedback_button(assigns) do
|
37 |
+
~H"""
|
38 |
+
<button
|
39 |
+
phx-click="add_feedback"
|
40 |
+
phx-value-code={@code}
|
41 |
+
phx-value-text={@text}
|
42 |
+
phx-value-response={@response}
|
43 |
+
type="button"
|
44 |
+
class={"px-1 py-0.5 hover:bg-slate-300 #{@class}"}
|
45 |
+
>
|
46 |
+
<.icon name={@icon_name} />
|
47 |
+
</button>
|
48 |
+
"""
|
49 |
+
end
|
50 |
end
|
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
@@ -56,7 +56,7 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
56 |
<:col :let={row} label="Codes">
|
57 |
<div class="min-w-[18rem] max-w-md flex flex-col items-stretch gap-2">
|
58 |
<%= for %TagResult{code: code, label: label, score: score} <- row.tags do %>
|
59 |
-
<.tag_result_chip code={code} label={label} score={score} />
|
60 |
<% end %>
|
61 |
</div>
|
62 |
</:col>
|
@@ -96,6 +96,13 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
96 |
{:noreply, socket}
|
97 |
end
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
@impl true
|
100 |
def handle_info({:transcription_row, chunk_result}, socket) do
|
101 |
# The processing sends a message as each chunk of text is coded. See here for some background and potential
|
|
|
56 |
<:col :let={row} label="Codes">
|
57 |
<div class="min-w-[18rem] max-w-md flex flex-col items-stretch gap-2">
|
58 |
<%= for %TagResult{code: code, label: label, score: score} <- row.tags do %>
|
59 |
+
<.tag_result_chip code={code} label={label} score={score} text={row.text} />
|
60 |
<% end %>
|
61 |
</div>
|
62 |
</:col>
|
|
|
96 |
{:noreply, socket}
|
97 |
end
|
98 |
|
99 |
+
@impl true
|
100 |
+
def handle_event("add_feedback", params, socket) do
|
101 |
+
result = MedicalTranscription.CodeFeedback.track_response(params)
|
102 |
+
|
103 |
+
{:noreply, put_flash(socket, :info, result)}
|
104 |
+
end
|
105 |
+
|
106 |
@impl true
|
107 |
def handle_info({:transcription_row, chunk_result}, socket) do
|
108 |
# The processing sends a message as each chunk of text is coded. See here for some background and potential
|