Commit ·
3a8280c
1
Parent(s): 2dfe07a
feat: Account for not founds
Browse files- lib/medical_transcription/transcription_server.ex +20 -1
- lib/medical_transcription/transcriptions.ex +26 -0
- lib/medical_transcription_web/controllers/error_html/404.html.heex +18 -0
- lib/medical_transcription_web/fallback.ex +3 -0
- lib/medical_transcription_web/live/transcriptions_live/show.ex +3 -1
- test/medical_transcription_web/live/transcriptions_live_show_test.exs +31 -0
lib/medical_transcription/transcription_server.ex
CHANGED
|
@@ -25,11 +25,20 @@ defmodule MedicalTranscription.TranscriptionServer do
|
|
| 25 |
@impl GenServer
|
| 26 |
def handle_continue(:start, {:transcription, transcription} = state) do
|
| 27 |
stream_transcription_and_search(transcription.filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
{:noreply, state}
|
| 29 |
end
|
| 30 |
|
| 31 |
@impl GenServer
|
| 32 |
-
def handle_info({:chunk, result},
|
|
|
|
|
|
|
| 33 |
%Transcription{id: id} = transcription
|
| 34 |
|
| 35 |
Transcriptions.create_chunk(%{
|
|
@@ -58,6 +67,16 @@ defmodule MedicalTranscription.TranscriptionServer do
|
|
| 58 |
|
| 59 |
@impl GenServer
|
| 60 |
def terminate(reason, state) do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
reason
|
| 62 |
end
|
| 63 |
|
|
|
|
| 25 |
@impl GenServer
|
| 26 |
def handle_continue(:start, {:transcription, transcription} = state) do
|
| 27 |
stream_transcription_and_search(transcription.filename)
|
| 28 |
+
|
| 29 |
+
Phoenix.PubSub.broadcast(
|
| 30 |
+
:medicode_pubsub,
|
| 31 |
+
"transcriptions:#{transcription.id}",
|
| 32 |
+
{:transcription_started, transcription.id}
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
{:noreply, state}
|
| 36 |
end
|
| 37 |
|
| 38 |
@impl GenServer
|
| 39 |
+
def handle_info({:chunk, result}, state) do
|
| 40 |
+
{:transcription, transcription} = state
|
| 41 |
+
|
| 42 |
%Transcription{id: id} = transcription
|
| 43 |
|
| 44 |
Transcriptions.create_chunk(%{
|
|
|
|
| 67 |
|
| 68 |
@impl GenServer
|
| 69 |
def terminate(reason, state) do
|
| 70 |
+
{:transcription, transcription} = state
|
| 71 |
+
|
| 72 |
+
%Transcription{id: id} = transcription
|
| 73 |
+
|
| 74 |
+
Phoenix.PubSub.broadcast(
|
| 75 |
+
:medicode_pubsub,
|
| 76 |
+
"transcriptions:#{id}",
|
| 77 |
+
{:transcription_finished, reason}
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
reason
|
| 81 |
end
|
| 82 |
|
lib/medical_transcription/transcriptions.ex
CHANGED
|
@@ -38,6 +38,32 @@ defmodule MedicalTranscription.Transcriptions do
|
|
| 38 |
@doc """
|
| 39 |
Gets a single transcription.
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
Raises `Ecto.NoResultsError` if the Transcription does not exist.
|
| 42 |
|
| 43 |
## Examples
|
|
|
|
| 38 |
@doc """
|
| 39 |
Gets a single transcription.
|
| 40 |
|
| 41 |
+
Returns `nil` if the Transcription does not exist.
|
| 42 |
+
|
| 43 |
+
## Examples
|
| 44 |
+
|
| 45 |
+
iex> get_transcription(123)
|
| 46 |
+
%Transcription{}
|
| 47 |
+
|
| 48 |
+
iex> get_transcription(456)
|
| 49 |
+
nil
|
| 50 |
+
|
| 51 |
+
"""
|
| 52 |
+
def get_transcription(id, preload_transcription_chunks \\ false) do
|
| 53 |
+
query =
|
| 54 |
+
if preload_transcription_chunks do
|
| 55 |
+
Transcription
|
| 56 |
+
|> preload(:chunks)
|
| 57 |
+
else
|
| 58 |
+
Transcription
|
| 59 |
+
end
|
| 60 |
+
|
| 61 |
+
Repo.get(query, id)
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
@doc """
|
| 65 |
+
Gets a single transcription.
|
| 66 |
+
|
| 67 |
Raises `Ecto.NoResultsError` if the Transcription does not exist.
|
| 68 |
|
| 69 |
## Examples
|
lib/medical_transcription_web/controllers/error_html/404.html.heex
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="[scrollbar-gutter:stable]">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<meta name="csrf-token" content={get_csrf_token()} />
|
| 7 |
+
<.live_title suffix=" · Phoenix Framework">
|
| 8 |
+
<%= assigns[:page_title] || "MedicalTranscription" %>
|
| 9 |
+
</.live_title>
|
| 10 |
+
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
|
| 11 |
+
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
| 12 |
+
</script>
|
| 13 |
+
</head>
|
| 14 |
+
<body class="bg-white antialiased px-5 py-7">
|
| 15 |
+
<h1>Not Found</h1>
|
| 16 |
+
</body>
|
| 17 |
+
</html>
|
| 18 |
+
|
lib/medical_transcription_web/fallback.ex
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
defmodule MedicalTranscription.Fallback do
|
| 2 |
+
defexception message: "Not found", plug_status: 404
|
| 3 |
+
end
|
lib/medical_transcription_web/live/transcriptions_live/show.ex
CHANGED
|
@@ -10,6 +10,8 @@ defmodule MedicalTranscriptionWeb.TranscriptionsLive.Show do
|
|
| 10 |
def mount(params, session, socket) do
|
| 11 |
transcription = get_transcription(params["id"])
|
| 12 |
|
|
|
|
|
|
|
| 13 |
if connected?(socket),
|
| 14 |
do: Phoenix.PubSub.subscribe(:medicode_pubsub, "transcriptions:#{transcription.id}")
|
| 15 |
|
|
@@ -174,6 +176,6 @@ defmodule MedicalTranscriptionWeb.TranscriptionsLive.Show do
|
|
| 174 |
{:noreply, assign(socket, :status, :success)}
|
| 175 |
end
|
| 176 |
|
| 177 |
-
defp get_transcription(id), do: Transcriptions.get_transcription
|
| 178 |
defp list_transcriptions(user), do: Transcriptions.list_transcriptions(user)
|
| 179 |
end
|
|
|
|
| 10 |
def mount(params, session, socket) do
|
| 11 |
transcription = get_transcription(params["id"])
|
| 12 |
|
| 13 |
+
if is_nil(transcription), do: raise MedicalTranscription.Fallback
|
| 14 |
+
|
| 15 |
if connected?(socket),
|
| 16 |
do: Phoenix.PubSub.subscribe(:medicode_pubsub, "transcriptions:#{transcription.id}")
|
| 17 |
|
|
|
|
| 176 |
{:noreply, assign(socket, :status, :success)}
|
| 177 |
end
|
| 178 |
|
| 179 |
+
defp get_transcription(id), do: Transcriptions.get_transcription(id)
|
| 180 |
defp list_transcriptions(user), do: Transcriptions.list_transcriptions(user)
|
| 181 |
end
|
test/medical_transcription_web/live/transcriptions_live_show_test.exs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
defmodule MedicalTranscriptionWeb.TranscriptionsLive.ShowTest do
|
| 2 |
+
use MedicalTranscriptionWeb.ConnCase, async: true
|
| 3 |
+
|
| 4 |
+
import Phoenix.LiveViewTest
|
| 5 |
+
import MedicalTranscription.{AccountsFixtures, TranscriptionsFixtures}
|
| 6 |
+
|
| 7 |
+
setup %{conn: conn} do
|
| 8 |
+
password = valid_user_password()
|
| 9 |
+
user = user_fixture(%{password: password})
|
| 10 |
+
transcription = transcription_fixture(%{filename: "my-audio.mp3"})
|
| 11 |
+
%{conn: log_in_user(conn, user), current_user: user, transcription: transcription}
|
| 12 |
+
end
|
| 13 |
+
|
| 14 |
+
describe "/" do
|
| 15 |
+
test "renders transcription show screen", %{conn: conn, transcription: transcription} do
|
| 16 |
+
conn = get(conn, "/transcriptions/#{transcription.id}")
|
| 17 |
+
assert html_response(conn, 200) =~ "Medical Code Transcriber"
|
| 18 |
+
|
| 19 |
+
{:ok, view, html} = live(conn)
|
| 20 |
+
assert html =~ "my-audio.mp3"
|
| 21 |
+
|
| 22 |
+
assert_redirected view, ~p"/transcriptions/#{transcription.id}"
|
| 23 |
+
end
|
| 24 |
+
|
| 25 |
+
test "renders 'Not Found' for 404", %{conn: conn} do
|
| 26 |
+
invalid_id = Ecto.UUID.generate()
|
| 27 |
+
conn = get(conn, "/transcriptions/#{invalid_id}")
|
| 28 |
+
assert html_response(conn, 404) =~ "Transcription not found"
|
| 29 |
+
end
|
| 30 |
+
end
|
| 31 |
+
end
|