aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/patientissue/ApiPatientIssue.scala
blob: 7e0b174724388fe43c879ce5379513ead5a25345 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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,
                                 evidence: String,
                                 archiveRequired: Boolean,
                                 meta: String)

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 \ "evidence").format[String] and
      (JsPath \ "archiveRequired").format[Boolean] and
      (JsPath \ "meta").format[String](Format(Reads { x =>
        JsSuccess(Json.stringify(x))
      }, Writes[String](Json.parse)))
  )(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,
    evidence = x.evidence,
    archiveRequired = x.archiveRequired,
    meta = x.meta
  )
}