aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala b/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala
new file mode 100644
index 0000000..d50be2c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala
@@ -0,0 +1,27 @@
+package xyz.driver.pdsuidomain.storage
+
+import com.google.cloud.storage.StorageOptions
+import com.typesafe.scalalogging.StrictLogging
+import xyz.driver.pdsuidomain.entities.MedicalRecord.PdfSource
+
+import scala.concurrent.{ExecutionContext, Future, blocking}
+
+object MedicalRecordDocumentStorage extends StrictLogging {
+ private val storage = StorageOptions.getDefaultInstance.getService
+
+ def fetchPdf(bucket: String, path: String)
+ (implicit ec: ExecutionContext): Future[PdfSource] = {
+ logger.trace(s"fetchPdf(bucket=$bucket, path=$path)")
+ Future {
+ blocking {
+ Option(storage.get(bucket, path)) match {
+ case Some(blob) =>
+ PdfSource.Channel(() => blob.reader())
+ case None =>
+ logger.error(s"Failed to find the pdf file $path in bucket: $bucket")
+ PdfSource.Empty
+ }
+ }
+ }
+ }
+}