aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/arm.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/bridgeuploadqueue.scala68
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/common.scala66
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion.scala175
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document.scala221
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala35
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala72
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala108
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm.scala107
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export.scala127
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata.scala155
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention.scala147
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/listresponse.scala45
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient.scala118
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala65
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patientdefiningcriteria.scala18
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala39
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory.scala30
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthypothesis.scala35
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala58
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala65
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala213
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala43
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue.scala72
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/slotarm.scala44
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign.scala29
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trial.scala187
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala134
30 files changed, 0 insertions, 2564 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm.scala
deleted file mode 100644
index 69029b6..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities._
-
-object arm {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToArm(json: JsValue, orig: Arm): Arm = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Arm json object does not contain `name` field: $json"))
- orig.copy(name = name)
-
- case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json")
- }
-
- implicit val armFormat: RootJsonFormat[Arm] = new RootJsonFormat[Arm] {
- override def write(obj: Arm): JsValue =
- JsObject(
- "id" -> obj.id.toJson,
- "name" -> obj.name.toJson,
- "originalName" -> obj.originalName.toJson,
- "trialId" -> obj.trialId.toJson
- )
-
- override def read(json: JsValue): Arm = json.asJsObject.getFields("trialId", "name") match {
- case Seq(trialId, name) =>
- Arm(
- id = json.asJsObject.fields.get("id").flatMap(_.convertTo[Option[LongId[Arm]]]).getOrElse(LongId(0)),
- name = name.convertTo[String],
- trialId = trialId.convertTo[StringId[Trial]],
- originalName = name.convertTo[String]
- )
-
- case _ => deserializationError(s"Expected Json Object as Arm, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/bridgeuploadqueue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/bridgeuploadqueue.scala
deleted file mode 100644
index 6725a15..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/bridgeuploadqueue.scala
+++ /dev/null
@@ -1,68 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json._
-import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue
-import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue.Item
-
-object bridgeuploadqueue {
- import DefaultJsonProtocol._
- import common._
-
- implicit val queueUploadItemFormat: RootJsonFormat[BridgeUploadQueue.Item] = new RootJsonFormat[Item] {
- override def write(obj: Item) =
- JsObject(
- "kind" -> obj.kind.toJson,
- "tag" -> obj.tag.toJson,
- "created" -> obj.created.toJson,
- "attempts" -> obj.attempts.toJson,
- "nextAttempt" -> obj.nextAttempt.toJson,
- "completed" -> obj.completed.toJson
- )
-
- override def read(json: JsValue): Item = json match {
- case JsObject(fields) =>
- val kind = fields
- .get("kind")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"BridgeUploadQueue.Item json object does not contain `kind` field: $json"))
-
- val tag = fields
- .get("tag")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"BridgeUploadQueue.Item json object does not contain `tag` field: $json"))
-
- val created = fields
- .get("created")
- .map(_.convertTo[LocalDateTime])
- .getOrElse(
- deserializationError(s"BridgeUploadQueue.Item json object does not contain `created` field: $json"))
-
- val attempts = fields
- .get("attempts")
- .map(_.convertTo[Int])
- .getOrElse(
- deserializationError(s"BridgeUploadQueue.Item json object does not contain `attempts` field: $json"))
-
- val nextAttempt = fields
- .get("nextAttempt")
- .map(_.convertTo[LocalDateTime])
- .getOrElse(
- deserializationError(s"BridgeUploadQueue.Item json object does not contain `nextAttempt` field: $json"))
-
- BridgeUploadQueue.Item(
- kind = kind,
- tag = tag,
- created = created,
- attempts = attempts,
- nextAttempt = nextAttempt,
- completed = true,
- dependencyKind = None,
- dependencyTag = None
- )
-
- case _ => deserializationError(s"Expected Json Object as BridgeUploadQueue.Item, but got $json")
- }
- }
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/common.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/common.scala
deleted file mode 100644
index 26adb9c..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/common.scala
+++ /dev/null
@@ -1,66 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.{LocalDate, LocalDateTime, ZoneId, ZonedDateTime}
-
-import spray.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
-
-object common {
-
- implicit def longIdFormat[T] = new RootJsonFormat[LongId[T]] {
- override def write(id: LongId[T]): JsNumber = JsNumber(id.id)
- override def read(json: JsValue): LongId[T] = json match {
- case JsNumber(value) => LongId(value.toLong)
- case _ => deserializationError(s"Expected number as LongId, but got $json")
- }
- }
-
- implicit def stringIdFormat[T] = new RootJsonFormat[StringId[T]] {
- override def write(id: StringId[T]): JsString = JsString(id.toString)
- override def read(json: JsValue): StringId[T] = json match {
- case JsString(value) => StringId(value)
- case _ => deserializationError(s"Expected string as StringId, but got $json")
- }
- }
-
- implicit def uuidIdFormat[T] = new RootJsonFormat[UuidId[T]] {
- override def write(id: UuidId[T]): JsString = JsString(id.toString)
- override def read(json: JsValue): UuidId[T] = json match {
- case JsString(value) => UuidId(value)
- case _ => deserializationError(s"Expected string as UuidId, but got $json")
- }
- }
-
- implicit def dateTimeFormat = new RootJsonFormat[LocalDateTime] {
- override def write(date: LocalDateTime): JsString = JsString(ZonedDateTime.of(date, ZoneId.of("Z")).toString)
- override def read(json: JsValue): LocalDateTime = json match {
- case JsString(value) => ZonedDateTime.parse(value).toLocalDateTime
- case _ => deserializationError(s"Expected date as LocalDateTime, but got $json")
- }
- }
-
- implicit def zonedDateTimeFormat = new RootJsonFormat[ZonedDateTime] {
- override def write(date: ZonedDateTime): JsString = JsString(date.toString)
- override def read(json: JsValue): ZonedDateTime = json match {
- case JsString(value) => ZonedDateTime.parse(value)
- case _ => deserializationError(s"Expected date as ZonedDateTime, but got $json")
- }
- }
-
- implicit def dateFormat = new RootJsonFormat[LocalDate] {
- override def write(date: LocalDate): JsString = JsString(date.toString)
- override def read(json: JsValue): LocalDate = json match {
- case JsString(value) => LocalDate.parse(value)
- case _ => deserializationError(s"Expected date as LocalDate, but got $json")
- }
- }
-
- implicit val integerFormat: RootJsonFormat[Integer] = new RootJsonFormat[Integer] {
- override def write(obj: Integer): JsNumber = JsNumber(obj.intValue())
- override def read(json: JsValue): Integer = json match {
- case JsNumber(value) => value.toInt
- case _ => deserializationError(s"Expected number as Integer, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion.scala
deleted file mode 100644
index c4e89f0..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion.scala
+++ /dev/null
@@ -1,175 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.entities.labels.{Label, LabelCategory}
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities._
-import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion
-
-object criterion {
- import DefaultJsonProtocol._
- import common._
-
- implicit val criterionLabelWriter: RootJsonWriter[CriterionLabel] = new RootJsonWriter[CriterionLabel] {
- override def write(obj: CriterionLabel) = JsObject(
- "labelId" -> obj.labelId.toJson,
- "categoryId" -> obj.categoryId.toJson,
- "value" -> obj.value.map {
- case true => "Yes"
- case false => "No"
- }.toJson,
- "isDefining" -> obj.isDefining.toJson
- )
- }
-
- def jsValueToCriterionLabel(json: JsValue, criterionId: LongId[Criterion]): CriterionLabel = json match {
- case JsObject(fields) =>
- val labelId = fields
- .get("labelId")
- .flatMap(_.convertTo[Option[LongId[Label]]])
-
- val categoryId = fields
- .get("categoryId")
- .flatMap(_.convertTo[Option[LongId[LabelCategory]]])
-
- val value = fields
- .get("value")
- .flatMap(_.convertTo[Option[String]])
- .map {
- case "Yes" => true
- case "No" => false
- case other =>
- deserializationError(s"Unknown `value` of CriterionLabel object: expected `yes` or `no`, but got $other")
- }
-
- val isDefining = fields
- .get("isDefining")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationError(s"CriterionLabel json object does not contain `isDefining` field: $json"))
-
- CriterionLabel(
- id = LongId(0L),
- labelId = labelId,
- criterionId = criterionId,
- categoryId = categoryId,
- value = value,
- isDefining = isDefining
- )
-
- case _ => deserializationError(s"Expected Json Object as CriterionLabel, but got $json")
- }
-
- def applyUpdateToCriterion(json: JsValue, orig: RichCriterion): RichCriterion = json match {
- case JsObject(fields) =>
- val text = fields
- .get("text")
- .map(_.convertTo[String])
-
- val isCompound = fields
- .get("isCompound")
- .exists(_.convertTo[Boolean])
-
- val meta = fields
- .get("meta")
- .map(_.convertTo[Option[String]].getOrElse("{}"))
- .getOrElse(orig.criterion.meta)
-
- val inclusion = fields
- .get("inclusion")
- .map(_.convertTo[Option[Boolean]])
- .getOrElse(orig.criterion.inclusion)
-
- val arms = fields
- .get("arms")
- .map(_.convertTo[Option[List[LongId[EligibilityArm]]]].getOrElse(List.empty[LongId[EligibilityArm]]))
- .getOrElse(orig.armIds)
-
- val labels = fields
- .get("labels")
- .map(_.convertTo[Option[List[JsValue]]].getOrElse(List.empty[JsValue]))
- .map(_.map(l => jsValueToCriterionLabel(l, orig.criterion.id)))
- .getOrElse(orig.labels)
-
- orig.copy(
- criterion = orig.criterion.copy(
- meta = meta,
- text = text,
- isCompound = isCompound,
- inclusion = inclusion
- ),
- armIds = arms,
- labels = labels
- )
-
- case _ => deserializationError(s"Expected Json Object as partial Criterion, but got $json")
- }
-
- implicit val richCriterionFormat: RootJsonFormat[RichCriterion] = new RootJsonFormat[RichCriterion] {
- override def write(obj: RichCriterion): JsValue =
- JsObject(
- "id" -> obj.criterion.id.toJson,
- "meta" -> Option(obj.criterion.meta).toJson,
- "arms" -> obj.armIds.toJson,
- "text" -> obj.criterion.text.toJson,
- "isCompound" -> obj.criterion.isCompound.toJson,
- "labels" -> obj.labels.map(_.toJson).toJson,
- "trialId" -> obj.criterion.trialId.toJson,
- "inclusion" -> obj.criterion.inclusion.toJson
- )
-
- override def read(json: JsValue): RichCriterion = json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[Criterion]]])
-
- val trialId = fields
- .get("trialId")
- .map(_.convertTo[StringId[Trial]])
- .getOrElse(deserializationError(s"Criterion json object does not contain `trialId` field: $json"))
-
- val text = fields
- .get("text")
- .flatMap(_.convertTo[Option[String]])
-
- val isCompound = fields
- .get("isCompound")
- .exists(_.convertTo[Boolean])
-
- val meta = fields
- .get("meta")
- .flatMap(_.convertTo[Option[String]])
-
- val inclusion = fields
- .get("inclusion")
- .flatMap(_.convertTo[Option[Boolean]])
-
- val arms = fields
- .get("arms")
- .map(_.convertTo[Seq[LongId[EligibilityArm]]])
- .getOrElse(Seq.empty[LongId[EligibilityArm]])
-
- val labels = fields
- .get("labels")
- .map(_.convertTo[Seq[JsValue]])
- .map(_.map(l => jsValueToCriterionLabel(l, LongId(0))))
- .getOrElse(Seq.empty[CriterionLabel])
-
- RichCriterion(
- criterion = Criterion(
- id = id.getOrElse(LongId(0)),
- trialId = trialId,
- text = text,
- isCompound = isCompound,
- meta = meta.getOrElse(""),
- inclusion = inclusion
- ),
- armIds = arms,
- labels = labels
- )
-
- case _ => deserializationError(s"Expected Json Object as Criterion, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document.scala
deleted file mode 100644
index 66e95f3..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document.scala
+++ /dev/null
@@ -1,221 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.{LocalDate, LocalDateTime}
-
-import spray.json._
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.{LongId, TextJson}
-import xyz.driver.pdsuidomain.entities._
-
-object document {
- import DefaultJsonProtocol._
- import Document._
- import common._
-
- implicit val documentStatusFormat: RootJsonFormat[Status] = new EnumJsonFormat[Status](
- "New" -> Status.New,
- "Organized" -> Status.Organized,
- "Extracted" -> Status.Extracted,
- "Done" -> Status.Done,
- "Flagged" -> Status.Flagged,
- "Archived" -> Status.Archived
- )
-
- implicit val requiredTypeFormat: RootJsonFormat[RequiredType] = new EnumJsonFormat[RequiredType](
- "OPN" -> RequiredType.OPN,
- "PN" -> RequiredType.PN
- )
-
- implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat2(Meta.apply)
-
- implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] {
- override def read(json: JsValue): DocumentType = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Document type json object does not contain `name` field: $json"))
-
- DocumentType
- .fromString(name)
- .getOrElse(deserializationError(s"Unknown document type: $name"))
-
- case _ => deserializationError(s"Expected Json Object as Document type, but got $json")
- }
-
- override def write(obj: DocumentType) =
- JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
- }
-
- implicit val fullDocumentMetaFormat = new RootJsonFormat[TextJson[Meta]] {
- override def write(obj: TextJson[Meta]): JsValue = obj.content.toJson
- override def read(json: JsValue) = TextJson(documentMetaFormat.read(json))
- }
-
- def applyUpdateToDocument(json: JsValue, orig: Document): Document = json match {
- case JsObject(fields) =>
- val physician = fields
- .get("physician")
- .map(_.convertTo[String])
-
- val typeId = fields
- .get("typeId")
- .map(_.convertTo[Option[LongId[DocumentType]]])
- .getOrElse(orig.typeId)
-
- val provider = fields
- .get("provider")
- .map(_.convertTo[Option[String]])
- .getOrElse(orig.providerName)
-
- val providerTypeId = fields
- .get("providerTypeId")
- .map(_.convertTo[Option[LongId[ProviderType]]])
- .getOrElse(orig.providerTypeId)
-
- val institutionName = fields
- .get("institutionName")
- .map(_.convertTo[Option[String]])
- .getOrElse(orig.institutionName)
-
- val meta = fields
- .get("meta")
- .map(_.convertTo[Option[TextJson[Meta]]])
- .getOrElse(orig.meta)
-
- val startDate = fields
- .get("startDate")
- .map(_.convertTo[Option[LocalDate]])
- .getOrElse(orig.startDate)
-
- val endDate = fields
- .get("endDate")
- .map(_.convertTo[Option[LocalDate]])
- .getOrElse(orig.endDate)
-
- orig.copy(
- physician = physician.orElse(orig.physician),
- typeId = typeId,
- providerName = provider,
- providerTypeId = providerTypeId,
- institutionName = institutionName,
- meta = meta,
- startDate = startDate,
- endDate = endDate
- )
-
- case _ => deserializationError(s"Expected Json Object as partial Document, but got $json")
- }
-
- implicit val documentFormat: RootJsonFormat[Document] = new RootJsonFormat[Document] {
- override def write(document: Document): JsValue =
- JsObject(
- "id" -> document.id.toJson,
- "recordId" -> document.recordId.toJson,
- "physician" -> document.physician.toJson,
- "typeId" -> document.typeId.toJson,
- "provider" -> document.providerName.toJson,
- "providerTypeId" -> document.providerTypeId.toJson,
- "requiredType" -> document.requiredType.toJson,
- "institutionName" -> document.institutionName.toJson,
- "startDate" -> document.startDate.toJson,
- "endDate" -> document.endDate.toJson,
- "status" -> document.status.toJson,
- "previousStatus" -> document.previousStatus.toJson,
- "assignee" -> document.assignee.toJson,
- "previousAssignee" -> document.previousAssignee.toJson,
- "meta" -> document.meta.toJson,
- "lastActiveUser" -> document.lastActiveUserId.toJson,
- "lastUpdate" -> document.lastUpdate.toJson,
- "labelVersion" -> document.labelVersion.toJson
- )
-
- override def read(json: JsValue): Document = json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[Document]]])
-
- val recordId = fields
- .get("recordId")
- .map(_.convertTo[LongId[MedicalRecord]])
- .getOrElse(deserializationError(s"Document create json object does not contain `recordId` field: $json"))
-
- val status = fields
- .get("status")
- .flatMap(_.convertTo[Option[Document.Status]])
-
- val previousStatus = fields
- .get("previousStatus")
- .flatMap(_.convertTo[Option[Document.Status]])
-
- val physician = fields
- .get("physician")
- .flatMap(_.convertTo[Option[String]])
-
- val typeId = fields
- .get("typeId")
- .flatMap(_.convertTo[Option[LongId[DocumentType]]])
-
- val requiredType = fields
- .get("requiredType")
- .flatMap(_.convertTo[Option[Document.RequiredType]])
-
- val provider = fields
- .get("provider")
- .flatMap(_.convertTo[Option[String]])
-
- val providerTypeId = fields
- .get("providerTypeId")
- .flatMap(_.convertTo[Option[LongId[ProviderType]]])
-
- val institutionName = fields
- .get("institutionName")
- .flatMap(_.convertTo[Option[String]])
-
- val meta = fields
- .get("meta")
- .flatMap(_.convertTo[Option[TextJson[Meta]]])
-
- val startDate = fields
- .get("startDate")
- .flatMap(_.convertTo[Option[LocalDate]])
-
- val endDate = fields
- .get("endDate")
- .flatMap(_.convertTo[Option[LocalDate]])
-
- val lastUpdate = fields
- .get("lastUpdate")
- .flatMap(_.convertTo[Option[LocalDateTime]])
-
- val labelVersion = fields
- .get("labelVersion")
- .flatMap(_.convertTo[Option[Int]])
-
- Document(
- id = id.getOrElse(LongId(0)),
- recordId = recordId,
- status = status.getOrElse(Document.Status.New),
- physician = physician,
- typeId = typeId,
- startDate = startDate,
- endDate = endDate,
- providerName = provider,
- providerTypeId = providerTypeId,
- requiredType = requiredType,
- institutionName = institutionName,
- meta = meta,
- previousStatus = previousStatus,
- assignee = None,
- previousAssignee = None,
- lastActiveUserId = None,
- lastUpdate = lastUpdate.getOrElse(LocalDateTime.MIN),
- labelVersion = labelVersion.getOrElse(0)
- )
-
- case _ => deserializationError(s"Expected Json Object as Document, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala
deleted file mode 100644
index 1652f7b..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala
+++ /dev/null
@@ -1,35 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.core.json._
-import xyz.driver.pdsuidomain.entities._
-
-object documenthistory {
- import DefaultJsonProtocol._
- import DocumentHistory._
- import common._
-
- implicit val documentStateFormat = new EnumJsonFormat[State](
- "New" -> State.New,
- "Extract" -> State.Extract,
- "Done" -> State.Done,
- "Review" -> State.Review,
- "Flag" -> State.Flag,
- "Archive" -> State.Archive
- )
-
- implicit val documentActionFormat = new EnumJsonFormat[Action](
- "Start" -> Action.Start,
- "Submit" -> Action.Submit,
- "Unassign" -> Action.Unassign,
- "Resolve" -> Action.Resolve,
- "Flag" -> Action.Flag,
- "Archive" -> Action.Archive,
- "PostEvidence" -> Action.PostEvidence,
- "CreateDocument" -> Action.CreateDocument,
- "ReadDocument" -> Action.ReadDocument
- )
-
- implicit val documentHistoryFormat: RootJsonFormat[DocumentHistory] = jsonFormat6(DocumentHistory.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
deleted file mode 100644
index 037a3ad..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue.scala
+++ /dev/null
@@ -1,72 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json._
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities._
-
-object documentissue {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToDocumentIssue(json: JsValue, orig: DocumentIssue): DocumentIssue = json match {
- case JsObject(fields) =>
- val text = fields
- .get("text")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"DocumentIssue json object does not contain `text` field: $json"))
-
- val archiveRequired = fields
- .get("archiveRequired")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationError(s"DocumentIssue json object does not contain `archiveRequired` field: $json"))
-
- val startPage = fields.get("startPage").map(_.convertTo[Option[Double]])
- val endPage = fields.get("endPage").map(_.convertTo[Option[Double]])
-
- orig.copy(
- text = text,
- archiveRequired = archiveRequired,
- startPage = startPage.getOrElse(orig.startPage),
- endPage = endPage.getOrElse(orig.endPage)
- )
-
- case _ => deserializationError(s"Expected Json Object as partial DocumentIssue, but got $json")
-
- }
-
- def jsValueToDocumentIssue(json: JsValue,
- documentId: LongId[Document],
- userId: xyz.driver.core.Id[User]): DocumentIssue =
- json match {
- case JsObject(fields) =>
- val text = fields
- .get("text")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"DocumentIssue json object does not contain `text` field: $json"))
-
- val id = fields.get("id").map(_.convertTo[LongId[DocumentIssue]])
- val startPage = fields.get("startPage").flatMap(_.convertTo[Option[Double]])
- val endPage = fields.get("endPage").flatMap(_.convertTo[Option[Double]])
-
- DocumentIssue(
- id = id.getOrElse(LongId(0)),
- userId = userId,
- documentId = documentId,
- lastUpdate = LocalDateTime.MIN,
- isDraft = true,
- text = text,
- archiveRequired = false,
- startPage = startPage,
- endPage = endPage
- )
-
- case _ => deserializationError(s"Expected Json Object as DocumentIssue, but got $json")
- }
-
- implicit val documentIssueFormat: RootJsonFormat[DocumentIssue] = jsonFormat9(DocumentIssue.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala
deleted file mode 100644
index 925ba65..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala
+++ /dev/null
@@ -1,108 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json.DefaultJsonProtocol._
-import spray.json._
-import DefaultJsonProtocol._
-import xyz.driver.core.Id
-import xyz.driver.core.json._
-import xyz.driver.entities.labels.LabelValue
-import xyz.driver.pdsuidomain.entities.eligibility._
-
-object eligibility {
- import export._
- import xyz.driver.formats.json.assay._
- import xyz.driver.formats.json.common._
- import xyz.driver.formats.json.labels._
- import xyz.driver.formats.json.process._
- import xyz.driver.pdsuidomain.formats.json.document._
- import xyz.driver.pdsuidomain.formats.json.record._
- import xyz.driver.pdsuidomain.formats.json.export._
-
- implicit val molecularDocumentFormat: RootJsonFormat[MolecularEvidenceDocument] = jsonFormat7(
- MolecularEvidenceDocument)
- implicit val clinicalDocumentFormat: RootJsonFormat[ClinicalEvidenceDocument] = jsonFormat7(ClinicalEvidenceDocument)
-
- implicit val evidenceDocumentFormat: RootJsonFormat[EvidenceDocument] =
- GadtJsonFormat.create[EvidenceDocument]("evidenceDocumentType") {
- case _: MolecularEvidenceDocument => "Molecular"
- case _: ClinicalEvidenceDocument => "Clinical"
- } {
- case "Molecular" => molecularDocumentFormat
- case "Clinical" => clinicalDocumentFormat
- }
-
- implicit object evidenceFormat extends RootJsonFormat[Evidence] {
-
- override def write(evidence: Evidence): JsValue = {
- JsObject(
- "evidenceId" -> evidence.evidenceId.toJson,
- "evidenceText" -> evidence.evidenceText.toJson,
- "labelValue" -> evidence.labelValue.toJson,
- "document" -> evidence.document.toJson,
- "isPrimaryValue" -> evidence.isPrimaryValue.toJson
- )
- }
-
- override def read(json: JsValue): Evidence = {
- json match {
- case JsObject(fields) =>
- val evidenceId = fields
- .get("evidenceId")
- .map(_.convertTo[Id[Evidence]])
-
- val evidenceText = fields
- .get("evidenceText")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Evidence json object do not contain 'evidenceText' field: $json"))
-
- val labelValue = fields
- .get("labelValue")
- .map(_.convertTo[LabelValue])
- .getOrElse(deserializationError(s"Evidence json object do not contain 'labelValue' field: $json"))
-
- val isDriverDocument = fields
- .get("document")
- .flatMap {
- case JsObject(fieldMap) =>
- fieldMap
- .get("isDriverDocument")
- .map(_.convertTo[Boolean])
- case _ => deserializationError(s"Expected Json Object as 'isDriverDocument', but got $json")
- }
- .getOrElse(deserializationError(s"Evidence json object do not contain 'document' field: $json"))
-
- val document = customDocumentParser(isDriverDocument, fields, json)
-
- val isPrimaryValue = fields
- .get("isPrimaryValue")
- .map(_.convertTo[Option[Boolean]])
- .getOrElse(deserializationError(s"Evidence json object do not contain 'isPrimaryValue' field: $json"))
-
- Evidence(evidenceId, evidenceText, labelValue, document, isPrimaryValue)
- case _ => deserializationError(s"Expected Json Object as 'Evidence', but got $json")
- }
- }
-
- def customDocumentParser(isDriverDocument: Boolean,
- fields: Map[String, JsValue],
- json: JsValue): EvidenceDocument = {
- fields.get("document").fold { deserializationError(s"Expected Json Object as 'Document', but got $json") } {
- document =>
- if (isDriverDocument) document.convertTo[MolecularEvidenceDocument]
- else document.convertTo[ClinicalEvidenceDocument]
- }
- }
- }
-
- implicit def labelWithEvidenceJsonFormat: RootJsonFormat[LabelEvidence] = jsonFormat2(LabelEvidence)
-
- implicit def labelRankingFormat: RootJsonFormat[LabelMismatchRank] = jsonFormat4(LabelMismatchRank)
- implicit def labelRankingsFormat: RootJsonFormat[MismatchRankedLabels] = jsonFormat2(MismatchRankedLabels)
-
- implicit def matchedPatientFormat: RootJsonFormat[MatchedPatient] = jsonFormat6(MatchedPatient)
-
- implicit lazy val eligibleTrialFormat: RootJsonFormat[EligibleTrial] = jsonFormat2(EligibleTrial.apply)
- implicit lazy val eligibleArmFormat: RootJsonFormat[EligibleArm] = jsonFormat2(EligibleArm.apply)
- implicit lazy val eligibleCriterionFormat: RootJsonFormat[EligibleCriterion] = jsonFormat2(EligibleCriterion.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm.scala
deleted file mode 100644
index 5827f62..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibilityarm.scala
+++ /dev/null
@@ -1,107 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.entities.patient.CancerType
-import xyz.driver.formats.json.patient._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities._
-
-object eligibilityarm {
-
- import DefaultJsonProtocol._
- import common._
-
- private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = {
- deserializationError(s"$className json object do not contain '$field' field: $json")
- }
-
- private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = {
- deserializationError(s"Expected Json Object as $className, but got $json")
- }
-
- implicit def eligibilityArmWithDiseasesWriter: RootJsonWriter[EligibilityArmWithDiseases] =
- new RootJsonWriter[EligibilityArmWithDiseases] {
- override def write(obj: EligibilityArmWithDiseases): JsValue = {
- JsObject(
- "id" -> obj.eligibilityArm.id.toJson,
- "name" -> obj.eligibilityArm.name.toJson,
- "originalName" -> obj.eligibilityArm.originalName.toJson,
- "trialId" -> obj.eligibilityArm.trialId.toJson,
- "diseases" -> obj.eligibilityArmDiseases.map(_.disease.toJson).toJson
- )
- }
- }
-
- implicit def eligibilityArmWithDiseasesReader: RootJsonReader[EligibilityArmWithDiseases] = {
- new RootJsonReader[EligibilityArmWithDiseases] {
- implicit val className: String = "create EligibilityArmWithDiseases"
-
- override def read(json: JsValue): EligibilityArmWithDiseases = {
- json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[EligibilityArm]]])
-
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationErrorFieldMessage("name", json))
-
- val trialId = fields
- .get("trialId")
- .map(_.convertTo[StringId[Trial]])
- .getOrElse(deserializationErrorFieldMessage("trialId", json))
-
- val diseases = fields
- .get("diseases")
- .map(_.convertTo[Seq[String]])
- .getOrElse(deserializationErrorFieldMessage("diseases", json))
-
- val eligibilityArm = EligibilityArm(
- id = id.getOrElse(LongId(0)),
- name = name,
- trialId = trialId,
- originalName = name
- )
-
- EligibilityArmWithDiseases(
- eligibilityArm,
- diseases.map { disease =>
- val condition = CancerType
- .fromString(disease)
- .getOrElse(throw new NoSuchElementException(s"unknown condition $disease"))
- EligibilityArmDisease(eligibilityArm.id, condition)
- }
- )
- case _ => deserializationErrorEntityMessage(json)
- }
- }
- }
- }
-
- def applyUpdateToEligibilityArmWithDiseases(json: JsValue,
- orig: EligibilityArmWithDiseases): EligibilityArmWithDiseases = {
- implicit val className: String = "update EligibilityArmWithDiseases"
- json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(orig.eligibilityArm.name)
-
- val diseases = fields
- .get("diseases")
- .map(_.convertTo[Seq[CancerType]].map(x => EligibilityArmDisease(orig.eligibilityArm.id, x)))
- .getOrElse(orig.eligibilityArmDiseases)
-
- orig.copy(
- eligibilityArm = orig.eligibilityArm
- .copy(name = name),
- eligibilityArmDiseases = diseases
- )
-
- case _ => deserializationErrorEntityMessage(json)
- }
- }
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export.scala
deleted file mode 100644
index 8fb7d03..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export.scala
+++ /dev/null
@@ -1,127 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.core.json.idFormat
-import xyz.driver.entities.labels.Label
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities.export.patient._
-import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels}
-import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm}
-
-object export {
- import DefaultJsonProtocol._
- import common._
- import document._
- import record._
-
- private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = {
- deserializationError(s"$className json object do not contain '$field' field: $json")
- }
-
- private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = {
- deserializationError(s"Expected Json Object as $className, but got $json")
- }
-
- implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] =
- jsonFormat5(ExportPatientLabelEvidenceDocument.apply)
-
- implicit val patientLabelEvidenceFormat: RootJsonFormat[ExportPatientLabelEvidence] =
- jsonFormat(ExportPatientLabelEvidence.apply, "evidenceId", "labelValue", "evidenceText", "document")
-
- implicit val patientLabelFormat: RootJsonFormat[ExportPatientLabel] =
- jsonFormat(ExportPatientLabel.apply, "labelId", "evidence")
-
- implicit val patientWithLabelsFormat: RootJsonFormat[ExportPatientWithLabels] =
- jsonFormat(ExportPatientWithLabels.apply, "patientId", "labelVersion", "labels")
-
- implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat3(ExportTrialArm.apply)
-
- implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] =
- new RootJsonFormat[ExportTrialLabelCriterion] {
- implicit val className: String = "ExportTrialLabelCriterion"
-
- override def write(obj: ExportTrialLabelCriterion): JsValue =
- JsObject(
- "value" -> obj.value
- .map {
- case true => "Yes"
- case false => "No"
- }
- .getOrElse("Unknown")
- .toJson,
- "labelId" -> obj.labelId.toJson,
- "criterionId" -> obj.criterionId.toJson,
- "criterionText" -> obj.criteria.toJson,
- "armIds" -> obj.armIds.toJson,
- "isCompound" -> obj.isCompound.toJson,
- "isDefining" -> obj.isDefining.toJson,
- "inclusion" -> obj.inclusion.toJson
- )
-
- override def read(json: JsValue): ExportTrialLabelCriterion = {
- json match {
- case JsObject(fields) =>
- val value = fields
- .get("value")
- .map(_.convertTo[String])
- .map {
- case "Yes" => Option(true)
- case "No" => Option(false)
- case "Unknown" => Option.empty[Boolean]
- }
- .getOrElse(deserializationErrorFieldMessage("value", json))
-
- val labelId = fields
- .get("labelId")
- .map(_.convertTo[LongId[Label]])
- .getOrElse(deserializationErrorFieldMessage("labelId", json))
-
- val criterionId = fields
- .get("criterionId")
- .map(_.convertTo[LongId[Criterion]])
- .getOrElse(deserializationErrorFieldMessage("criterionId", json))
-
- val criterionText = fields
- .get("criterionText")
- .map(_.convertTo[String])
- .getOrElse(deserializationErrorFieldMessage("criterionText", json))
-
- val armIds = fields
- .get("armIds")
- .map(_.convertTo[Set[LongId[EligibilityArm]]])
- .getOrElse(deserializationErrorFieldMessage("armIds", json))
-
- val isCompound = fields
- .get("isCompound")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationErrorFieldMessage("isCompound", json))
-
- val isDefining = fields
- .get("isDefining")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationErrorFieldMessage("isDefining", json))
-
- val inclusion = fields
- .get("inclusion")
- .flatMap(_.convertTo[Option[Boolean]])
-
- ExportTrialLabelCriterion(
- criterionId,
- value,
- labelId,
- armIds,
- criterionText,
- isCompound,
- isDefining,
- inclusion
- )
-
- case _ => deserializationErrorEntityMessage(json)
- }
- }
- }
-
- implicit val trialWithLabelsFormat: RootJsonFormat[ExportTrialWithLabels] =
- jsonFormat(ExportTrialWithLabels.apply, "nctId", "trialId", "lastReviewed", "labelVersion", "arms", "criteria")
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata.scala
deleted file mode 100644
index 232bb39..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata.scala
+++ /dev/null
@@ -1,155 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue}
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuicommon.domain.{LongId, TextJson}
-import xyz.driver.pdsuidomain.entities._
-import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData
-
-object extracteddata {
- import DefaultJsonProtocol._
- import ExtractedData._
- import common._
-
- implicit val metaKeywordFormat: RootJsonFormat[Meta.Keyword] = jsonFormat4(Meta.Keyword)
- implicit val metaTextLayerPositionFormat: RootJsonFormat[Meta.TextLayerPosition] = jsonFormat3(
- Meta.TextLayerPosition)
- implicit val metaEvidenceFormat: RootJsonFormat[Meta.Evidence] = jsonFormat3(Meta.Evidence)
-
- implicit val extractedDataMetaFormat: RootJsonFormat[Meta] = jsonFormat2(Meta.apply)
- implicit val fullExtractedDataMetaFormat = new RootJsonFormat[TextJson[Meta]] {
- override def write(obj: TextJson[Meta]): JsValue = obj.content.toJson
- override def read(json: JsValue): TextJson[Meta] = TextJson(extractedDataMetaFormat.read(json))
- }
-
- implicit val extractedDataLabelWriter: JsonWriter[ExtractedDataLabel] = new JsonWriter[ExtractedDataLabel] {
- override def write(label: ExtractedDataLabel): JsObject = {
- JsObject(
- "id" -> label.labelId.toJson,
- "categoryId" -> label.categoryId.toJson,
- "value" -> label.value.toJson
- )
- }
- }
-
- def applyLabelsForExtractedData(json: JsValue, dataId: LongId[ExtractedData]): ExtractedDataLabel = json match {
- case JsObject(fields) =>
- val labelId = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[Label]]])
-
- val categoryId = fields
- .get("categoryId")
- .flatMap(_.convertTo[Option[LongId[LabelCategory]]])
-
- val value = fields
- .get("value")
- .flatMap(_.convertTo[Option[LabelValue]])
-
- ExtractedDataLabel(
- id = LongId(0),
- dataId = dataId,
- labelId = labelId,
- categoryId = categoryId,
- value = value
- )
-
- case _ => deserializationError(s"Expected Json Object as ExtractedDataLabel, but got $json")
- }
-
- def applyUpdateToExtractedData(json: JsValue, orig: RichExtractedData): RichExtractedData = json match {
- case JsObject(fields) =>
- val keywordId = fields
- .get("keywordId")
- .map(_.convertTo[Option[LongId[Keyword]]])
- .getOrElse(orig.extractedData.keywordId)
-
- val evidence = fields
- .get("evidence")
- .map(_.convertTo[Option[String]])
- .getOrElse(orig.extractedData.evidenceText)
-
- val meta = fields
- .get("meta")
- .map(_.convertTo[Option[TextJson[Meta]]])
- .getOrElse(orig.extractedData.meta)
-
- val labels = fields
- .get("labels")
- .map(
- _.convertTo[Option[List[JsValue]]]
- .getOrElse(List.empty[JsValue])
- .map(l => applyLabelsForExtractedData(l, orig.extractedData.id)))
- .getOrElse(orig.labels)
-
- val extractedData = orig.extractedData.copy(
- keywordId = keywordId,
- evidenceText = evidence,
- meta = meta
- )
-
- orig.copy(
- extractedData = extractedData,
- labels = labels
- )
-
- case _ => deserializationError(s"Expected Json Object as partial ExtractedData, but got $json")
- }
-
- implicit val extractedDataFormat: RootJsonFormat[RichExtractedData] = new RootJsonFormat[RichExtractedData] {
- override def write(richData: RichExtractedData): JsValue =
- JsObject(
- "id" -> richData.extractedData.id.toJson,
- "documentId" -> richData.extractedData.documentId.toJson,
- "keywordId" -> richData.extractedData.keywordId.toJson,
- "evidence" -> richData.extractedData.evidenceText.toJson,
- "meta" -> richData.extractedData.meta.toJson,
- "labels" -> richData.labels.map(_.toJson).toJson
- )
-
- override def read(json: JsValue): RichExtractedData = json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[ExtractedData]]])
-
- val documentId = fields
- .get("documentId")
- .map(_.convertTo[LongId[Document]])
- .getOrElse(
- deserializationError(s"ExtractedData create json object does not contain `documentId` field: $json"))
-
- val keywordId = fields
- .get("keywordId")
- .flatMap(_.convertTo[Option[LongId[Keyword]]])
-
- val evidence = fields
- .get("evidence")
- .flatMap(_.convertTo[Option[String]])
-
- val meta = fields
- .get("meta")
- .flatMap(_.convertTo[Option[TextJson[Meta]]])
-
- val labels = fields
- .get("labels")
- .map(_.convertTo[List[JsValue]])
- .getOrElse(List.empty[JsValue])
- .map(l => applyLabelsForExtractedData(l, LongId(0)))
-
- val extractedData = ExtractedData(
- id = id.getOrElse(LongId(0L)),
- documentId = documentId,
- keywordId = keywordId,
- evidenceText = evidence,
- meta = meta
- )
-
- RichExtractedData(extractedData, labels)
-
- case _ => deserializationError(s"Expected Json Object as ExtractedData, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis.scala
deleted file mode 100644
index c5f6141..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities._
-
-object hypothesis {
- import DefaultJsonProtocol._
- import common._
-
- implicit val hypothesisFormat: RootJsonFormat[Hypothesis] = jsonFormat4(Hypothesis.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention.scala
deleted file mode 100644
index bf528e6..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention.scala
+++ /dev/null
@@ -1,147 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities.InterventionType.DeliveryMethod
-import xyz.driver.pdsuidomain.entities._
-
-object intervention {
- import DefaultJsonProtocol._
- import common._
-
- implicit def interventionFormat: RootJsonFormat[InterventionWithArms] = new RootJsonFormat[InterventionWithArms] {
- override def write(obj: InterventionWithArms) =
- JsObject(
- "id" -> obj.intervention.id.toJson,
- "name" -> obj.intervention.name.toJson,
- "typeId" -> obj.intervention.typeId.toJson,
- "dosage" -> obj.intervention.dosage.toJson,
- "isActive" -> obj.intervention.isActive.toJson,
- "arms" -> obj.arms.map(_.armId).toJson,
- "trialId" -> obj.intervention.trialId.toJson,
- "deliveryMethod" -> obj.intervention.deliveryMethod.toJson,
- "originalName" -> obj.intervention.originalName.toJson,
- "originalDosage" -> obj.intervention.originalDosage.toJson,
- "originalType" -> obj.intervention.originalType.toJson
- )
-
- override def read(json: JsValue): InterventionWithArms = json match {
- case JsObject(fields) =>
- val trialId = fields
- .get("trialId")
- .map(_.convertTo[StringId[Trial]])
- .getOrElse(deserializationError(s"Intervention json object does not contain `trialId` field: $json"))
-
- val typeId = fields
- .get("typeId")
- .flatMap(_.convertTo[Option[LongId[InterventionType]]])
-
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse("")
-
- val dosage = fields
- .get("dosage")
- .map(_.convertTo[String])
-
- val isActive = fields
- .get("isActive")
- .exists(_.convertTo[Boolean])
-
- val deliveryMethod = fields
- .get("deliveryMethod")
- .flatMap(_.convertTo[Option[String]])
-
- val arms = fields
- .get("arms")
- .map(_.convertTo[List[LongId[SlotArm]]])
- .map(_ map (x => InterventionArm(armId = x, interventionId = LongId(0L))))
- .getOrElse(List.empty[InterventionArm])
-
- InterventionWithArms(
- intervention = Intervention(
- id = LongId(0L),
- trialId = trialId,
- name = name,
- originalName = name,
- typeId = typeId,
- originalType = None,
- dosage = dosage.getOrElse(""),
- originalDosage = dosage.getOrElse(""),
- isActive = isActive,
- deliveryMethod = deliveryMethod
- ),
- arms = arms
- )
-
- case _ => deserializationError(s"Expected Json Object as create Intervention json, but got $json")
- }
- }
-
- def applyUpdateToInterventionWithArms(json: JsValue, orig: InterventionWithArms): InterventionWithArms = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
-
- val typeId = fields
- .get("typeId")
- .map(_.convertTo[Option[LongId[InterventionType]]])
-
- val dosage = fields
- .get("dosage")
- .map(_.convertTo[String])
-
- val isActive = fields
- .get("isActive")
- .map(_.convertTo[Boolean])
-
- val deliveryMethod = fields
- .get("deliveryMethod")
- .map(_.convertTo[Option[String]])
- .getOrElse(orig.intervention.deliveryMethod)
-
- val origIntervention = orig.intervention
- val arms = fields
- .get("arms")
- .map(_.convertTo[List[LongId[SlotArm]]].map(x => InterventionArm(x, orig.intervention.id)))
-
- orig.copy(
- intervention = origIntervention.copy(
- name = name.getOrElse(origIntervention.name),
- typeId = typeId.getOrElse(origIntervention.typeId),
- dosage = dosage.getOrElse(origIntervention.dosage),
- isActive = isActive.getOrElse(origIntervention.isActive),
- deliveryMethod = deliveryMethod
- ),
- arms = arms.getOrElse(orig.arms)
- )
-
- case _ => deserializationError(s"Expected Json Object as partial Intervention, but got $json")
- }
-
- implicit def interventionTypeFormat: JsonFormat[InterventionType] = new RootJsonFormat[InterventionType] {
- override def read(json: JsValue): InterventionType = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json"))
-
- InterventionType
- .typeFromString(name)
- .getOrElse(deserializationError(s"Unknown intervention type: $name"))
-
- case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json")
- }
-
- override def write(obj: InterventionType) =
- JsObject(
- "id" -> obj.id.toJson,
- "name" -> obj.name.toJson,
- "deliveryMethods" -> obj.deliveryMethods.map(DeliveryMethod.methodToString).toJson
- )
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/listresponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/listresponse.scala
deleted file mode 100644
index 1e359d6..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/listresponse.scala
+++ /dev/null
@@ -1,45 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json.DefaultJsonProtocol._
-import spray.json._
-import xyz.driver.pdsuidomain.ListResponse
-import xyz.driver.pdsuidomain.formats.json.common._
-
-object listresponse {
- private val itemsField = "items"
- private val metaField = "meta"
-
- implicit val listResponseMetaFormat: RootJsonFormat[ListResponse.Meta] = jsonFormat4(ListResponse.Meta.apply)
-
- implicit def listResponseWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] =
- new RootJsonWriter[ListResponse[T]] {
- override def write(listResponse: ListResponse[T]): JsValue = {
- JsObject(
- itemsField -> listResponse.items.map(_.toJson).toJson,
- metaField -> listResponse.meta.toJson
- )
- }
- }
-
- implicit def listResponseReader[T: JsonReader]: RootJsonReader[ListResponse[T]] =
- new RootJsonReader[ListResponse[T]] {
- override def read(json: JsValue): ListResponse[T] = json match {
- case JsObject(fields) =>
- val items = fields
- .get(itemsField)
- .map {
- case JsArray(elements) => elements.map(_.convertTo[T])(collection.breakOut)
- case x => deserializationError(s"Expected Array as JsArray, but got $x")
- }
- .getOrElse(deserializationError(s"ListResponse json object does not contain `$itemsField` field: $json"))
-
- val meta = fields
- .get(metaField)
- .map(_.convertTo[ListResponse.Meta])
- .getOrElse(deserializationError(s"ListResponse json object does not contain `$metaField` field: $json"))
-
- ListResponse(items, meta)
- case _ => deserializationError(s"Expected ListResponse json object, but got $json")
- }
- }
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient.scala
deleted file mode 100644
index 774a1ff..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient.scala
+++ /dev/null
@@ -1,118 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.{LocalDate, LocalDateTime}
-
-import spray.json._
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.entities.clinic.TestOrder
-import xyz.driver.entities.common.FullName
-import xyz.driver.entities.patient.CancerType
-import xyz.driver.formats.json.common._
-import xyz.driver.formats.json.patient._
-import xyz.driver.pdsuicommon.domain.UuidId
-import xyz.driver.pdsuidomain.entities._
-
-object patient {
- import DefaultJsonProtocol._
- import Patient._
- import common._
-
- implicit val patientStatusFormat: RootJsonFormat[Status] = new EnumJsonFormat[Status](
- "New" -> Status.New,
- "Verified" -> Status.Verified,
- "Reviewed" -> Status.Reviewed,
- "Curated" -> Status.Curated,
- "Done" -> Status.Done,
- "Flagged" -> Status.Flagged
- )
-
- implicit val patientFormat: RootJsonFormat[Patient] = new RootJsonFormat[Patient] {
- override def write(patient: Patient): JsValue =
- JsObject(
- "id" -> patient.id.toJson,
- "status" -> patient.status.toJson,
- "name" -> patient.name.toJson,
- "dob" -> patient.dob.toJson,
- "assignee" -> patient.assignee.toJson,
- "previousStatus" -> patient.previousStatus.toJson,
- "previousAssignee" -> patient.previousAssignee.toJson,
- "lastActiveUser" -> patient.lastActiveUserId.toJson,
- "lastUpdate" -> patient.lastUpdate.toJson,
- "disease" -> patient.disease.toJson,
- "orderId" -> patient.orderId.toJson
- )
-
- override def read(json: JsValue): Patient = {
- json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .map(_.convertTo[UuidId[Patient]])
- .getOrElse(deserializationError(s"Patient create json object does not contain `id` field: $json"))
-
- val status = fields
- .get("status")
- .map(_.convertTo[Patient.Status])
- .getOrElse(deserializationError(s"Patient create json object does not contain `status` field: $json"))
-
- val name = fields
- .get("name")
- .map(_.convertTo[FullName[Patient]])
- .getOrElse(deserializationError(s"Patient create json object does not contain `name` field: $json"))
-
- val dob = fields
- .get("dob")
- .map(_.convertTo[LocalDate])
- .getOrElse(deserializationError(s"Patient create json object does not contain `dob` field: $json"))
-
- val assignee = fields
- .get("assignee")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
-
- val previousStatus = fields
- .get("previousStatus")
- .flatMap(_.convertTo[Option[Patient.Status]])
-
- val previousAssignee = fields
- .get("previousAssignee")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
-
- val lastActiveUser = fields
- .get("lastActiveUser")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
-
- val disease = fields
- .get("disease")
- .map(_.convertTo[CancerType])
- .getOrElse(deserializationError(s"Patient create json object does not contain `disease` field: $json"))
-
- val orderId = fields
- .get("orderId")
- .map(_.convertTo[xyz.driver.core.Id[TestOrder]])
- .getOrElse(deserializationError(s"Patient create json object does not contain `orderId` field: $json"))
-
- val lastUpdate = fields
- .get("lastUpdate")
- .map(_.convertTo[LocalDateTime])
- .getOrElse(deserializationError(s"Patient create json object does not contain `lastUpdate` field: $json"))
-
- Patient(id,
- status,
- name,
- dob,
- assignee,
- previousStatus,
- previousAssignee,
- lastActiveUser,
- isUpdateRequired = false,
- disease,
- orderId,
- lastUpdate)
-
- case _ => deserializationError(s"Expected Json Object as Trial, but got $json")
- }
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala
deleted file mode 100644
index 035310b..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientcriterion.scala
+++ /dev/null
@@ -1,65 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.entities.labels.{Label, LabelValue}
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities._
-
-object patientcriterion {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToPatientCriterion(json: JsValue, orig: PatientCriterion): PatientCriterion = json match {
- case JsObject(fields) =>
- val eligibilityStatus = fields
- .get("eligibilityStatus")
- .map(_.convertTo[LabelValue])
- .getOrElse(orig.eligibilityStatus)
-
- val verifiedEligibilityStatus = fields
- .get("verifiedEligibilityStatus")
- .map(_.convertTo[LabelValue])
- .getOrElse(orig.verifiedEligibilityStatus)
-
- orig.copy(
- eligibilityStatus = eligibilityStatus,
- verifiedEligibilityStatus = verifiedEligibilityStatus
- )
-
- case _ => deserializationError(s"Expected Json Object as partial PatientCriterion, but got $json")
- }
-
- implicit val draftPatientCriterionFormat: RootJsonFormat[DraftPatientCriterion] = jsonFormat3(
- DraftPatientCriterion.apply)
- implicit val draftPatientCriterionListReader = new JsonReader[List[DraftPatientCriterion]] {
- override def read(json: JsValue) = json.convertTo[List[JsValue]].map(_.convertTo[DraftPatientCriterion])
- }
-
- implicit val patientCriterionFormat: RootJsonFormat[PatientCriterion] = jsonFormat14(PatientCriterion.apply)
- implicit val patientCriterionArmFormat: RootJsonFormat[PatientCriterionArm] = jsonFormat3(PatientCriterionArm.apply)
-
- implicit val richPatientCriterionFormat: RootJsonFormat[RichPatientCriterion] =
- new RootJsonFormat[RichPatientCriterion] {
- override def read(json: JsValue): RichPatientCriterion = {
- val fields = json.asJsObject.fields
- val labelId = fields.getOrElse("labelId", deserializationError("field 'labelId' is missing"))
- val arms = fields.getOrElse("armList", deserializationError("field 'arms' is missing"))
- RichPatientCriterion(
- json.convertTo[PatientCriterion],
- labelId.convertTo[LongId[Label]],
- arms.convertTo[List[PatientCriterionArm]]
- )
- }
- override def write(obj: RichPatientCriterion): JsValue = {
- JsObject(
- obj.patientCriterion.toJson.asJsObject.fields ++
- Map(
- "labelId" -> obj.labelId.toJson,
- "armList" -> obj.armList.toJson
- )
- )
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientdefiningcriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientdefiningcriteria.scala
deleted file mode 100644
index a67115c..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientdefiningcriteria.scala
+++ /dev/null
@@ -1,18 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuidomain.entities.PatientLabel
-
-object patientdefiningcriteria {
- import common._
-
- implicit val patientLabelDefiningCriteriaWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] {
- override def write(obj: PatientLabel) =
- JsObject(
- "id" -> obj.id.toJson,
- "value" -> obj.verifiedPrimaryValue.toJson
- )
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
deleted file mode 100644
index d719c5c..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
+++ /dev/null
@@ -1,39 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuidomain.entities._
-
-object patienteligibletrial {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToTrialArmGroup(json: JsValue, orig: PatientTrialArmGroupView): PatientTrialArmGroupView =
- json match {
- case JsObject(fields) =>
- val isVerified = fields
- .get("isVerified")
- .map(_.convertTo[Boolean])
- .getOrElse(orig.isVerified)
-
- orig.copy(isVerified = isVerified)
-
- case _ => deserializationError(s"Expected Json Object as partial PatientTrialArmGroupView, but got $json")
- }
-
- implicit val patientEligibleTrialWriter: RootJsonWriter[RichPatientEligibleTrial] =
- new RootJsonWriter[RichPatientEligibleTrial] {
- override def write(obj: RichPatientEligibleTrial) =
- JsObject(
- "id" -> obj.group.id.toJson,
- "patientId" -> obj.group.patientId.toJson,
- "trialId" -> obj.group.trialId.toJson,
- "trialTitle" -> obj.trial.title.toJson,
- "arms" -> obj.arms.map(_.armName).toJson,
- "hypothesisId" -> obj.trial.hypothesisId.toJson,
- "verifiedEligibilityStatus" -> obj.group.verifiedEligibilityStatus.toJson,
- "isVerified" -> obj.group.isVerified.toJson
- )
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory.scala
deleted file mode 100644
index c9cdc63..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory.scala
+++ /dev/null
@@ -1,30 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.core.json._
-import xyz.driver.pdsuidomain.entities._
-
-object patienthistory {
- import DefaultJsonProtocol._
- import PatientHistory._
- import common._
-
- implicit val patientStateFormat: RootJsonFormat[State] = new EnumJsonFormat[State](
- "Verify" -> State.Verify,
- "Curate" -> State.Curate,
- "Review" -> State.Review,
- "Flag" -> State.Flag
- )
-
- implicit val patientActionFormat: RootJsonFormat[Action] = new EnumJsonFormat[Action](
- "Start" -> Action.Start,
- "Submit" -> Action.Submit,
- "Unassign" -> Action.Unassign,
- "Resolve" -> Action.Resolve,
- "Flag" -> Action.Flag,
- "Archive" -> Action.Archive
- )
-
- implicit val patientHistoryFormat: RootJsonFormat[PatientHistory] = jsonFormat6(PatientHistory.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthypothesis.scala
deleted file mode 100644
index da991a4..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthypothesis.scala
+++ /dev/null
@@ -1,35 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities._
-
-object patienthypothesis {
- import DefaultJsonProtocol._
- import common._
- import xyz.driver.core.json._
-
- def applyUpdateToPatientHypothesis(json: JsValue, orig: PatientHypothesis): PatientHypothesis = json match {
- case JsObject(fields) =>
- val rationale = if (fields.contains("rationale")) {
- fields.get("rationale").map(_.convertTo[String])
- } else orig.rationale
-
- orig.copy(rationale = rationale)
-
- case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json")
- }
-
- implicit val patientHypothesisWriter: RootJsonWriter[PatientHypothesis] =
- new RootJsonWriter[PatientHypothesis] {
- override def write(obj: PatientHypothesis): JsValue = {
- JsObject(
- "id" -> obj.id.toJson,
- "patientId" -> obj.patientId.toJson,
- "hypothesisId" -> obj.hypothesisId.toJson,
- "matchedTrials" -> obj.matchedTrials.toJson,
- "rationale" -> obj.rationale.toJson
- )
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
deleted file mode 100644
index ed05325..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json._
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
-import xyz.driver.pdsuidomain.entities._
-
-object patientissue {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToPatientIssue(json: JsValue, orig: PatientIssue): PatientIssue = {
- json.asJsObject.getFields("text", "archiveRequired") match {
- case Seq(text, archiveRequired) =>
- orig.copy(
- text = text.convertTo[String],
- archiveRequired = archiveRequired.convertTo[Boolean]
- )
-
- case _ => deserializationError(s"Expected Json Object as partial PatientIssue, but got $json")
- }
- }
-
- def jsValueToPatientIssue(json: JsValue,
- patientId: UuidId[Patient],
- userId: xyz.driver.core.Id[User]): PatientIssue = {
- json.asJsObject.getFields("text") match {
- case Seq(text) =>
- PatientIssue(
- id = json.asJsObject.fields.get("id").flatMap(_.convertTo[Option[LongId[PatientIssue]]]).getOrElse(LongId(0)),
- userId = userId,
- patientId = patientId,
- lastUpdate = LocalDateTime.MIN,
- isDraft = true,
- text = text.convertTo[String],
- archiveRequired = false
- )
-
- case _ => deserializationError(s"Expected Json Object as PatientIssue, but got $json")
- }
-
- }
-
- implicit val patientIssueWriter: RootJsonWriter[PatientIssue] = new RootJsonWriter[PatientIssue] {
- override def write(obj: PatientIssue) = JsObject(
- "id" -> obj.id.toJson,
- "text" -> obj.text.toJson,
- "lastUpdate" -> obj.lastUpdate.toJson,
- "userId" -> obj.userId.toJson,
- "isDraft" -> obj.isDraft.toJson,
- "archiveRequired" -> obj.archiveRequired.toJson
- )
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala
deleted file mode 100644
index 615b3a2..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientlabel.scala
+++ /dev/null
@@ -1,65 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.entities.labels.LabelValue
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuidomain.entities._
-import xyz.driver.formats.json.labels._
-import xyz.driver.pdsuidomain.formats.json.record._
-import xyz.driver.pdsuidomain.formats.json.document._
-
-object patientlabel {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToPatientLabel(json: JsValue, orig: PatientLabel): PatientLabel = json match {
- case JsObject(fields) =>
- val primaryValue = fields
- .get("primaryValue")
- .map(_.convertTo[LabelValue])
- .getOrElse(orig.primaryValue)
-
- val verifiedPrimaryValue = fields
- .get("verifiedPrimaryValue")
- .map(_.convertTo[LabelValue])
- .getOrElse(orig.verifiedPrimaryValue)
-
- orig.copy(
- primaryValue = primaryValue,
- verifiedPrimaryValue = verifiedPrimaryValue
- )
-
- case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json")
- }
-
- implicit val patientLabelFormat: RootJsonFormat[PatientLabel] = jsonFormat8(PatientLabel.apply)
-
- implicit val richPatientLabelFormat: RootJsonFormat[RichPatientLabel] = new RootJsonFormat[RichPatientLabel] {
- override def read(json: JsValue): RichPatientLabel = {
- val isVerified =
- json.asJsObject.fields.getOrElse("isVerified", deserializationError("isVerified field is missing"))
- RichPatientLabel(json.convertTo[PatientLabel], isVerified.convertTo[Boolean])
- }
- override def write(obj: RichPatientLabel): JsValue = {
- val labelFields = obj.patientLabel.toJson.asJsObject.fields
- JsObject(labelFields ++ Map("isVerified" -> obj.isVerified.toJson))
- }
- }
-
- implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] =
- new RootJsonWriter[PatientLabelEvidenceView] {
- override def write(evidence: PatientLabelEvidenceView): JsValue =
- JsObject(
- "id" -> evidence.id.toJson,
- "value" -> evidence.value.toJson,
- "evidenceText" -> evidence.evidenceText.toJson,
- "documentId" -> evidence.documentId.toJson,
- "evidenceId" -> evidence.evidenceId.toJson,
- "reportId" -> evidence.reportId.toJson,
- "documentType" -> evidence.documentType.toJson,
- "date" -> evidence.date.toJson,
- "providerType" -> evidence.providerType.toJson
- )
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala
deleted file mode 100644
index d3fe2c9..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala
+++ /dev/null
@@ -1,213 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json._
-import xyz.driver.core.Id
-import xyz.driver.core.json._
-import xyz.driver.entities.clinic.ClinicalRecord
-import xyz.driver.pdsuicommon.domain.{LongId, TextJson, UuidId}
-import xyz.driver.pdsuidomain.entities.MedicalRecord.Meta._
-import xyz.driver.pdsuidomain.entities._
-
-object record {
- import DefaultJsonProtocol._
- import MedicalRecord._
- import common._
-
- implicit val recordStatusFormat: EnumJsonFormat[Status] = new EnumJsonFormat[Status](
- "New" -> Status.New,
- "Cleaned" -> Status.Cleaned,
- "Reviewed" -> Status.Reviewed,
- "Organized" -> Status.Organized,
- "Done" -> Status.Done,
- "Flagged" -> Status.Flagged,
- "Archived" -> Status.Archived
- )
-
- implicit val providerTypeFormat: RootJsonFormat[ProviderType] = new RootJsonFormat[ProviderType] {
- override def read(json: JsValue): ProviderType = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Provider type json object does not contain `name` field: $json"))
-
- ProviderType
- .fromString(name)
- .getOrElse(deserializationError(s"Unknown provider type: $name"))
-
- case _ => deserializationError(s"Expected Json Object as Provider type, but got $json")
- }
-
- override def write(obj: ProviderType) =
- JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
- }
-
- implicit val duplicateMetaFormat: RootJsonFormat[Duplicate] = new RootJsonFormat[Duplicate] {
- override def write(obj: Duplicate) =
- JsObject(
- "type" -> "duplicate".toJson,
- "startPage" -> obj.startPage.toJson,
- "endPage" -> obj.endPage.toJson,
- "startOriginalPage" -> obj.startOriginalPage.toJson,
- "endOriginalPage" -> obj.endOriginalPage.toJson
- )
-
- override def read(json: JsValue): Duplicate = json match {
- case JsObject(fields) =>
- val startPage = fields
- .get("startPage")
- .map(_.convertTo[Double])
- .getOrElse(deserializationError(s"Duplicate meta json object does not contain `startPage` field: $json"))
-
- val endPage = fields
- .get("endPage")
- .map(_.convertTo[Double])
- .getOrElse(deserializationError(s"Duplicate meta json object does not contain `endPage` field: $json"))
-
- val startOriginalPage = fields
- .get("startOriginalPage")
- .map(_.convertTo[Double])
- .getOrElse(
- deserializationError(s"Duplicate meta json object does not contain `startOriginalPage` field: $json"))
-
- val endOriginalPage = fields
- .get("endOriginalPage")
- .flatMap(_.convertTo[Option[Double]])
-
- Duplicate(
- startPage = startPage,
- endPage = endPage,
- startOriginalPage = startOriginalPage,
- endOriginalPage = endOriginalPage
- )
-
- case _ => deserializationError(s"Expected JsObject as Duplicate meta of medical record, but got $json")
- }
- }
-
- implicit val reorderMetaFormat: RootJsonFormat[Reorder] = new RootJsonFormat[Reorder] {
- override def write(obj: Reorder) =
- JsObject("type" -> "reorder".toJson, "items" -> obj.items.toJson)
-
- override def read(json: JsValue): Reorder = json match {
- case JsObject(fields) =>
- val items = fields
- .get("items")
- .map(_.convertTo[Seq[Int]])
- .getOrElse(deserializationError(s"Reorder meta json object does not contain `items` field: $json"))
-
- Reorder(items)
-
- case _ => deserializationError(s"Expected JsObject as Reorder meta of medical record, but got $json")
- }
- }
-
- implicit val rotateMetaFormat: RootJsonFormat[Rotation] = new RootJsonFormat[Rotation] {
- override def write(obj: Rotation) =
- JsObject("type" -> "rotation".toJson, "items" -> obj.items.toJson)
-
- override def read(json: JsValue): Rotation = json match {
- case JsObject(fields) =>
- val items = fields
- .get("items")
- .map(_.convertTo[Map[String, Int]])
- .getOrElse(deserializationError(s"Rotation meta json object does not contain `items` field: $json"))
-
- Rotation(items = items)
-
- case _ => deserializationError(s"Expected JsObject as Rotation meta of medical record, but got $json")
- }
- }
-
- implicit val recordMetaTypeFormat: GadtJsonFormat[MedicalRecord.Meta] = {
- GadtJsonFormat.create[Meta]("type")({ case m => m.metaType }) {
- case "duplicate" => duplicateMetaFormat
- case "reorder" => reorderMetaFormat
- case "rotation" => rotateMetaFormat
- }
- }
-
- implicit val recordMetaFormat: RootJsonFormat[TextJson[List[Meta]]] = new RootJsonFormat[TextJson[List[Meta]]] {
- override def write(obj: TextJson[List[Meta]]): JsArray = JsArray(obj.content.map(_.toJson).toVector)
- override def read(json: JsValue): TextJson[List[Meta]] = json match {
- case JsArray(values) => TextJson[List[Meta]](values.map(_.convertTo[Meta]).toList)
- case _ => deserializationError(s"Expected array as Meta, but got $json")
- }
- }
-
- implicit val recordFormat: RootJsonFormat[MedicalRecord] =
- new RootJsonFormat[MedicalRecord] {
- override def write(record: MedicalRecord): JsValue =
- JsObject(
- "id" -> record.id.toJson,
- "patientId" -> record.patientId.toJson,
- "caseId" -> record.caseId.toJson,
- "disease" -> record.disease.toJson,
- "physician" -> record.physician.toJson,
- "status" -> record.status.toJson,
- "previousStatus" -> record.previousStatus.toJson,
- "assignee" -> record.assignee.toJson,
- "previousAssignee" -> record.previousAssignee.toJson,
- "requestId" -> record.requestId.toJson,
- "meta" -> record.meta.getOrElse(TextJson[List[Meta]](List.empty)).toJson,
- "lastActiveUser" -> record.lastActiveUserId.toJson,
- "lastUpdate" -> record.lastUpdate.toJson,
- "totalPages" -> record.totalPages.toJson
- )
-
- override def read(json: JsValue): MedicalRecord = json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .flatMap(_.convertTo[Option[LongId[MedicalRecord]]])
-
- val disease = fields
- .get("disease")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"MedicalRecord json object does not contain `disease` field: $json"))
-
- val patientId = fields
- .get("patientId")
- .map(_.convertTo[UuidId[Patient]])
- .getOrElse(deserializationError(s"MedicalRecord json object does not contain `patientId` field: $json"))
-
- val requestId = fields
- .get("requestId")
- .map(_.convertTo[Id[ClinicalRecord]])
- .getOrElse(deserializationError(s"MedicalRecord json object does not contain `requestId` field: $json"))
-
- MedicalRecord(
- id = id.getOrElse(LongId(0)),
- status = MedicalRecord.Status.New,
- previousStatus = None,
- assignee = None,
- previousAssignee = None,
- lastActiveUserId = None,
- patientId = patientId,
- requestId = requestId,
- disease = disease,
- caseId = None,
- physician = None,
- meta = None,
- lastUpdate = LocalDateTime.now(),
- totalPages = 0
- )
-
- case _ => deserializationError(s"Expected Json Object as MedicalRecord, but got $json")
- }
- }
-
- def applyUpdateToMedicalRecord(json: JsValue, orig: MedicalRecord): MedicalRecord = json match {
- case JsObject(fields) =>
- val meta = fields
- .get("meta")
- .map(_.convertTo[Option[TextJson[List[Meta]]]])
- .getOrElse(orig.meta)
- orig.copy(meta = meta)
-
- case _ => deserializationError(s"Expected Json Object as partial MedicalRecord, but got $json")
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala
deleted file mode 100644
index be9dae9..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala
+++ /dev/null
@@ -1,43 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.core.json._
-import xyz.driver.pdsuidomain.entities._
-
-object recordhistory {
- import DefaultJsonProtocol._
- import MedicalRecordHistory._
- import common._
-
- implicit val recordStateFormat = new EnumJsonFormat[State](
- "New" -> State.New,
- "Clean" -> State.Clean,
- "Organize" -> State.Organize,
- "Review" -> State.Review,
- "Done" -> State.Done,
- "Flag" -> State.Flag,
- "Archive" -> State.Archive
- )
-
- implicit val recordActionFormat = new EnumJsonFormat[Action](
- "Start" -> Action.Start,
- "Submit" -> Action.Submit,
- "Unassign" -> Action.Unassign,
- "Resolve" -> Action.Resolve,
- "Flag" -> Action.Flag,
- "Archive" -> Action.Archive,
- "SaveDuplicate" -> Action.SaveDuplicate,
- "SaveReorder" -> Action.SaveReorder,
- "SaveRotation" -> Action.SaveRotation,
- "DeleteDuplicate" -> Action.DeleteDuplicate,
- "DeleteReorder" -> Action.DeleteReorder,
- "DeleteRotation" -> Action.DeleteRotation,
- "CreateDocument" -> Action.CreateDocument,
- "DeleteDocument" -> Action.DeleteDocument,
- "CreateRecord" -> Action.CreateRecord,
- "ReadRecord" -> Action.ReadRecord
- )
-
- implicit val recordHistoryFormat: RootJsonFormat[MedicalRecordHistory] = jsonFormat6(MedicalRecordHistory.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue.scala
deleted file mode 100644
index e7f2f65..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue.scala
+++ /dev/null
@@ -1,72 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json._
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities._
-
-object recordissue {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToRecordIssue(json: JsValue, orig: MedicalRecordIssue): MedicalRecordIssue = json match {
- case JsObject(fields) =>
- val text = fields
- .get("text")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"MedicalRecordIssue json object does not contain `text` field: $json"))
-
- val archiveRequired = fields
- .get("archiveRequired")
- .map(_.convertTo[Boolean])
- .getOrElse(
- deserializationError(s"MedicalRecordIssue json object does not contain `archiveRequired` field: $json"))
-
- val startPage = fields.get("startPage").map(_.convertTo[Double])
- val endPage = fields.get("endPage").map(_.convertTo[Double])
-
- orig.copy(
- text = text,
- archiveRequired = archiveRequired,
- startPage = startPage,
- endPage = endPage
- )
-
- case _ => deserializationError(s"Expected Json Object as partial MedicalRecordIssue, but got $json")
-
- }
-
- def jsValueToRecordIssue(json: JsValue,
- recordId: LongId[MedicalRecord],
- userId: xyz.driver.core.Id[User]): MedicalRecordIssue = json match {
- case JsObject(fields) =>
- val text = fields
- .get("text")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"MedicalRecordIssue json object does not contain `text` field: $json"))
-
- val id = fields.get("id").flatMap(_.convertTo[Option[LongId[MedicalRecordIssue]]]).getOrElse(LongId(0))
- val startPage = fields.get("startPage").map(_.convertTo[Double])
- val endPage = fields.get("endPage").map(_.convertTo[Double])
-
- MedicalRecordIssue(
- id = id,
- userId = userId,
- recordId = recordId,
- lastUpdate = LocalDateTime.MIN,
- isDraft = true,
- text = text,
- archiveRequired = false,
- startPage = startPage,
- endPage = endPage
- )
-
- case _ => deserializationError(s"Expected Json Object as MedicalRecordIssue, but got $json")
- }
-
- implicit val recordIssueFormat: RootJsonFormat[MedicalRecordIssue] = jsonFormat9(MedicalRecordIssue.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/slotarm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/slotarm.scala
deleted file mode 100644
index 60d6521..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/slotarm.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities.{SlotArm, Trial}
-
-object slotarm {
- import DefaultJsonProtocol._
- import common._
-
- def applyUpdateToArm(json: JsValue, orig: SlotArm): SlotArm = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Arm json object does not contain `name` field: $json"))
- orig.copy(name = name)
-
- case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json")
- }
-
- implicit def slotArmFormat: RootJsonFormat[SlotArm] = new RootJsonFormat[SlotArm] {
- override def write(obj: SlotArm): JsValue =
- JsObject(
- "id" -> obj.id.toJson,
- "name" -> obj.name.toJson,
- "originalName" -> obj.originalName.toJson,
- "trialId" -> obj.trialId.toJson
- )
-
- override def read(json: JsValue): SlotArm = json.asJsObject.getFields("trialId", "name") match {
- case Seq(trialId, name) =>
- SlotArm(
- id = json.asJsObject.fields.get("id").flatMap(_.convertTo[Option[LongId[SlotArm]]]).getOrElse(LongId(0)),
- name = name.convertTo[String],
- trialId = trialId.convertTo[StringId[Trial]],
- originalName = name.convertTo[String]
- )
-
- case _ => deserializationError(s"Expected Json Object as Arm, but got $json")
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign.scala
deleted file mode 100644
index 60c7e70..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign.scala
+++ /dev/null
@@ -1,29 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities._
-
-object studydesign {
- import DefaultJsonProtocol._
- import common._
-
- implicit val studyDesignFormat: RootJsonFormat[StudyDesign] = new RootJsonFormat[StudyDesign] {
- override def read(json: JsValue): StudyDesign = json match {
- case JsObject(fields) =>
- val name = fields
- .get("name")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Study design json object does not contain `name` field: $json"))
-
- StudyDesign
- .fromString(name)
- .getOrElse(deserializationError(s"Unknown study design: $name"))
-
- case _ => deserializationError(s"Expected Json Object as Study design, but got $json")
- }
-
- override def write(obj: StudyDesign) =
- JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial.scala
deleted file mode 100644
index cdc52d9..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial.scala
+++ /dev/null
@@ -1,187 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.{LocalDateTime, ZoneId, ZonedDateTime}
-
-import spray.json._
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
-import xyz.driver.pdsuidomain.entities._
-
-object trial {
- import DefaultJsonProtocol._
- import Trial._
- import common._
-
- implicit val trialStatusFormat: RootJsonFormat[Status] = new EnumJsonFormat[Status](
- "New" -> Status.New,
- "ReviewSummary" -> Status.ReviewSummary,
- "Summarized" -> Status.Summarized,
- "PendingUpdate" -> Status.PendingUpdate,
- "Update" -> Status.Update,
- "ReviewCriteria" -> Status.ReviewCriteria,
- "Done" -> Status.Done,
- "Flagged" -> Status.Flagged,
- "Archived" -> Status.Archived
- )
-
- implicit val trialFormat: RootJsonFormat[Trial] = new RootJsonFormat[Trial] {
- override def write(obj: Trial) =
- JsObject(
- "id" -> obj.id.toJson,
- "externalid" -> obj.externalId.toJson,
- "lastUpdate" -> ZonedDateTime.of(obj.lastUpdate, ZoneId.of("Z")).toJson,
- "status" -> obj.status.toJson,
- "assignee" -> obj.assignee.toJson,
- "previousStatus" -> obj.previousStatus.toJson,
- "previousAssignee" -> obj.previousAssignee.toJson,
- "lastActiveUser" -> obj.lastActiveUserId.toJson,
- "phase" -> obj.phase.toJson,
- "hypothesisId" -> obj.hypothesisId.toJson,
- "studyDesignId" -> obj.studyDesignId.toJson,
- "originalStudyDesignId" -> obj.originalStudyDesign.toJson,
- "isPartner" -> obj.isPartner.toJson,
- "overview" -> obj.overview.toJson,
- "overviewTemplate" -> obj.overviewTemplate.toJson,
- "isUpdated" -> obj.isUpdated.toJson,
- "title" -> obj.title.toJson,
- "originalTitle" -> obj.originalTitle.toJson
- )
-
- override def read(json: JsValue): Trial = {
- json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .map(_.convertTo[StringId[Trial]])
- .getOrElse(deserializationError(s"Trial create json object does not contain `id` field: $json"))
- val externalid = fields
- .get("externalid")
- .map(_.convertTo[UuidId[Trial]])
- .getOrElse(deserializationError(s"Trial create json object does not contain `externalid` field: $json"))
- val status = fields
- .get("status")
- .map(_.convertTo[Trial.Status])
- .getOrElse(deserializationError(s"Trial create json object does not contain `status` field: $json"))
- val assignee = fields
- .get("assignee")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
- val previousStatus = fields
- .get("previousStatus")
- .flatMap(_.convertTo[Option[Trial.Status]])
- val previousAssignee = fields
- .get("previousAssignee")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
- val lastActiveUser = fields
- .get("lastActiveUser")
- .flatMap(_.convertTo[Option[xyz.driver.core.Id[User]]])
- val lastUpdate = fields
- .get("lastUpdate")
- .map(_.convertTo[LocalDateTime])
- .getOrElse(deserializationError(s"Trial create json object does not contain `lastUpdate` field: $json"))
- val phase = fields
- .get("phase")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Trial create json object does not contain `phase` field: $json"))
- val hypothesisId = fields
- .get("hypothesisId")
- .flatMap(_.convertTo[Option[UuidId[Hypothesis]]])
- val studyDesignId = fields
- .get("studyDesignId")
- .flatMap(_.convertTo[Option[LongId[StudyDesign]]])
- val originalStudyDesignId = fields
- .get("originalStudyDesignId")
- .flatMap(_.convertTo[Option[String]])
- val isPartner = fields
- .get("isPartner")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationError(s"Trial create json object does not contain `isPartner` field: $json"))
- val overview = fields
- .get("overview")
- .flatMap(_.convertTo[Option[String]])
- val overviewTemplate = fields
- .get("overviewTemplate")
- .map(_.convertTo[String])
- .getOrElse(
- deserializationError(s"Trial create json object does not contain `overviewTemplate` field: $json"))
- val isUpdated = fields
- .get("isUpdated")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationError(s"Trial create json object does not contain `isUpdated` field: $json"))
- val title = fields
- .get("title")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Trial create json object does not contain `title` field: $json"))
- val originalTitle = fields
- .get("originalTitle")
- .map(_.convertTo[String])
- .getOrElse(deserializationError(s"Trial create json object does not contain `originalTitle` field: $json"))
-
- Trial(
- id,
- externalid,
- status,
- assignee,
- previousStatus,
- previousAssignee,
- lastActiveUser,
- lastUpdate,
- phase,
- hypothesisId,
- studyDesignId,
- originalStudyDesignId,
- isPartner,
- overview,
- overviewTemplate,
- isUpdated,
- title,
- originalTitle
- )
-
- case _ => deserializationError(s"Expected Json Object as Trial, but got $json")
- }
- }
- }
-
- def applyUpdateToTrial(json: JsValue, orig: Trial): Trial = json match {
- case JsObject(fields) =>
- val hypothesisId = fields
- .get("hypothesisId")
- .map(_.convertTo[Option[UuidId[Hypothesis]]])
- .getOrElse(orig.hypothesisId)
-
- val studyDesignId = fields
- .get("studyDesignId")
- .map(_.convertTo[Option[LongId[StudyDesign]]])
- .getOrElse(orig.studyDesignId)
-
- val overview = fields
- .get("overview")
- .map(_.convertTo[Option[String]])
- .getOrElse(orig.overview)
-
- val title = fields
- .get("title")
- .map(_.convertTo[Option[String]].getOrElse(""))
- .getOrElse(orig.title)
-
- val originalTitle = fields
- .get("originalTitle")
- .flatMap(_.convertTo[Option[String]])
- .getOrElse(orig.originalTitle)
-
- orig.copy(
- hypothesisId = hypothesisId,
- studyDesignId = studyDesignId,
- overview = overview,
- title = title,
- originalTitle = originalTitle
- )
-
- case _ => deserializationError(s"Expected Json Object as Trial, but got $json")
- }
-
- implicit val trialCreationRequestFormat: RootJsonFormat[TrialCreationRequest] =
- jsonFormat3(TrialCreationRequest.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala
deleted file mode 100644
index f71ec12..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala
+++ /dev/null
@@ -1,32 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import spray.json._
-import xyz.driver.core.json._
-import xyz.driver.pdsuidomain.entities._
-
-object trialhistory {
- import DefaultJsonProtocol._
- import TrialHistory._
- import common._
-
- implicit val trialStateFormat = new EnumJsonFormat[State](
- "Summarize" -> State.Summarize,
- "Criteriarize" -> State.Criteriarize,
- "Review" -> State.Review,
- "ReviewSummary" -> State.ReviewSummary,
- "ReviewCriteria" -> State.ReviewCriteria,
- "Flag" -> State.Flag
- )
-
- implicit val trialActionFormat = new EnumJsonFormat[Action](
- "Start" -> Action.Start,
- "Submit" -> Action.Submit,
- "Unassign" -> Action.Unassign,
- "Resolve" -> Action.Resolve,
- "Flag" -> Action.Flag,
- "Archive" -> Action.Archive
- )
-
- implicit val trialHistoryFormat: RootJsonFormat[TrialHistory] = jsonFormat7(TrialHistory.apply)
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala
deleted file mode 100644
index 79882c2..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala
+++ /dev/null
@@ -1,134 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json
-
-import java.time.LocalDateTime
-
-import spray.json.{RootJsonReader, _}
-import xyz.driver.core.{Id, auth}
-import xyz.driver.core.auth.User
-import xyz.driver.core.json._
-import xyz.driver.pdsuicommon.domain.{LongId, StringId}
-import xyz.driver.pdsuidomain.entities._
-
-object trialissue {
-
- import DefaultJsonProtocol._
- import common._
-
- private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = {
- deserializationError(s"$className json object do not contain '$field' field: $json")
- }
-
- private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = {
- deserializationError(s"Expected Json Object as $className, but got $json")
- }
-
- def applyUpdateToTrialIssue(json: JsValue, orig: TrialIssue): TrialIssue = {
- json.asJsObject.getFields("text", "evidence", "archiveRequired", "meta") match {
- case Seq(text, evidence, archiveRequired, meta) =>
- orig.copy(
- text = text.convertTo[String],
- evidence = evidence.convertTo[String],
- archiveRequired = archiveRequired.convertTo[Boolean],
- meta = meta.convertTo[String]
- )
-
- case _ => deserializationError(s"Expected Json Object as partial TrialIssue, but got $json")
- }
- }
-
- def jsValueToTrialIssue(json: JsValue, trialId: StringId[Trial], userId: xyz.driver.core.Id[User]): TrialIssue = {
- json.asJsObject.getFields("text", "evidence", "meta") match {
- case Seq(text, evidence, meta) =>
- TrialIssue(
- id = json.asJsObject.fields.get("id").flatMap(_.convertTo[Option[LongId[TrialIssue]]]).getOrElse(LongId(0)),
- userId = userId,
- trialId = trialId,
- lastUpdate = LocalDateTime.MIN,
- isDraft = true,
- text = text.convertTo[String],
- evidence = evidence.convertTo[String],
- archiveRequired = false,
- meta = meta.convertTo[String]
- )
-
- case _ => deserializationError(s"Expected Json Object as TrialIssue, but got $json")
- }
-
- }
-
- implicit val trialIssueWriter = new RootJsonWriter[TrialIssue] {
- override def write(obj: TrialIssue) = JsObject(
- "id" -> obj.id.toJson,
- "text" -> obj.text.toJson,
- "lastUpdate" -> obj.lastUpdate.toJson,
- "userId" -> obj.userId.toJson,
- "isDraft" -> obj.isDraft.toJson,
- "evidence" -> obj.evidence.toJson,
- "archiveRequired" -> obj.archiveRequired.toJson,
- "meta" -> obj.meta.toJson
- )
- }
-
- def trialIssueReader(trialId: StringId[Trial]): RootJsonReader[TrialIssue] =
- new RootJsonReader[TrialIssue] {
- implicit val className: String = "TrialIssue"
-
- override def read(json: JsValue): TrialIssue = json match {
- case JsObject(fields) =>
- val id = fields
- .get("id")
- .map(_.convertTo[LongId[TrialIssue]])
- .getOrElse(deserializationErrorFieldMessage("id", json))
-
- val text = fields
- .get("text")
- .map(_.convertTo[String])
- .getOrElse(deserializationErrorFieldMessage("text", json))
-
- val lastUpdate = fields
- .get("lastUpdate")
- .map(_.convertTo[LocalDateTime])
- .getOrElse(deserializationErrorFieldMessage("lastUpdate", json))
-
- val userId = fields
- .get("userId")
- .map(_.convertTo[Id[auth.User]])
- .getOrElse(deserializationErrorFieldMessage("userId", json))
-
- val isDraft = fields
- .get("isDraft")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationErrorFieldMessage("isDraft", json))
-
- val evidence = fields
- .get("evidence")
- .map(_.convertTo[String])
- .getOrElse(deserializationErrorFieldMessage("evidence", json))
-
- val archiveRequired = fields
- .get("archiveRequired")
- .map(_.convertTo[Boolean])
- .getOrElse(deserializationErrorFieldMessage("archiveRequired", json))
-
- val meta = fields
- .get("meta")
- .map(_.convertTo[String])
- .getOrElse(deserializationErrorFieldMessage("meta", json))
-
- TrialIssue(
- id = id,
- userId = userId,
- trialId = trialId,
- lastUpdate = lastUpdate,
- isDraft = isDraft,
- text = text,
- evidence = evidence,
- archiveRequired = archiveRequired,
- meta = meta
- )
-
- case _ => deserializationErrorEntityMessage(json)
- }
- }
-
-}