Commit ·
dd83613
1
Parent(s): 4d43dfd
feat: PDF report from transcription text and codes
Browse files
lib/medicode/transcriptions.ex
CHANGED
|
@@ -102,6 +102,22 @@ defmodule Medicode.Transcriptions do
|
|
| 102 |
Repo.get!(query, id)
|
| 103 |
end
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
@doc """
|
| 106 |
Gets a single transcription chunk.
|
| 107 |
|
|
|
|
| 102 |
Repo.get!(query, id)
|
| 103 |
end
|
| 104 |
|
| 105 |
+
@doc """
|
| 106 |
+
Concatenates transcription chunks into a single text.
|
| 107 |
+
|
| 108 |
+
## Examples
|
| 109 |
+
|
| 110 |
+
iex> get_text_from_transcription(%Transcription{})
|
| 111 |
+
"This is a transcription."
|
| 112 |
+
"""
|
| 113 |
+
def get_text_from_transcription(transcription) do
|
| 114 |
+
TranscriptionChunk
|
| 115 |
+
|> where([c], c.transcription_id == ^transcription.id)
|
| 116 |
+
|> select([c], c.text)
|
| 117 |
+
|> Repo.all()
|
| 118 |
+
|> Enum.map_join(" ", & &1)
|
| 119 |
+
end
|
| 120 |
+
|
| 121 |
@doc """
|
| 122 |
Gets a single transcription chunk.
|
| 123 |
|
lib/medicode_web/components/transcription_report_component.ex
CHANGED
|
@@ -7,8 +7,16 @@ defmodule MedicodeWeb.Components.TranscriptionReportComponent do
|
|
| 7 |
|
| 8 |
def render(assigns) do
|
| 9 |
~H"""
|
| 10 |
-
<
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
end
|
| 14 |
end
|
|
|
|
| 7 |
|
| 8 |
def render(assigns) do
|
| 9 |
~H"""
|
| 10 |
+
<div style="padding: 1rem 2rem;">
|
| 11 |
+
<h1>Transcription</h1>
|
| 12 |
+
<p><%= @text %></p>
|
| 13 |
+
<div>
|
| 14 |
+
<div :for={code_vector <- @finalized_code_vectors}>
|
| 15 |
+
<h2><%= code_vector.code %></h2>
|
| 16 |
+
<p><%= code_vector.description %></p>
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
</div>
|
| 20 |
"""
|
| 21 |
end
|
| 22 |
end
|
lib/medicode_web/controllers/transcription_reports_controller.ex
CHANGED
|
@@ -5,8 +5,18 @@ defmodule MedicodeWeb.TranscriptionReportsController do
|
|
| 5 |
|
| 6 |
def show(conn, _params) do
|
| 7 |
transcription = Transcriptions.get_transcription!(conn.params["id"])
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
### We will write this function later.
|
| 12 |
{:ok, pdf} = to_pdf(conn.assigns)
|
|
|
|
| 5 |
|
| 6 |
def show(conn, _params) do
|
| 7 |
transcription = Transcriptions.get_transcription!(conn.params["id"])
|
| 8 |
+
text = Transcriptions.get_text_from_transcription(transcription)
|
| 9 |
|
| 10 |
+
finalized_codes =
|
| 11 |
+
transcription.id
|
| 12 |
+
|> Transcriptions.list_transcription_finalized_codes()
|
| 13 |
+
|> Enum.map(fn chunk_code_vector -> chunk_code_vector.code_vector end)
|
| 14 |
+
|
| 15 |
+
conn =
|
| 16 |
+
conn
|
| 17 |
+
|> assign(:transcription, transcription)
|
| 18 |
+
|> assign(:text, text)
|
| 19 |
+
|> assign(:finalized_code_vectors, finalized_codes)
|
| 20 |
|
| 21 |
### We will write this function later.
|
| 22 |
{:ok, pdf} = to_pdf(conn.assigns)
|