aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/ExportFormatSuite.scala
blob: 9c53d3b0496c2b55139a3d01452424a482705598 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package xyz.driver.pdsuidomain.formats.json

import java.time.{LocalDate, LocalDateTime}

import org.scalatest.{FlatSpec, Matchers}
import spray.json._
import xyz.driver.core.Id
import xyz.driver.entities.clinic.ClinicalRecord
import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
import xyz.driver.pdsuidomain.entities.{DocumentType, ProviderType}

class ExportFormatSuite extends FlatSpec with Matchers {
  import xyz.driver.pdsuidomain.formats.json.export._

  "Json format for ExportPatientWithLabels" should "read and write correct JSON" in {
    import xyz.driver.pdsuidomain.entities.export.patient._
    val document = ExportPatientLabelEvidenceDocument(
      documentId = LongId(101),
      requestId = Id[ClinicalRecord]("7b54a75d-4197-4b27-9045-b9b6cb131be9"),
      documentType = DocumentType.OutpatientPhysicianNote,
      providerType = ProviderType.Surgery,
      date = LocalDate.parse("2017-08-10")
    )

    val labels = List(
      ExportPatientLabel(
        id = LongId(1),
        evidences = List(
          ExportPatientLabelEvidence(
            id = LongId(11),
            value = LabelValue.Yes,
            evidenceText = "evidence text 11",
            document = document
          ),
          ExportPatientLabelEvidence(
            id = LongId(12),
            value = LabelValue.No,
            evidenceText = "evidence text 12",
            document = document
          )
        )
      ),
      ExportPatientLabel(
        id = LongId(2),
        evidences = List(
          ExportPatientLabelEvidence(
            id = LongId(12),
            value = LabelValue.Yes,
            evidenceText = "evidence text 12",
            document = document
          ),
          ExportPatientLabelEvidence(
            id = LongId(13),
            value = LabelValue.Yes,
            evidenceText = "evidence text 13",
            document = document
          )
        )
      )
    )
    val patientWithLabels = ExportPatientWithLabels(
      patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
      labelVersion = 1L,
      labels = labels
    )

    val writtenJson = patientWithLabelsFormat.write(patientWithLabels)
    writtenJson should be(
      """{"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","labelVersion":1,"labels":[{"labelId":1,"evidence":[{"evidenceId":11,
         "labelValue":"Yes","evidenceText":"evidence text 11","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
         "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}},
        {"evidenceId":12,"labelValue":"No","evidenceText":"evidence text 12","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
         "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}}]},
        {"labelId":2,"evidence":[{"evidenceId":12,"labelValue":"Yes","evidenceText":"evidence text 12","document":
        {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"Outpatient Physician Note"},
        "providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}},{"evidenceId":13,"labelValue":"Yes","evidenceText":"evidence text 13",
        "document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"Outpatient Physician Note"},
        "providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}}]}]}""".parseJson)
  }

  "Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in {
    import xyz.driver.pdsuidomain.entities.export.trial._
    val arms = List(
      ExportTrialArm(armId = LongId(1), armName = "arm 1", diseaseList = Seq("Breast")),
      ExportTrialArm(armId = LongId(2), armName = "arm 2", diseaseList = Seq("Breast"))
    )
    val criteriaList = List(
      ExportTrialLabelCriterion(
        criterionId = LongId(10),
        value = Some(true),
        labelId = LongId(21),
        armIds = Set(LongId(1), LongId(2)),
        criteria = "criteria 10 text",
        isCompound = false,
        isDefining = false,
        inclusion = Some(false)
      ),
      ExportTrialLabelCriterion(
        criterionId = LongId(11),
        value = None,
        labelId = LongId(21),
        armIds = Set(LongId(2)),
        criteria = "criteria 11 text",
        isCompound = true,
        isDefining = false,
        inclusion = None
      )
    )
    val trialWithLabels = ExportTrialWithLabels(
      nctId = StringId("NCT000001"),
      trialId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"),
      lastReviewed = LocalDateTime.parse("2017-08-10T18:00:00"),
      labelVersion = 1L,
      arms = arms,
      criteria = criteriaList
    )

    val writtenJson = trialWithLabelsFormat.write(trialWithLabels)
    writtenJson should be(
      """{"nctId":"NCT000001","trialId":"40892a07-c638-49d2-9795-1edfefbbcc7c","lastReviewed":"2017-08-10T18:00Z",
        "labelVersion":1,"arms":[{"armId":1,"armName":"arm 1","diseaseList":["Breast"]},{"armId":2,"armName":"arm 2","diseaseList":["Breast"]}],"criteria":[
        {"value":"Yes","labelId":21,"criterionId":10,"criterionText":"criteria 10 text","armIds":[1,2],"isCompound":false,
        "isDefining":false,"inclusion":false},
        {"value":"Unknown","labelId":21,"criterionId":11,"criterionText":"criteria 11 text","armIds":[2],"isCompound":true,
        "isDefining":false,"inclusion":null}]}""".parseJson)
  }

}