aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala
blob: 9ce281e4de4b3a9a33f32b54485464965909e873 (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._
import xyz.driver.pdsuicommon.domain.FuzzyValue
import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidence

final case class ApiExportPatientLabelEvidence(evidenceId: String,
                                               labelValue: String,
                                               evidenceText: String,
                                               document: ApiExportPatientLabelEvidenceDocument)

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)
  )
}