aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/trial')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala104
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/TrialStatus.scala30
3 files changed, 0 insertions, 178 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala
deleted file mode 100644
index f89f181..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiPartialTrial.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.trial
-
-import java.util.UUID
-
-import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
-import xyz.driver.pdsuidomain.entities.Trial
-import org.davidbild.tristate.Tristate
-import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath
-import play.api.libs.functional.syntax._
-import play.api.libs.json._
-
-final case class ApiPartialTrial(hypothesisId: Tristate[UUID],
- studyDesignId: Tristate[Long],
- overview: Tristate[String],
- title: Tristate[String]) {
-
- def applyTo(orig: Trial): Trial = {
- orig.copy(
- hypothesisId = hypothesisId.map(UuidId(_)).cata(Some(_), None, orig.hypothesisId),
- studyDesignId = studyDesignId.map(LongId(_)).cata(Some(_), None, orig.studyDesignId),
- overview = overview.cata(Some(_), None, orig.overview),
- title = title.cata(Some(_).getOrElse(""), "", orig.title)
- )
- }
-}
-
-object ApiPartialTrial {
-
- private val reads: Reads[ApiPartialTrial] = (
- (JsPath \ "hypothesisId").readTristate[UUID] and
- (JsPath \ "studyDesignId").readTristate[Long] and
- (JsPath \ "overview").readTristate[String] and
- (JsPath \ "title").readTristate[String]
- )(ApiPartialTrial.apply _)
-
- private val writes: Writes[ApiPartialTrial] = (
- (JsPath \ "hypothesisId").writeTristate[UUID] and
- (JsPath \ "studyDesignId").writeTristate[Long] and
- (JsPath \ "overview").writeTristate[String] and
- (JsPath \ "title").writeTristate[String]
- )(unlift(ApiPartialTrial.unapply))
-
- implicit val format: Format[ApiPartialTrial] = Format(reads, writes)
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala
deleted file mode 100644
index 1b4ac64..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala
+++ /dev/null
@@ -1,104 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.trial
-
-import java.time.{ZoneId, ZonedDateTime}
-import java.util.UUID
-import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
-
-import xyz.driver.pdsuidomain.entities.Trial
-import play.api.libs.functional.syntax._
-import play.api.libs.json._
-
-final case class ApiTrial(id: String,
- externalId: UUID,
- lastUpdate: ZonedDateTime,
- status: String,
- assignee: Option[String],
- previousStatus: Option[String],
- previousAssignee: Option[String],
- lastActiveUser: Option[String],
- condition: String,
- phase: String,
- hypothesisId: Option[UUID],
- studyDesignId: Option[Long],
- originalStudyDesign: Option[String],
- isPartner: Boolean,
- overview: Option[String],
- overviewTemplate: String,
- isUpdated: Boolean,
- title: String,
- originalTitle: String) {
-
- def toDomain = Trial(
- id = StringId(this.id),
- externalId = UuidId(this.externalId),
- status = TrialStatus.statusFromString(this.status),
- assignee = this.assignee.map(id => StringId(id)),
- previousStatus = this.previousStatus.map(s => TrialStatus.statusFromString(s)),
- previousAssignee = this.previousAssignee.map(id => StringId(id)),
- lastActiveUserId = this.lastActiveUser.map(id => StringId(id)),
- lastUpdate = this.lastUpdate.toLocalDateTime,
- condition = Trial.Condition
- .fromString(this.condition)
- .getOrElse(
- throw new NoSuchElementException(s"unknown condition ${this.condition}")
- ),
- phase = this.phase,
- hypothesisId = this.hypothesisId.map(id => UuidId(id)),
- studyDesignId = this.studyDesignId.map(id => LongId(id)),
- originalStudyDesign = this.originalStudyDesign,
- isPartner = this.isPartner,
- overview = this.overview,
- overviewTemplate = this.overviewTemplate,
- isUpdated = this.isUpdated,
- title = this.title,
- originalTitle = this.originalTitle
- )
-
-}
-
-object ApiTrial {
-
- implicit val format: Format[ApiTrial] = (
- (JsPath \ "id").format[String] and
- (JsPath \ "externalid").format[UUID] and
- (JsPath \ "lastUpdate").format[ZonedDateTime] and
- (JsPath \ "status").format[String] and
- (JsPath \ "assignee").formatNullable[String] and
- (JsPath \ "previousStatus").formatNullable[String] and
- (JsPath \ "previousAssignee").formatNullable[String] and
- (JsPath \ "lastActiveUser").formatNullable[String] and
- (JsPath \ "condition").format[String] and
- (JsPath \ "phase").format[String] and
- (JsPath \ "hypothesisId").formatNullable[UUID] and
- (JsPath \ "studyDesignId").formatNullable[Long] and
- (JsPath \ "originalStudyDesignId").formatNullable[String] and
- (JsPath \ "isPartner").format[Boolean] and
- (JsPath \ "overview").formatNullable[String] and
- (JsPath \ "overviewTemplate").format[String] and
- (JsPath \ "isUpdated").format[Boolean] and
- (JsPath \ "title").format[String] and
- (JsPath \ "originalTitle").format[String]
- )(ApiTrial.apply, unlift(ApiTrial.unapply))
-
- def fromDomain(trial: Trial): ApiTrial = ApiTrial(
- id = trial.id.id,
- externalId = trial.externalId.id,
- status = TrialStatus.statusToString(trial.status),
- assignee = trial.assignee.map(_.id),
- previousStatus = trial.previousStatus.map(TrialStatus.statusToString),
- previousAssignee = trial.previousAssignee.map(_.id),
- lastActiveUser = trial.lastActiveUserId.map(_.id),
- lastUpdate = ZonedDateTime.of(trial.lastUpdate, ZoneId.of("Z")),
- condition = trial.condition.toString,
- phase = trial.phase,
- hypothesisId = trial.hypothesisId.map(_.id),
- studyDesignId = trial.studyDesignId.map(_.id),
- originalStudyDesign = trial.originalStudyDesign,
- isPartner = trial.isPartner,
- overview = trial.overview,
- overviewTemplate = trial.overviewTemplate,
- isUpdated = trial.isUpdated,
- title = trial.title,
- originalTitle = trial.originalTitle
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/TrialStatus.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/TrialStatus.scala
deleted file mode 100644
index a5b557b..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/TrialStatus.scala
+++ /dev/null
@@ -1,30 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.trial
-
-import xyz.driver.pdsuidomain.entities.Trial.Status
-
-object TrialStatus {
-
- val statusFromString: PartialFunction[String, Status] = {
- case "New" => Status.New
- case "ReviewSummary" => Status.ReviewSummary
- case "Summarized" => Status.Summarized
- case "PendingUpdate" => Status.PendingUpdate
- case "Update" => Status.Update
- case "ReviewCriteria" => Status.ReviewCriteria
- case "Done" => Status.Done
- case "Flagged" => Status.Flagged
- case "Archived" => Status.Archived
- }
-
- def statusToString(x: Status): String = x match {
- case Status.New => "New"
- case Status.ReviewSummary => "ReviewSummary"
- case Status.Summarized => "Summarized"
- case Status.PendingUpdate => "PendingUpdate"
- case Status.Update => "Update"
- case Status.ReviewCriteria => "ReviewCriteria"
- case Status.Done => "Done"
- case Status.Flagged => "Flagged"
- case Status.Archived => "Archived"
- }
-}