aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala
blob: 0ef1c681ef40f468ed282c80813349ee5e98a307 (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
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)
  )
}