defmodule MedicalTranscriptionWeb.Components do
@moduledoc """
Functional UI components for the main transcription and coding view.
"""
use Phoenix.Component
alias Phoenix.LiveView.JS
alias MedicalTranscription.Utilities
import MedicalTranscriptionWeb.CoreComponents
alias MedicalTranscriptionWeb.Components.TranscriptionTextComponent
use MedicalTranscriptionWeb, :verified_routes
def upload_form(assigns) do
~H"""
<.icon name="hero-arrow-path" class="w-4 h-4 animate-spin" />
Transcribing and tagging audio file...
<% end %>
"""
end
def result_heading(assigns) do
if Enum.member?([:loading, :streaming_audio, :success], assigns.status) do
~H"""
<%= for {dom_id, row} <- @rows do %>
<.live_component
module={TranscriptionTextComponent}
id={dom_id}
start_mark={row.start_mark}
end_mark={row.end_mark}
text={row.text}
/>
<% end %>
"""
end
def tag_result(assigns) do
~H"""
<.feedback_button code_vector_id={@code_vector_id} text={@text} response="true" />
<.feedback_button code_vector_id={@code_vector_id} text={@text} response="false" />
<%= @code %>
<%= @label %>
"""
end
def code_color(weighting) do
cond do
:positive in weighting and :negative in weighting -> "bg-orange-200/40"
:positive in weighting -> "bg-emerald-200/40"
:negative in weighting -> "bg-red-200/40"
true -> ""
end
end
def code_title(score, weighting) do
weighting_description =
if length(weighting) > 0 do
weighting
|> Utilities.tally()
|> Utilities.tally_to_string()
|> String.replace_prefix("", "Weighting: ")
else
""
end
"Similarity score: #{trunc(score * 100) / 100}. #{weighting_description}"
end
defp feedback_button(assigns) do
~H"""