diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/document')
3 files changed, 16 insertions, 30 deletions
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 index 0fd96b3..73b6166 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocument.scala @@ -17,18 +17,20 @@ final case class ApiDocument(id: Long, endDate: Option[LocalDate], provider: Option[String], providerTypeId: Option[Long], + requiredType: Option[String], status: Option[String], previousStatus: Option[String], assignee: Option[Long], previousAssignee: Option[Long], + lastActiveUser: Option[Long], meta: Option[String]) object ApiDocument { private val statusFormat = Format( Reads.StringReads.filter(ValidationError("unknown status")) { - case x if DocumentUtils.statusFromString.isDefinedAt(x) => true - case _ => false + case x if Document.RequiredType.fromString.isDefinedAt(x) => true + case _ => false }, Writes.StringWrites ) @@ -43,10 +45,12 @@ object ApiDocument { (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[Long] and (JsPath \ "previousAssignee").formatNullable[Long] and + (JsPath \ "lastActiveUser").formatNullable[Long] and (JsPath \ "meta").formatNullable(Format(Reads { x => JsSuccess(Json.stringify(x)) }, Writes[String](Json.parse))) @@ -63,10 +67,12 @@ object ApiDocument { endDate = document.endDate, provider = document.providerName, providerTypeId = document.providerTypeId.map(_.id), - status = Option(DocumentUtils.statusToString(document.status)), - previousStatus = document.previousStatus.map(DocumentUtils.statusToString), + 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/ApiPartialDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala index 7682bb5..84e9e09 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiPartialDocument.scala @@ -31,15 +31,17 @@ final case class ApiPartialDocument(recordId: Option[Long], def applyTo(orig: Document): Document = Document( id = orig.id, - status = status.map(DocumentUtils.statusFromString).getOrElse(orig.status), + status = status.map(Document.Status.fromString).getOrElse(orig.status), previousStatus = orig.previousStatus, assignee = assignee.map(LongId[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), @@ -64,10 +66,12 @@ final case class ApiPartialDocument(recordId: Option[Long], 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 { @@ -87,7 +91,7 @@ object ApiPartialDocument { (JsPath \ "provider").readTristate[String] and (JsPath \ "providerTypeId").readTristate[Long] and (JsPath \ "status").readNullable[String](Reads.of[String].filter(ValidationError("unknown status"))({ - case x if DocumentUtils.statusFromString.isDefinedAt(x) => true + case x if Document.Status.fromString.isDefinedAt(x) => true case _ => false })) and (JsPath \ "assignee").readTristate[Long] and diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/DocumentUtils.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/DocumentUtils.scala deleted file mode 100644 index 24e388e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/DocumentUtils.scala +++ /dev/null @@ -1,24 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.document - -import xyz.driver.pdsuidomain.entities.Document.Status - -object DocumentUtils { - - val statusFromString: PartialFunction[String, Status] = { - case "New" => Status.New - case "Organized" => Status.Organized - case "Extracted" => Status.Extracted - 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.Organized => "Organized" - case Status.Extracted => "Extracted" - case Status.Done => "Done" - case Status.Flagged => "Flagged" - case Status.Archived => "Archived" - } -} |