noahsettersten
commited on
Commit
•
b01bac2
1
Parent(s):
48ded1e
refactor: Create feedback context
Browse files
lib/medical_transcription/feedback.ex
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defmodule MedicalTranscription.Feedback do
|
2 |
+
alias MedicalTranscription.Feedback.CodeFeedback
|
3 |
+
|
4 |
+
def track_response(params) do
|
5 |
+
changeset = CodeFeedback.changeset(%CodeFeedback{}, params)
|
6 |
+
|
7 |
+
case MedicalTranscription.Repo.insert(changeset) do
|
8 |
+
{:ok, _code_feedback} ->
|
9 |
+
{:ok, "Success!"}
|
10 |
+
|
11 |
+
{:error, changeset} ->
|
12 |
+
messages =
|
13 |
+
Ecto.Changeset.traverse_errors(changeset, fn {msg, opts} ->
|
14 |
+
Enum.reduce(opts, msg, fn {key, value}, acc ->
|
15 |
+
String.replace(acc, "%{#{key}}", to_string(value))
|
16 |
+
end)
|
17 |
+
end)
|
18 |
+
|
19 |
+
{:error, messages}
|
20 |
+
end
|
21 |
+
end
|
22 |
+
end
|
lib/medical_transcription/{code_feedback.ex → feedback/code_feedback.ex}
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
defmodule MedicalTranscription.CodeFeedback do
|
2 |
@moduledoc """
|
3 |
Represents a user's feedback on a given code classification.
|
4 |
"""
|
@@ -17,25 +17,4 @@ defmodule MedicalTranscription.CodeFeedback do
|
|
17 |
|> Ecto.Changeset.cast(params, [:text, :text_vector, :response, :code_vector_id])
|
18 |
|> Ecto.Changeset.validate_required([:text, :text_vector, :response, :code_vector_id])
|
19 |
end
|
20 |
-
|
21 |
-
def track_response(params) do
|
22 |
-
changeset =
|
23 |
-
%MedicalTranscription.CodeFeedback{}
|
24 |
-
|> changeset(params)
|
25 |
-
|
26 |
-
case MedicalTranscription.Repo.insert(changeset) do
|
27 |
-
{:ok, _code_feedback} ->
|
28 |
-
{:ok, "Success!"}
|
29 |
-
|
30 |
-
{:error, changeset} ->
|
31 |
-
messages =
|
32 |
-
Ecto.Changeset.traverse_errors(changeset, fn {msg, opts} ->
|
33 |
-
Enum.reduce(opts, msg, fn {key, value}, acc ->
|
34 |
-
String.replace(acc, "%{#{key}}", to_string(value))
|
35 |
-
end)
|
36 |
-
end)
|
37 |
-
|
38 |
-
{:error, messages}
|
39 |
-
end
|
40 |
-
end
|
41 |
end
|
|
|
1 |
+
defmodule MedicalTranscription.Feedback.CodeFeedback do
|
2 |
@moduledoc """
|
3 |
Represents a user's feedback on a given code classification.
|
4 |
"""
|
|
|
17 |
|> Ecto.Changeset.cast(params, [:text, :text_vector, :response, :code_vector_id])
|
18 |
|> Ecto.Changeset.validate_required([:text, :text_vector, :response, :code_vector_id])
|
19 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
end
|
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
@@ -87,7 +87,7 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
87 |
result =
|
88 |
params
|
89 |
|> Map.put("text_vector", text_vector)
|
90 |
-
|> MedicalTranscription.
|
91 |
|
92 |
socket =
|
93 |
case result do
|
|
|
87 |
result =
|
88 |
params
|
89 |
|> Map.put("text_vector", text_vector)
|
90 |
+
|> MedicalTranscription.Feedback.track_response()
|
91 |
|
92 |
socket =
|
93 |
case result do
|