Commit
•
0fc3ad2
1
Parent(s):
1ff8f01
feat: Support renaming transcriptions
Browse files
assets/js/app.js
CHANGED
@@ -28,13 +28,24 @@ let Hooks = {};
|
|
28 |
* The phx-blur event didn't seem to have a way to send along the text of the field as there is no `value` attribute
|
29 |
* because it isn't a form field.
|
30 |
*/
|
31 |
-
Hooks.
|
32 |
mounted() {
|
33 |
this.el.addEventListener("blur", (e) => {
|
34 |
-
const phxTarget = e.target.attributes["phx-target"]
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
});
|
39 |
},
|
40 |
};
|
|
|
28 |
* The phx-blur event didn't seem to have a way to send along the text of the field as there is no `value` attribute
|
29 |
* because it isn't a form field.
|
30 |
*/
|
31 |
+
Hooks.ContentEditor = {
|
32 |
mounted() {
|
33 |
this.el.addEventListener("blur", (e) => {
|
34 |
+
const phxTarget = e.target.attributes["phx-target"]?.value;
|
35 |
+
const eventName = e.target.attributes["phx-event-name"].value;
|
36 |
+
const value = e.target.textContent.trim();
|
37 |
+
|
38 |
+
if (!!value) {
|
39 |
+
if (phxTarget) {
|
40 |
+
this.pushEventTo(phxTarget, eventName, {
|
41 |
+
value,
|
42 |
+
});
|
43 |
+
} else {
|
44 |
+
this.pushEvent(eventName, {
|
45 |
+
value,
|
46 |
+
});
|
47 |
+
}
|
48 |
+
}
|
49 |
});
|
50 |
},
|
51 |
};
|
lib/medical_transcription_web/components/components.ex
CHANGED
@@ -70,6 +70,8 @@ defmodule MedicodeWeb.Components do
|
|
70 |
"""
|
71 |
end
|
72 |
|
|
|
|
|
73 |
attr(:transcription, Medicode.Transcriptions.Transcription, required: true)
|
74 |
attr(:summary_keywords, :list, default: [])
|
75 |
|
@@ -97,7 +99,16 @@ defmodule MedicodeWeb.Components do
|
|
97 |
|
98 |
<div class="px-[14px] py-3 flex items-center gap-3 bg-brand rounded-lg text-white mr-4 overflow-hidden">
|
99 |
<img src={~p"/images/document.svg"} width="20" />
|
100 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
</div>
|
102 |
</div>
|
103 |
</div>
|
|
|
70 |
"""
|
71 |
end
|
72 |
|
73 |
+
attr(:id, :string, required: true)
|
74 |
+
attr(:target, :any, required: true)
|
75 |
attr(:transcription, Medicode.Transcriptions.Transcription, required: true)
|
76 |
attr(:summary_keywords, :list, default: [])
|
77 |
|
|
|
99 |
|
100 |
<div class="px-[14px] py-3 flex items-center gap-3 bg-brand rounded-lg text-white mr-4 overflow-hidden">
|
101 |
<img src={~p"/images/document.svg"} width="20" />
|
102 |
+
<p
|
103 |
+
id={@id}
|
104 |
+
contenteditable
|
105 |
+
phx-hook="ContentEditor"
|
106 |
+
phx-event-name="rename_transcription"
|
107 |
+
role="textbox"
|
108 |
+
class="font-secondary"
|
109 |
+
>
|
110 |
+
<%= @transcription.filename %>
|
111 |
+
</p>
|
112 |
</div>
|
113 |
</div>
|
114 |
</div>
|
lib/medical_transcription_web/components/transcription_text_component.ex
CHANGED
@@ -83,8 +83,9 @@ defmodule MedicodeWeb.Components.TranscriptionTextComponent do
|
|
83 |
contenteditable
|
84 |
role="textbox"
|
85 |
class="h-full min-h-full rounded p-2"
|
86 |
-
phx-hook="
|
87 |
phx-target={@myself}
|
|
|
88 |
>
|
89 |
<.highlight text={@chunk.text} keywords={@chunk.keywords} />
|
90 |
</p>
|
|
|
83 |
contenteditable
|
84 |
role="textbox"
|
85 |
class="h-full min-h-full rounded p-2"
|
86 |
+
phx-hook="ContentEditor"
|
87 |
phx-target={@myself}
|
88 |
+
phx-event-name="reclassify_transcription"
|
89 |
>
|
90 |
<.highlight text={@chunk.text} keywords={@chunk.keywords} />
|
91 |
</p>
|
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
@@ -76,11 +76,24 @@ defmodule MedicodeWeb.HomeLive.Index do
|
|
76 |
{:noreply, push_navigate(socket, to: ~p"/transcriptions/#{transcription.id}")}
|
77 |
end
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
transcriptions = list_transcriptions(socket.assigns.current_user)
|
81 |
|
82 |
socket =
|
83 |
socket
|
|
|
84 |
|> assign(:transcriptions, transcriptions)
|
85 |
|
86 |
{:noreply, socket}
|
@@ -92,4 +105,8 @@ defmodule MedicodeWeb.HomeLive.Index do
|
|
92 |
defp list_transcriptions(user) do
|
93 |
Transcriptions.list_transcriptions(user)
|
94 |
end
|
|
|
|
|
|
|
|
|
95 |
end
|
|
|
76 |
{:noreply, push_navigate(socket, to: ~p"/transcriptions/#{transcription.id}")}
|
77 |
end
|
78 |
|
79 |
+
@impl Phoenix.LiveView
|
80 |
+
def handle_info({:transcription_created, _transcription_id}, socket) do
|
81 |
+
transcriptions = list_transcriptions(socket.assigns.current_user)
|
82 |
+
|
83 |
+
socket =
|
84 |
+
socket
|
85 |
+
|> assign(:transcriptions, transcriptions)
|
86 |
+
|
87 |
+
{:noreply, socket}
|
88 |
+
end
|
89 |
+
|
90 |
+
def handle_info({:transcription_updated, transcription_id}, socket) do
|
91 |
+
transcription = get_transcription(transcription_id)
|
92 |
transcriptions = list_transcriptions(socket.assigns.current_user)
|
93 |
|
94 |
socket =
|
95 |
socket
|
96 |
+
|> assign(:transcription, transcription)
|
97 |
|> assign(:transcriptions, transcriptions)
|
98 |
|
99 |
{:noreply, socket}
|
|
|
105 |
defp list_transcriptions(user) do
|
106 |
Transcriptions.list_transcriptions(user)
|
107 |
end
|
108 |
+
|
109 |
+
defp get_transcription(id) do
|
110 |
+
Transcriptions.get_transcription(id, true)
|
111 |
+
end
|
112 |
end
|
lib/medical_transcription_web/live/transcriptions_live/show.ex
CHANGED
@@ -50,7 +50,12 @@ defmodule MedicodeWeb.TranscriptionsLive.Show do
|
|
50 |
|
51 |
<main class="flex-1 pl-16 pr-16 pt-[25px]">
|
52 |
<div class="flex flex-col h-full mx-auto max-w-5xl">
|
53 |
-
<.result_heading
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
<img
|
56 |
:if={@transcription.status == :transcribing}
|
@@ -109,8 +114,29 @@ defmodule MedicodeWeb.TranscriptionsLive.Show do
|
|
109 |
{:noreply, socket}
|
110 |
end
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
@impl true
|
113 |
-
def handle_info({:transcription_created,
|
114 |
transcriptions = list_transcriptions(socket.assigns.current_user)
|
115 |
|
116 |
socket =
|
@@ -131,6 +157,18 @@ defmodule MedicodeWeb.TranscriptionsLive.Show do
|
|
131 |
{:noreply, socket}
|
132 |
end
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
def handle_info({:transcription_started, _transcription}, socket) do
|
135 |
{:noreply, assign(socket, :status, :loading)}
|
136 |
end
|
|
|
50 |
|
51 |
<main class="flex-1 pl-16 pr-16 pt-[25px]">
|
52 |
<div class="flex flex-col h-full mx-auto max-w-5xl">
|
53 |
+
<.result_heading
|
54 |
+
id="transcription-name"
|
55 |
+
target={self()}
|
56 |
+
transcription={@transcription}
|
57 |
+
summary_keywords={@summary_keywords}
|
58 |
+
/>
|
59 |
|
60 |
<img
|
61 |
:if={@transcription.status == :transcribing}
|
|
|
114 |
{:noreply, socket}
|
115 |
end
|
116 |
|
117 |
+
def handle_event("rename_transcription", %{"value" => new_name}, socket) do
|
118 |
+
new_name_trimmed = String.trim(new_name)
|
119 |
+
|
120 |
+
if socket.assigns.transcription.filename == new_name_trimmed do
|
121 |
+
{:noreply, socket}
|
122 |
+
else
|
123 |
+
{:ok, transcription} =
|
124 |
+
Transcriptions.update_transcription(socket.assigns.transcription, %{
|
125 |
+
filename: new_name_trimmed
|
126 |
+
})
|
127 |
+
|
128 |
+
Phoenix.PubSub.broadcast(
|
129 |
+
:medicode_pubsub,
|
130 |
+
"medicode:#{socket.assigns.current_user.id}",
|
131 |
+
{:transcription_updated, transcription.id}
|
132 |
+
)
|
133 |
+
|
134 |
+
{:noreply, assign(socket, :transcription, transcription)}
|
135 |
+
end
|
136 |
+
end
|
137 |
+
|
138 |
@impl true
|
139 |
+
def handle_info({:transcription_created, _transcription_id}, socket) do
|
140 |
transcriptions = list_transcriptions(socket.assigns.current_user)
|
141 |
|
142 |
socket =
|
|
|
157 |
{:noreply, socket}
|
158 |
end
|
159 |
|
160 |
+
def handle_info({:transcription_updated, transcription_id}, socket) do
|
161 |
+
transcription = get_transcription(transcription_id)
|
162 |
+
transcriptions = list_transcriptions(socket.assigns.current_user)
|
163 |
+
|
164 |
+
socket =
|
165 |
+
socket
|
166 |
+
|> assign(:transcription, transcription)
|
167 |
+
|> assign(:transcriptions, transcriptions)
|
168 |
+
|
169 |
+
{:noreply, socket}
|
170 |
+
end
|
171 |
+
|
172 |
def handle_info({:transcription_started, _transcription}, socket) do
|
173 |
{:noreply, assign(socket, :status, :loading)}
|
174 |
end
|