defmodule MedicodeWeb.Components do @moduledoc """ Functional UI components for the main transcription and coding view. """ use Phoenix.Component use MedicodeWeb, :verified_routes import MedicodeWeb.CoreComponents attr(:audio_upload, Phoenix.LiveView.UploadConfig, required: true) @doc """ Displays a form containing a button for listening to live audio and a file upload for recorded audio files. """ 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 attr(:visible, :boolean, required: true) @doc """ A loading icon and message displayed while the audio is being processed. """ 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 attr(:id, :string, required: true) attr(:target, :any, required: true) attr(:transcription, Medicode.Transcriptions.Transcription, required: true) attr(:summary_keywords, :list, default: []) attr(:finalized_codes, :list, default: []) attr(:timezone, :string, default: "Etc/UTC") @doc """ Shows the status and keywords for the current session. """ def result_heading(assigns) do assigns = assign_new(assigns, :transcript_inserted_at, fn _ -> assigns.transcription.inserted_at |> DateTime.shift_zone!(assigns.timezone) |> Calendar.strftime("%a, %b %d, %Y, %I:%M %p") end) ~H"""

<%= @transcription.filename %>

<%= @transcript_inserted_at %>

Summary Keywords

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

Finalized Codes

<%= code_vector.code %>
<.link href={~p"/transcription/reports/#{@transcription.id}"} class="font-semibold text-brand hover:underline" download={"transcription-report-#{@transcription.id}.pdf"} > Download Report
""" end # Formats keywords for display in the result_heading component defp format_keywords(keyword_predictions) do keyword_predictions |> List.flatten() |> Enum.sort_by(& &1.score, :desc) |> Enum.take(7) end attr(:code, :string, required: true) attr(:label, :string, required: true) @doc """ Displays a single code and its description. """ def code_display(assigns) do ~H"""

<%= @code %>

<%= @label %>

""" end end