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"""
<.live_file_input class="flex-1 cursor-pointer file:hidden file:font-secondary file:text-sm file:rounded-full file:px-4 file:py-2 file:border-0 file:bg-brand file:hover:bg-brand-active file:text-white" upload={@audio_upload} />

Audio file can be .mp3

""" end def loading_message(assigns) do ~H""" <%= if @visible do %>
<.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"""
<%= case @status do %> <% status when status in [:loading, :streaming_audio] -> %> <% :success -> %> <% end %> <.record_button_in_heading status={@status} />
<%= @filename %>
<%= Calendar.strftime(DateTime.now!("Etc/UTC"), "%a, %b %d, %Y, %I:%M %p") %>

Summary Keywords

<%= for keyword <- format_keywords(@summary_keywords) do %> <%= keyword.label %>, <% end %>

""" else ~H"" end end def record_button_in_heading(assigns) when assigns.status == :streaming_audio do ~H""" """ end def record_button_in_heading(assigns) do ~H""" """ end def format_keywords(keyword_predictions) do keyword_predictions |> List.flatten() |> Enum.sort_by(& &1.score, :desc) |> Enum.take(7) end def result_list(assigns) 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""" """ end end