Commit ·
f665ffc
1
Parent(s): de48058
feat: Broadcast when transcriptions are created
Browse files
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
|
@@ -5,6 +5,10 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 5 |
|
| 6 |
@impl Phoenix.LiveView
|
| 7 |
def mount(_params, session, socket) do
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
socket =
|
| 9 |
socket
|
| 10 |
|> assign(:transcriptions, list_transcriptions(session["current_user"]))
|
|
@@ -42,7 +46,6 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 42 |
{:noreply, socket}
|
| 43 |
end
|
| 44 |
|
| 45 |
-
@impl true
|
| 46 |
def handle_event("save", _params, socket) do
|
| 47 |
_filename =
|
| 48 |
socket.assigns.uploads.audio.entries
|
|
@@ -62,11 +65,27 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 62 |
filename: Enum.at(uploaded_files, 0)
|
| 63 |
})
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
Transcriptions.transcribe_audio(transcription)
|
| 66 |
|
| 67 |
{:noreply, push_navigate(socket, to: ~p"/transcriptions/#{transcription.id}")}
|
| 68 |
end
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def error_to_string(:too_large), do: "Too large"
|
| 71 |
def error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
| 72 |
|
|
|
|
| 5 |
|
| 6 |
@impl Phoenix.LiveView
|
| 7 |
def mount(_params, session, socket) do
|
| 8 |
+
if connected?(socket) do
|
| 9 |
+
Phoenix.PubSub.subscribe(:medicode_pubsub, "medicode:#{session["current_user"].id}")
|
| 10 |
+
end
|
| 11 |
+
|
| 12 |
socket =
|
| 13 |
socket
|
| 14 |
|> assign(:transcriptions, list_transcriptions(session["current_user"]))
|
|
|
|
| 46 |
{:noreply, socket}
|
| 47 |
end
|
| 48 |
|
|
|
|
| 49 |
def handle_event("save", _params, socket) do
|
| 50 |
_filename =
|
| 51 |
socket.assigns.uploads.audio.entries
|
|
|
|
| 65 |
filename: Enum.at(uploaded_files, 0)
|
| 66 |
})
|
| 67 |
|
| 68 |
+
Phoenix.PubSub.broadcast(
|
| 69 |
+
:medicode_pubsub,
|
| 70 |
+
"medicode:#{socket.assigns.current_user.id}",
|
| 71 |
+
{:transcription_created, transcription.id}
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
Transcriptions.transcribe_audio(transcription)
|
| 75 |
|
| 76 |
{:noreply, push_navigate(socket, to: ~p"/transcriptions/#{transcription.id}")}
|
| 77 |
end
|
| 78 |
|
| 79 |
+
def handle_info({:transcription_created, transcription_id}, socket) do
|
| 80 |
+
transcriptions = list_transcriptions(socket.assigns.current_user)
|
| 81 |
+
|
| 82 |
+
socket =
|
| 83 |
+
socket
|
| 84 |
+
|> assign(:transcriptions, transcriptions)
|
| 85 |
+
|
| 86 |
+
{:noreply, socket}
|
| 87 |
+
end
|
| 88 |
+
|
| 89 |
def error_to_string(:too_large), do: "Too large"
|
| 90 |
def error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
| 91 |
|
lib/medical_transcription_web/live/transcriptions_live/show.ex
CHANGED
|
@@ -12,8 +12,10 @@ defmodule MedicalTranscriptionWeb.TranscriptionsLive.Show do
|
|
| 12 |
|
| 13 |
if is_nil(transcription), do: raise(MedicalTranscription.Fallback)
|
| 14 |
|
| 15 |
-
if connected?(socket)
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
transcription_chunk_ids = Enum.map(transcription.chunks, &%{id: &1.id})
|
| 19 |
|
|
@@ -108,6 +110,16 @@ defmodule MedicalTranscriptionWeb.TranscriptionsLive.Show do
|
|
| 108 |
end
|
| 109 |
|
| 110 |
@impl true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
def handle_info({:transcription_updated, %{id: chunk_id}}, socket) do
|
| 112 |
transcription = get_transcription(socket.assigns.transcription.id)
|
| 113 |
|
|
|
|
| 12 |
|
| 13 |
if is_nil(transcription), do: raise(MedicalTranscription.Fallback)
|
| 14 |
|
| 15 |
+
if connected?(socket) do
|
| 16 |
+
Phoenix.PubSub.subscribe(:medicode_pubsub, "medicode:#{session["current_user"].id}")
|
| 17 |
+
Phoenix.PubSub.subscribe(:medicode_pubsub, "transcriptions:#{transcription.id}")
|
| 18 |
+
end
|
| 19 |
|
| 20 |
transcription_chunk_ids = Enum.map(transcription.chunks, &%{id: &1.id})
|
| 21 |
|
|
|
|
| 110 |
end
|
| 111 |
|
| 112 |
@impl true
|
| 113 |
+
def handle_info({:transcription_created, transcription_id}, socket) do
|
| 114 |
+
transcriptions = list_transcriptions(socket.assigns.current_user)
|
| 115 |
+
|
| 116 |
+
socket =
|
| 117 |
+
socket
|
| 118 |
+
|> assign(:transcriptions, transcriptions)
|
| 119 |
+
|
| 120 |
+
{:noreply, socket}
|
| 121 |
+
end
|
| 122 |
+
|
| 123 |
def handle_info({:transcription_updated, %{id: chunk_id}}, socket) do
|
| 124 |
transcription = get_transcription(socket.assigns.transcription.id)
|
| 125 |
|