From 54b15dae509212f6661dc1f1bc4ca248cb487443 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Fri, 20 Oct 2017 16:25:04 +0700 Subject: PDSUI-2336 Deleted api classes of play format, userhistory and message services --- .../formats/json/document/ApiDocument.scala | 114 ------------------ .../formats/json/document/ApiDocumentType.scala | 27 ----- .../formats/json/document/ApiPartialDocument.scala | 131 --------------------- .../formats/json/document/ApiProviderType.scala | 27 ----- 4 files changed, 299 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/document') 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 250e650..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala +++ /dev/null @@ -1,114 +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.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], - institutionName: Option[String], - status: Option[String], - previousStatus: Option[String], - assignee: Option[String], - previousAssignee: Option[String], - lastActiveUser: Option[String], - meta: Option[String], - labelVersion: Int) { - - 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), - institutionName = this.institutionName, - meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[Document.Meta](x))), - startDate = this.startDate, - endDate = this.endDate, - lastUpdate = this.lastUpdate.toLocalDateTime(), - labelVersion = this.labelVersion - ) - -} - -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 \ "institutionName").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))) and - (JsPath \ "labelVersion").format[Int] - )(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), - institutionName = document.institutionName, - 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)), - labelVersion = document.labelVersion - ) - } -} 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 22bea6b..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala +++ /dev/null @@ -1,27 +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.pdsuidomain.entities.DocumentType - -final case class ApiDocumentType(id: Long, name: String) { - - def toDomain: DocumentType = - DocumentType - .fromString(name) - .getOrElse(throw new IllegalArgumentException(s"Unknown document type name $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 ecbdaed..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala +++ /dev/null @@ -1,131 +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], - institutionName: Tristate[String], - 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, - institutionName = institutionName.cata(Some(_), None, orig.institutionName), - 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, - labelVersion = orig.labelVersion - ) - - 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, - institutionName = institutionName.toOption, - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption, - previousStatus = None, - assignee = None, - previousAssignee = None, - lastActiveUserId = None, - lastUpdate = LocalDateTime.MIN, - labelVersion = 0 - ) - } 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 \ "institutionName").readTristate[String] 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 \ "institutionName").writeTristate[String] 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 9c0c216..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala +++ /dev/null @@ -1,27 +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.pdsuidomain.entities.ProviderType - -final case class ApiProviderType(id: Long, name: String) { - - def toDomain: ProviderType = - ProviderType - .fromString(name) - .getOrElse(throw new IllegalArgumentException(s"Unknown provider type name $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 - ) -} -- cgit v1.2.3