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
|
package xyz.driver.pdsuidomain.formats.json.sprayformats
import java.time.LocalDateTime
import org.scalatest.{FlatSpec, Matchers}
import spray.json._
import xyz.driver.entities.labels.LabelValue
import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
import xyz.driver.pdsuidomain.entities.{PatientCriterionArm, PatientTrialArmGroupView, Trial}
import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial
class PatientEligibleTrialFormatSuite extends FlatSpec with Matchers {
import patienteligibletrial._
"Json format for PatientEligibleTrial" should "read and write correct JSON" in {
val trial = Trial(
id = StringId("NCT000001"),
externalId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"),
status = Trial.Status.Done,
assignee = None,
previousStatus = None,
previousAssignee = None,
lastActiveUserId = None,
lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"),
phase = "",
hypothesisId = Some(UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4")),
studyDesignId = Some(LongId(321)),
originalStudyDesign = None,
isPartner = false,
overview = None,
overviewTemplate = "",
isUpdated = false,
title = "trial title",
originalTitle = "orig trial title"
)
val group = PatientTrialArmGroupView(
id = LongId(1),
patientId = UuidId("748b5884-3528-4cb9-904b-7a8151d6e343"),
trialId = StringId("NCT000001"),
hypothesisId = UuidId("e76e2fc4-a29c-44fb-a81b-8856d06bb1d4"),
eligibilityStatus = Some(LabelValue.Yes),
verifiedEligibilityStatus = Some(LabelValue.Yes),
isVerified = false
)
val arms = List(
PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(31), armName = "arm 31"),
PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(32), armName = "arm 32")
)
val orig = RichPatientEligibleTrial(trial, group, arms)
val writtenJson = patientEligibleTrialWriter.write(orig)
writtenJson should be(
"""{"id":1,"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","trialId":"NCT000001","trialTitle":"trial title",
"hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","verifiedEligibilityStatus":"Yes","isVerified":false,"arms":["arm 31","arm 32"]}""".parseJson)
val updatePatientEligibleTrialJson = """{"isVerified":true}""".parseJson
val expectedUpdatedPatientTrialArmGroup = group.copy(isVerified = true)
val parsedUpdatePatientTrialArmGroup = applyUpdateToTrialArmGroup(updatePatientEligibleTrialJson, group)
parsedUpdatePatientTrialArmGroup should be(expectedUpdatedPatientTrialArmGroup)
}
}
|