aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-14 14:46:19 -0700
committervlad <vlad@driver.xyz>2017-06-14 14:46:19 -0700
commit7b8ac40ab6501ec53c5a55962fe4a3d54666ae8d (patch)
tree211a6a544facb278807d47cc3d91f0cee59f2466
parent59aababea4a8856ac972fe452b14003f82fe3706 (diff)
downloadrest-query-7b8ac40ab6501ec53c5a55962fe4a3d54666ae8d.tar.gz
rest-query-7b8ac40ab6501ec53c5a55962fe4a3d54666ae8d.tar.bz2
rest-query-7b8ac40ab6501ec53c5a55962fe4a3d54666ae8d.zip
Update for recent PDS UI changesv0.1.4
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/http/AsyncHttpClientFetcher.scala25
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/logging/Implicits.scala18
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala42
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala23
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala15
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientDocument.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala6
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala59
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala25
11 files changed, 63 insertions, 167 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/AsyncHttpClientFetcher.scala b/src/main/scala/xyz/driver/pdsuicommon/http/AsyncHttpClientFetcher.scala
index d693019..3f99d2a 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/http/AsyncHttpClientFetcher.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/http/AsyncHttpClientFetcher.scala
@@ -40,19 +40,17 @@ class AsyncHttpClientFetcher(settings: AsyncHttpClientFetcher.Settings)
logger.info("{}, apply({})", fingerPrint, url)
val promise = Promise[Response]()
- httpClient
- .prepareGet(url.toString)
- .execute(new AsyncCompletionHandler[Response] {
- override def onCompleted(response: Response): Response = {
- promise.success(response)
- response
- }
-
- override def onThrowable(t: Throwable): Unit = {
- promise.failure(t)
- super.onThrowable(t)
- }
- })
+ httpClient.prepareGet(url.toString).execute(new AsyncCompletionHandler[Response] {
+ override def onCompleted(response: Response): Response = {
+ promise.success(response)
+ response
+ }
+
+ override def onThrowable(t: Throwable): Unit = {
+ promise.failure(t)
+ super.onThrowable(t)
+ }
+ })
// Promises have their own ExecutionContext
// So, we have to hack it.
@@ -62,7 +60,6 @@ class AsyncHttpClientFetcher(settings: AsyncHttpClientFetcher.Settings)
if (response.getStatusCode == 200) {
// DO NOT LOG body, it could be PHI
- // logger.trace(response.getResponseBody())
val bytes = response.getResponseBodyAsBytes
logger.debug("{}, size is {}B", fingerPrint, bytes.size.asInstanceOf[AnyRef])
Future.successful(bytes)
diff --git a/src/main/scala/xyz/driver/pdsuicommon/logging/Implicits.scala b/src/main/scala/xyz/driver/pdsuicommon/logging/Implicits.scala
index 84cf31e..e1660e2 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/logging/Implicits.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/logging/Implicits.scala
@@ -3,7 +3,7 @@ package xyz.driver.pdsuicommon.logging
import java.io.File
import java.net.{URI, URL}
import java.nio.file.Path
-import java.time.LocalDateTime
+import java.time.{LocalDate, LocalDateTime}
import java.util.UUID
import scala.concurrent.duration.Duration
@@ -29,23 +29,27 @@ trait Implicits {
implicit def localDateTimeToPhiString(x: LocalDateTime): PhiString = Unsafe(x.toString)
+ implicit def localDateToPhiString(x: LocalDate): PhiString = Unsafe(x.toString)
+
implicit def durationToPhiString(x: Duration): PhiString = Unsafe(x.toString)
implicit def uuidToPhiString(x: UUID): PhiString = Unsafe(x.toString)
- implicit def tuple2ToPhiString[T1, T2](x: (T1, T2))(implicit inner1: T1 => PhiString,
- inner2: T2 => PhiString): PhiString = x match {
+ implicit def tuple2ToPhiString[T1, T2](x: (T1, T2))
+ (implicit inner1: T1 => PhiString,
+ inner2: T2 => PhiString): PhiString = x match {
case (a, b) => phi"($a, $b)"
}
- implicit def tuple3ToPhiString[T1, T2, T3](x: (T1, T2, T3))(implicit inner1: T1 => PhiString,
- inner2: T2 => PhiString,
- inner3: T3 => PhiString): PhiString = x match {
+ implicit def tuple3ToPhiString[T1, T2, T3](x: (T1, T2, T3))
+ (implicit inner1: T1 => PhiString,
+ inner2: T2 => PhiString,
+ inner3: T3 => PhiString): PhiString = x match {
case (a, b, c) => phi"($a, $b, $c)"
}
implicit def optionToPhiString[T](opt: Option[T])(implicit inner: T => PhiString): PhiString = opt match {
- case None => phi"None"
+ case None => phi"None"
case Some(x) => phi"Some($x)"
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala
deleted file mode 100644
index 4f1f1b9..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/DirectReport.scala
+++ /dev/null
@@ -1,42 +0,0 @@
-package xyz.driver.pdsuidomain.entities
-
-import java.time.LocalDateTime
-
-import xyz.driver.pdsuicommon.domain.UuidId
-import xyz.driver.pdsuicommon.logging._
-import xyz.driver.pdsuicommon.utils.Utils
-import xyz.driver.pdsuidomain.entities.DirectReport.ReportType
-
-object DirectReport {
-
- sealed trait ReportType extends Product with Serializable {
- def oneOf(xs: ReportType*): Boolean = xs.contains(this)
-
- def oneOf(xs: Set[ReportType]): Boolean = xs.contains(this)
- }
-
- object ReportType {
- case object IHC extends ReportType
- case object DNA extends ReportType
- case object CFDNA extends ReportType
-
- val All = Set(IHC, DNA, CFDNA)
- implicit def toPhiString(x: ReportType): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass))
- }
-
- implicit def toPhiString(x: DirectReport): PhiString = {
- import x._
- phi"DirectReport(id=$id, patientId=$patientId, reportType=$reportType, date=${Unsafe(date)}, " +
- phi"documentType=${Unsafe(documentType)}, providerType=${Unsafe(providerType)}, " +
- phi"providerName=${Unsafe(providerName)})"
- }
-
-}
-
-case class DirectReport(id: UuidId[DirectReport],
- patientId: UuidId[Patient],
- reportType: ReportType,
- date: LocalDateTime,
- documentType: String,
- providerType: String,
- providerName: String)
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
index b10f67a..9fc1992 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala
@@ -1,6 +1,6 @@
package xyz.driver.pdsuidomain.entities
-import java.time.LocalDateTime
+import java.time.{LocalDate, LocalDateTime}
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.core.{JsonGenerator, JsonParser}
@@ -101,15 +101,15 @@ object Document {
startDate <- Validators.nonEmpty("startDate")(input.startDate)
isOrderRight <- input.endDate match {
- case Some(endDate) if startDate.isAfter(endDate) =>
- Validators.fail("The start date should be less, than the end one")
+ case Some(endDate) if startDate.isAfter(endDate) =>
+ Validators.fail("The start date should be less, than the end one")
- case _ => Validators.success(true)
- }
+ case _ => Validators.success(true)
+ }
areDatesInThePast <- {
- val dates = List(input.startDate, input.endDate).flatten
- val now = LocalDateTime.now()
+ val dates = List(input.startDate, input.endDate).flatten
+ val now = LocalDate.now()
val hasInvalid = dates.exists(_.isAfter(now))
if (hasInvalid) Validators.fail("Dates should be in the past")
@@ -129,17 +129,18 @@ case class Document(id: LongId[Document] = LongId(0L),
recordId: LongId[MedicalRecord],
physician: Option[String],
typeId: Option[LongId[DocumentType]], // not null
- providerName: Option[String], // not null
+ providerName: Option[String], // not null
providerTypeId: Option[LongId[ProviderType]], // not null
meta: Option[TextJson[Meta]], // not null
- startDate: Option[LocalDateTime], // not null
- endDate: Option[LocalDateTime],
+ startDate: Option[LocalDate], // not null
+ endDate: Option[LocalDate],
lastUpdate: LocalDateTime) {
import Document.Status._
if (previousStatus.nonEmpty) {
- assert(AllPrevious.contains(previousStatus.get), s"Previous status has invalid value: ${previousStatus.get}")
+ assert(AllPrevious.contains(previousStatus.get),
+ s"Previous status has invalid value: ${previousStatus.get}")
}
// TODO: with the current business logic code this constraint sometimes harmful
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala
index 5df5253..c0ead6f 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientEligibleTrial.scala
@@ -23,12 +23,9 @@ object PatientCriterion {
case None => None
case Some(FuzzyValue.Maybe) => Some(FuzzyValue.Maybe)
case Some(_) if criterionValue.isEmpty => Some(FuzzyValue.Maybe)
- case Some(status) =>
- Some(
- FuzzyValue.fromBoolean(
- FuzzyValue.fromBoolean(
- criterionValue.getOrElse(throw new IllegalArgumentException("Criterion should not be empty"))) == status
- ))
+ case Some(status) => Some(FuzzyValue.fromBoolean(
+ FuzzyValue.fromBoolean(criterionValue.get) == status
+ ))
}
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala
index 633a347..cb6f8a0 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala
@@ -25,14 +25,13 @@ object PatientLabelEvidence {
implicit def toPhiString(x: PatientLabelEvidence): PhiString = {
import x._
phi"PatientLabelEvidence(id=$id, patientLabelId=$patientLabelId, value=${Unsafe(value)}, " +
- phi"documentId=$documentId, evidenceId=$evidenceId, reportId=$reportId)"
+ phi"documentId=$documentId, evidenceId=$evidenceId)"
}
}
-final case class PatientLabelEvidence(id: LongId[PatientLabelEvidence],
- patientLabelId: LongId[PatientLabel],
- value: FuzzyValue,
- evidenceText: String,
- reportId: Option[UuidId[DirectReport]],
- documentId: Option[LongId[Document]],
- evidenceId: Option[LongId[ExtractedData]])
+case class PatientLabelEvidence(id: LongId[PatientLabelEvidence],
+ patientLabelId: LongId[PatientLabel],
+ value: FuzzyValue,
+ evidenceText: String,
+ documentId: LongId[Document],
+ evidenceId: LongId[ExtractedData])
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientDocument.scala
index 88e1a45..8e72023 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientDocument.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientDocument.scala
@@ -1,6 +1,6 @@
package xyz.driver.pdsuidomain.entities
-import java.time.LocalDateTime
+import java.time.LocalDate
import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
import xyz.driver.pdsuicommon.logging._
@@ -13,7 +13,7 @@ case class RawPatientDocument(disease: String,
documentId: LongId[Document],
documentType: String,
documentProviderType: String,
- documentStartDate: LocalDateTime,
+ documentStartDate: LocalDate,
documentStatus: Document.Status)
object RawPatientDocument {
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
index e0cf06b..052b2fa 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
@@ -1,6 +1,6 @@
package xyz.driver.pdsuidomain.entities
-import java.time.LocalDateTime
+import java.time.LocalDate
import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId}
import xyz.driver.pdsuicommon.logging._
@@ -16,8 +16,8 @@ case class RawPatientLabel(patientId: UuidId[Patient],
requestId: RecordRequestId,
documentType: String,
providerType: String,
- startDate: LocalDateTime,
- endDate: Option[LocalDateTime])
+ startDate: LocalDate,
+ endDate: Option[LocalDate])
object RawPatientLabel {
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
index d696569..978c4b8 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
@@ -1,6 +1,6 @@
package xyz.driver.pdsuidomain.entities.export.patient
-import java.time.LocalDateTime
+import java.time.LocalDate
import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuicommon.logging._
@@ -10,7 +10,7 @@ case class ExportPatientLabelEvidenceDocument(documentId: LongId[Document],
requestId: RecordRequestId,
documentType: String,
providerType: String,
- date: LocalDateTime)
+ date: LocalDate)
object ExportPatientLabelEvidenceDocument extends PhiLogging {
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala
deleted file mode 100644
index 5be037c..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala
+++ /dev/null
@@ -1,59 +0,0 @@
-package xyz.driver.pdsuidomain.services
-
-import java.time.LocalDateTime
-
-import xyz.driver.pdsuicommon.auth.AnonymousRequestContext
-import xyz.driver.pdsuicommon.db.SearchFilterExpr
-import xyz.driver.pdsuicommon.domain.{StringId, UuidId}
-import xyz.driver.pdsuicommon.error.DomainError
-import xyz.driver.pdsuicommon.logging._
-import xyz.driver.pdsuidomain.entities.{Patient, Trial}
-import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels
-import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrial, ExportTrialWithLabels}
-
-import scala.concurrent.Future
-
-object ExportService {
-
- sealed trait GetPatientReply
- object GetPatientReply {
- type Error = GetPatientReply with DomainError
-
- case class Entity(x: ExportPatientWithLabels) extends GetPatientReply
-
- case object NotFoundError extends GetPatientReply with DomainError.NotFoundError {
- def userMessage: String = "Patient not found"
- }
- }
-
- sealed trait GetTrialListReply
- object GetTrialListReply {
- case class EntityList(xs: Seq[ExportTrial], totalFound: Int, lastUpdate: Option[LocalDateTime])
- extends GetTrialListReply
- }
-
- sealed trait GetTrialReply
- object GetTrialReply {
- type Error = GetTrialReply with DomainError
-
- case class Entity(x: ExportTrialWithLabels) extends GetTrialReply
-
- case object NotFoundError extends GetTrialReply with DomainError.NotFoundError {
- def userMessage: String = "Trial not found"
- }
- }
-}
-
-trait ExportService extends PhiLogging {
-
- import ExportService._
-
- def getPatient(id: UuidId[Patient])(implicit requestContext: AnonymousRequestContext): Future[GetPatientReply]
-
- def getTrialList(filter: SearchFilterExpr = SearchFilterExpr.Empty)(
- implicit requestContext: AnonymousRequestContext): Future[GetTrialListReply]
-
- def getTrial(trialId: StringId[Trial], condition: String)(
- implicit requestContext: AnonymousRequestContext): Future[GetTrialReply]
-
-}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala
index da8d6f3..78edc10 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/DocumentSuite.scala
@@ -1,6 +1,6 @@
package xyz.driver.pdsuidomain
-import java.time.LocalDateTime
+import java.time.{LocalDate, LocalDateTime}
import java.time.temporal.ChronoUnit
import xyz.driver.pdsuicommon.BaseSuite
@@ -13,22 +13,21 @@ class DocumentSuite extends BaseSuite {
"can't submit invalid data" - {
val base = sampleDocument
- val now = LocalDateTime.now()
- val past1 = now.minus(2, ChronoUnit.DAYS)
- val past2 = past1.plus(1, ChronoUnit.DAYS)
+ val now = LocalDate.now()
+ val past1 = now.minus(2, ChronoUnit.DAYS)
+ val past2 = past1.plus(1, ChronoUnit.DAYS)
val future1 = now.plus(1, ChronoUnit.DAYS)
val future2 = future1.plus(1, ChronoUnit.DAYS)
Seq(
- "startDate should be non-empty" -> base.copy(startDate = None),
- "startDate should be greater, than endDate" -> base.copy(startDate = Some(past2), endDate = Some(past1)),
+ "startDate should be non-empty" -> base.copy(startDate = None),
+ "startDate should be greater, than endDate" -> base.copy(startDate = Some(past2), endDate = Some(past1)),
"startDate and endDate should be in the past" -> base.copy(startDate = Some(future1), endDate = Some(future2))
- ).foreach {
- case (title, orig) =>
- s"$title" in {
- val r = Document.validator(orig)
- assert(r.isLeft, s"should fail, but: ${r.right}")
- }
+ ).foreach { case (title, orig) =>
+ s"$title" in {
+ val r = Document.validator(orig)
+ assert(r.isLeft, s"should fail, but: ${r.right}")
+ }
}
}
}
@@ -47,7 +46,7 @@ class DocumentSuite extends BaseSuite {
typeId = Some(LongId(123)),
providerName = Some("etst"),
providerTypeId = Some(LongId(123)),
- startDate = Some(lastUpdate.minusDays(2)),
+ startDate = Some(lastUpdate.toLocalDate.minusDays(2)),
endDate = None,
lastUpdate = lastUpdate,
meta = Some(TextJson(Document.Meta(None, 1.1, 2.2)))