diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats')
99 files changed, 0 insertions, 4969 deletions
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 3fbeac8..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/ListResponse.scala +++ /dev/null @@ -1,56 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json - -import java.time.LocalDateTime - -import xyz.driver.pdsuicommon.db.Pagination -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) - -object ListResponse { - - final case class Meta(itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) - - object Meta { - def apply(itemsCount: Int, pagination: Pagination, lastUpdate: Option[LocalDateTime]): Meta = { - Meta(itemsCount, pagination.pageNumber, pagination.pageSize, lastUpdate) - } - } - - private val listResponseMetaJsonReads: Reads[Meta] = { - ((JsPath \ "itemsCount").read[Int] and - (JsPath \ "pageNumber").read[Int] and - (JsPath \ "pageSize").read[Int] and - (JsPath \ "lastUpdate").readNullable[LocalDateTime]).apply { - (itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) => - Meta(itemsCount, pageNumber, pageSize, lastUpdate) - } - } - - implicit val listResponseMetaJsonWrites: Writes[Meta] = ( - (JsPath \ "itemsCount").write[Int] and - (JsPath \ "pageNumber").write[Int] and - (JsPath \ "pageSize").write[Int] and - (JsPath \ "lastUpdate").write[Option[LocalDateTime]] - )(unlift(Meta.unapply)) - - implicit val listResponseMetaJsonFormat: Format[Meta] = Format( - listResponseMetaJsonReads, - listResponseMetaJsonWrites - ) - - implicit def listResponseJsonWrites[T](implicit f: Writes[T]): Writes[ListResponse[T]] = - ( - (JsPath \ "items").write[Seq[T]] and - (JsPath \ "meta").write[Meta] - )(unlift(ListResponse.unapply[T])) - - implicit def listResponseJsonFormat[T](implicit f: Format[T]): Format[ListResponse[T]] = - ( - (JsPath \ "items").format(seqJsonFormat[T]) and - (JsPath \ "meta").format[Meta] - )(ListResponse.apply[T], unlift(ListResponse.unapply[T])) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiArm.scala deleted file mode 100644 index 32e2b54..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiArm.scala +++ /dev/null @@ -1,35 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.arm - -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.Arm -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -final case class ApiArm(id: Long, name: String, originalName: String, trialId: String) { - - def toDomain: Arm = Arm( - id = LongId(this.id), - name = this.name, - originalName = this.originalName, - trialId = StringId(this.trialId), - deleted = None // if we have an ApiArm object, the Arm itself has not been deleted - ) - -} - -object ApiArm { - - implicit val format: Format[ApiArm] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] and - (JsPath \ "originalName").format[String] and - (JsPath \ "trialId").format[String] - )(ApiArm.apply, unlift(ApiArm.unapply)) - - def fromDomain(arm: Arm): ApiArm = ApiArm( - id = arm.id.id, - name = arm.name, - originalName = arm.originalName, - trialId = arm.trialId.id - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiCreateArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiCreateArm.scala deleted file mode 100644 index 5168e94..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiCreateArm.scala +++ /dev/null @@ -1,20 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.arm - -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.Arm -import play.api.libs.json.{Format, Json} - -final case class ApiCreateArm(name: String, trialId: String) { - - def toDomain = Arm( - id = LongId(0), - name = name, - trialId = StringId(trialId), - originalName = name - ) -} - -object ApiCreateArm { - - implicit val format: Format[ApiCreateArm] = Json.format[ApiCreateArm] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiPartialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiPartialArm.scala deleted file mode 100644 index f85d7ff..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/arm/ApiPartialArm.scala +++ /dev/null @@ -1,14 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.arm - -import xyz.driver.pdsuidomain.entities.Arm -import play.api.libs.json.{Format, Json} - -final case class ApiPartialArm(name: String) { - - def applyTo(arm: Arm): Arm = arm.copy(name = name) -} - -object ApiPartialArm { - - implicit val format: Format[ApiPartialArm] = Json.format -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala deleted file mode 100644 index f1e15f3..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala +++ /dev/null @@ -1,23 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.category - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.entities.CategoryWithLabels -import xyz.driver.pdsuidomain.formats.json.label.ApiLabel - -final case class ApiCategory(id: Long, name: String, labels: List[ApiLabel]) - -object ApiCategory { - - implicit val format: Format[ApiCategory] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] and - (JsPath \ "labels").format[List[ApiLabel]] - )(ApiCategory.apply, unlift(ApiCategory.unapply)) - - def fromDomain(categoryWithLabels: CategoryWithLabels) = ApiCategory( - id = categoryWithLabels.category.id.id, - name = categoryWithLabels.category.name, - labels = categoryWithLabels.labels.map(x => ApiLabel(x.id.id, x.name, x.categoryId.id)) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala deleted file mode 100644 index 4986b17..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala +++ /dev/null @@ -1,55 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.criterion - -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Trial} -import xyz.driver.pdsuidomain.formats.json.label.ApiCriterionLabel -import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion - -final case class ApiCriterion(id: Long, - meta: Option[String], - arms: Seq[Long], - text: Option[String], - isCompound: Boolean, - labels: Seq[ApiCriterionLabel], - trialId: String) { - - def toDomain = RichCriterion( - criterion = Criterion( - id = LongId[Criterion](id), - trialId = StringId[Trial](trialId), - text, - isCompound, - meta.getOrElse("") - ), - armIds = arms.map(LongId[Arm]), - labels = labels.map(_.toDomain(LongId[Criterion](id))) - ) -} - -object ApiCriterion { - - implicit val format: Format[ApiCriterion] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "meta").formatNullable(Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) and - (JsPath \ "arms").format(seqJsonFormat[Long]) and - (JsPath \ "text").formatNullable[String] and - (JsPath \ "isCompound").format[Boolean] and - (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] - )(ApiCriterion.apply, unlift(ApiCriterion.unapply)) - - def fromDomain(richCriterion: RichCriterion) = ApiCriterion( - id = richCriterion.criterion.id.id, - meta = Option(richCriterion.criterion.meta), - arms = richCriterion.armIds.map(_.id), - text = richCriterion.criterion.text, - isCompound = richCriterion.criterion.isCompound, - labels = richCriterion.labels.map(ApiCriterionLabel.fromDomain), - trialId = richCriterion.criterion.trialId.id - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala deleted file mode 100644 index ab7641f..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala +++ /dev/null @@ -1,43 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.criterion - -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import xyz.driver.pdsuidomain.entities._ -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuidomain.formats.json.label.ApiCriterionLabel -import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion - -final case class ApiNewCriterion(meta: Option[String], - arms: Option[Seq[Long]], - text: Option[String], - isCompound: Option[Boolean], - labels: Seq[ApiCriterionLabel], - trialId: String) { - - def toDomain = RichCriterion( - criterion = Criterion( - id = LongId(0L), - meta = meta.getOrElse(""), - trialId = StringId(trialId), - isCompound = isCompound.getOrElse(false), - text = text - ), - armIds = arms.getOrElse(Seq.empty).map(LongId[Arm]), - labels = labels.map(_.toDomain(LongId(Long.MaxValue))) // A developer should specify right criterionId himself - ) -} - -object ApiNewCriterion { - - implicit val format: Format[ApiNewCriterion] = ( - (JsPath \ "meta").formatNullable(Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) and - (JsPath \ "arms").formatNullable(seqJsonFormat[Long]) and - (JsPath \ "text").formatNullable[String] and - (JsPath \ "isCompound").formatNullable[Boolean] and - (JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and - (JsPath \ "trialId").format[String] - )(ApiNewCriterion.apply, unlift(ApiNewCriterion.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala deleted file mode 100644 index 2bcda56..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala +++ /dev/null @@ -1,60 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.criterion - -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import xyz.driver.pdsuidomain.entities.{Arm, Criterion} -import org.davidbild.tristate._ -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuidomain.formats.json.label.ApiCriterionLabel -import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion - -final case class ApiUpdateCriterion(meta: Tristate[String], - arms: Tristate[Seq[Long]], - text: Option[String], - isCompound: Option[Boolean], - labels: Tristate[Seq[ApiCriterionLabel]]) { - - def applyTo(orig: RichCriterion): RichCriterion = RichCriterion( - criterion = applyTo(orig.criterion), - armIds = arms.cata(_.map(LongId[Arm]), Seq.empty, orig.armIds), - labels = labels.cata(_.map(_.toDomain(orig.criterion.id)), Seq.empty, orig.labels) - ) - - private def applyTo(orig: Criterion): Criterion = Criterion( - id = orig.id, - meta = meta.cata(identity, "{}", orig.meta), - text = text.orElse(orig.text), - isCompound = isCompound.getOrElse(orig.isCompound), - trialId = orig.trialId - ) -} - -object ApiUpdateCriterion { - - private val reads: Reads[ApiUpdateCriterion] = ( - (JsPath \ "meta") - .readTristate(Reads { x => - JsSuccess(Json.stringify(x)) - }) - .map { - case Tristate.Present("{}") => Tristate.Absent - case x => x - } and - (JsPath \ "arms").readTristate(seqJsonFormat[Long]) and - (JsPath \ "text").readNullable[String] and - (JsPath \ "isCompound").readNullable[Boolean] and - (JsPath \ "labels").readTristate(seqJsonFormat[ApiCriterionLabel]) - )(ApiUpdateCriterion.apply _) - - private val writes: Writes[ApiUpdateCriterion] = ( - (JsPath \ "meta").writeTristate(Writes[String](Json.parse)) and - (JsPath \ "arms").writeTristate(seqJsonFormat[Long]) and - (JsPath \ "text").writeNullable[String] and - (JsPath \ "isCompound").writeNullable[Boolean] and - (JsPath \ "labels").writeTristate(seqJsonFormat[ApiCriterionLabel]) - )(unlift(ApiUpdateCriterion.unapply)) - - implicit val format: Format[ApiUpdateCriterion] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala deleted file mode 100644 index 1869ff3..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala +++ /dev/null @@ -1,107 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.document - -import java.time.{LocalDate, ZoneId, ZonedDateTime} -import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson} -import xyz.driver.pdsuicommon.json.JsonSerializer - -import xyz.driver.pdsuidomain.entities._ -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.json.JsonSerializer - -final case class ApiDocument(id: Long, - recordId: Long, - physician: Option[String], - lastUpdate: ZonedDateTime, - typeId: Option[Long], - startDate: Option[LocalDate], - endDate: Option[LocalDate], - provider: Option[String], - providerTypeId: Option[Long], - requiredType: Option[String], - status: Option[String], - previousStatus: Option[String], - assignee: Option[String], - previousAssignee: Option[String], - lastActiveUser: Option[String], - meta: Option[String]) { - - private def extractStatus(status: String): Document.Status = - Document.Status.fromString(status).getOrElse(throw new NoSuchElementException(s"Status $status unknown")) - - private def extractRequiredType(tpe: String): Document.RequiredType = - Document.RequiredType.fromString(tpe).getOrElse(throw new NoSuchElementException(s"RequitedType $tpe unknown")) - - def toDomain = Document( - id = LongId(this.id), - status = extractStatus(this.status.getOrElse("")), - previousStatus = previousStatus.map(extractStatus), - assignee = this.assignee.map(StringId(_)), - previousAssignee = this.previousAssignee.map(StringId(_)), - lastActiveUserId = this.lastActiveUser.map(StringId(_)), - recordId = LongId(this.recordId), - physician = this.physician, - typeId = this.typeId.map(LongId(_)), - providerName = this.provider, - providerTypeId = this.providerTypeId.map(LongId(_)), - requiredType = this.requiredType.map(extractRequiredType), - meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[Document.Meta](x))), - startDate = this.startDate, - endDate = this.endDate, - lastUpdate = this.lastUpdate.toLocalDateTime() - ) - -} - -object ApiDocument { - - private val statusFormat = Format( - Reads.StringReads.filter(ValidationError("unknown status")) { x => - Document.Status.fromString(x).isDefined - }, - Writes.StringWrites - ) - - implicit val format: Format[ApiDocument] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "recordId").format[Long] and - (JsPath \ "physician").formatNullable[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "typeId").formatNullable[Long] and - (JsPath \ "startDate").formatNullable[LocalDate] and - (JsPath \ "endDate").formatNullable[LocalDate] and - (JsPath \ "provider").formatNullable[String] and - (JsPath \ "providerTypeId").formatNullable[Long] and - (JsPath \ "requiredType").formatNullable[String] and - (JsPath \ "status").formatNullable(statusFormat) and - (JsPath \ "previousStatus").formatNullable(statusFormat) and - (JsPath \ "assignee").formatNullable[String] and - (JsPath \ "previousAssignee").formatNullable[String] and - (JsPath \ "lastActiveUser").formatNullable[String] and - (JsPath \ "meta").formatNullable(Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) - )(ApiDocument.apply, unlift(ApiDocument.unapply)) - - def fromDomain(document: Document): ApiDocument = { - ApiDocument( - id = document.id.id, - recordId = document.recordId.id, - physician = document.physician, - lastUpdate = ZonedDateTime.of(document.lastUpdate, ZoneId.of("Z")), - typeId = document.typeId.map(_.id), - startDate = document.startDate, - endDate = document.endDate, - provider = document.providerName, - providerTypeId = document.providerTypeId.map(_.id), - requiredType = document.requiredType.map(Document.RequiredType.requiredTypeToString), - status = Option(Document.Status.statusToString(document.status)), - previousStatus = document.previousStatus.map(Document.Status.statusToString), - assignee = document.assignee.map(_.id), - previousAssignee = document.previousAssignee.map(_.id), - lastActiveUser = document.lastActiveUserId.map(_.id), - meta = document.meta.map(meta => JsonSerializer.serialize(meta.content)) - ) - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala deleted file mode 100644 index 8b4974f..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala +++ /dev/null @@ -1,28 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.document - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.DocumentType - -final case class ApiDocumentType(id: Long, name: String) { - - def toDomain = DocumentType( - id = LongId(this.id), - name = this.name - ) - -} - -object ApiDocumentType { - - implicit val format: Format[ApiDocumentType] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] - )(ApiDocumentType.apply, unlift(ApiDocumentType.unapply)) - - def fromDomain(documentType: DocumentType) = ApiDocumentType( - id = documentType.id.id, - name = documentType.name - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala deleted file mode 100644 index eae0c62..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala +++ /dev/null @@ -1,124 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.document - -import java.time.{LocalDate, LocalDateTime} - -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson} -import xyz.driver.pdsuicommon.json.{JsonSerializer, JsonValidationException} -import xyz.driver.pdsuicommon.validation.{AdditionalConstraints, JsonValidationErrors} -import xyz.driver.pdsuidomain.entities.Document.Meta -import xyz.driver.pdsuidomain.entities._ - -import scala.collection.breakOut -import scala.util.Try - -final case class ApiPartialDocument(recordId: Option[Long], - physician: Option[String], - typeId: Tristate[Long], - startDate: Tristate[LocalDate], - endDate: Tristate[LocalDate], - provider: Tristate[String], - providerTypeId: Tristate[Long], - status: Option[String], - assignee: Tristate[String], - meta: Tristate[String]) { - - import xyz.driver.pdsuicommon.domain.User - - def applyTo(orig: Document): Document = Document( - id = orig.id, - status = status.flatMap(Document.Status.fromString).getOrElse(orig.status), - previousStatus = orig.previousStatus, - assignee = assignee.map(StringId[User]).cata(Some(_), None, orig.assignee), - previousAssignee = orig.previousAssignee, - lastActiveUserId = orig.lastActiveUserId, - recordId = recordId.map(LongId[MedicalRecord]).getOrElse(orig.recordId), - physician = physician.orElse(orig.physician), - typeId = typeId.map(LongId[DocumentType]).cata(Some(_), None, orig.typeId), - providerName = provider.cata(Some(_), None, orig.providerName), - providerTypeId = providerTypeId.map(LongId[ProviderType]).cata(Some(_), None, orig.providerTypeId), - requiredType = orig.requiredType, - meta = meta.cata(x => Some(TextJson(JsonSerializer.deserialize[Meta](x))), None, orig.meta), - startDate = startDate.cata(Some(_), None, orig.startDate), - endDate = endDate.cata(Some(_), None, orig.endDate), - lastUpdate = LocalDateTime.MIN // Should update internally in a business logic module - ) - - def toDomain: Try[Document] = Try { - val validation = Map(JsPath \ "recordId" -> AdditionalConstraints.optionNonEmptyConstraint(recordId)) - - val validationErrors: JsonValidationErrors = validation.collect({ - case (fieldName, e: Invalid) => (fieldName, e.errors) - })(breakOut) - - if (validationErrors.isEmpty) { - Document( - id = LongId(0), - recordId = recordId.map(LongId[MedicalRecord]).get, - status = Document.Status.New, - physician = physician, - typeId = typeId.map(LongId[DocumentType]).toOption, - startDate = startDate.toOption, - endDate = endDate.toOption, - providerName = provider.toOption, - providerTypeId = providerTypeId.map(LongId[ProviderType]).toOption, - requiredType = None, - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption, - previousStatus = None, - assignee = None, - previousAssignee = None, - lastActiveUserId = None, - lastUpdate = LocalDateTime.MIN - ) - } else { - throw new JsonValidationException(validationErrors) - } - } -} - -object ApiPartialDocument { - - private val reads: Reads[ApiPartialDocument] = ( - (JsPath \ "recordId").readNullable[Long] and - (JsPath \ "physician").readNullable[String] and - (JsPath \ "typeId").readTristate[Long] and - (JsPath \ "startDate").readTristate[LocalDate] and - (JsPath \ "endDate").readTristate[LocalDate] and - (JsPath \ "provider").readTristate[String] and - (JsPath \ "providerTypeId").readTristate[Long] and - (JsPath \ "status").readNullable[String]( - Reads - .of[String] - .filter(ValidationError("unknown status"))( - Document.Status.fromString(_).isDefined - )) and - (JsPath \ "assignee").readTristate[String] and - (JsPath \ "meta") - .readTristate(Reads { x => - JsSuccess(Json.stringify(x)) - }) - .map { - case Tristate.Present("{}") => Tristate.Absent - case x => x - } - )(ApiPartialDocument.apply _) - - private val writes: Writes[ApiPartialDocument] = ( - (JsPath \ "recordId").writeNullable[Long] and - (JsPath \ "physician").writeNullable[String] and - (JsPath \ "typeId").writeTristate[Long] and - (JsPath \ "startDate").writeTristate[LocalDate] and - (JsPath \ "endDate").writeTristate[LocalDate] and - (JsPath \ "provider").writeTristate[String] and - (JsPath \ "providerTypeId").writeTristate[Long] and - (JsPath \ "status").writeNullable[String] and - (JsPath \ "assignee").writeTristate[String] and - (JsPath \ "meta").writeTristate(Writes[String](Json.parse)) - )(unlift(ApiPartialDocument.unapply)) - - implicit val format: Format[ApiPartialDocument] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala deleted file mode 100644 index c0eddad..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala +++ /dev/null @@ -1,28 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.document - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.ProviderType - -final case class ApiProviderType(id: Long, name: String) { - - def toDomain = ProviderType( - id = LongId(this.id), - name = this.name - ) - -} - -object ApiProviderType { - - implicit val format: Format[ApiProviderType] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] - )(ApiProviderType.apply, unlift(ApiProviderType.unapply)) - - def fromDomain(providerType: ProviderType) = ApiProviderType( - id = providerType.id.id, - name = providerType.name - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory/ApiDocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory/ApiDocumentHistory.scala deleted file mode 100644 index 5aae774..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory/ApiDocumentHistory.scala +++ /dev/null @@ -1,27 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.documenthistory - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.json.{Format, Json} -import xyz.driver.pdsuidomain.entities.DocumentHistory - -final case class ApiDocumentHistory(id: Long, - executor: String, - documentId: Long, - state: String, - action: String, - created: ZonedDateTime) - -object ApiDocumentHistory { - implicit val format: Format[ApiDocumentHistory] = - Json.format[ApiDocumentHistory] - - def fromDomain(x: DocumentHistory) = ApiDocumentHistory( - id = x.id.id, - executor = x.executor.id, - documentId = x.documentId.id, - state = DocumentHistory.State.stateToString(x.state), - action = DocumentHistory.Action.actionToString(x.action), - created = ZonedDateTime.of(x.created, ZoneId.of("Z")) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiDocumentIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiDocumentIssue.scala deleted file mode 100644 index f157bb2..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiDocumentIssue.scala +++ /dev/null @@ -1,40 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.documentissue - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuidomain.entities.DocumentIssue - -final case class ApiDocumentIssue(id: Long, - startPage: Option[Double], - endPage: Option[Double], - text: String, - lastUpdate: ZonedDateTime, - userId: String, - isDraft: Boolean, - archiveRequired: Boolean) - -object ApiDocumentIssue { - implicit val format: Format[ApiDocumentIssue] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "text").format[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "userId").format[String] and - (JsPath \ "isDraft").format[Boolean] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiDocumentIssue.apply, unlift(ApiDocumentIssue.unapply)) - - def fromDomain(x: DocumentIssue) = ApiDocumentIssue( - id = x.id.id, - startPage = x.startPage, - endPage = x.endPage, - text = x.text, - lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")), - userId = x.userId.id, - isDraft = x.isDraft, - archiveRequired = x.archiveRequired - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiPartialDocumentIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiPartialDocumentIssue.scala deleted file mode 100644 index c29b703..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documentissue/ApiPartialDocumentIssue.scala +++ /dev/null @@ -1,42 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.documentissue - -import java.time.LocalDateTime - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -import xyz.driver.pdsuidomain.entities.{Document, DocumentIssue} - -final case class ApiPartialDocumentIssue(startPage: Option[Double], - endPage: Option[Double], - text: String, - archiveRequired: Boolean) { - def applyTo(x: DocumentIssue): DocumentIssue = x.copy( - startPage = startPage, - endPage = endPage, - text = text, - archiveRequired = archiveRequired - ) - - def toDomain(userId: StringId[User], documentId: LongId[Document]) = - DocumentIssue( - id = LongId(0), - userId = userId, - documentId = documentId, - startPage = startPage, - endPage = endPage, - lastUpdate = LocalDateTime.MIN, - isDraft = true, - text = text, - archiveRequired = false - ) -} - -object ApiPartialDocumentIssue { - implicit val format: Format[ApiPartialDocumentIssue] = ( - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "text").format[String] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiPartialDocumentIssue.apply, unlift(ApiPartialDocumentIssue.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala deleted file mode 100644 index e0f23e3..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/evidence/ApiPatientLabelEvidence.scala +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.evidence - -import java.time.LocalDate - -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue -import xyz.driver.pdsuidomain.entities.PatientLabelEvidenceView - -final case class ApiPatientLabelEvidence(id: Long, - value: String, - evidenceText: String, - documentId: Option[Long], - evidenceId: Option[Long], - reportId: Option[String], - documentType: String, - date: LocalDate, - providerType: String) - -object ApiPatientLabelEvidence { - - implicit val format: Format[ApiPatientLabelEvidence] = Json.format - - def fromDomain(x: PatientLabelEvidenceView) = ApiPatientLabelEvidence( - id = x.id.id, - value = FuzzyValue.valueToString(x.value), - evidenceText = x.evidenceText, - documentId = x.documentId.map(_.id), - evidenceId = x.evidenceId.map(_.id), - reportId = x.reportId.map(_.toString), - documentType = x.documentType, - date = x.date.get, - providerType = x.providerType - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala deleted file mode 100644 index 0ef1c68..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala +++ /dev/null @@ -1,28 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabel - -final case class ApiExportPatientLabel(id: String, evidences: List[ApiExportPatientLabelEvidence]) { - - def toDomain = ExportPatientLabel( - id = LongId(this.id.toLong), - evidences = this.evidences.map(_.toDomain) - ) - -} - -object ApiExportPatientLabel { - - implicit val format: Format[ApiExportPatientLabel] = ( - (JsPath \ "labelId").format[String] and - (JsPath \ "evidence").format[List[ApiExportPatientLabelEvidence]] - )(ApiExportPatientLabel.apply, unlift(ApiExportPatientLabel.unapply)) - - def fromDomain(label: ExportPatientLabel) = ApiExportPatientLabel( - id = label.id.toString, - evidences = label.evidences.map(ApiExportPatientLabelEvidence.fromDomain) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala deleted file mode 100644 index d141762..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala +++ /dev/null @@ -1,38 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidence - -final case class ApiExportPatientLabelEvidence(evidenceId: String, - labelValue: String, - evidenceText: String, - document: ApiExportPatientLabelEvidenceDocument) { - - def toDomain = ExportPatientLabelEvidence( - id = LongId(this.evidenceId.toLong), - value = FuzzyValue.fromString - .applyOrElse(this.labelValue, (s: String) => throw new NoSuchElementException(s"Unknown fuzzy value $s")), - evidenceText = this.evidenceText, - document = this.document.toDomain - ) - -} - -object ApiExportPatientLabelEvidence { - - implicit val format: Format[ApiExportPatientLabelEvidence] = ( - (JsPath \ "evidenceId").format[String] and - (JsPath \ "labelValue").format[String](Writes[String](x => JsString(x.toUpperCase))) and - (JsPath \ "evidenceText").format[String] and - (JsPath \ "document").format[ApiExportPatientLabelEvidenceDocument] - )(ApiExportPatientLabelEvidence.apply, unlift(ApiExportPatientLabelEvidence.unapply)) - - def fromDomain(evidence: ExportPatientLabelEvidence) = ApiExportPatientLabelEvidence( - evidenceId = evidence.id.toString, - labelValue = FuzzyValue.valueToString(evidence.value), - evidenceText = evidence.evidenceText, - document = ApiExportPatientLabelEvidenceDocument.fromDomain(evidence.document) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala deleted file mode 100644 index 6999301..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala +++ /dev/null @@ -1,46 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import java.time.LocalDate -import java.util.UUID - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.RecordRequestId -import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidenceDocument - -final case class ApiExportPatientLabelEvidenceDocument(documentId: String, - requestId: String, - documentType: String, - providerType: String, - date: LocalDate) { - - def toDomain = ExportPatientLabelEvidenceDocument( - documentId = LongId(this.documentId.toLong), - requestId = RecordRequestId(UUID.fromString(this.requestId)), - documentType = this.documentType, - providerType = this.providerType, - date = this.date - ) - -} - -object ApiExportPatientLabelEvidenceDocument { - - implicit val format: Format[ApiExportPatientLabelEvidenceDocument] = ( - (JsPath \ "documentId").format[String] and - (JsPath \ "requestId").format[String] and - (JsPath \ "documentType").format[String] and - (JsPath \ "providerType").format[String] and - (JsPath \ "date").format[LocalDate] - )(ApiExportPatientLabelEvidenceDocument.apply, unlift(ApiExportPatientLabelEvidenceDocument.unapply)) - - def fromDomain(document: ExportPatientLabelEvidenceDocument) = - ApiExportPatientLabelEvidenceDocument( - documentId = document.documentId.toString, - requestId = document.requestId.toString, - documentType = document.documentType, - providerType = document.providerType, - date = document.date - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala deleted file mode 100644 index fc9bab7..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels - -final case class ApiExportPatientWithLabels(patientId: String, labelVersion: Long, labels: List[ApiExportPatientLabel]) { - - def toDomain = ExportPatientWithLabels( - patientId = UuidId(this.patientId), - labelVersion = this.labelVersion, - labels = this.labels.map(_.toDomain) - ) - -} - -object ApiExportPatientWithLabels { - - implicit val format: Format[ApiExportPatientWithLabels] = ( - (JsPath \ "patientId").format[String] and - (JsPath \ "labelVersion").format[Long] and - (JsPath \ "labels").format[List[ApiExportPatientLabel]] - )(ApiExportPatientWithLabels.apply, unlift(ApiExportPatientWithLabels.unapply)) - - def fromDomain(patient: ExportPatientWithLabels) = ApiExportPatientWithLabels( - patientId = patient.patientId.toString, - labelVersion = patient.labelVersion, - labels = patient.labels.map(ApiExportPatientLabel.fromDomain) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala deleted file mode 100644 index ea96f58..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala +++ /dev/null @@ -1,27 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.Arm -import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialArm - -final case class ApiExportTrialArm(armId: String, armName: String) { - - def toDomain: ExportTrialArm = { - ExportTrialArm(LongId[Arm](armId.toLong), armName) - } -} - -object ApiExportTrialArm { - - implicit val format: Format[ApiExportTrialArm] = ( - (JsPath \ "armId").format[String] and - (JsPath \ "armName").format[String] - )(ApiExportTrialArm.apply, unlift(ApiExportTrialArm.unapply)) - - def fromDomain(arm: ExportTrialArm) = ApiExportTrialArm( - armId = arm.armId.toString, - armName = arm.armName - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala deleted file mode 100644 index df1ebb4..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala +++ /dev/null @@ -1,55 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialLabelCriterion -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label} - -final case class ApiExportTrialLabelCriterion(value: String, - labelId: String, - criterionId: String, - criterionText: String, - armIds: List[String], - isCompound: Boolean, - isDefining: Boolean) { - - def toDomain: ExportTrialLabelCriterion = { - ExportTrialLabelCriterion( - LongId[Criterion](criterionId.toLong), - FuzzyValue.fromString.lift(value).map(_ == FuzzyValue.Yes), - LongId[Label](labelId.toLong), - armIds.map(armId => LongId[Arm](armId.toLong)).toSet, - criterionText, - isCompound, - isDefining - ) - } -} - -object ApiExportTrialLabelCriterion { - - implicit val format: Format[ApiExportTrialLabelCriterion] = ( - (JsPath \ "value").format[String](Writes[String](x => JsString(x.toUpperCase))) and - (JsPath \ "labelId").format[String] and - (JsPath \ "criterionId").format[String] and - (JsPath \ "criterionText").format[String] and - (JsPath \ "armIds").format[List[String]] and - (JsPath \ "isCompound").format[Boolean] and - (JsPath \ "isDefining").format[Boolean] - )(ApiExportTrialLabelCriterion.apply, unlift(ApiExportTrialLabelCriterion.unapply)) - - def fromDomain(x: ExportTrialLabelCriterion) = ApiExportTrialLabelCriterion( - value = x.value - .map { x => - FuzzyValue.valueToString(FuzzyValue.fromBoolean(x)) - } - .getOrElse("Unknown"), - labelId = x.labelId.toString, - criterionId = x.criterionId.toString, - criterionText = x.criteria, - armIds = x.armIds.map(_.toString).toList, - isCompound = x.isCompound, - isDefining = x.isDefining - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala deleted file mode 100644 index e383a1f..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala +++ /dev/null @@ -1,53 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import java.time.{Instant, ZoneId} - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.{StringId, UuidId} -import xyz.driver.pdsuidomain.entities.Trial -import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels - -final case class ApiExportTrialWithLabels(nctId: String, - trialId: String, - condition: String, - lastReviewed: Long, - labelVersion: Long, - arms: List[ApiExportTrialArm], - criteria: List[ApiExportTrialLabelCriterion]) { - - def toDomain: ExportTrialWithLabels = { - ExportTrialWithLabels( - StringId[Trial](nctId), - UuidId[Trial](trialId), - condition, - lastReviewed = Instant.ofEpochMilli(lastReviewed).atZone(ZoneId.of("Z")).toLocalDateTime, - labelVersion, - arms.map(_.toDomain), - criteria.map(_.toDomain) - ) - } -} - -object ApiExportTrialWithLabels { - - implicit val format: Format[ApiExportTrialWithLabels] = ( - (JsPath \ "nctId").format[String] and - (JsPath \ "trialId").format[String] and - (JsPath \ "disease").format[String] and - (JsPath \ "lastReviewed").format[Long] and - (JsPath \ "labelVersion").format[Long] and - (JsPath \ "arms").format[List[ApiExportTrialArm]] and - (JsPath \ "criteria").format[List[ApiExportTrialLabelCriterion]] - )(ApiExportTrialWithLabels.apply, unlift(ApiExportTrialWithLabels.unapply)) - - def fromDomain(x: ExportTrialWithLabels) = ApiExportTrialWithLabels( - nctId = x.nctId.id, - trialId = x.trialId.toString, - condition = x.condition, - lastReviewed = x.lastReviewed.atZone(ZoneId.of("Z")).toEpochSecond, - labelVersion = x.labelVersion, - arms = x.arms.map(ApiExportTrialArm.fromDomain), - criteria = x.criteria.map(ApiExportTrialLabelCriterion.fromDomain) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala deleted file mode 100644 index 4182c8d..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala +++ /dev/null @@ -1,64 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.extracteddata - -import xyz.driver.pdsuicommon.domain.{LongId, TextJson} -import xyz.driver.pdsuidomain.entities.ExtractedData -import xyz.driver.pdsuidomain.formats.json.label.ApiExtractedDataLabel -import play.api.libs.json._ -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import xyz.driver.pdsuicommon.json.JsonSerializer -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - -// The specification: https://driverinc.atlassian.net/wiki/pages/viewpage.action?pageId=33423387 -// Note, that there is "Extracted data object or Temporary extracted data object" in specification -// ApiExtractedData represents both types -final case class ApiExtractedData(id: Long, - documentId: Long, - keywordId: Option[Long], - evidence: Option[String], - meta: Option[String], - // An empty list and no-existent list are different cases - labels: Option[List[ApiExtractedDataLabel]]) { - - def toDomain = RichExtractedData( - extractedData = ExtractedData( - id = LongId(this.id), - documentId = LongId(this.documentId), - keywordId = this.keywordId.map(LongId(_)), - evidenceText = this.evidence, - meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[ExtractedData.Meta](x))) - ), - labels = labels.getOrElse(List.empty).map(_.toDomain()) - ) - -} - -object ApiExtractedData { - - implicit val format: Format[ApiExtractedData] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "documentId").format[Long] and - (JsPath \ "keywordId").formatNullable[Long] and - (JsPath \ "evidence").formatNullable[String] and - (JsPath \ "meta").formatNullable[String] and - (JsPath \ "labels").formatNullable[List[ApiExtractedDataLabel]]( - Format( - Reads - .of[List[ApiExtractedDataLabel]] - .filter(ValidationError("empty labels"))({ - case x if x.nonEmpty => true - case _ => false - }), - Writes.of[List[ApiExtractedDataLabel]] - )) - )(ApiExtractedData.apply, unlift(ApiExtractedData.unapply)) - - def fromDomain(extractedDataWithLabels: RichExtractedData) = ApiExtractedData( - id = extractedDataWithLabels.extractedData.id.id, - documentId = extractedDataWithLabels.extractedData.documentId.id, - keywordId = extractedDataWithLabels.extractedData.keywordId.map(_.id), - evidence = extractedDataWithLabels.extractedData.evidenceText, - meta = extractedDataWithLabels.extractedData.meta.map(x => JsonSerializer.serialize(x.content)), - labels = Option(extractedDataWithLabels.labels.map(ApiExtractedDataLabel.fromDomain)) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala deleted file mode 100644 index cfd55fd..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala +++ /dev/null @@ -1,80 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.extracteddata - -import xyz.driver.pdsuicommon.domain.{LongId, TextJson} -import xyz.driver.pdsuidomain.entities.ExtractedData.Meta -import xyz.driver.pdsuidomain.entities._ -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.json.{JsonSerializer, JsonValidationException} -import xyz.driver.pdsuicommon.validation.{AdditionalConstraints, JsonValidationErrors} -import xyz.driver.pdsuidomain.formats.json.label.ApiExtractedDataLabel -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - -import scala.collection._ - -final case class ApiPartialExtractedData(documentId: Option[Long], - keywordId: Option[Long], - evidence: Tristate[String], - meta: Tristate[String], - labels: Tristate[List[ApiExtractedDataLabel]]) { - - def applyTo(orig: RichExtractedData): RichExtractedData = RichExtractedData( - extractedData = applyTo(orig.extractedData), - labels = labels.cata(_.map(_.toDomain(orig.extractedData.id)), List.empty, orig.labels) - ) - - private def applyTo(orig: ExtractedData): ExtractedData = ExtractedData( - id = orig.id, - documentId = orig.documentId, - keywordId = keywordId.map(LongId[Keyword]).orElse(orig.keywordId), - evidenceText = evidence.cata(Some(_), None, orig.evidenceText), - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).cata(Some(_), None, orig.meta) - ) - - def toDomain: RichExtractedData = { - val validation = Map( - JsPath \ "documentId" -> AdditionalConstraints.optionNonEmptyConstraint(documentId) - ) - - val validationErrors: JsonValidationErrors = validation.collect({ - case (fieldName, e: Invalid) => (fieldName, e.errors) - })(breakOut) - - if (validationErrors.isEmpty) { - val extractedData = ExtractedData( - documentId = documentId.map(LongId[Document]).get, - keywordId = keywordId.map(LongId[Keyword]), - evidenceText = evidence.toOption, - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption - ) - val labelList = labels.map(_.map(_.toDomain())) - RichExtractedData(extractedData, labelList.getOrElse(List.empty)) - } else { - throw new JsonValidationException(validationErrors) - } - } -} - -object ApiPartialExtractedData { - - private val reads: Reads[ApiPartialExtractedData] = ( - (JsPath \ "documentId").readNullable[Long] and - (JsPath \ "keywordId").readNullable[Long] and - (JsPath \ "evidence").readTristate[String] and - (JsPath \ "meta").readTristate[String] and - (JsPath \ "labels").readTristate[List[ApiExtractedDataLabel]] - )(ApiPartialExtractedData.apply _) - - private val writes: Writes[ApiPartialExtractedData] = ( - (JsPath \ "documentId").writeNullable[Long] and - (JsPath \ "keywordId").writeNullable[Long] and - (JsPath \ "evidence").writeTristate[String] and - (JsPath \ "meta").writeTristate[String] and - (JsPath \ "labels").writeTristate[List[ApiExtractedDataLabel]] - )(unlift(ApiPartialExtractedData.unapply)) - - implicit val format: Format[ApiPartialExtractedData] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis/ApiHypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis/ApiHypothesis.scala deleted file mode 100644 index bf18a60..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/hypothesis/ApiHypothesis.scala +++ /dev/null @@ -1,35 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.hypothesis - -import java.util.UUID - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuidomain.entities.Hypothesis - -final case class ApiHypothesis(id: UUID, name: String, treatmentType: String, description: String) { - - def toDomain = Hypothesis( - id = UuidId[Hypothesis](id), - name = name, - treatmentType = treatmentType, - description = description - ) -} - -object ApiHypothesis { - - implicit val format: Format[ApiHypothesis] = ( - (JsPath \ "id").format[UUID] and - (JsPath \ "name").format[String] and - (JsPath \ "treatmentType").format[String] and - (JsPath \ "description").format[String] - )(ApiHypothesis.apply, unlift(ApiHypothesis.unapply)) - - def fromDomain(hypothesis: Hypothesis) = ApiHypothesis( - id = hypothesis.id.id, - name = hypothesis.name, - treatmentType = hypothesis.treatmentType, - description = hypothesis.description - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala deleted file mode 100644 index 39acbde..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala +++ /dev/null @@ -1,72 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.intervention - -import xyz.driver.pdsuicommon.domain.{LongId, StringId} -import xyz.driver.pdsuidomain.entities.{Intervention, InterventionArm, InterventionWithArms} -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} - -final case class ApiIntervention(id: Long, - name: String, - typeId: Option[Long], - description: String, - isActive: Boolean, - arms: List[Long], - trialId: String, - originalName: String, - originalDescription: String, - originalType: Option[String]) { - - def toDomain = { - val intervention = Intervention( - id = LongId(this.id), - trialId = StringId(this.trialId), - name = this.name, - originalName = this.originalName, - typeId = this.typeId.map(id => LongId(id)), - originalType = this.originalType.map(id => id.toString), - description = this.description, - originalDescription = this.originalDescription, - isActive = this.isActive - ) - - InterventionWithArms(intervention, this.arms.map { armId => - InterventionArm(LongId(armId), intervention.id) - }) - - } - -} - -object ApiIntervention { - - implicit val format: Format[ApiIntervention] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] and - (JsPath \ "typeId").formatNullable[Long] and - (JsPath \ "description").format[String] and - (JsPath \ "isActive").format[Boolean] and - (JsPath \ "arms").format[List[Long]] and - (JsPath \ "trialId").format[String] and - (JsPath \ "originalName").format[String] and - (JsPath \ "originalDescription").format[String] and - (JsPath \ "originalType").formatNullable[String] - )(ApiIntervention.apply, unlift(ApiIntervention.unapply)) - - def fromDomain(interventionWithArms: InterventionWithArms): ApiIntervention = { - import interventionWithArms.intervention - import interventionWithArms.arms - - ApiIntervention( - id = intervention.id.id, - name = intervention.name, - typeId = intervention.typeId.map(_.id), - description = intervention.description, - isActive = intervention.isActive, - arms = arms.map(_.armId.id), - trialId = intervention.trialId.id, - originalName = intervention.originalName, - originalDescription = intervention.originalDescription, - originalType = intervention.originalType - ) - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala deleted file mode 100644 index ebef225..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiInterventionType.scala +++ /dev/null @@ -1,24 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.intervention - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.InterventionType - -final case class ApiInterventionType(id: Long, name: String) { - - def toDomain = InterventionType(id = LongId[InterventionType](id), name = name) -} - -object ApiInterventionType { - - implicit val format: Format[ApiInterventionType] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] - )(ApiInterventionType.apply, unlift(ApiInterventionType.unapply)) - - def fromDomain(interventionType: InterventionType) = ApiInterventionType( - id = interventionType.id.id, - name = interventionType.name - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala deleted file mode 100644 index f67ba6b..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala +++ /dev/null @@ -1,44 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.intervention - -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities.{InterventionArm, InterventionWithArms} -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -final case class ApiPartialIntervention(typeId: Option[Long], - description: Option[String], - isActive: Option[Boolean], - arms: Option[List[Long]]) { - - def applyTo(orig: InterventionWithArms): InterventionWithArms = { - val origIntervention = orig.intervention - val draftArmList = arms.map(_.map(x => InterventionArm(LongId(x), orig.intervention.id))) - orig.copy( - intervention = origIntervention.copy( - typeId = typeId.map(LongId(_)).orElse(origIntervention.typeId), - description = description.getOrElse(origIntervention.description), - isActive = isActive.getOrElse(origIntervention.isActive) - ), - arms = draftArmList.getOrElse(orig.arms) - ) - } -} - -object ApiPartialIntervention { - - private val reads: Reads[ApiPartialIntervention] = ( - (JsPath \ "typeId").readNullable[Long] and - (JsPath \ "description").readNullable[String] and - (JsPath \ "isActive").readNullable[Boolean] and - (JsPath \ "arms").readNullable[List[Long]] - )(ApiPartialIntervention.apply _) - - private val writes: Writes[ApiPartialIntervention] = ( - (JsPath \ "typeId").writeNullable[Long] and - (JsPath \ "description").writeNullable[String] and - (JsPath \ "isActive").writeNullable[Boolean] and - (JsPath \ "arms").writeNullable[List[Long]] - )(unlift(ApiPartialIntervention.unapply)) - - implicit val format: Format[ApiPartialIntervention] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala deleted file mode 100644 index a9d02fc..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala +++ /dev/null @@ -1,23 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.keyword - -import xyz.driver.pdsuidomain.entities.KeywordWithLabels -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.formats.json.label.ApiLabel - -final case class ApiKeyword(id: Long, keyword: String, labels: List[ApiLabel]) - -object ApiKeyword { - - implicit val format: Format[ApiKeyword] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "keyword").format[String] and - (JsPath \ "labels").format[List[ApiLabel]] - )(ApiKeyword.apply, unlift(ApiKeyword.unapply)) - - def fromDomain(keywordWithLabels: KeywordWithLabels) = ApiKeyword( - id = keywordWithLabels.keyword.id.id, - keyword = keywordWithLabels.keyword.keyword, - labels = keywordWithLabels.labels.map(x => ApiLabel(x.id.id, x.name, x.categoryId.id)) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala deleted file mode 100644 index 7a65af8..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala +++ /dev/null @@ -1,53 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.label - -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.{Category, Criterion, CriterionLabel, Label} -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -/** - * @param value Yes|No - */ -final case class ApiCriterionLabel(labelId: Option[Long], - categoryId: Option[Long], - value: Option[String], - isDefining: Boolean) { - - def toDomain(criterionId: LongId[Criterion]) = CriterionLabel( - id = LongId(0L), - labelId = labelId.map(LongId[Label]), - criterionId = criterionId, - categoryId = categoryId.map(LongId[Category]), - value = value.map { - case "Yes" => true - case "No" => false - }, - isDefining = isDefining - ) -} - -object ApiCriterionLabel { - - def fromDomain(x: CriterionLabel) = ApiCriterionLabel( - labelId = x.labelId.map(_.id), - categoryId = x.categoryId.map(_.id), - value = x.value.map { x => - FuzzyValue.valueToString(FuzzyValue.fromBoolean(x)) - }, - isDefining = x.isDefining - ) - - implicit val format: Format[ApiCriterionLabel] = ( - (JsPath \ "labelId").formatNullable[Long] and - (JsPath \ "categoryId").formatNullable[Long] and - (JsPath \ "value").formatNullable[String]( - Format(Reads - .of[String] - .filter(ValidationError("unknown value"))({ x => - x == "Yes" || x == "No" - }), - Writes.of[String])) and - (JsPath \ "isDefining").format[Boolean] - )(ApiCriterionLabel.apply, unlift(ApiCriterionLabel.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala deleted file mode 100644 index cb45025..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala +++ /dev/null @@ -1,40 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.label - -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.{Category, ExtractedData, ExtractedDataLabel, Label} -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -final case class ApiExtractedDataLabel(id: Option[Long], categoryId: Option[Long], value: Option[String]) { - - def toDomain(dataId: LongId[ExtractedData] = LongId(0)) = ExtractedDataLabel( - id = LongId(0), - dataId = dataId, - labelId = id.map(LongId[Label]), - categoryId = categoryId.map(LongId[Category]), - value = value.map(FuzzyValue.fromString) - ) -} - -object ApiExtractedDataLabel { - - implicit val format: Format[ApiExtractedDataLabel] = ( - (JsPath \ "id").formatNullable[Long] and - (JsPath \ "categoryId").formatNullable[Long] and - (JsPath \ "value").formatNullable[String]( - Format(Reads - .of[String] - .filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String])) - )(ApiExtractedDataLabel.apply, unlift(ApiExtractedDataLabel.unapply)) - - def fromDomain(dataLabel: ExtractedDataLabel) = ApiExtractedDataLabel( - id = dataLabel.labelId.map(_.id), - categoryId = dataLabel.categoryId.map(_.id), - value = dataLabel.value.map(FuzzyValue.valueToString) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala deleted file mode 100644 index 042b380..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala +++ /dev/null @@ -1,22 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.label - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.entities.Label - -final case class ApiLabel(id: Long, name: String, categoryId: Long) - -object ApiLabel { - - implicit val format: Format[ApiLabel] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] and - (JsPath \ "categoryId").format[Long] - )(ApiLabel.apply, unlift(ApiLabel.unapply)) - - def fromDomain(x: Label) = ApiLabel( - id = x.id.id, - name = x.name, - categoryId = x.categoryId.id - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala deleted file mode 100644 index 425eeac..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiMessage.scala +++ /dev/null @@ -1,79 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.message - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} -import xyz.driver.pdsuidomain.entities.Message - -final case class ApiMessage(id: Long, - text: String, - lastUpdate: ZonedDateTime, - userId: String, - isDraft: Boolean, - recordId: Option[Long], - documentId: Option[Long], - patientId: Option[String], - trialId: Option[String], - startPage: Option[Double], - endPage: Option[Double], - evidence: Option[String], - archiveRequired: Option[Boolean], - meta: Option[String]) { - - def toDomain = Message( - id = LongId(this.id), - text = this.text, - lastUpdate = this.lastUpdate.toLocalDateTime(), - userId = StringId(this.userId), - isDraft = this.isDraft, - recordId = this.recordId.map(id => LongId(id)), - documentId = this.documentId.map(id => LongId(id)), - patientId = this.patientId.map(id => UuidId(id)), - trialId = this.trialId.map(id => StringId(id)), - startPage = this.startPage, - endPage = this.endPage, - evidence = this.evidence, - archiveRequired = this.archiveRequired, - meta = this.meta - ) - -} - -object ApiMessage { - - def fromDomain(domain: Message) = ApiMessage( - id = domain.id.id, - text = domain.text, - lastUpdate = ZonedDateTime.of(domain.lastUpdate, ZoneId.of("Z")), - userId = domain.userId.id, - isDraft = domain.isDraft, - recordId = domain.recordId.map(_.id), - documentId = domain.documentId.map(_.id), - patientId = domain.patientId.map(_.toString), - trialId = domain.trialId.map(_.toString), - startPage = domain.startPage, - endPage = domain.endPage, - evidence = domain.evidence, - archiveRequired = domain.archiveRequired, - meta = domain.meta - ) - - implicit val format: Format[ApiMessage] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "text").format[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "userId").format[String] and - (JsPath \ "isDraft").format[Boolean] and - (JsPath \ "recordId").formatNullable[Long] and - (JsPath \ "documentId").formatNullable[Long] and - (JsPath \ "patientId").formatNullable[String] and - (JsPath \ "trialId").formatNullable[String] and - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "evidence").formatNullable[String] and - (JsPath \ "archiveRequired").formatNullable[Boolean] and - (JsPath \ "meta").formatNullable[String] - )(ApiMessage.apply, unlift(ApiMessage.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiPartialMessage.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiPartialMessage.scala deleted file mode 100644 index a2656f2..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/message/ApiPartialMessage.scala +++ /dev/null @@ -1,82 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.message - -import java.time.LocalDateTime - -import xyz.driver.pdsuicommon.domain._ -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.entities.Message - -final case class ApiPartialMessage(text: Option[String], - recordId: Option[Long], - documentId: Option[Long], - patientId: Option[String], - trialId: Option[String], - startPage: Option[Double], - endPage: Option[Double], - evidence: Option[String], - archiveRequired: Option[Boolean], - meta: Option[String]) { - - def toDomain(userId: StringId[User]) = Message( - id = LongId(0), - text = text.getOrElse(""), - userId = userId, - isDraft = true, - recordId = recordId.map(LongId(_)), - documentId = documentId.map(LongId(_)), - patientId = patientId.map(UuidId(_)), - trialId = trialId.map(StringId(_)), - startPage = startPage, - endPage = endPage, - evidence = evidence, - archiveRequired = archiveRequired, - meta = meta, - lastUpdate = LocalDateTime.MIN - ) - - def applyTo(orig: Message): Message = { - orig.copy( - text = text.getOrElse(""), - recordId = recordId.map(LongId(_)), - documentId = documentId.map(LongId(_)), - patientId = patientId.map(UuidId(_)), - trialId = trialId.map(StringId(_)), - startPage = startPage, - endPage = endPage, - evidence = evidence, - archiveRequired = archiveRequired, - meta = meta, - lastUpdate = LocalDateTime.MIN - ) - } -} - -object ApiPartialMessage { - - implicit val format: Format[ApiPartialMessage] = ( - (JsPath \ "text").formatNullable[String] and - (JsPath \ "recordId").formatNullable[Long] and - (JsPath \ "documentId").formatNullable[Long] and - (JsPath \ "patientId").formatNullable[String] and - (JsPath \ "trialId").formatNullable[String] and - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "evidence").formatNullable[String] and - (JsPath \ "archiveRequired").formatNullable[Boolean] and - (JsPath \ "meta").formatNullable[String] - )(ApiPartialMessage.apply, unlift(ApiPartialMessage.unapply)) - - def fromDomain(domain: Message) = ApiPartialMessage( - text = Some(domain.text), - recordId = domain.recordId.map(_.id), - documentId = domain.documentId.map(_.id), - patientId = domain.patientId.map(_.toString), - trialId = domain.trialId.map(_.toString), - startPage = domain.startPage, - endPage = domain.endPage, - evidence = domain.evidence, - archiveRequired = domain.archiveRequired, - meta = domain.meta - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordCreateRequest.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordCreateRequest.scala deleted file mode 100644 index 5c12415..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordCreateRequest.scala +++ /dev/null @@ -1,9 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.password - -import play.api.libs.json.{Format, Json} - -final case class PasswordCreateRequest(password: String, key: String) - -object PasswordCreateRequest { - implicit val format: Format[PasswordCreateRequest] = Json.format[PasswordCreateRequest] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordUpdateRequest.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordUpdateRequest.scala deleted file mode 100644 index 07851ea..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/password/PasswordUpdateRequest.scala +++ /dev/null @@ -1,9 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.password - -import play.api.libs.json.{Format, Json} - -final case class PasswordUpdateRequest(password: String, oldPassword: String) - -object PasswordUpdateRequest { - implicit val format: Format[PasswordUpdateRequest] = Json.format[PasswordUpdateRequest] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala deleted file mode 100644 index db430ae..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/ApiPatient.scala +++ /dev/null @@ -1,73 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient - -import java.time.{LocalDate, ZoneId, ZonedDateTime} -import java.util.UUID - -import xyz.driver.pdsuicommon.domain.{StringId, UuidId} -import xyz.driver.pdsuidomain.entities.{Patient, PatientOrderId} -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} - -final case class ApiPatient(id: String, - status: String, - name: String, - dob: LocalDate, - assignee: Option[String], - previousStatus: Option[String], - previousAssignee: Option[String], - lastActiveUser: Option[String], - lastUpdate: ZonedDateTime, - condition: String, - orderId: UUID) { - - private def extractStatus(status: String): Patient.Status = - PatientStatus.statusFromString - .applyOrElse(status, (s: String) => throw new NoSuchElementException(s"Unknown status $s")) - - def toDomain = Patient( - id = UuidId(this.id), - status = extractStatus(this.status), - name = this.name, - dob = this.dob, - assignee = this.assignee.map(StringId(_)), - previousStatus = this.previousStatus.map(extractStatus), - previousAssignee = this.previousAssignee.map(StringId(_)), - lastActiveUserId = this.lastActiveUser.map(StringId(_)), - isUpdateRequired = false, - condition = this.condition, - orderId = PatientOrderId(this.orderId), - lastUpdate = this.lastUpdate.toLocalDateTime - ) - -} - -object ApiPatient { - - implicit val format: Format[ApiPatient] = ( - (JsPath \ "id").format[String] and - (JsPath \ "status").format[String] and - (JsPath \ "name").format[String] and - (JsPath \ "dob").format[LocalDate] and - (JsPath \ "assignee").formatNullable[String] and - (JsPath \ "previousStatus").formatNullable[String] and - (JsPath \ "previousAssignee").formatNullable[String] and - (JsPath \ "lastActiveUser").formatNullable[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "condition").format[String] and - (JsPath \ "orderId").format[UUID] - )(ApiPatient.apply, unlift(ApiPatient.unapply)) - - def fromDomain(patient: Patient) = ApiPatient( - id = patient.id.toString, - status = PatientStatus.statusToString(patient.status), - name = patient.name, - dob = patient.dob, - assignee = patient.assignee.map(_.id), - previousStatus = patient.previousStatus.map(PatientStatus.statusToString), - previousAssignee = patient.previousAssignee.map(_.id), - lastActiveUser = patient.lastActiveUserId.map(_.id), - lastUpdate = ZonedDateTime.of(patient.lastUpdate, ZoneId.of("Z")), - condition = patient.condition, - orderId = patient.orderId.id - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala deleted file mode 100644 index a23a1de..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/PatientStatus.scala +++ /dev/null @@ -1,24 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient - -import xyz.driver.pdsuidomain.entities.Patient.Status - -object PatientStatus { - - val statusFromString: PartialFunction[String, Status] = { - case "New" => Status.New - case "Verified" => Status.Verified - case "Reviewed" => Status.Reviewed - case "Curated" => Status.Curated - case "Flagged" => Status.Flagged - case "Done" => Status.Done - } - - def statusToString(x: Status): String = x match { - case Status.New => "New" - case Status.Verified => "Verified" - case Status.Reviewed => "Reviewed" - case Status.Curated => "Curated" - case Status.Flagged => "Flagged" - case Status.Done => "Done" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala deleted file mode 100644 index 03ff275..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPartialPatientEligibleTrial.scala +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.eligible - -import xyz.driver.pdsuidomain.entities.PatientTrialArmGroupView -import play.api.libs.json.{Format, Json} - -final case class ApiPartialPatientEligibleTrial(isVerified: Option[Boolean]) { - - def applyTo(orig: PatientTrialArmGroupView): PatientTrialArmGroupView = { - orig.copy( - isVerified = isVerified.getOrElse(orig.isVerified) - ) - } -} - -object ApiPartialPatientEligibleTrial { - - implicit val format: Format[ApiPartialPatientEligibleTrial] = Json.format -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala deleted file mode 100644 index 4136715..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/eligible/ApiPatientEligibleTrial.scala +++ /dev/null @@ -1,51 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.eligible - -import java.util.UUID - -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial - -final case class ApiPatientEligibleTrial(id: Long, - patientId: String, - trialId: String, - trialTitle: String, - arms: List[String], - hypothesisId: UUID, - verifiedEligibilityStatus: Option[String], - isVerified: Boolean) - -object ApiPatientEligibleTrial { - - implicit val apiEligibleTrialJsonFormat: Format[ApiPatientEligibleTrial] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "patientId").format[String] and - (JsPath \ "trialId").format[String] and - (JsPath \ "trialTitle").format[String] and - (JsPath \ "arms").format[List[String]] and - (JsPath \ "hypothesisId").format[UUID] and - (JsPath \ "verifiedEligibilityStatus").formatNullable[String](Format( - Reads - .of[String] - .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String] - )) and - (JsPath \ "isVerified").format[Boolean] - )(ApiPatientEligibleTrial.apply, unlift(ApiPatientEligibleTrial.unapply)) - - def fromDomain(eligibleTrialWithTrial: RichPatientEligibleTrial) = ApiPatientEligibleTrial( - id = eligibleTrialWithTrial.group.id.id, - patientId = eligibleTrialWithTrial.group.patientId.toString, - trialId = eligibleTrialWithTrial.group.trialId.id, - trialTitle = eligibleTrialWithTrial.trial.title, - arms = eligibleTrialWithTrial.arms.map(_.armName), - hypothesisId = eligibleTrialWithTrial.group.hypothesisId.id, - eligibleTrialWithTrial.group.verifiedEligibilityStatus.map(FuzzyValue.valueToString), - eligibleTrialWithTrial.group.isVerified - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala deleted file mode 100644 index 0858ce1..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPartialPatientHypothesis.scala +++ /dev/null @@ -1,27 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.hypothesis - -import xyz.driver.pdsuidomain.entities.PatientHypothesis -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 ApiPartialPatientHypothesis(rationale: Tristate[String]) { - - def applyTo(orig: PatientHypothesis): PatientHypothesis = { - orig.copy( - rationale = rationale.cata(Some(_), None, orig.rationale) - ) - } -} - -object ApiPartialPatientHypothesis { - - implicit val reads: Reads[ApiPartialPatientHypothesis] = - (__ \ "rationale").readTristate[String].map(x => ApiPartialPatientHypothesis(x)) - - implicit val writes: Writes[ApiPartialPatientHypothesis] = - (__ \ "rationale").writeTristate[String].contramap(_.rationale) - - implicit val format: Format[ApiPartialPatientHypothesis] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala deleted file mode 100644 index 584ff72..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/hypothesis/ApiPatientHypothesis.scala +++ /dev/null @@ -1,35 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.hypothesis - -import java.util.UUID - -import xyz.driver.pdsuidomain.entities.PatientHypothesis -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -final case class ApiPatientHypothesis(id: UUID, - patientId: String, - hypothesisId: UUID, - matchedTrials: Long, - rationale: Option[String], - isRationaleRequired: Boolean) - -object ApiPatientHypothesis { - - implicit val apiPatientHypothesisJsonFormat: Format[ApiPatientHypothesis] = ( - (JsPath \ "id").format[UUID] and - (JsPath \ "patientId").format[String] and - (JsPath \ "hypothesisId").format[UUID] and - (JsPath \ "matchedTrials").format[Long] and - (JsPath \ "rationale").formatNullable[String] and - (JsPath \ "isRationaleRequired").format[Boolean] - )(ApiPatientHypothesis.apply, unlift(ApiPatientHypothesis.unapply)) - - def fromDomain(patientHypothesis: PatientHypothesis, isRationaleRequired: Boolean) = ApiPatientHypothesis( - id = patientHypothesis.id.id, - patientId = patientHypothesis.patientId.toString, - hypothesisId = patientHypothesis.hypothesisId.id, - matchedTrials = patientHypothesis.matchedTrials, - rationale = patientHypothesis.rationale, - isRationaleRequired = isRationaleRequired - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala deleted file mode 100644 index 91d0a0e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPartialPatientLabel.scala +++ /dev/null @@ -1,44 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.label - -import xyz.driver.pdsuidomain.entities.PatientLabel -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue - -final case class ApiPartialPatientLabel(primaryValue: Option[String], verifiedPrimaryValue: Tristate[String]) { - - def applyTo(orig: PatientLabel): PatientLabel = { - orig.copy( - primaryValue = primaryValue.map(FuzzyValue.fromString).orElse(orig.primaryValue), - verifiedPrimaryValue = - verifiedPrimaryValue.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedPrimaryValue) - ) - } -} - -object ApiPartialPatientLabel { - - implicit val format: Format[ApiPartialPatientLabel] = ( - (JsPath \ "primaryValue").formatNullable[String]( - Format(Reads - .of[String] - .filter(ValidationError("unknown primary value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String])) and - (JsPath \ "verifiedPrimaryValue").formatTristate[String]( - Format( - Reads - .of[String] - .filter(ValidationError("unknown verified primary value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String] - )) - )(ApiPartialPatientLabel.apply, unlift(ApiPartialPatientLabel.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala deleted file mode 100644 index fc8687b..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabel.scala +++ /dev/null @@ -1,47 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.label - -import xyz.driver.pdsuidomain.entities.PatientLabel -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue - -final case class ApiPatientLabel(id: Long, - labelId: Long, - primaryValue: Option[String], - verifiedPrimaryValue: Option[String], - score: Int, - isImplicitMatch: Boolean, - isVisible: Boolean, - isVerified: Boolean) - -object ApiPatientLabel { - - implicit val apiPatientLabelJsonFormat: Format[ApiPatientLabel] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "labelId").format[Long] and - (JsPath \ "primaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and - (JsPath \ "verifiedPrimaryValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and - (JsPath \ "score").format[Int] and - (JsPath \ "isImplicitMatch").format[Boolean] and - (JsPath \ "isVisible").format[Boolean] and - (JsPath \ "isVerified").format[Boolean] - ) (ApiPatientLabel.apply, unlift(ApiPatientLabel.unapply)) - - def fromDomain(patientLabel: PatientLabel, isVerified: Boolean): ApiPatientLabel = ApiPatientLabel( - id = patientLabel.id.id, - labelId = patientLabel.labelId.id, - primaryValue = patientLabel.primaryValue.map(FuzzyValue.valueToString), - verifiedPrimaryValue = patientLabel.verifiedPrimaryValue.map(FuzzyValue.valueToString), - score = patientLabel.score, - isImplicitMatch = patientLabel.isImplicitMatch, - isVisible = patientLabel.isVisible, - isVerified = isVerified - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala deleted file mode 100644 index ae64c33..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/label/ApiPatientLabelDefiningCriteria.scala +++ /dev/null @@ -1,29 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.label - -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue -import xyz.driver.pdsuidomain.entities.PatientLabel - -final case class ApiPatientLabelDefiningCriteria(labelId: Long, value: Option[String]) - -object ApiPatientLabelDefiningCriteria { - - implicit val format: Format[ApiPatientLabelDefiningCriteria] = ( - (JsPath \ "labelId").format[Long] and - (JsPath \ "value").formatNullable[String]( - Format(Reads - .of[String] - .filter(ValidationError("unknown value"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String])) - )(ApiPatientLabelDefiningCriteria.apply, unlift(ApiPatientLabelDefiningCriteria.unapply)) - - def fromDomain(x: PatientLabel) = ApiPatientLabelDefiningCriteria( - labelId = x.labelId.id, - value = x.verifiedPrimaryValue.map(FuzzyValue.valueToString) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala deleted file mode 100644 index 399bc7d..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterion.scala +++ /dev/null @@ -1,47 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.trial - -import xyz.driver.pdsuidomain.entities.PatientCriterion -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath, Reads, Writes} -import xyz.driver.pdsuicommon.domain.FuzzyValue - -final case class ApiPartialPatientCriterion(eligibilityStatus: Option[String], - verifiedEligibilityStatus: Tristate[String]) { - - def applyTo(orig: PatientCriterion): PatientCriterion = { - orig.copy( - eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString).orElse(orig.eligibilityStatus), - verifiedEligibilityStatus = - verifiedEligibilityStatus.cata(x => Some(FuzzyValue.fromString(x)), None, orig.verifiedEligibilityStatus) - ) - } -} - -object ApiPartialPatientCriterion { - - implicit val format: Format[ApiPartialPatientCriterion] = ( - (JsPath \ "eligibilityStatus").formatNullable[String]( - Format( - Reads - .of[String] - .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String] - )) and - (JsPath \ "verifiedEligibilityStatus").formatTristate[String]( - Format( - Reads - .of[String] - .filter(ValidationError("unknown verified eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String] - )) - )(ApiPartialPatientCriterion.apply, unlift(ApiPartialPatientCriterion.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala deleted file mode 100644 index 4b08970..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPartialPatientCriterionList.scala +++ /dev/null @@ -1,36 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.trial - -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.PatientCriterion -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath, Reads, Writes} -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion - -final case class ApiPartialPatientCriterionList(id: Long, - eligibilityStatus: Option[String], - isVerified: Option[Boolean]) { - - def toDomain: DraftPatientCriterion = DraftPatientCriterion( - id = LongId[PatientCriterion](id), - eligibilityStatus = eligibilityStatus.map(FuzzyValue.fromString), - isVerified = isVerified - ) -} - -object ApiPartialPatientCriterionList { - - implicit val format: Format[ApiPartialPatientCriterionList] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "eligibilityStatus").formatNullable[String](Format( - Reads - .of[String] - .filter(ValidationError("unknown eligibility status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), - Writes.of[String] - )) and - (JsPath \ "isVerified").formatNullable[Boolean] - )(ApiPartialPatientCriterionList.apply, unlift(ApiPartialPatientCriterionList.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala deleted file mode 100644 index 75347f4..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala +++ /dev/null @@ -1,74 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patient.trial - -import java.time.{ZoneId, ZonedDateTime} - -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities.{Label, PatientCriterion, PatientCriterionArm} -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath, Reads, Writes} - -final case class ApiPatientCriterion(id: Long, - labelId: Long, - nctId: String, - criterionId: Long, - criterionText: String, - criterionValue: Option[String], - criterionIsDefining: Boolean, - criterionIsCompound: Boolean, - arms: List[String], - eligibilityStatus: Option[String], - verifiedEligibilityStatus: Option[String], - isVerified: Boolean, - isVisible: Boolean, - lastUpdate: ZonedDateTime) - -object ApiPatientCriterion { - - implicit val format: Format[ApiPatientCriterion] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "labelId").format[Long] and - (JsPath \ "nctId").format[String] and - (JsPath \ "criterionId").format[Long] and - (JsPath \ "criterionText").format[String] and - (JsPath \ "criterionValue").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown value"))({ x => - x == "Yes" || x == "No" - }), Writes.of[String])) and - (JsPath \ "criterionIsDefining").format[Boolean] and - (JsPath \ "criterionIsCompound").format[Boolean] and - (JsPath \ "arms").format[List[String]] and - (JsPath \ "eligibilityStatus").formatNullable[String](Format(Reads.of[String].filter(ValidationError("unknown status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and - (JsPath \ "verifiedEligibilityStatus").formatNullable[String](Format( - Reads.of[String].filter(ValidationError("unknown status"))({ - case x if FuzzyValue.fromString.isDefinedAt(x) => true - case _ => false - }), Writes.of[String])) and - (JsPath \ "isVerified").format[Boolean] and - (JsPath \ "isVisible").format[Boolean] and - (JsPath \ "lastUpdate").format[ZonedDateTime] - ) (ApiPatientCriterion.apply, unlift(ApiPatientCriterion.unapply)) - - def fromDomain(patientCriterion: PatientCriterion, - labelId: LongId[Label], - arms: List[PatientCriterionArm]) = ApiPatientCriterion( - id = patientCriterion.id.id, - labelId = labelId.id, - nctId = patientCriterion.nctId.id, - criterionId = patientCriterion.criterionId.id, - criterionText = patientCriterion.criterionText, - criterionValue = patientCriterion.criterionValue.map { x => - FuzzyValue.valueToString(FuzzyValue.fromBoolean(x)) - }, - criterionIsDefining = patientCriterion.criterionIsDefining, - criterionIsCompound = patientCriterion.criterionValue.isEmpty, - arms = arms.map(_.armName), - eligibilityStatus = patientCriterion.eligibilityStatus.map(FuzzyValue.valueToString), - verifiedEligibilityStatus = patientCriterion.verifiedEligibilityStatus.map(FuzzyValue.valueToString), - isVerified = patientCriterion.isVerified, - isVisible = patientCriterion.isVisible, - lastUpdate = ZonedDateTime.of(patientCriterion.lastUpdate, ZoneId.of("Z")) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala deleted file mode 100644 index cdcd510..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienthistory/ApiPatientHistory.scala +++ /dev/null @@ -1,28 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patienthistory - -import java.time.{ZoneId, ZonedDateTime} -import java.util.UUID - -import play.api.libs.json.{Format, Json} -import xyz.driver.pdsuidomain.entities.PatientHistory - -final case class ApiPatientHistory(id: Long, - executor: String, - patientId: UUID, - state: String, - action: String, - created: ZonedDateTime) - -object ApiPatientHistory { - implicit val format: Format[ApiPatientHistory] = - Json.format[ApiPatientHistory] - - def fromDomain(x: PatientHistory) = ApiPatientHistory( - id = x.id.id, - executor = x.executor.id, - patientId = x.patientId.id, - state = PatientHistory.State.stateToString(x.state), - action = PatientHistory.Action.actionToString(x.action), - created = ZonedDateTime.of(x.created, ZoneId.of("Z")) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPartialPatientIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPartialPatientIssue.scala deleted file mode 100644 index eadd1f8..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPartialPatientIssue.scala +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patientissue - -import java.time.LocalDateTime - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuidomain.entities.{Patient, PatientIssue} - -final case class ApiPartialPatientIssue(text: String, archiveRequired: Boolean) { - def applyTo(x: PatientIssue): PatientIssue = x.copy( - text = text, - archiveRequired = archiveRequired - ) - - def toDomain(userId: StringId[User], patientId: UuidId[Patient]) = - PatientIssue( - id = LongId(0), - userId = userId, - patientId = patientId, - lastUpdate = LocalDateTime.MIN, - isDraft = true, - text = text, - archiveRequired = false - ) -} - -object ApiPartialPatientIssue { - implicit val format: Format[ApiPartialPatientIssue] = ( - (JsPath \ "text").format[String] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiPartialPatientIssue.apply, unlift(ApiPartialPatientIssue.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala deleted file mode 100644 index d1a216c..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.patientissue - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuidomain.entities.PatientIssue - -final case class ApiPatientIssue(id: Long, - text: String, - lastUpdate: ZonedDateTime, - userId: String, - isDraft: Boolean, - archiveRequired: Boolean) - -object ApiPatientIssue { - implicit val format: Format[ApiPatientIssue] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "text").format[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "userId").format[String] and - (JsPath \ "isDraft").format[Boolean] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiPatientIssue.apply, unlift(ApiPatientIssue.unapply)) - - def fromDomain(x: PatientIssue) = ApiPatientIssue( - id = x.id.id, - text = x.text, - lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")), - userId = x.userId.id, - isDraft = x.isDraft, - archiveRequired = x.archiveRequired - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala deleted file mode 100644 index cd76670..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/queue/ApiQueueUploadItem.scala +++ /dev/null @@ -1,38 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.queue - -import java.time.LocalDateTime - -import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue -import play.api.libs.json.{Format, Json} - -final case class ApiQueueUploadItem(kind: String, - tag: String, - created: LocalDateTime, - attempts: Int, - nextAttempt: LocalDateTime, - completed: Boolean) { - def toDomain = BridgeUploadQueue.Item( - kind = kind, - tag = tag, - created = created, - attempts = attempts, - nextAttempt = nextAttempt, - completed = true, - dependencyKind = None, - dependencyTag = None - ) -} - -object ApiQueueUploadItem { - - def fromDomain(domain: BridgeUploadQueue.Item) = ApiQueueUploadItem( - kind = domain.kind, - tag = domain.tag, - created = domain.created, - attempts = domain.attempts, - nextAttempt = domain.nextAttempt, - completed = domain.completed - ) - - implicit val format: Format[ApiQueueUploadItem] = Json.format[ApiQueueUploadItem] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala deleted file mode 100644 index 2e5943e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiCreateRecord.scala +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.record - -import java.time.LocalDateTime -import java.util.UUID - -import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuidomain.entities._ -import play.api.libs.json._ - -final case class ApiCreateRecord(disease: String, patientId: String, requestId: UUID) { - - def toDomain = MedicalRecord( - id = LongId(0), - status = MedicalRecord.Status.New, - previousStatus = None, - assignee = None, - previousAssignee = None, - lastActiveUserId = None, - patientId = UuidId(patientId), - requestId = RecordRequestId(requestId), - disease = disease, - caseId = None, - physician = None, - meta = None, - predictedMeta = None, - predictedDocuments = None, - lastUpdate = LocalDateTime.now() - ) -} - -object ApiCreateRecord { - - implicit val format: Format[ApiCreateRecord] = Json.format[ApiCreateRecord] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala deleted file mode 100644 index b255892..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiRecord.scala +++ /dev/null @@ -1,100 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.record - -import java.time.{ZoneId, ZonedDateTime} -import java.util.UUID - -import xyz.driver.pdsuidomain.entities.CaseId -import xyz.driver.pdsuidomain.entities.MedicalRecord -import xyz.driver.pdsuidomain.entities.MedicalRecord.Status -import xyz.driver.pdsuidomain.entities.RecordRequestId -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.json.JsonSerializer -import xyz.driver.pdsuicommon.domain.{LongId, StringId, TextJson, UuidId} - -final case class ApiRecord(id: Long, - patientId: String, - caseId: Option[String], - disease: String, - physician: Option[String], - lastUpdate: ZonedDateTime, - status: String, - previousStatus: Option[String], - assignee: Option[String], - previousAssignee: Option[String], - lastActiveUser: Option[String], - requestId: UUID, - meta: String) { - - private def extractStatus(status: String): Status = - Status - .fromString(status) - .getOrElse( - throw new NoSuchElementException(s"Status $status not found") - ) - - def toDomain = MedicalRecord( - id = LongId(this.id), - status = extractStatus(this.status), - previousStatus = this.previousStatus.map(extractStatus), - assignee = this.assignee.map(StringId(_)), - previousAssignee = this.previousAssignee.map(StringId(_)), - lastActiveUserId = this.lastActiveUser.map(StringId(_)), - patientId = UuidId(patientId), - requestId = RecordRequestId(this.requestId), - disease = this.disease, - caseId = caseId.map(CaseId(_)), - physician = this.physician, - meta = Some(TextJson(JsonSerializer.deserialize[List[MedicalRecord.Meta]](this.meta))), - predictedMeta = None, - predictedDocuments = None, - lastUpdate = this.lastUpdate.toLocalDateTime() - ) - -} - -object ApiRecord { - - private val statusFormat = Format( - Reads.StringReads.filter(ValidationError("unknown status")) { - case x if MedicalRecordStatus.statusFromString.isDefinedAt(x) => true - case _ => false - }, - Writes.StringWrites - ) - - implicit val format: Format[ApiRecord] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "patientId").format[String] and - (JsPath \ "caseId").formatNullable[String] and - (JsPath \ "disease").format[String] and - (JsPath \ "physician").formatNullable[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "status").format(statusFormat) and - (JsPath \ "previousStatus").formatNullable(statusFormat) and - (JsPath \ "assignee").formatNullable[String] and - (JsPath \ "previousAssignee").formatNullable[String] and - (JsPath \ "lastActiveUser").formatNullable[String] and - (JsPath \ "requestId").format[UUID] and - (JsPath \ "meta").format(Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) - )(ApiRecord.apply, unlift(ApiRecord.unapply)) - - def fromDomain(record: MedicalRecord) = ApiRecord( - id = record.id.id, - patientId = record.patientId.toString, - caseId = record.caseId.map(_.id), - disease = record.disease, - physician = record.physician, - lastUpdate = ZonedDateTime.of(record.lastUpdate, ZoneId.of("Z")), - status = MedicalRecordStatus.statusToString(record.status), - previousStatus = record.previousStatus.map(MedicalRecordStatus.statusToString), - assignee = record.assignee.map(_.id), - previousAssignee = record.previousAssignee.map(_.id), - lastActiveUser = record.lastActiveUserId.map(_.id), - requestId = record.requestId.id, - meta = record.meta.map(x => JsonSerializer.serialize(x.content)).getOrElse("[]") - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiUpdateRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiUpdateRecord.scala deleted file mode 100644 index 47bc493..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/ApiUpdateRecord.scala +++ /dev/null @@ -1,52 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.record - -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{StringId, TextJson, User} -import xyz.driver.pdsuicommon.json.JsonSerializer -import xyz.driver.pdsuidomain.entities.MedicalRecord.Meta -import xyz.driver.pdsuidomain.entities._ - -final case class ApiUpdateRecord(status: Option[String], assignee: Tristate[String], meta: Tristate[String]) { - - def applyTo(orig: MedicalRecord): MedicalRecord = { - orig.copy( - status = status.map(MedicalRecordStatus.statusFromString).getOrElse(orig.status), - assignee = assignee.map(StringId[User]).cata(Some(_), None, orig.assignee), - meta = meta.cata(x => Some(TextJson(JsonSerializer.deserialize[List[Meta]](x))), None, orig.meta) - ) - } -} - -object ApiUpdateRecord { - - private val reads: Reads[ApiUpdateRecord] = ( - (JsPath \ "status").readNullable[String]( - Reads - .of[String] - .filter(ValidationError("unknown status"))({ - case x if MedicalRecordStatus.statusFromString.isDefinedAt(x) => true - case _ => false - })) and - (JsPath \ "assignee").readTristate[String] and - (JsPath \ "meta") - .readTristate(Reads { x => - JsSuccess(Json.stringify(x)) - }) - .map { - case Tristate.Present("{}") => Tristate.Absent - case x => x - } - )(ApiUpdateRecord.apply _) - - private val writes: Writes[ApiUpdateRecord] = ( - (JsPath \ "status").writeNullable[String] and - (JsPath \ "assignee").writeTristate[String] and - (JsPath \ "meta").writeTristate(Writes[String](Json.parse)) - )(unlift(ApiUpdateRecord.unapply)) - - implicit val format: Format[ApiUpdateRecord] = Format(reads, writes) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/MedicalRecordStatus.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/MedicalRecordStatus.scala deleted file mode 100644 index a77b76b..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record/MedicalRecordStatus.scala +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.record - -import xyz.driver.pdsuidomain.entities.MedicalRecord.Status - -object MedicalRecordStatus { - - val statusFromString: PartialFunction[String, Status] = { - case "Unprocessed" => Status.Unprocessed - case "PreCleaning" => Status.PreCleaning - case "New" => Status.New - case "Cleaned" => Status.Cleaned - case "PreOrganized" => Status.PreOrganized - case "PreOrganizing" => Status.PreOrganizing - case "Reviewed" => Status.Reviewed - case "Organized" => Status.Organized - case "Done" => Status.Done - case "Flagged" => Status.Flagged - case "Archived" => Status.Archived - } - - def statusToString(x: Status): String = x match { - case Status.Unprocessed => "Unprocessed" - case Status.PreCleaning => "PreCleaning" - case Status.New => "New" - case Status.Cleaned => "Cleaned" - case Status.PreOrganized => "PreOrganized" - case Status.PreOrganizing => "PreOrganizing" - case Status.Reviewed => "Reviewed" - case Status.Organized => "Organized" - case Status.Done => "Done" - case Status.Flagged => "Flagged" - case Status.Archived => "Archived" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory/ApiRecordHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory/ApiRecordHistory.scala deleted file mode 100644 index c55a78f..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory/ApiRecordHistory.scala +++ /dev/null @@ -1,27 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.recordhistory - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.json.{Format, Json} -import xyz.driver.pdsuidomain.entities.MedicalRecordHistory - -final case class ApiRecordHistory(id: Long, - executor: String, - recordId: Long, - state: String, - action: String, - created: ZonedDateTime) - -object ApiRecordHistory { - implicit val format: Format[ApiRecordHistory] = - Json.format[ApiRecordHistory] - - def fromDomain(x: MedicalRecordHistory) = ApiRecordHistory( - id = x.id.id, - executor = x.executor.id, - recordId = x.recordId.id, - state = MedicalRecordHistory.State.stateToString(x.state), - action = MedicalRecordHistory.Action.actionToString(x.action), - created = ZonedDateTime.of(x.created, ZoneId.of("Z")) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiPartialRecordIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiPartialRecordIssue.scala deleted file mode 100644 index 890ad69..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiPartialRecordIssue.scala +++ /dev/null @@ -1,42 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.recordissue - -import java.time.LocalDateTime - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -import xyz.driver.pdsuidomain.entities.{MedicalRecord, MedicalRecordIssue} - -final case class ApiPartialRecordIssue(startPage: Option[Double], - endPage: Option[Double], - text: String, - archiveRequired: Boolean) { - def applyTo(x: MedicalRecordIssue): MedicalRecordIssue = x.copy( - startPage = startPage, - endPage = endPage, - text = text, - archiveRequired = archiveRequired - ) - - def toDomain(userId: StringId[User], recordId: LongId[MedicalRecord]) = - MedicalRecordIssue( - id = LongId(0), - userId = userId, - recordId = recordId, - startPage = startPage, - endPage = endPage, - lastUpdate = LocalDateTime.MIN, - isDraft = true, - text = text, - archiveRequired = false - ) -} - -object ApiPartialRecordIssue { - implicit val format: Format[ApiPartialRecordIssue] = ( - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "text").format[String] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiPartialRecordIssue.apply, unlift(ApiPartialRecordIssue.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiRecordIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiRecordIssue.scala deleted file mode 100644 index 45bc469..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordissue/ApiRecordIssue.scala +++ /dev/null @@ -1,40 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.recordissue - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuidomain.entities.MedicalRecordIssue - -final case class ApiRecordIssue(id: Long, - startPage: Option[Double], - endPage: Option[Double], - text: String, - lastUpdate: ZonedDateTime, - userId: String, - isDraft: Boolean, - archiveRequired: Boolean) - -object ApiRecordIssue { - implicit val format: Format[ApiRecordIssue] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "startPage").formatNullable[Double] and - (JsPath \ "endPage").formatNullable[Double] and - (JsPath \ "text").format[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "userId").format[String] and - (JsPath \ "isDraft").format[Boolean] and - (JsPath \ "archiveRequired").format[Boolean] - )(ApiRecordIssue.apply, unlift(ApiRecordIssue.unapply)) - - def fromDomain(x: MedicalRecordIssue) = ApiRecordIssue( - id = x.id.id, - startPage = x.startPage, - endPage = x.endPage, - text = x.text, - lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")), - userId = x.userId.id, - isDraft = x.isDraft, - archiveRequired = x.archiveRequired - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionRequest.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionRequest.scala deleted file mode 100644 index fbe9689..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionRequest.scala +++ /dev/null @@ -1,12 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.session - -import xyz.driver.pdsuicommon.domain.Email -import play.api.libs.json._ -import xyz.driver.pdsuicommon.json.Serialization._ - -final case class NewSessionRequest(email: Email, password: String) - -object NewSessionRequest { - - implicit val format: Format[NewSessionRequest] = Json.format[NewSessionRequest] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionResponse.scala deleted file mode 100644 index 55e05b1..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/session/NewSessionResponse.scala +++ /dev/null @@ -1,11 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.session - -import play.api.libs.json.Json -import xyz.driver.pdsuidomain.formats.json.user.ApiUser - -final case class NewSessionResponse(token: String, user: ApiUser) - -object NewSessionResponse { - - implicit val format = Json.format[NewSessionResponse] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala deleted file mode 100644 index 39af1c3..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/arm.scala +++ /dev/null @@ -1,44 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -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") - } - - def 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 = 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/sprayformats/bridgeuploadqueue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/bridgeuploadqueue.scala deleted file mode 100644 index 77fb4d2..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/bridgeuploadqueue.scala +++ /dev/null @@ -1,68 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -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/sprayformats/common.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala deleted file mode 100644 index dbd0a43..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala +++ /dev/null @@ -1,74 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.{LocalDate, LocalDateTime, ZoneId, ZonedDateTime} - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, 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 def fuzzyValueFormat: RootJsonFormat[FuzzyValue] = new RootJsonFormat[FuzzyValue] { - override def write(value: FuzzyValue): JsString = JsString(FuzzyValue.valueToString(value)) - override def read(json: JsValue): FuzzyValue = json match { - case JsString(value) => FuzzyValue.fromString(value) - case _ => deserializationError(s"Expected value as FuzzyValue, 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/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala deleted file mode 100644 index 732bcad..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala +++ /dev/null @@ -1,158 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -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 = new JsonWriter[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") - .map(_.convertTo[LongId[Label]]) - - val categoryId = fields - .get("categoryId") - .map(_.convertTo[LongId[Category]]) - - val value = fields - .get("value") - .map(_.convertTo[String] match { - 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 arms = fields - .get("arms") - .map(_.convertTo[Option[List[LongId[Arm]]]].getOrElse(List.empty[LongId[Arm]])) - .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 - ), - armIds = arms, - labels = labels - ) - - case _ => deserializationError(s"Expected Json Object as partial Criterion, but got $json") - } - - val richCriterionFormat = 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 - ) - - override def read(json: JsValue): RichCriterion = json match { - case JsObject(fields) => - 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") - .map(_.convertTo[String]) - - val isCompound = fields - .get("isCompound") - .exists(_.convertTo[Boolean]) - - val meta = fields - .get("meta") - .map(_.convertTo[String]) - .getOrElse("") - - val arms = fields - .get("arms") - .map(_.convertTo[List[LongId[Arm]]]) - .getOrElse(List.empty[LongId[Arm]]) - - val labels = fields - .get("labels") - .map(_.convertTo[List[JsValue]]) - .map(_.map(l => jsValueToCriterionLabel(l, LongId(0)))) - .getOrElse(List.empty[CriterionLabel]) - - RichCriterion( - criterion = Criterion( - id = LongId(0), - trialId = trialId, - text = text, - isCompound = isCompound, - meta = meta - ), - 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/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala deleted file mode 100644 index baf1b4e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ /dev/null @@ -1,164 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.{LocalDate, LocalDateTime} - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuicommon.domain.{LongId, TextJson} -import xyz.driver.pdsuidomain.entities._ - -object document { - import DefaultJsonProtocol._ - import Document._ - import common._ - - implicit val documentStatusFormat = new EnumJsonFormat[Status]( - "New" -> Status.New, - "Organized" -> Status.Organized, - "Extracted" -> Status.Extracted, - "Done" -> Status.Done, - "Flagged" -> Status.Flagged, - "Archived" -> Status.Archived - ) - - implicit val requiredTypeFormat = new EnumJsonFormat[RequiredType]( - "OPN" -> RequiredType.OPN, - "PN" -> RequiredType.PN - ) - - implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply) - - 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 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, - 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.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, - "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 - ) - - override def read(json: JsValue): Document = json match { - case JsObject(fields) => - val recordId = fields - .get("recordId") - .map(_.convertTo[LongId[MedicalRecord]]) - .getOrElse(deserializationError(s"Document create json object does not contain `recordId` field: $json")) - - val physician = fields - .get("physician") - .map(_.convertTo[String]) - - val typeId = fields - .get("typeId") - .map(_.convertTo[LongId[DocumentType]]) - - val provider = fields - .get("provider") - .map(_.convertTo[String]) - - val providerTypeId = fields - .get("providerTypeId") - .map(_.convertTo[LongId[ProviderType]]) - - val meta = fields - .get("meta") - .map(_.convertTo[TextJson[Meta]]) - - val startDate = fields - .get("startDate") - .map(_.convertTo[LocalDate]) - - val endDate = fields - .get("endDate") - .map(_.convertTo[LocalDate]) - - Document( - id = LongId(0), - recordId = recordId, - status = Document.Status.New, - physician = physician, - typeId = typeId, - startDate = startDate, - endDate = endDate, - providerName = provider, - providerTypeId = providerTypeId, - requiredType = None, - meta = meta, - previousStatus = None, - assignee = None, - previousAssignee = None, - lastActiveUserId = None, - lastUpdate = LocalDateTime.MIN - ) - - case _ => deserializationError(s"Expected Json Object as Document, but got $json") - } - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenthistory.scala deleted file mode 100644 index 419c252..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenthistory.scala +++ /dev/null @@ -1,29 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuidomain.entities._ - -object documenthistory { - import DefaultJsonProtocol._ - import common._ - import DocumentHistory._ - - implicit val documentStateFormat = new EnumJsonFormat[State]( - "Extract" -> State.Extract, - "Review" -> State.Review, - "Flag" -> State.Flag - ) - - implicit val documentActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive - ) - - implicit val documentHistoryFormat: RootJsonFormat[DocumentHistory] = jsonFormat6(DocumentHistory.apply) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala deleted file mode 100644 index 28b2a5e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala +++ /dev/null @@ -1,77 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -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[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 DocumentIssue, but got $json") - - } - - def jsValueToDocumentIssue(json: JsValue, documentId: LongId[Document], userId: StringId[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 startPage = fields.get("startPage").map(_.convertTo[Double]) - val endPage = fields.get("endPage").map(_.convertTo[Double]) - DocumentIssue( - id = 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 documentIssueWriter = new JsonWriter[DocumentIssue] { - override def write(obj: DocumentIssue) = JsObject( - "id" -> obj.id.toJson, - "startPage" -> obj.startPage.toJson, - "endPage" -> obj.endPage.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/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala deleted file mode 100644 index 20b6ed0..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ /dev/null @@ -1,78 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuidomain.entities.export.patient._ -import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} - -object export { - import DefaultJsonProtocol._ - import common._ - import record._ - - implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5( - ExportPatientLabelEvidenceDocument.apply) - - implicit val patientLabelEvidenceWriter: JsonWriter[ExportPatientLabelEvidence] = - new JsonWriter[ExportPatientLabelEvidence] { - override def write(obj: ExportPatientLabelEvidence): JsValue = - JsObject( - "evidenceId" -> obj.id.toJson, - "labelValue" -> obj.value.toJson, - "evidenceText" -> obj.evidenceText.toJson, - "document" -> obj.document.toJson - ) - } - - implicit val patientLabelWriter: JsonWriter[ExportPatientLabel] = new JsonWriter[ExportPatientLabel] { - override def write(obj: ExportPatientLabel): JsValue = - JsObject( - "labelId" -> obj.id.toJson, - "evidence" -> obj.evidences.map(_.toJson).toJson - ) - } - - implicit val patientWithLabelsWriter: JsonWriter[ExportPatientWithLabels] = new JsonWriter[ExportPatientWithLabels] { - override def write(obj: ExportPatientWithLabels): JsValue = - JsObject( - "patientId" -> obj.patientId.toJson, - "labelVersion" -> obj.labelVersion.toJson, - "labels" -> obj.labels.map(_.toJson).toJson - ) - } - - implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat2(ExportTrialArm.apply) - - implicit val trialLabelCriterionWriter: JsonWriter[ExportTrialLabelCriterion] = - new JsonWriter[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 - ) - } - - implicit val trialWithLabelsWriter: JsonWriter[ExportTrialWithLabels] = new JsonWriter[ExportTrialWithLabels] { - override def write(obj: ExportTrialWithLabels) = - JsObject( - "nctId" -> obj.nctId.toJson, - "trialId" -> obj.trialId.toJson, - "disease" -> obj.condition.toJson, - "lastReviewed" -> obj.lastReviewed.toJson, - "labelVersion" -> obj.labelVersion.toJson, - "arms" -> obj.arms.toJson, - "criteria" -> obj.criteria.map(_.toJson).toJson - ) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala deleted file mode 100644 index 42473bc..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala +++ /dev/null @@ -1,148 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - -object extracteddata { - import DefaultJsonProtocol._ - import common._ - import ExtractedData._ - - 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") - .map(_.convertTo[LongId[Label]]) - - val categoryId = fields - .get("categoryId") - .map(_.convertTo[LongId[Category]]) - - val value = fields - .get("value") - .map(_.convertTo[FuzzyValue]) - - 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.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 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") - .map(_.convertTo[LongId[Keyword]]) - - val evidence = fields - .get("evidence") - .map(_.convertTo[String]) - - val meta = fields - .get("meta") - .map(_.convertTo[TextJson[Meta]]) - - val labels = fields - .get("labels") - .map(_.convertTo[List[JsValue]]) - .getOrElse(List.empty[JsValue]) - .map(l => applyLabelsForExtractedData(l, LongId(0))) - - val extractedData = ExtractedData( - 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/sprayformats/hypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/hypothesis.scala deleted file mode 100644 index c05ff23..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/hypothesis.scala +++ /dev/null @@ -1,12 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -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/sprayformats/intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala deleted file mode 100644 index a8ce950..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala +++ /dev/null @@ -1,60 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuidomain.entities._ - -object intervention { - import DefaultJsonProtocol._ - import common._ - - implicit val interventionWriter: JsonWriter[InterventionWithArms] = new JsonWriter[InterventionWithArms] { - override def write(obj: InterventionWithArms) = - JsObject( - "id" -> obj.intervention.id.toJson, - "name" -> obj.intervention.name.toJson, - "typeId" -> obj.intervention.typeId.toJson, - "description" -> obj.intervention.description.toJson, - "isActive" -> obj.intervention.isActive.toJson, - "arms" -> obj.arms.map(_.armId).toJson, - "trialId" -> obj.intervention.trialId.toJson, - "originalName" -> obj.intervention.originalName.toJson, - "originalDescription" -> obj.intervention.originalDescription.toJson, - "originalType" -> obj.intervention.originalType.toJson - ) - } - - def applyUpdateToInterventionWithArms(json: JsValue, orig: InterventionWithArms): InterventionWithArms = json match { - case JsObject(fields) => - val typeId = fields - .get("typeId") - .map(_.convertTo[LongId[InterventionType]]) - - val description = fields - .get("description") - .map(_.convertTo[String]) - - val isActive = fields - .get("isActive") - .map(_.convertTo[Boolean]) - - val origIntervention = orig.intervention - val arms = fields - .get("arms") - .map(_.convertTo[List[LongId[Arm]]].map(x => InterventionArm(x, orig.intervention.id))) - - orig.copy( - intervention = origIntervention.copy( - typeId = typeId.orElse(origIntervention.typeId), - description = description.getOrElse(origIntervention.description), - isActive = isActive.getOrElse(origIntervention.isActive) - ), - arms = arms.getOrElse(orig.arms) - ) - - case _ => deserializationError(s"Expected Json Object as partial Intervention, but got $json") - } - - implicit val interventionTypeFormat: RootJsonFormat[InterventionType] = jsonFormat2(InterventionType.apply) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala deleted file mode 100644 index 724c391..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ /dev/null @@ -1,46 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuidomain.entities._ - -object patient { - import DefaultJsonProtocol._ - import common._ - import Patient._ - - implicit val patientStatusFormat = new EnumJsonFormat[Status]( - "New" -> Status.New, - "Verified" -> Status.Verified, - "Reviewed" -> Status.Reviewed, - "Curated" -> Status.Curated, - "Done" -> Status.Done, - "Flagged" -> Status.Flagged - ) - - implicit val patientOrderIdFormat = new RootJsonFormat[PatientOrderId] { - override def write(orderId: PatientOrderId): JsString = JsString(orderId.toString) - override def read(json: JsValue): PatientOrderId = json match { - case JsString(value) => PatientOrderId(value) - case _ => deserializationError(s"Expected string as PatientOrderId, but got $json") - } - } - - implicit val patientWriter: JsonWriter[Patient] = new JsonWriter[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, - "condition" -> patient.condition.toJson, - "orderId" -> patient.orderId.toJson - ) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala deleted file mode 100644 index 53e927d..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala +++ /dev/null @@ -1,68 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion - -object patientcriterion { - import DefaultJsonProtocol._ - import common._ - - def applyUpdateToPatientCriterion(json: JsValue, orig: PatientCriterion): PatientCriterion = json match { - case JsObject(fields) => - val eligibilityStatus = if (fields.contains("eligibilityStatus")) { - fields - .get("eligibilityStatus") - .map(_.convertTo[FuzzyValue]) - } else orig.eligibilityStatus - - val verifiedEligibilityStatus = if (fields.contains("verifiedEligibilityStatus")) { - fields - .get("verifiedEligibilityStatus") - .map(_.convertTo[FuzzyValue]) - } else 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 patientCriterionWriter: JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] = - new JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] { - override def write(obj: (PatientCriterion, LongId[Label], List[PatientCriterionArm])): JsValue = { - val criterion = obj._1 - val labelId = obj._2 - val arms = obj._3 - JsObject( - "id" -> criterion.id.toJson, - "labelId" -> labelId.toJson, - "nctId" -> criterion.nctId.toJson, - "criterionId" -> criterion.criterionId.toJson, - "criterionText" -> criterion.criterionText.toJson, - "criterionValue" -> criterion.criterionValue.map { - case true => "Yes" - case false => "No" - }.toJson, - "criterionIsDefining" -> criterion.criterionIsDefining.toJson, - "criterionIsCompound" -> criterion.criterionValue.isEmpty.toJson, - "arms" -> arms.map(_.armName).toJson, - "eligibilityStatus" -> criterion.eligibilityStatus.toJson, - "verifiedEligibilityStatus" -> criterion.verifiedEligibilityStatus.toJson, - "isVerified" -> criterion.isVerified.toJson, - "isVisible" -> criterion.isVisible.toJson, - "lastUpdate" -> criterion.lastUpdate.toJson - ) - } - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala deleted file mode 100644 index b97570a..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuidomain.entities.PatientLabel - -object patientdefiningcriteria { - import DefaultJsonProtocol._ - import common._ - - implicit val patientLabelDefiningCriteriaWriter: JsonWriter[PatientLabel] = new JsonWriter[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/sprayformats/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala deleted file mode 100644 index 894e453..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala +++ /dev/null @@ -1,39 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial - -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: JsonWriter[RichPatientEligibleTrial] = - new JsonWriter[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/sprayformats/patienthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthistory.scala deleted file mode 100644 index da7a664..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthistory.scala +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuidomain.entities._ - -object patienthistory { - import DefaultJsonProtocol._ - import common._ - import PatientHistory._ - - implicit val patientStateFormat = new EnumJsonFormat[State]( - "Verify" -> State.Verify, - "Curate" -> State.Curate, - "Review" -> State.Review, - "Flag" -> State.Flag - ) - - implicit val patientActionFormat = 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/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala deleted file mode 100644 index 4f2783c..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala +++ /dev/null @@ -1,37 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuidomain.entities._ - -object patienthypothesis { - import DefaultJsonProtocol._ - import common._ - - 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: JsonWriter[(PatientHypothesis, Boolean)] = - new JsonWriter[(PatientHypothesis, Boolean)] { - override def write(obj: (PatientHypothesis, Boolean)): JsValue = { - val patientHypothesis = obj._1 - val isRationaleRequired = obj._2 - JsObject( - "id" -> patientHypothesis.id.toJson, - "patientId" -> patientHypothesis.patientId.toJson, - "hypothesisId" -> patientHypothesis.hypothesisId.toJson, - "matchedTrials" -> patientHypothesis.matchedTrials.toJson, - "rationale" -> patientHypothesis.rationale.toJson, - "isRationaleRequired" -> isRationaleRequired.toJson - ) - } - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala deleted file mode 100644 index 7d35bd1..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala +++ /dev/null @@ -1,54 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User, 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: StringId[User]): PatientIssue = { - json.asJsObject.getFields("text") match { - case Seq(text) => - PatientIssue( - id = 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 = new JsonWriter[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/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala deleted file mode 100644 index 3b52833..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala +++ /dev/null @@ -1,64 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue -import xyz.driver.pdsuidomain.entities._ - -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[Option[FuzzyValue]]) - .getOrElse(orig.primaryValue) - - val verifiedPrimaryValue = fields - .get("verifiedPrimaryValue") - .map(_.convertTo[Option[FuzzyValue]]) - .getOrElse(orig.verifiedPrimaryValue) - - orig.copy( - primaryValue = primaryValue, - verifiedPrimaryValue = verifiedPrimaryValue - ) - - case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") - } - - implicit val patientLabelWriter: JsonWriter[(PatientLabel, Boolean)] = new JsonWriter[(PatientLabel, Boolean)] { - override def write(obj: (PatientLabel, Boolean)): JsValue = { - val patientLabel = obj._1 - val isVerified = obj._2 - JsObject( - "id" -> patientLabel.id.toJson, - "labelId" -> patientLabel.labelId.toJson, - "primaryValue" -> patientLabel.primaryValue.toJson, - "verifiedPrimaryValue" -> patientLabel.verifiedPrimaryValue.toJson, - "score" -> patientLabel.score.toJson, - "isImplicitMatch" -> patientLabel.isImplicitMatch.toJson, - "isVisible" -> patientLabel.isVisible.toJson, - "isVerified" -> isVerified.toJson - ) - } - } - - implicit val patientLabelEvidenceWriter: JsonWriter[PatientLabelEvidenceView] = - new JsonWriter[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/sprayformats/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala deleted file mode 100644 index e378dbd..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala +++ /dev/null @@ -1,237 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime -import java.util.UUID - -import spray.json._ -import xyz.driver.core.json.{EnumJsonFormat, GadtJsonFormat} -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 = new EnumJsonFormat[Status]( - "Unprocessed" -> Status.Unprocessed, - "PreOrganized" -> Status.PreOrganized, - "New" -> Status.New, - "Cleaned" -> Status.Cleaned, - "PreOrganized" -> Status.PreOrganized, - "PreOrganizing" -> Status.PreOrganizing, - "Reviewed" -> Status.Reviewed, - "Organized" -> Status.Organized, - "Done" -> Status.Done, - "Flagged" -> Status.Flagged, - "Archived" -> Status.Archived - ) - - implicit val requestIdFormat = new RootJsonFormat[RecordRequestId] { - override def write(requestId: RecordRequestId): JsString = JsString(requestId.toString) - override def read(json: JsValue): RecordRequestId = json match { - case JsString(value) => RecordRequestId(UUID.fromString(value)) - case _ => deserializationError(s"Expected string as RecordRequestId, but got $json") - } - } - - implicit val caseIdFormat = new RootJsonFormat[CaseId] { - override def write(caseId: CaseId): JsString = JsString(caseId.toString) - override def read(json: JsValue): CaseId = json match { - case JsString(value) => CaseId(value) - case _ => deserializationError(s"Expected string as CaseId, but got $json") - } - } - - implicit val duplicateMetaFormat: RootJsonFormat[Duplicate] = new RootJsonFormat[Duplicate] { - override def write(obj: Duplicate) = - JsObject( - "type" -> "duplicate".toJson, - "predicted" -> obj.predicted.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 predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - - 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") - .map(_.convertTo[Double]) - - Duplicate( - predicted = predicted, - 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, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) - - override def read(json: JsValue): Reorder = json match { - case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - - val items = fields - .get("items") - .map(_.convertTo[Seq[Int]]) - .getOrElse(deserializationError(s"Reorder meta json object does not contain `items` field: $json")) - - Reorder( - predicted = predicted, - items = 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, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) - - override def read(json: JsValue): Rotation = json match { - case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - - val items = fields - .get("items") - .map(_.convertTo[Map[String, Int]]) - .getOrElse(deserializationError(s"Rotation meta json object does not contain `items` field: $json")) - - Rotation( - predicted = predicted, - 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 = 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.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 - ) - - override def read(json: JsValue): MedicalRecord = json match { - case JsObject(fields) => - 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[RecordRequestId]) - .getOrElse(deserializationError(s"MedicalRecord json object does not contain `requestId` field: $json")) - - MedicalRecord( - id = 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, - predictedMeta = None, - predictedDocuments = None, - lastUpdate = LocalDateTime.now() - ) - - 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/sprayformats/recordhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordhistory.scala deleted file mode 100644 index bd14d43..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordhistory.scala +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuidomain.entities._ - -object recordhistory { - import DefaultJsonProtocol._ - import common._ - import MedicalRecordHistory._ - - implicit val recordStateFormat = new EnumJsonFormat[State]( - "Clean" -> State.Clean, - "Organize" -> State.Organize, - "Review" -> State.Review, - "Flag" -> State.Flag - ) - - implicit val recordActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive - ) - - implicit val recordHistoryFormat: RootJsonFormat[MedicalRecordHistory] = jsonFormat6(MedicalRecordHistory.apply) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala deleted file mode 100644 index 4ae04d0..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala +++ /dev/null @@ -1,79 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -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: StringId[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 startPage = fields.get("startPage").map(_.convertTo[Double]) - val endPage = fields.get("endPage").map(_.convertTo[Double]) - MedicalRecordIssue( - id = LongId(0), - 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 recordIssueWriter = new JsonWriter[MedicalRecordIssue] { - override def write(obj: MedicalRecordIssue) = JsObject( - "id" -> obj.id.toJson, - "startPage" -> obj.startPage.toJson, - "endPage" -> obj.endPage.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/sprayformats/studydesign.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/studydesign.scala deleted file mode 100644 index e801666..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/studydesign.scala +++ /dev/null @@ -1,12 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.pdsuidomain.entities._ - -object studydesign { - import DefaultJsonProtocol._ - import common._ - - implicit val studyDesignFormat: RootJsonFormat[StudyDesign] = jsonFormat2(StudyDesign.apply) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala deleted file mode 100644 index c1751bf..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala +++ /dev/null @@ -1,90 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.{ZoneId, ZonedDateTime} - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuidomain.entities._ - -object trial { - import DefaultJsonProtocol._ - import common._ - import Trial._ - - implicit val trialStatusFormat = 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 conditionFormat = new EnumJsonFormat[Condition]( - "Breast" -> Condition.Breast, - "Lung" -> Condition.Lung, - "Prostate" -> Condition.Prostate - ) - - implicit val trialWriter: JsonWriter[Trial] = new JsonWriter[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, - "condition" -> obj.condition.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 - ) - } - - 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) - - orig.copy( - hypothesisId = hypothesisId, - studyDesignId = studyDesignId, - overview = overview, - title = title - ) - - case _ => deserializationError(s"Expected Json Object as Trial, but got $json") - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialhistory.scala deleted file mode 100644 index 844c5f5..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialhistory.scala +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -import xyz.driver.core.json.EnumJsonFormat -import xyz.driver.pdsuidomain.entities._ - -object trialhistory { - import DefaultJsonProtocol._ - import common._ - import TrialHistory._ - - implicit val trialStateFormat = new EnumJsonFormat[State]( - "Summarize" -> State.Summarize, - "Criteriarize" -> State.Criteriarize, - "Review" -> State.Review, - "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] = jsonFormat6(TrialHistory.apply) - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala deleted file mode 100644 index 572f44d..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala +++ /dev/null @@ -1,60 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import java.time.LocalDateTime - -import spray.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -import xyz.driver.pdsuidomain.entities._ - -object trialissue { - import DefaultJsonProtocol._ - import common._ - - 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: StringId[User]): TrialIssue = { - json.asJsObject.getFields("text", "evidence", "meta") match { - case Seq(text, evidence, meta) => - TrialIssue( - id = 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 JsonWriter[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 - ) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign/ApiStudyDesign.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign/ApiStudyDesign.scala deleted file mode 100644 index 1e9a226..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/studydesign/ApiStudyDesign.scala +++ /dev/null @@ -1,24 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.studydesign - -import xyz.driver.pdsuidomain.entities.StudyDesign -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuicommon.domain.LongId - -final case class ApiStudyDesign(id: Long, name: String) { - - def toDomain = StudyDesign(id = LongId[StudyDesign](id), name = name) -} - -object ApiStudyDesign { - - implicit val format: Format[ApiStudyDesign] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "name").format[String] - )(ApiStudyDesign.apply, unlift(ApiStudyDesign.unapply)) - - def fromDomain(studyDesign: StudyDesign) = ApiStudyDesign( - id = studyDesign.id.id, - name = studyDesign.name - ) -} 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" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory/ApiTrialHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory/ApiTrialHistory.scala deleted file mode 100644 index 38faeb8..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory/ApiTrialHistory.scala +++ /dev/null @@ -1,26 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.trialhistory - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.json.{Format, Json} -import xyz.driver.pdsuidomain.entities.TrialHistory - -final case class ApiTrialHistory(id: Long, - executor: String, - trialId: String, - state: String, - action: String, - created: ZonedDateTime) - -object ApiTrialHistory { - implicit val format: Format[ApiTrialHistory] = Json.format[ApiTrialHistory] - - def fromDomain(x: TrialHistory) = ApiTrialHistory( - id = x.id.id, - executor = x.executor.id, - trialId = x.trialId.id, - state = TrialHistory.State.stateToString(x.state), - action = TrialHistory.Action.actionToString(x.action), - created = ZonedDateTime.of(x.created, ZoneId.of("Z")) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiPartialTrialIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiPartialTrialIssue.scala deleted file mode 100644 index fc31371..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiPartialTrialIssue.scala +++ /dev/null @@ -1,40 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.trialissue - -import java.time.LocalDateTime - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain.{LongId, StringId, User} -import xyz.driver.pdsuidomain.entities.{Trial, TrialIssue} - -final case class ApiPartialTrialIssue(text: String, evidence: String, archiveRequired: Boolean, meta: String) { - def applyTo(x: TrialIssue): TrialIssue = x.copy( - text = text, - evidence = evidence, - archiveRequired = archiveRequired, - meta = meta - ) - - def toDomain(userId: StringId[User], trialId: StringId[Trial]) = TrialIssue( - id = LongId(0), - userId = userId, - trialId = trialId, - lastUpdate = LocalDateTime.MIN, - isDraft = true, - text = text, - evidence = evidence, - archiveRequired = false, - meta = meta - ) -} - -object ApiPartialTrialIssue { - implicit val format: Format[ApiPartialTrialIssue] = ( - (JsPath \ "text").format[String] and - (JsPath \ "evidence").format[String] and - (JsPath \ "archiveRequired").format[Boolean] and - (JsPath \ "meta").format[String](Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) - )(ApiPartialTrialIssue.apply, unlift(ApiPartialTrialIssue.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala deleted file mode 100644 index c9475c6..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala +++ /dev/null @@ -1,60 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.trialissue - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuidomain.entities.TrialIssue - -final case class ApiTrialIssue(id: Long, - trialId: String, - text: String, - lastUpdate: ZonedDateTime, - userId: String, - isDraft: Boolean, - evidence: String, - archiveRequired: Boolean, - meta: String) { - - def toDomain = TrialIssue( - id = LongId(this.id), - trialId = StringId(this.trialId), - text = this.text, - userId = StringId(this.userId), - lastUpdate = this.lastUpdate.toLocalDateTime, - isDraft = this.isDraft, - evidence = this.evidence, - archiveRequired = this.archiveRequired, - meta = this.meta - ) - -} - -object ApiTrialIssue { - implicit val format: Format[ApiTrialIssue] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "trialId").format[String] and - (JsPath \ "text").format[String] and - (JsPath \ "lastUpdate").format[ZonedDateTime] and - (JsPath \ "userId").format[String] and - (JsPath \ "isDraft").format[Boolean] and - (JsPath \ "evidence").format[String] and - (JsPath \ "archiveRequired").format[Boolean] and - (JsPath \ "meta").format[String](Format(Reads { x => - JsSuccess(Json.stringify(x)) - }, Writes[String](Json.parse))) - )(ApiTrialIssue.apply, unlift(ApiTrialIssue.unapply)) - - def fromDomain(x: TrialIssue) = ApiTrialIssue( - id = x.id.id, - trialId = x.trialId.id, - text = x.text, - lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")), - userId = x.userId.id, - isDraft = x.isDraft, - evidence = x.evidence, - archiveRequired = x.archiveRequired, - meta = x.meta - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiPartialUser.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiPartialUser.scala deleted file mode 100644 index cf20d32..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiPartialUser.scala +++ /dev/null @@ -1,76 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.user - -import java.util.UUID - -import xyz.driver.pdsuicommon.domain._ -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -import scala.collection._ -import scala.util.Try -import xyz.driver.pdsuicommon.json.JsonValidationException -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import xyz.driver.pdsuicommon.validation.{AdditionalConstraints, JsonValidationErrors} - -final case class ApiPartialUser(email: Option[String], name: Option[String], roles: Option[Seq[String]]) { - - def applyTo(orig: User): Try[User] = Try { - val validation = Map( - JsPath \ "name" -> AdditionalConstraints.optionNonEmptyConstraint(name) - ) - - val validationErrors: JsonValidationErrors = validation.collect({ - case (fieldName, e: Invalid) => (fieldName, e.errors) - })(breakOut) - - if (validationErrors.isEmpty) { - orig.copy(name = name.get) - } else { - throw new JsonValidationException(validationErrors) - } - } - - def toDomain(id: StringId[User] = StringId(UUID.randomUUID().toString)): Try[User] = Try { - val validation = Map( - JsPath \ "email" -> AdditionalConstraints.optionNonEmptyConstraint(email), - JsPath \ "name" -> AdditionalConstraints.optionNonEmptyConstraint(name), - JsPath \ "roles" -> AdditionalConstraints.optionNonEmptyConstraint(roles) - ) - - val validationErrors: JsonValidationErrors = validation.collect({ - case (fieldName, e: Invalid) => (fieldName, e.errors) - })(breakOut) - - if (validationErrors.isEmpty) { - val userEmail = email.map(x => Email(x.toLowerCase)).get - User( - id = id, - email = userEmail, - name = name.get, - roles = roles.toSeq.flatMap(_.map(UserRole.roleFromString)).toSet, - latestActivity = None, - deleted = None - ) - } else { - throw new JsonValidationException(validationErrors) - } - } -} - -object ApiPartialUser { - - implicit val format: Format[ApiPartialUser] = ( - (JsPath \ "email").formatNullable[String](Format(Reads.email, Writes.StringWrites)) and - (JsPath \ "name").formatNullable[String]( - Format( - Reads.filterNot[String](ValidationError("Username is too long (max length is 255 chars)", 255))( - _.length > 255), - Writes.StringWrites - )) and - (JsPath \ "roles").formatNullable[Seq[String]]( - Format(seqJsonFormat[String].filter(ValidationError("unknown roles"))( - _.forall(UserRole.roleFromString.isDefinedAt)), - Writes.of[Seq[String]])) - )(ApiPartialUser.apply, unlift(ApiPartialUser.unapply)) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiUser.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiUser.scala deleted file mode 100644 index c21edd1..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/ApiUser.scala +++ /dev/null @@ -1,39 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.user - -import java.time.{ZoneId, ZonedDateTime} - -import xyz.driver.pdsuicommon.domain.User -import xyz.driver.pdsuicommon.json.Serialization.seqJsonFormat -import play.api.data.validation.ValidationError -import play.api.libs.functional.syntax._ -import play.api.libs.json._ - -import scala.collection.Seq - -final case class ApiUser(id: String, - email: String, - name: String, - roles: Seq[String], - latestActivity: Option[ZonedDateTime]) - -object ApiUser { - - implicit val format: Format[ApiUser] = ( - (JsPath \ "id").format[String] and - (JsPath \ "email").format[String](Reads.email) and - (JsPath \ "name").format[String] and - (JsPath \ "roles").format( - Format( - seqJsonFormat[String].filter(ValidationError("unknown role"))(_.forall(UserRole.roleFromString.isDefinedAt)), - Writes.of[Seq[String]])) and - (JsPath \ "latestActivity").formatNullable[ZonedDateTime] - )(ApiUser.apply, unlift(ApiUser.unapply)) - - def fromDomain(user: User) = ApiUser( - user.id.id, - user.email.value, - user.name, - user.roles.map(UserRole.roleToString).toSeq, - user.latestActivity.map(ZonedDateTime.of(_, ZoneId.of("Z"))) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/UserRole.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/UserRole.scala deleted file mode 100644 index 412a969..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/user/UserRole.scala +++ /dev/null @@ -1,37 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.user - -import xyz.driver.pdsuicommon.domain.User.Role - -object UserRole { - - val roleFromString: PartialFunction[String, Role] = { - case "Cleaner" => Role.RecordCleaner - case "Organizer" => Role.RecordOrganizer - case "Extractor" => Role.DocumentExtractor - case "RecordAdmin" => Role.RecordAdmin - case "TrialSummarizer" => Role.TrialSummarizer - case "CriteriaCurator" => Role.CriteriaCurator - case "TrialAdmin" => Role.TrialAdmin - case "EligibilityVerifier" => Role.EligibilityVerifier - case "TreatmentMatchingAdmin" => Role.TreatmentMatchingAdmin - case "RoutesCurator" => Role.RoutesCurator - case "SystemUser" => Role.SystemUser - case "ResearchOncologist" => Role.ResearchOncologist - // No Mixed at this time - } - - def roleToString(x: Role): String = x match { - case Role.RecordCleaner => "Cleaner" - case Role.RecordOrganizer => "Organizer" - case Role.DocumentExtractor => "Extractor" - case Role.RecordAdmin => "RecordAdmin" - case Role.TrialSummarizer => "TrialSummarizer" - case Role.CriteriaCurator => "CriteriaCurator" - case Role.TrialAdmin => "TrialAdmin" - case Role.EligibilityVerifier => "EligibilityVerifier" - case Role.TreatmentMatchingAdmin => "TreatmentMatchingAdmin" - case Role.RoutesCurator => "RoutesCurator" - case Role.SystemUser => "SystemUser" - case Role.ResearchOncologist => "ResearchOncologist" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala deleted file mode 100644 index 127337f..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/userhistory/ApiUserHistory.scala +++ /dev/null @@ -1,43 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.userhistory - -import java.time.{ZoneId, ZonedDateTime} - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.entities.UserHistory - -final case class ApiUserHistory(id: Long, - executor: String, - recordId: Option[Long], - documentId: Option[Long], - trialId: Option[String], - patientId: Option[String], - state: String, - action: String, - created: ZonedDateTime) - -object ApiUserHistory { - implicit val format: Format[ApiUserHistory] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "executor").format[String] and - (JsPath \ "recordId").formatNullable[Long] and - (JsPath \ "documentId").formatNullable[Long] and - (JsPath \ "trialId").formatNullable[String] and - (JsPath \ "patientId").formatNullable[String] and - (JsPath \ "state").format[String] and - (JsPath \ "action").format[String] and - (JsPath \ "created").format[ZonedDateTime] - )(ApiUserHistory.apply, unlift(ApiUserHistory.unapply)) - - def fromDomain(x: UserHistory) = ApiUserHistory( - id = x.id.id, - executor = x.executor.id, - recordId = x.recordId.map(_.id), - documentId = x.documentId.map(_.id), - trialId = x.trialId.map(_.id), - patientId = x.patientId.map(_.id.toString), - state = UserHistory.State.stateToString(x.state), - action = UserHistory.Action.actionToString(x.action), - created = ZonedDateTime.of(x.created, ZoneId.of("Z")) - ) -} |