aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-30 23:06:43 -0700
committervlad <vlad@driver.xyz>2017-06-30 23:06:43 -0700
commit56187bec9276f51886a01a2752c663f2227d9fc3 (patch)
tree3ddafc15152df5c1b2a6c69f0aa97a03ef7e819d
parent96d81a36286e41035ff4068859a3b0f9da924fbc (diff)
downloadrest-query-0.1.13.tar.gz
rest-query-0.1.13.tar.bz2
rest-query-0.1.13.zip
Export entities JSON formatsv0.1.13
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/LinkedPatient.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/UserHistory.scala86
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala7
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala25
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala22
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala28
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala34
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala22
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala26
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala20
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala39
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala15
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala38
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/linkedpatient/ApiLinkedPatient.scala8
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala38
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala21
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/LinkedPatientService.scala10
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/MailService.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/QueueUploadService.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/UserHistoryService.scala7
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/SendGridMailService.scala9
24 files changed, 387 insertions, 116 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/LinkedPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/LinkedPatient.scala
index e82bcc3..1b30c64 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/LinkedPatient.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/LinkedPatient.scala
@@ -11,6 +11,4 @@ object LinkedPatient {
}
}
-case class LinkedPatient(userId: LongId[User],
- patientId: UuidId[Patient],
- trialId: StringId[Trial])
+case class LinkedPatient(userId: LongId[User], patientId: UuidId[Patient], trialId: StringId[Trial])
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala
index 60298b9..34e3741 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala
@@ -8,7 +8,7 @@ import xyz.driver.pdsuicommon.logging._
object PatientLabelEvidenceView {
implicit def toPhiString(x: PatientLabelEvidenceView): PhiString = {
import x._
- phi"PatientLabelEvidenceViewRepository.Row(id=$id, value=$value, documentId=$documentId, " +
+ phi"PatientLabelEvidenceView(id=$id, value=$value, documentId=$documentId, " +
phi"evidenceId=$evidenceId, reportId=$reportId, patientId=$patientId, labelId=$labelId, " +
phi"isImplicitMatch=$isImplicitMatch)"
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/UserHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/UserHistory.scala
index b55369e..4abb205 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/UserHistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/UserHistory.scala
@@ -21,7 +21,7 @@ object UserHistory {
def forDocument(executor: LongId[User],
documentId: LongId[Document],
state: UserHistory.State,
- action: UserHistory.Action): UserHistory = UserHistory (
+ action: UserHistory.Action): UserHistory = UserHistory(
id = LongId(0L),
executor = executor,
documentId = Some(documentId),
@@ -32,7 +32,7 @@ object UserHistory {
def forRecord(executor: LongId[User],
recordId: LongId[MedicalRecord],
state: UserHistory.State,
- action: UserHistory.Action): UserHistory = UserHistory (
+ action: UserHistory.Action): UserHistory = UserHistory(
id = LongId(0L),
executor = executor,
recordId = Some(recordId),
@@ -43,7 +43,7 @@ object UserHistory {
def forTrial(executor: LongId[User],
trialId: StringId[Trial],
state: UserHistory.State,
- action: UserHistory.Action): UserHistory = UserHistory (
+ action: UserHistory.Action): UserHistory = UserHistory(
id = LongId(0L),
executor = executor,
trialId = Some(trialId),
@@ -54,7 +54,7 @@ object UserHistory {
def forPatient(executor: LongId[User],
patientId: UuidId[Patient],
state: UserHistory.State,
- action: UserHistory.Action): UserHistory = UserHistory (
+ action: UserHistory.Action): UserHistory = UserHistory(
id = LongId(0L),
executor = executor,
patientId = Some(patientId),
@@ -70,40 +70,40 @@ object UserHistory {
}
object State {
- case object Clean extends State
- case object Organize extends State
- case object Extract extends State
- case object Summarize extends State
+ case object Clean extends State
+ case object Organize extends State
+ case object Extract extends State
+ case object Summarize extends State
case object Criteriarize extends State
- case object Verify extends State
- case object Curate extends State
- case object Review extends State
- case object Flag extends State
+ case object Verify extends State
+ case object Curate extends State
+ case object Review extends State
+ case object Flag extends State
val All: Set[State] = Set[State](Clean, Organize, Extract, Summarize, Criteriarize, Verify, Curate, Review, Flag)
val fromString: PartialFunction[String, State] = {
- case "Clean" => State.Clean
- case "Organize" => State.Organize
- case "Extract" => State.Extract
- case "Summarize" => State.Summarize
+ case "Clean" => State.Clean
+ case "Organize" => State.Organize
+ case "Extract" => State.Extract
+ case "Summarize" => State.Summarize
case "Criteriarize" => State.Criteriarize
- case "Verify" => State.Verify
- case "Curate" => State.Curate
- case "Review" => State.Review
- case "Flag" => State.Flag
+ case "Verify" => State.Verify
+ case "Curate" => State.Curate
+ case "Review" => State.Review
+ case "Flag" => State.Flag
}
def stateToString(x: State): String = x match {
- case State.Clean => "Clean"
- case State.Organize => "Organize"
- case State.Extract => "Extract"
- case State.Summarize => "Summarize"
+ case State.Clean => "Clean"
+ case State.Organize => "Organize"
+ case State.Extract => "Extract"
+ case State.Summarize => "Summarize"
case State.Criteriarize => "Criteriarize"
- case State.Verify => "Verify"
- case State.Curate => "Curate"
- case State.Review => "Review"
- case State.Flag => "Flag"
+ case State.Verify => "Verify"
+ case State.Curate => "Curate"
+ case State.Review => "Review"
+ case State.Flag => "Flag"
}
implicit def toPhiString(x: State): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass))
@@ -117,31 +117,31 @@ object UserHistory {
}
object Action {
- case object Start extends Action
- case object Submit extends Action
+ case object Start extends Action
+ case object Submit extends Action
case object Unassign extends Action
- case object Resolve extends Action
- case object Flag extends Action
- case object Archive extends Action
+ case object Resolve extends Action
+ case object Flag extends Action
+ case object Archive extends Action
val All: Set[Action] = Set[Action](Start, Submit, Unassign, Resolve, Flag, Archive)
val fromString: PartialFunction[String, Action] = {
- case "Start" => Action.Start
- case "Submit" => Action.Submit
+ case "Start" => Action.Start
+ case "Submit" => Action.Submit
case "Unassign" => Action.Unassign
- case "Resolve" => Action.Resolve
- case "Flag" => Action.Flag
- case "Archive" => Action.Archive
+ case "Resolve" => Action.Resolve
+ case "Flag" => Action.Flag
+ case "Archive" => Action.Archive
}
def actionToString(x: Action): String = x match {
- case Action.Start => "Start"
- case Action.Submit => "Submit"
+ case Action.Start => "Start"
+ case Action.Submit => "Submit"
case Action.Unassign => "Unassign"
- case Action.Resolve => "Resolve"
- case Action.Flag => "Flag"
- case Action.Archive => "Archive"
+ case Action.Resolve => "Resolve"
+ case Action.Flag => "Flag"
+ case Action.Archive => "Archive"
}
implicit def toPhiString(x: Action): PhiString = Unsafe(Utils.getClassSimpleName(x.getClass))
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala
index 5474413..5135c21 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala
@@ -4,9 +4,7 @@ import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuidomain.entities.{Label, RawPatientLabel}
-final case class ExportPatientLabel(id: LongId[Label],
- name: String,
- evidences: List[ExportPatientLabelEvidence])
+final case class ExportPatientLabel(id: LongId[Label], name: String, evidences: List[ExportPatientLabelEvidence])
object ExportPatientLabel extends PhiLogging {
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala
index e6262ed..bd6173b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientWithLabels.scala
@@ -6,7 +6,9 @@ import xyz.driver.pdsuidomain.entities.{Patient, RawPatientLabel}
import scala.collection.breakOut
-final case class ExportPatientWithLabels(patientId: UuidId[Patient], labelVersion: Long, labels: List[ExportPatientLabel])
+final case class ExportPatientWithLabels(patientId: UuidId[Patient],
+ labelVersion: Long,
+ labels: List[ExportPatientLabel])
object ExportPatientWithLabels {
@@ -15,8 +17,7 @@ object ExportPatientWithLabels {
phi"ExportPatientWithLabels(patientId=$patientId, version=${Unsafe(labelVersion)}, labels=$labels)"
}
- def fromRaw(patientId: UuidId[Patient],
- rawPatientRefs: List[RawPatientLabel]) = ExportPatientWithLabels(
+ def fromRaw(patientId: UuidId[Patient], rawPatientRefs: List[RawPatientLabel]) = ExportPatientWithLabels(
patientId = patientId,
labelVersion = 1L, // TODO It is needed to replace this mock label version.
labels = rawPatientRefs
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala
index 1655a88..60b74ff 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialWithLabels.scala
@@ -36,16 +36,21 @@ object ExportTrialWithLabels {
condition = trial.condition,
lastReviewed = trial.lastReviewed,
labelVersion = 1, // TODO It is needed to replace this mock label version.
- arms = rawData.groupBy(_.armId).map { case (armId, rawTrials) =>
- ExportTrialArm(armId, rawTrials.head.armName)
- }(breakOut),
- criteria = rawData.groupBy { x =>
- (x.criterionId, x.labelId)
- }.map {
- case (_, rawTrialLabels) =>
- val armIds = rawTrialLabels.map(_.criterionArmId).toSet
- ExportTrialLabelCriterion.fromRaw(rawTrialLabels.head, armIds)
- }(breakOut)
+ arms = rawData
+ .groupBy(_.armId)
+ .map {
+ case (armId, rawTrials) =>
+ ExportTrialArm(armId, rawTrials.head.armName)
+ }(breakOut),
+ criteria = rawData
+ .groupBy { x =>
+ (x.criterionId, x.labelId)
+ }
+ .map {
+ case (_, rawTrialLabels) =>
+ val armIds = rawTrialLabels.map(_.criterionArmId).toSet
+ ExportTrialLabelCriterion.fromRaw(rawTrialLabels.head, armIds)
+ }(breakOut)
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala
new file mode 100644
index 0000000..78a73a6
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala
@@ -0,0 +1,22 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabel
+
+final case class ApiExportPatientLabel(id: String, labelName: String, evidences: List[ApiExportPatientLabelEvidence])
+
+object ApiExportPatientLabel {
+
+ implicit val format: Format[ApiExportPatientLabel] = (
+ (JsPath \ "labelId").format[String] and
+ (JsPath \ "labelName").format[String] and
+ (JsPath \ "evidence").format[List[ApiExportPatientLabelEvidence]]
+ ) (ApiExportPatientLabel.apply, unlift(ApiExportPatientLabel.unapply))
+
+ def fromDomain(label: ExportPatientLabel) = ApiExportPatientLabel(
+ id = label.id.toString,
+ labelName = label.name,
+ evidences = label.evidences.map(ApiExportPatientLabelEvidence.fromDomain)
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala
new file mode 100644
index 0000000..b38c2a0
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala
@@ -0,0 +1,28 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+import xyz.driver.pdsuicommon.domain.FuzzyValue
+import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidence
+
+final case class ApiExportPatientLabelEvidence(evidenceId: String,
+ labelValue: String,
+ evidenceText: String,
+ document: ApiExportPatientLabelEvidenceDocument)
+
+object ApiExportPatientLabelEvidence {
+
+ implicit val format: Format[ApiExportPatientLabelEvidence] = (
+ (JsPath \ "evidenceId").format[String] and
+ (JsPath \ "labelValue").format[String](Writes[String](x => JsString(x.toUpperCase))) and
+ (JsPath \ "evidenceText").format[String] and
+ (JsPath \ "document").format[ApiExportPatientLabelEvidenceDocument]
+ ) (ApiExportPatientLabelEvidence.apply, unlift(ApiExportPatientLabelEvidence.unapply))
+
+ def fromDomain(evidence: ExportPatientLabelEvidence) = ApiExportPatientLabelEvidence(
+ evidenceId = evidence.id.toString,
+ labelValue = FuzzyValue.valueToString(evidence.value),
+ evidenceText = evidence.evidenceText,
+ document = ApiExportPatientLabelEvidenceDocument.fromDomain(evidence.document)
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala
new file mode 100644
index 0000000..d094014
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala
@@ -0,0 +1,34 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import java.time.LocalDate
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidenceDocument
+
+final case class ApiExportPatientLabelEvidenceDocument(documentId: String,
+ requestId: String,
+ documentType: String,
+ providerType: String,
+ date: LocalDate)
+
+
+object ApiExportPatientLabelEvidenceDocument {
+
+ implicit val format: Format[ApiExportPatientLabelEvidenceDocument] = (
+ (JsPath \ "documentId").format[String] and
+ (JsPath \ "requestId").format[String] and
+ (JsPath \ "documentType").format[String] and
+ (JsPath \ "providerType").format[String] and
+ (JsPath \ "date").format[LocalDate]
+ ) (ApiExportPatientLabelEvidenceDocument.apply, unlift(ApiExportPatientLabelEvidenceDocument.unapply))
+
+ def fromDomain(document: ExportPatientLabelEvidenceDocument) =
+ ApiExportPatientLabelEvidenceDocument(
+ documentId = document.documentId.toString,
+ requestId = document.requestId.toString,
+ documentType = document.documentType,
+ providerType = document.providerType,
+ date = document.date
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala
new file mode 100644
index 0000000..d5b9eb3
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala
@@ -0,0 +1,22 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels
+
+final case class ApiExportPatientWithLabels(patientId: String, labelVersion: Long, labels: List[ApiExportPatientLabel])
+
+object ApiExportPatientWithLabels {
+
+ implicit val format: Format[ApiExportPatientWithLabels] = (
+ (JsPath \ "patientId").format[String] and
+ (JsPath \ "labelVersion").format[Long] and
+ (JsPath \ "labels").format[List[ApiExportPatientLabel]]
+ ) (ApiExportPatientWithLabels.apply, unlift(ApiExportPatientWithLabels.unapply))
+
+ def fromDomain(patient: ExportPatientWithLabels) = ApiExportPatientWithLabels(
+ patientId = patient.patientId.toString,
+ labelVersion = patient.labelVersion,
+ labels = patient.labels.map(ApiExportPatientLabel.fromDomain)
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala
new file mode 100644
index 0000000..b12cb93
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala
@@ -0,0 +1,26 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import java.time.ZoneId
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrial
+
+final case class ApiExportTrial(nctId: String, trialId: String, disease: String, lastReviewed: Long)
+
+object ApiExportTrial {
+
+ implicit val format: Format[ApiExportTrial] = (
+ (JsPath \ "nctId").format[String] and
+ (JsPath \ "trialId").format[String] and
+ (JsPath \ "disease").format[String] and
+ (JsPath \ "lastReviewed").format[Long]
+ ) (ApiExportTrial.apply, unlift(ApiExportTrial.unapply))
+
+ def fromDomain(trial: ExportTrial): ApiExportTrial = ApiExportTrial(
+ nctId = trial.nctId.id,
+ trialId = trial.trialId.toString,
+ disease = trial.condition.toString.toUpperCase,
+ lastReviewed = trial.lastReviewed.atZone(ZoneId.of("Z")).toEpochSecond
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala
new file mode 100644
index 0000000..0b77832
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala
@@ -0,0 +1,20 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialArm
+
+final case class ApiExportTrialArm(armId: String, armName: String)
+
+object ApiExportTrialArm {
+
+ implicit val format: Format[ApiExportTrialArm] = (
+ (JsPath \ "armId").format[String] and
+ (JsPath \ "armName").format[String]
+ ) (ApiExportTrialArm.apply, unlift(ApiExportTrialArm.unapply))
+
+ def fromDomain(arm: ExportTrialArm) = ApiExportTrialArm(
+ armId = arm.armId.toString,
+ armName = arm.armName
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala
new file mode 100644
index 0000000..09935c0
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala
@@ -0,0 +1,39 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import xyz.driver.pdsuicommon.domain.FuzzyValue
+import play.api.libs.functional.syntax._
+import play.api.libs.json._
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialLabelCriterion
+
+final case class ApiExportTrialLabelCriterion(value: String,
+ labelId: String,
+ criterionId: String,
+ criterionText: String,
+ armIds: List[String],
+ isCompound: Boolean,
+ isDefining: Boolean)
+
+object ApiExportTrialLabelCriterion {
+
+ implicit val format: Format[ApiExportTrialLabelCriterion] = (
+ (JsPath \ "value").format[String](Writes[String](x => JsString(x.toUpperCase))) and
+ (JsPath \ "labelId").format[String] and
+ (JsPath \ "criterionId").format[String] and
+ (JsPath \ "criterionText").format[String] and
+ (JsPath \ "armIds").format[List[String]] and
+ (JsPath \ "isCompound").format[Boolean] and
+ (JsPath \ "isDefining").format[Boolean]
+ ) (ApiExportTrialLabelCriterion.apply, unlift(ApiExportTrialLabelCriterion.unapply))
+
+ def fromDomain(x: ExportTrialLabelCriterion) = ApiExportTrialLabelCriterion(
+ value = x.value.map { x =>
+ FuzzyValue.valueToString(FuzzyValue.fromBoolean(x))
+ }.getOrElse("Unknown"),
+ labelId = x.labelId.toString,
+ criterionId = x.criterionId.toString,
+ criterionText = x.criteria,
+ armIds = x.armIds.map(_.toString).toList,
+ isCompound = x.isCompound,
+ isDefining = x.isDefining
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala
new file mode 100644
index 0000000..93ee42e
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala
@@ -0,0 +1,15 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import play.api.libs.json.{Format, Json}
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrial
+
+final case class ApiExportTrialList(trials: Seq[ApiExportTrial])
+
+object ApiExportTrialList {
+
+ implicit val format: Format[ApiExportTrialList] = Json.format
+
+ def fromDomain(trialList: Seq[ExportTrial]) = ApiExportTrialList(
+ trials = trialList.map(ApiExportTrial.fromDomain)
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala
new file mode 100644
index 0000000..dd855f7
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala
@@ -0,0 +1,38 @@
+package xyz.driver.pdsuidomain.formats.json.export
+
+import java.time.ZoneId
+
+import play.api.libs.functional.syntax._
+import play.api.libs.json.{Format, JsPath}
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels
+
+final case class ApiExportTrialWithLabels(nctId: String,
+ trialId: String,
+ condition: String,
+ lastReviewed: Long,
+ labelVersion: Long,
+ arms: List[ApiExportTrialArm],
+ criteria: List[ApiExportTrialLabelCriterion])
+
+object ApiExportTrialWithLabels {
+
+ implicit val format: Format[ApiExportTrialWithLabels] = (
+ (JsPath \ "nctId").format[String] and
+ (JsPath \ "trialId").format[String] and
+ (JsPath \ "disease").format[String] and
+ (JsPath \ "lastReviewed").format[Long] and
+ (JsPath \ "labelVersion").format[Long] and
+ (JsPath \ "arms").format[List[ApiExportTrialArm]] and
+ (JsPath \ "criteria").format[List[ApiExportTrialLabelCriterion]]
+ ) (ApiExportTrialWithLabels.apply, unlift(ApiExportTrialWithLabels.unapply))
+
+ def fromDomain(x: ExportTrialWithLabels) = ApiExportTrialWithLabels(
+ nctId = x.nctId.id,
+ trialId = x.trialId.toString,
+ condition = x.condition,
+ lastReviewed = x.lastReviewed.atZone(ZoneId.of("Z")).toEpochSecond,
+ labelVersion = x.labelVersion,
+ arms = x.arms.map(ApiExportTrialArm.fromDomain),
+ criteria = x.criteria.map(ApiExportTrialLabelCriterion.fromDomain)
+ )
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/linkedpatient/ApiLinkedPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/linkedpatient/ApiLinkedPatient.scala
index 20d4a74..327bda2 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/linkedpatient/ApiLinkedPatient.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/linkedpatient/ApiLinkedPatient.scala
@@ -1,4 +1,3 @@
-
package xyz.driver.pdsuidomain.formats.json.linkedpatient
import java.util.UUID
@@ -7,10 +6,7 @@ import play.api.libs.json.{Format, Json}
import xyz.driver.pdsuicommon.domain._
import xyz.driver.pdsuidomain.services.LinkedPatientService.RichLinkedPatient
-case class ApiLinkedPatient(email: String,
- name: String,
- patientId: UUID,
- trialId: String) {
+final case class ApiLinkedPatient(email: String, name: String, patientId: UUID, trialId: String) {
def toDomain = RichLinkedPatient(
email = Email(email),
@@ -28,6 +24,6 @@ object ApiLinkedPatient {
email = entity.email.value,
name = entity.name,
patientId = entity.patientId.id,
- trialId = entity.trialId.id
+ trialId = entity.trialId.id
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala
new file mode 100644
index 0000000..cd76670
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala
@@ -0,0 +1,38 @@
+package xyz.driver.pdsuidomain.formats.json.queue
+
+import java.time.LocalDateTime
+
+import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue
+import play.api.libs.json.{Format, Json}
+
+final case class ApiQueueUploadItem(kind: String,
+ tag: String,
+ created: LocalDateTime,
+ attempts: Int,
+ nextAttempt: LocalDateTime,
+ completed: Boolean) {
+ def toDomain = BridgeUploadQueue.Item(
+ kind = kind,
+ tag = tag,
+ created = created,
+ attempts = attempts,
+ nextAttempt = nextAttempt,
+ completed = true,
+ dependencyKind = None,
+ dependencyTag = None
+ )
+}
+
+object ApiQueueUploadItem {
+
+ def fromDomain(domain: BridgeUploadQueue.Item) = ApiQueueUploadItem(
+ kind = domain.kind,
+ tag = domain.tag,
+ created = domain.created,
+ attempts = domain.attempts,
+ nextAttempt = domain.nextAttempt,
+ completed = domain.completed
+ )
+
+ implicit val format: Format[ApiQueueUploadItem] = Json.format[ApiQueueUploadItem]
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala
index befff05..2d0df80 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala
@@ -27,7 +27,7 @@ object ApiUserHistory {
(JsPath \ "state").format[String] and
(JsPath \ "action").format[String] and
(JsPath \ "created").format[ZonedDateTime]
- ) (ApiUserHistory.apply, unlift(ApiUserHistory.unapply))
+ )(ApiUserHistory.apply, unlift(ApiUserHistory.unapply))
def fromDomain(x: UserHistory) = ApiUserHistory(
id = x.id.id,
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala
index 8fb399a..ddc927d 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala
@@ -28,7 +28,7 @@ object ExportService {
sealed trait GetTrialListReply
object GetTrialListReply {
case class EntityList(xs: Seq[ExportTrial], totalFound: Int, lastUpdate: Option[LocalDateTime])
- extends GetTrialListReply
+ extends GetTrialListReply
}
sealed trait GetTrialReply
@@ -47,18 +47,17 @@ trait ExportService {
import ExportService._
- def getPatient(id: UuidId[Patient])
- (implicit requestContext: AnonymousRequestContext): Future[GetPatientReply]
+ def getPatient(id: UuidId[Patient])(implicit requestContext: AnonymousRequestContext): Future[GetPatientReply]
- def getTrialList(filter: SearchFilterExpr = SearchFilterExpr.Empty)
- (implicit requestContext: AnonymousRequestContext): Future[GetTrialListReply]
+ def getTrialList(filter: SearchFilterExpr = SearchFilterExpr.Empty)(
+ implicit requestContext: AnonymousRequestContext): Future[GetTrialListReply]
- def getTrial(trialId: StringId[Trial], condition: String)
- (implicit requestContext: AnonymousRequestContext): Future[GetTrialReply]
+ def getTrial(trialId: StringId[Trial], condition: String)(
+ implicit requestContext: AnonymousRequestContext): Future[GetTrialReply]
- def getRecords(patientId: UuidId[Patient])
- (implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetListReply]
+ def getRecords(patientId: UuidId[Patient])(
+ implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetListReply]
- def getRecordPdf(recordId: LongId[MedicalRecord])
- (implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetPdfSourceReply]
+ def getRecordPdf(recordId: LongId[MedicalRecord])(
+ implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetPdfSourceReply]
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/LinkedPatientService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/LinkedPatientService.scala
index 8fc1662..a69283a 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/LinkedPatientService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/LinkedPatientService.scala
@@ -17,10 +17,7 @@ object LinkedPatientService {
def userMessage: String = "Patient not found"
}
- final case class RichLinkedPatient(email: Email,
- name: String,
- patientId: UuidId[Patient],
- trialId: StringId[Trial]) {
+ final case class RichLinkedPatient(email: Email, name: String, patientId: UuidId[Patient], trialId: StringId[Trial]) {
def toLinkedPatient(user: User) = LinkedPatient(
userId = user.id,
patientId = patientId,
@@ -45,10 +42,9 @@ object LinkedPatientService {
final case class Created(x: RichLinkedPatient, createdUser: Option[User]) extends CreateReply
case object PatientNotFoundError
- extends CreateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
+ extends CreateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
- case object TrialNotFoundError
- extends CreateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
+ case object TrialNotFoundError extends CreateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
final case class CommonError(userMessage: String) extends CreateReply with DomainError
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/MailService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/MailService.scala
index 3022716..53f897a 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/MailService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/MailService.scala
@@ -20,11 +20,11 @@ object MailService {
factory.setObjectHandler(new ScalaObjectHandler)
protected def inputStream: InputStream = getClass.getClassLoader.getResourceAsStream(filename)
- protected def templateContent: String = Source.fromInputStream(inputStream).getLines().mkString
+ protected def templateContent: String = Source.fromInputStream(inputStream).getLines().mkString
def content: String = {
val template = factory.compile(new StringReader(templateContent), filename)
- val writer = new StringWriter
+ val writer = new StringWriter
template
.execute(writer, parameters)
.close()
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/QueueUploadService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/QueueUploadService.scala
index 55a408f..f201fd9 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/QueueUploadService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/QueueUploadService.scala
@@ -21,7 +21,8 @@ object QueueUploadService {
type Error = CreateReply with DomainError
case class Created(x: BridgeUploadQueue.Item) extends CreateReply
- case object AuthorizationError extends CreateReply with DomainError.AuthorizationError with DefaultAccessDeniedError
+ case object AuthorizationError
+ extends CreateReply with DomainError.AuthorizationError with DefaultAccessDeniedError
case class CommonError(userMessage: String) extends CreateReply with DomainError
}
@@ -30,8 +31,9 @@ object QueueUploadService {
type Error = GetByIdReply with DomainError
case class Entity(x: BridgeUploadQueue.Item) extends GetByIdReply
- case object AuthorizationError extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError
- case object NotFoundError extends GetByIdReply with DomainError.NotFoundError with DefaultNotFoundError
+ case object AuthorizationError
+ extends GetByIdReply with DomainError.AuthorizationError with DefaultAccessDeniedError
+ case object NotFoundError extends GetByIdReply with DomainError.NotFoundError with DefaultNotFoundError
case class CommonError(userMessage: String) extends GetByIdReply with DomainError
}
@@ -39,11 +41,10 @@ object QueueUploadService {
object GetListReply {
type Error = GetListReply with DomainError
- case class EntityList(xs: Seq[BridgeUploadQueue.Item],
- totalFound: Int) extends GetListReply
+ case class EntityList(xs: Seq[BridgeUploadQueue.Item], totalFound: Int) extends GetListReply
case object AuthorizationError
- extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError
+ extends GetListReply with DomainError.AuthorizationError with DefaultAccessDeniedError
}
sealed trait ResetReply
@@ -51,9 +52,9 @@ object QueueUploadService {
type Error = ResetReply with DomainError
case class Updated(updated: BridgeUploadQueue.Item) extends ResetReply
- case object AuthorizationError extends ResetReply with DomainError.AuthorizationError with DefaultAccessDeniedError
- case object NotFoundError extends ResetReply with DefaultNotFoundError with DomainError.NotFoundError
- case class CommonError(userMessage: String) extends ResetReply with DomainError
+ case object AuthorizationError extends ResetReply with DomainError.AuthorizationError with DefaultAccessDeniedError
+ case object NotFoundError extends ResetReply with DefaultNotFoundError with DomainError.NotFoundError
+ case class CommonError(userMessage: String) extends ResetReply with DomainError
}
}
@@ -61,18 +62,15 @@ trait QueueUploadService {
import QueueUploadService._
- def create(kind: String, tag: String)
- (implicit requestContext: AuthenticatedRequestContext): Future[CreateReply]
+ def create(kind: String, tag: String)(implicit requestContext: AuthenticatedRequestContext): Future[CreateReply]
- def getById(kind: String, tag: String)
- (implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply]
+ def getById(kind: String, tag: String)(implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply]
def getAll(filter: SearchFilterExpr = SearchFilterExpr.Empty,
sorting: Option[Sorting] = None,
- pagination: Option[Pagination] = None)
- (implicit requestContext: AuthenticatedRequestContext): Future[GetListReply]
+ pagination: Option[Pagination] = None)(
+ implicit requestContext: AuthenticatedRequestContext): Future[GetListReply]
- def reset(kind: String, tag: String)
- (implicit requestContext: AuthenticatedRequestContext): Future[ResetReply]
+ def reset(kind: String, tag: String)(implicit requestContext: AuthenticatedRequestContext): Future[ResetReply]
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/UserHistoryService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/UserHistoryService.scala
index 3034027..e342813 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/UserHistoryService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/UserHistoryService.scala
@@ -13,8 +13,7 @@ object UserHistoryService {
object GetListReply {
case class EntityList(xs: Seq[UserHistory], totalFound: Int) extends GetListReply
- case object AuthorizationError
- extends GetListReply with DomainError.AuthorizationError {
+ case object AuthorizationError extends GetListReply with DomainError.AuthorizationError {
def userMessage: String = "Access denied"
}
}
@@ -26,6 +25,6 @@ trait UserHistoryService {
def getAll(filter: SearchFilterExpr = SearchFilterExpr.Empty,
sorting: Option[Sorting] = None,
- pagination: Option[Pagination] = None)
- (implicit requestContext: AuthenticatedRequestContext): Future[GetListReply]
+ pagination: Option[Pagination] = None)(
+ implicit requestContext: AuthenticatedRequestContext): Future[GetListReply]
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/SendGridMailService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/SendGridMailService.scala
index 37dc758..e308fe6 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/SendGridMailService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/SendGridMailService.scala
@@ -18,11 +18,11 @@ object SendGridMailService {
class SendGridMailService(settings: Settings) extends MailService with PhiLogging {
def sendTo(email: String, template: Template): Boolean = {
- val to = new Email(email)
+ val to = new Email(email)
val content = new Content(template.contentType, template.content)
- val mail = new Mail(new Email(settings.from), template.subject, to, content)
+ val mail = new Mail(new Email(settings.from), template.subject, to, content)
- val request = new Request()
+ val request = new Request()
val sendGrid = new SendGrid(settings.apiKey)
try {
@@ -35,8 +35,7 @@ class SendGridMailService(settings: Settings) extends MailService with PhiLoggin
}
response.statusCode == ExpectedHttpCode
- }
- catch {
+ } catch {
case NonFatal(e) =>
logger.error(phi"Can not send an email: $e")
false