aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientLabelFormatSuite.scala
blob: 9340d02b769f0cc59617814918061139b2b7e0e6 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package xyz.driver.pdsuidomain.formats.json

import java.time.LocalDate

import spray.json._
import org.scalatest.{FlatSpec, Matchers}
import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
import xyz.driver.pdsuidomain.entities._

class PatientLabelFormatSuite extends FlatSpec with Matchers {

  "Json format for RichPatientLabel" should "read and write correct JSON" in {
    import xyz.driver.pdsuidomain.formats.json.patientlabel._
    val orig = PatientLabel(
      id = LongId(1),
      patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
      labelId = LongId(20),
      primaryValue = LabelValue.Yes,
      verifiedPrimaryValue = LabelValue.Unknown,
      isVisible = true,
      score = 1,
      isImplicitMatch = false
    )
    val writtenJson = richPatientLabelFormat.write(RichPatientLabel(orig, isVerified = true))

    writtenJson should be(
      """{"id":1,"labelId":20,"primaryValue":"Yes","isVisible":true,"isVerified":true,"verifiedPrimaryValue":"Unknown",
        "score":1,"isImplicitMatch":false, "patientId":"748b5884-3528-4cb9-904b-7a8151d6e343"}""".parseJson)

    val updatePatientLabelJson      = """{"verifiedPrimaryValue":"No"}""".parseJson
    val expectedUpdatedPatientLabel = orig.copy(verifiedPrimaryValue = LabelValue.No)
    val parsedUpdatePatientLabel    = applyUpdateToPatientLabel(updatePatientLabelJson, orig)
    parsedUpdatePatientLabel should be(expectedUpdatedPatientLabel)
  }

  "Json format for PatientLabelEvidence" should "read and write correct JSON" in {
    import xyz.driver.pdsuidomain.formats.json.patientlabel._
    val orig = PatientLabelEvidenceView(
      id = LongId(1),
      value = LabelValue.Maybe,
      evidenceText = "evidence text",
      documentId = Some(LongId(21)),
      evidenceId = Some(LongId(10)),
      reportId = None,
      documentType = DocumentType.LaboratoryReport,
      date = Some(LocalDate.parse("2017-08-10")),
      providerType = ProviderType.EmergencyMedicine,
      patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
      labelId = LongId(20),
      isImplicitMatch = false
    )
    val writtenJson = patientLabelEvidenceWriter.write(orig)

    writtenJson should be(
      """{"id":1,"value":"Maybe","evidenceText":"evidence text","documentId":21,"evidenceId":10,"reportId":null,
        "documentType":{"id":3,"name":"Laboratory Report"},"date":"2017-08-10",
        "providerType":{"id":26,"name":"Emergency Medicine"}}""".parseJson)
  }

  "Json format for PatientLabelDefiningCriteria" should "read and write correct JSON" in {
    import xyz.driver.pdsuidomain.formats.json.patientdefiningcriteria._
    val orig = PatientLabel(
      id = LongId(1),
      patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
      labelId = LongId(20),
      primaryValue = LabelValue.Yes,
      verifiedPrimaryValue = LabelValue.Yes,
      isVisible = true,
      score = 1,
      isImplicitMatch = false
    )
    val writtenJson = patientLabelDefiningCriteriaWriter.write(orig)

    writtenJson should be("""{"id":1,"value":"Yes"}""".parseJson)
  }

}