timgremore commited on
Commit
4d43dfd
1 Parent(s): bcd90d6

feat: Wire up ChromicPDF and basic download route

Browse files
lib/medicode/application.ex CHANGED
@@ -29,6 +29,7 @@ defmodule Medicode.Application do
29
  Medicode.ClassificationSupervisor,
30
  strategy: :one_for_one, max_restarts: 1
31
  },
 
32
  # Start a worker by calling: Medicode.Worker.start_link(arg)
33
  # {Medicode.Worker, arg},
34
  # Start to serve requests, typically the last entry
 
29
  Medicode.ClassificationSupervisor,
30
  strategy: :one_for_one, max_restarts: 1
31
  },
32
+ ChromicPDF,
33
  # Start a worker by calling: Medicode.Worker.start_link(arg)
34
  # {Medicode.Worker, arg},
35
  # Start to serve requests, typically the last entry
lib/medicode_web/components/components.ex CHANGED
@@ -144,6 +144,14 @@ defmodule MedicodeWeb.Components do
144
  <%= chunk_code.code_vector.code %>
145
  </span>
146
  </div>
 
 
 
 
 
 
 
 
147
  </div>
148
  </div>
149
  """
 
144
  <%= chunk_code.code_vector.code %>
145
  </span>
146
  </div>
147
+
148
+ <.link
149
+ href={~p"/transcription/reports/#{@transcription.id}"}
150
+ class="font-semibold text-brand hover:underline"
151
+ download={"transcription-report-#{@transcription.id}.pdf"}
152
+ >
153
+ Download Report
154
+ </.link>
155
  </div>
156
  </div>
157
  """
lib/medicode_web/components/transcription_report_component.ex ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule MedicodeWeb.Components.TranscriptionReportComponent do
2
+ @moduledoc """
3
+ This module is responsible for rendering the transcription report component.
4
+ """
5
+
6
+ use Phoenix.LiveComponent
7
+
8
+ def render(assigns) do
9
+ ~H"""
10
+ <h1>Transcription</h1>
11
+ <p style="font-size: 200%;">ID: <%= @transcription.id %></p>
12
+ """
13
+ end
14
+ end
lib/medicode_web/controllers/transcription_reports_controller.ex ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule MedicodeWeb.TranscriptionReportsController do
2
+ use MedicodeWeb, :controller
3
+
4
+ alias Medicode.Transcriptions
5
+
6
+ def show(conn, _params) do
7
+ transcription = Transcriptions.get_transcription!(conn.params["id"])
8
+
9
+ conn = assign(conn, :transcription, transcription)
10
+
11
+ ### We will write this function later.
12
+ {:ok, pdf} = to_pdf(conn.assigns)
13
+
14
+ send_download(
15
+ conn,
16
+ {:binary, Base.decode64!(pdf)},
17
+ content_type: "application/pdf",
18
+ filename: "transcription_report.pdf"
19
+ )
20
+ end
21
+
22
+ defp to_pdf(assigns) do
23
+ [
24
+ content: content(assigns),
25
+ size: :a4
26
+ ]
27
+ |> ChromicPDF.Template.source_and_options()
28
+ |> ChromicPDF.print_to_pdf()
29
+ end
30
+
31
+ defp content(assigns) do
32
+ Phoenix.HTML.Safe.to_iodata(
33
+ MedicodeWeb.Components.TranscriptionReportComponent.render(assigns)
34
+ )
35
+ end
36
+ end
lib/medicode_web/router.ex CHANGED
@@ -69,6 +69,8 @@ defmodule MedicodeWeb.Router do
69
  scope "/", MedicodeWeb do
70
  pipe_through [:browser, :require_authenticated_user]
71
 
 
 
72
  live_session :require_authenticated_user,
73
  on_mount: [{MedicodeWeb.UserAuth, :ensure_authenticated}] do
74
  live "/users/settings", UserSettingsLive, :edit
 
69
  scope "/", MedicodeWeb do
70
  pipe_through [:browser, :require_authenticated_user]
71
 
72
+ get "/transcription/reports/:id", TranscriptionReportsController, :show
73
+
74
  live_session :require_authenticated_user,
75
  on_mount: [{MedicodeWeb.UserAuth, :ensure_authenticated}] do
76
  live "/users/settings", UserSettingsLive, :edit
mix.exs CHANGED
@@ -66,7 +66,8 @@ defmodule Medicode.MixProject do
66
  {:membrane_core, "~> 1.0"},
67
  {:membrane_raw_audio_format, "~> 0.12.0"},
68
  {:kino, "~> 0.12.3"},
69
- {:csv, "~> 3.2"}
 
70
  # {:membrane_portaudio_plugin, "~> 0.18.0"}
71
  ]
72
  end
 
66
  {:membrane_core, "~> 1.0"},
67
  {:membrane_raw_audio_format, "~> 0.12.0"},
68
  {:kino, "~> 0.12.3"},
69
+ {:csv, "~> 3.2"},
70
+ {:chromic_pdf, "~> 1.15"}
71
  # {:membrane_portaudio_plugin, "~> 0.18.0"}
72
  ]
73
  end
mix.lock CHANGED
@@ -10,6 +10,7 @@
10
  "bundlex": {:hex, :bundlex, "1.4.5", "ea06cb441af636baaf5232dced24c6b1ee5ccbe7a7cad8a348eb3100fa1d7b52", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:req, "~> 0.4.0", [hex: :req, repo: "hexpm", optional: false]}, {:zarex, "~> 1.0", [hex: :zarex, repo: "hexpm", optional: false]}], "hexpm", "bd4136100d3120740bf8eaa73ad74859d5ccd659cf0b27aa1645590a67a0172b"},
11
  "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
12
  "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
 
13
  "coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
14
  "comeonin": {:hex, :comeonin, "5.4.0", "246a56ca3f41d404380fc6465650ddaa532c7f98be4bda1b4656b3a37cc13abe", [:mix], [], "hexpm", "796393a9e50d01999d56b7b8420ab0481a7538d0caf80919da493b4a6e51faf1"},
15
  "complex": {:hex, :complex, "0.5.0", "af2d2331ff6170b61bb738695e481b27a66780e18763e066ee2cd863d0b1dd92", [:mix], [], "hexpm", "2683bd3c184466cfb94fad74cbfddfaa94b860e27ad4ca1bffe3bff169d91ef1"},
 
10
  "bundlex": {:hex, :bundlex, "1.4.5", "ea06cb441af636baaf5232dced24c6b1ee5ccbe7a7cad8a348eb3100fa1d7b52", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:req, "~> 0.4.0", [hex: :req, repo: "hexpm", optional: false]}, {:zarex, "~> 1.0", [hex: :zarex, repo: "hexpm", optional: false]}], "hexpm", "bd4136100d3120740bf8eaa73ad74859d5ccd659cf0b27aa1645590a67a0172b"},
11
  "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
12
  "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
13
+ "chromic_pdf": {:hex, :chromic_pdf, "1.15.2", "da099affe93dcd3438bcb5c38f39179f7f4f72c08a8b2799b50dcc21665f01b7", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14 or ~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websockex, ">= 0.4.3", [hex: :websockex, repo: "hexpm", optional: true]}], "hexpm", "c0e9d62b807c7df019bc642b20eb78f3445f09260413a210a240ee080c1fc8f1"},
14
  "coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
15
  "comeonin": {:hex, :comeonin, "5.4.0", "246a56ca3f41d404380fc6465650ddaa532c7f98be4bda1b4656b3a37cc13abe", [:mix], [], "hexpm", "796393a9e50d01999d56b7b8420ab0481a7538d0caf80919da493b4a6e51faf1"},
16
  "complex": {:hex, :complex, "0.5.0", "af2d2331ff6170b61bb738695e481b27a66780e18763e066ee2cd863d0b1dd92", [:mix], [], "hexpm", "2683bd3c184466cfb94fad74cbfddfaa94b860e27ad4ca1bffe3bff169d91ef1"},