defmodule MedicalTranscription.Transcriptions do @moduledoc """ The Transcriptions context. """ import Ecto.Query, warn: false alias MedicalTranscription.Repo alias MedicalTranscription.Transcriptions.Transcription @doc """ Create transcription record and begin transcribing ## Examples iex> create_and_transcribe_audio("my-audio.mp3") %Transcription{audio_file: "my-audio.mp3"} """ def transcribe_audio(transcription) do MedicalTranscription.TranscriptionSupervisor.start_transcription(transcription) end @doc """ Returns the list of transcriptions. ## Examples iex> list_transcriptions() [%Transcription{}, ...] """ def list_transcriptions(user) do Transcription |> where([t], t.user_id == ^user.id) |> Repo.all() end @doc """ Gets a single transcription. Raises `Ecto.NoResultsError` if the Transcription does not exist. ## Examples iex> get_transcription!(123) %Transcription{} iex> get_transcription!(456) ** (Ecto.NoResultsError) """ def get_transcription!(id), do: Repo.get!(Transcription, id) @doc """ Creates a transcription. ## Examples iex> create_transcription(%{field: value}) {:ok, %Transcription{}} iex> create_transcription(%{field: bad_value}) {:error, %Ecto.Changeset{}} """ def create_transcription(attrs \\ %{}) do %Transcription{} |> Transcription.changeset(attrs) |> Repo.insert() end @doc """ Updates a transcription. ## Examples iex> update_transcription(transcription, %{field: new_value}) {:ok, %Transcription{}} iex> update_transcription(transcription, %{field: bad_value}) {:error, %Ecto.Changeset{}} """ def update_transcription(%Transcription{} = transcription, attrs) do transcription |> Transcription.changeset(attrs) |> Repo.update() end @doc """ Deletes a transcription. ## Examples iex> delete_transcription(transcription) {:ok, %Transcription{}} iex> delete_transcription(transcription) {:error, %Ecto.Changeset{}} """ def delete_transcription(%Transcription{} = transcription) do Repo.delete(transcription) end @doc """ Returns an `%Ecto.Changeset{}` for tracking transcription changes. ## Examples iex> change_transcription(transcription) %Ecto.Changeset{data: %Transcription{}} """ def change_transcription(%Transcription{} = transcription, attrs \\ %{}) do Transcription.changeset(transcription, attrs) end end