Commit ·
bcd90d6
1
Parent(s): 8ba1194
feat: Clear finalized states for codes
Browse files
lib/medicode/transcriptions.ex
CHANGED
|
@@ -5,6 +5,8 @@ defmodule Medicode.Transcriptions do
|
|
| 5 |
|
| 6 |
import Ecto.Query, warn: false
|
| 7 |
|
|
|
|
|
|
|
| 8 |
alias Medicode.Repo
|
| 9 |
|
| 10 |
alias Medicode.Transcriptions.{
|
|
@@ -184,23 +186,32 @@ defmodule Medicode.Transcriptions do
|
|
| 184 |
code_vector_id,
|
| 185 |
user_id
|
| 186 |
) do
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|>
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
end
|
| 205 |
end
|
| 206 |
|
|
|
|
| 5 |
|
| 6 |
import Ecto.Query, warn: false
|
| 7 |
|
| 8 |
+
alias Ecto.Multi
|
| 9 |
+
|
| 10 |
alias Medicode.Repo
|
| 11 |
|
| 12 |
alias Medicode.Transcriptions.{
|
|
|
|
| 186 |
code_vector_id,
|
| 187 |
user_id
|
| 188 |
) do
|
| 189 |
+
multi =
|
| 190 |
+
Multi.new()
|
| 191 |
+
|> Multi.one(:chunk_code_vector, fn _changes ->
|
| 192 |
+
TranscriptionChunkCodeVector
|
| 193 |
+
|> where(
|
| 194 |
+
[v],
|
| 195 |
+
v.transcription_chunk_id == ^chunk_id and v.code_vector_id == ^code_vector_id
|
| 196 |
+
)
|
| 197 |
+
end)
|
| 198 |
+
|> Multi.update(:clear_finalized_state, fn %{chunk_code_vector: chunk_code_vector} ->
|
| 199 |
+
if is_nil(chunk_code_vector.finalized_at) do
|
| 200 |
+
Ecto.Changeset.change(chunk_code_vector,
|
| 201 |
+
finalized_at: DateTime.utc_now() |> DateTime.truncate(:second),
|
| 202 |
+
finalized_by_user_id: user_id
|
| 203 |
+
)
|
| 204 |
+
else
|
| 205 |
+
Ecto.Changeset.change(chunk_code_vector, finalized_at: nil, finalized_by_user_id: nil)
|
| 206 |
+
end
|
| 207 |
+
end)
|
| 208 |
+
|
| 209 |
+
case Repo.transaction(multi) do
|
| 210 |
+
{:ok, %{chunk_code_vector: chunk_code_vector}} ->
|
| 211 |
+
{:ok, chunk_code_vector}
|
| 212 |
+
|
| 213 |
+
{:error, failed_operation, failed_value, changes_so_far} ->
|
| 214 |
+
{:error, failed_operation, failed_value, changes_so_far}
|
| 215 |
end
|
| 216 |
end
|
| 217 |
|
lib/medicode_web/components/transcription_chunk_codings_component.ex
CHANGED
|
@@ -80,11 +80,18 @@ defmodule MedicodeWeb.Components.TranscriptionTextCodingsComponent do
|
|
| 80 |
>
|
| 81 |
Finalize
|
| 82 |
</button>
|
| 83 |
-
<
|
| 84 |
:if={!is_nil(@transcription_chunk_code_vector.finalized_at)}
|
| 85 |
-
|
| 86 |
-
class="opacity-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
</div>
|
| 89 |
<p class="text-base leading-[20.42px]"><%= @code_vector.description %></p>
|
| 90 |
<div class="flex flex-row items-center w-full gap-4">
|
|
@@ -102,6 +109,7 @@ defmodule MedicodeWeb.Components.TranscriptionTextCodingsComponent do
|
|
| 102 |
type="button"
|
| 103 |
aria-label={gettext("close")}
|
| 104 |
>
|
|
|
|
| 105 |
<.icon name="hero-x-mark-solid" class="opacity-40 group-hover:opacity-70" />
|
| 106 |
</button>
|
| 107 |
</div>
|
|
|
|
| 80 |
>
|
| 81 |
Finalize
|
| 82 |
</button>
|
| 83 |
+
<button
|
| 84 |
:if={!is_nil(@transcription_chunk_code_vector.finalized_at)}
|
| 85 |
+
type="button"
|
| 86 |
+
class="transition-all duration-300 opacity-0 group-hover:opacity-100 hover:bg-slate-200 px-2 border border-1 border-iron-mountain rounded-md"
|
| 87 |
+
phx-click="finalize_code"
|
| 88 |
+
phx-value-chunk_id={@chunk_id}
|
| 89 |
+
phx-value-code_vector_id={@code_vector.id}
|
| 90 |
+
phx-target={@myself}
|
| 91 |
+
title="Clear"
|
| 92 |
+
>
|
| 93 |
+
<.icon name="hero-check-badge" class="opacity-40 group-hover:opacity-70" />
|
| 94 |
+
</button>
|
| 95 |
</div>
|
| 96 |
<p class="text-base leading-[20.42px]"><%= @code_vector.description %></p>
|
| 97 |
<div class="flex flex-row items-center w-full gap-4">
|
|
|
|
| 109 |
type="button"
|
| 110 |
aria-label={gettext("close")}
|
| 111 |
>
|
| 112 |
+
Clear
|
| 113 |
<.icon name="hero-x-mark-solid" class="opacity-40 group-hover:opacity-70" />
|
| 114 |
</button>
|
| 115 |
</div>
|
test/medicode_web/live/transcriptions_live_show_test.exs
CHANGED
|
@@ -32,7 +32,9 @@ defmodule MedicodeWeb.TranscriptionsLive.ShowTest do
|
|
| 32 |
|
| 33 |
transcription_chunk_code_vector_fixture(%{
|
| 34 |
transcription_chunk_id: transcription_chunk1.id,
|
| 35 |
-
code_vector_id: code_vector2.id
|
|
|
|
|
|
|
| 36 |
})
|
| 37 |
|
| 38 |
transcription_chunk_code_vector_fixture(%{
|
|
@@ -45,7 +47,8 @@ defmodule MedicodeWeb.TranscriptionsLive.ShowTest do
|
|
| 45 |
current_user: user,
|
| 46 |
transcription: transcription,
|
| 47 |
transcription_chunk1: transcription_chunk1,
|
| 48 |
-
code_vector1: code_vector1
|
|
|
|
| 49 |
}
|
| 50 |
end
|
| 51 |
|
|
@@ -97,5 +100,30 @@ defmodule MedicodeWeb.TranscriptionsLive.ShowTest do
|
|
| 97 |
assert rendered =~ "Finalized Codes"
|
| 98 |
assert rendered =~ "001"
|
| 99 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
end
|
| 101 |
end
|
|
|
|
| 32 |
|
| 33 |
transcription_chunk_code_vector_fixture(%{
|
| 34 |
transcription_chunk_id: transcription_chunk1.id,
|
| 35 |
+
code_vector_id: code_vector2.id,
|
| 36 |
+
finalized_at: DateTime.utc_now(),
|
| 37 |
+
finalized_by_user_id: user.id
|
| 38 |
})
|
| 39 |
|
| 40 |
transcription_chunk_code_vector_fixture(%{
|
|
|
|
| 47 |
current_user: user,
|
| 48 |
transcription: transcription,
|
| 49 |
transcription_chunk1: transcription_chunk1,
|
| 50 |
+
code_vector1: code_vector1,
|
| 51 |
+
code_vector2: code_vector2
|
| 52 |
}
|
| 53 |
end
|
| 54 |
|
|
|
|
| 100 |
assert rendered =~ "Finalized Codes"
|
| 101 |
assert rendered =~ "001"
|
| 102 |
end
|
| 103 |
+
|
| 104 |
+
test "renders removes finalized state from selected codes", %{
|
| 105 |
+
conn: conn,
|
| 106 |
+
transcription: transcription,
|
| 107 |
+
transcription_chunk1: transcription_chunk1,
|
| 108 |
+
code_vector2: code_vector2
|
| 109 |
+
} do
|
| 110 |
+
conn = get(conn, "/transcriptions/#{transcription.id}")
|
| 111 |
+
assert html_response(conn, 200) =~ "MediCode"
|
| 112 |
+
|
| 113 |
+
{:ok, view, _html} = live(conn)
|
| 114 |
+
|
| 115 |
+
view
|
| 116 |
+
|> element(
|
| 117 |
+
"#chunk-#{transcription_chunk1.id}-coding-#{code_vector2.id} button[title=Clear]"
|
| 118 |
+
)
|
| 119 |
+
|> render_click()
|
| 120 |
+
|
| 121 |
+
_ = :sys.get_state(view.pid)
|
| 122 |
+
|
| 123 |
+
rendered = render(view)
|
| 124 |
+
|
| 125 |
+
refute rendered =~ "<span class=\"hero-check-badge"
|
| 126 |
+
refute rendered =~ "Finalized Codes"
|
| 127 |
+
end
|
| 128 |
end
|
| 129 |
end
|