Noah Settersten commited on
Commit
aeeeee4
·
1 Parent(s): 5d5de45

feat: Allow selecting a code that wasn't suggested

Browse files
lib/medical_transcription/coding.ex CHANGED
@@ -35,6 +35,12 @@ defmodule MedicalTranscription.Coding do
35
  num_rows >= 14_567
36
  end
37
 
 
 
 
 
 
 
38
  @doc """
39
  Takes a chunk of transcribed text and classifies it based on the list of code vectors in the database.
40
 
 
35
  num_rows >= 14_567
36
  end
37
 
38
+ def get_all_code_vectors do
39
+ # TODO: Limit this to a subset of codes for now. This will instead become a search function for auto-complete from
40
+ # the UI.
41
+ Repo.all(from v in CodeVector, limit: 100)
42
+ end
43
+
44
  @doc """
45
  Takes a chunk of transcribed text and classifies it based on the list of code vectors in the database.
46
 
lib/medical_transcription_web/components/code_select.ex ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule MedicalTranscriptionWeb.Components.CodeSelect do
2
+ @moduledoc """
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
+
9
+ @impl Phoenix.LiveComponent
10
+ def mount(socket) do
11
+ socket =
12
+ socket
13
+ |> assign(:codes, [])
14
+ |> assign(:selected_code, nil)
15
+
16
+ {:ok, socket}
17
+ end
18
+
19
+ @impl Phoenix.LiveComponent
20
+ def update_many(assigns_sockets) do
21
+ codes = lookup_codes()
22
+
23
+ Enum.map(assigns_sockets, fn {_assigns, socket} ->
24
+ assign(socket, :codes, codes)
25
+ end)
26
+ end
27
+
28
+ @impl Phoenix.LiveComponent
29
+ def render(assigns) do
30
+ ~H"""
31
+ <div>
32
+ <%= if is_nil(@selected_code) do %>
33
+ <select
34
+ class="w-full rounded"
35
+ phx-change="choose-code"
36
+ phx-blur="choose-code"
37
+ phx-target={@myself}
38
+ >
39
+ <option value="0">Choose another code...</option>
40
+ <%= for code <- @codes do %>
41
+ <option value={code.code}><%= code.code %>: <%= code.description %></option>
42
+ <% end %>
43
+ </select>
44
+ <% else %>
45
+ <p class="leading-normal font-bold text-type-black-primary uppercase">
46
+ User-selected code
47
+ </p>
48
+
49
+ <.tag_result
50
+ code_vector_id={@selected_code.id}
51
+ text=""
52
+ score={1.0}
53
+ weighting={[]}
54
+ code={@selected_code.code}
55
+ label={@selected_code.description}
56
+ />
57
+ <% end %>
58
+ </div>
59
+ """
60
+ end
61
+
62
+ @impl Phoenix.LiveComponent
63
+ def handle_event("choose-code", %{"value" => code}, socket) do
64
+ selected_code = Enum.find(socket.assigns.codes, &(&1.code == code))
65
+
66
+ {:noreply, assign(socket, :selected_code, selected_code)}
67
+ end
68
+
69
+ defp lookup_codes do
70
+ MedicalTranscription.Coding.get_all_code_vectors()
71
+ end
72
+ end
lib/medical_transcription_web/components/transcription_text_component.ex CHANGED
@@ -4,6 +4,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
4
 
5
  Once rendered, starts tasks to find relevant codes and keywords for the text.
6
  """
 
7
  use MedicalTranscriptionWeb, :live_component
8
 
9
  import MedicalTranscriptionWeb.Components
@@ -20,10 +21,14 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
20
  {:ok, socket}
21
  end
22
 
23
- defp assign_initial_state(%{start_mark: start_mark, end_mark: end_mark, text: text}, socket) do
 
 
 
24
  self_pid = self()
25
 
26
  initial_state = %{
 
27
  start_mark: start_mark,
28
  end_mark: end_mark,
29
  text: text,
@@ -88,6 +93,7 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
88
  weighting={weighting}
89
  />
90
  <% end %>
 
91
  </.async_result>
92
  </div>
93
  </div>
 
4
 
5
  Once rendered, starts tasks to find relevant codes and keywords for the text.
6
  """
7
+ alias MedicalTranscriptionWeb.Components.CodeSelect
8
  use MedicalTranscriptionWeb, :live_component
9
 
10
  import MedicalTranscriptionWeb.Components
 
21
  {:ok, socket}
22
  end
23
 
24
+ defp assign_initial_state(
25
+ %{id: id, start_mark: start_mark, end_mark: end_mark, text: text},
26
+ socket
27
+ ) do
28
  self_pid = self()
29
 
30
  initial_state = %{
31
+ id: id,
32
  start_mark: start_mark,
33
  end_mark: end_mark,
34
  text: text,
 
93
  weighting={weighting}
94
  />
95
  <% end %>
96
+ <.live_component module={CodeSelect} id={"#{@id}-code-select"} />
97
  </.async_result>
98
  </div>
99
  </div>