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
|
package xyz.driver.pdsuidomain
import java.time.{LocalDate, LocalDateTime}
import java.time.temporal.ChronoUnit
import xyz.driver.pdsuicommon.BaseSuite
import xyz.driver.pdsuicommon.domain.{LongId, TextJson}
import xyz.driver.pdsuidomain.entities.Document
class DocumentSuite extends BaseSuite {
"validation" - {
"can't submit invalid data" - {
val base = sampleDocument
val now = LocalDate.now()
val past1 = now.minus(2, ChronoUnit.DAYS)
val past2 = past1.plus(1, ChronoUnit.DAYS)
val future1 = now.plus(1, ChronoUnit.DAYS)
val future2 = future1.plus(1, ChronoUnit.DAYS)
Seq(
"startDate should be non-empty" -> base.copy(startDate = None),
"startDate should be greater, than endDate" -> base.copy(startDate = Some(past2), endDate = Some(past1)),
"startDate and endDate should be in the past" -> base.copy(startDate = Some(future1), endDate = Some(future2))
).foreach {
case (title, orig) =>
s"$title" in {
val r = Document.validator(orig)
assert(r.isLeft, s"should fail, but: ${r.right}")
}
}
}
}
"getRequiredType" - {
"getOPNType" in {
val documentForOPNType = sampleDocument.copy(
typeId = Some(LongId(1L)),
providerTypeId = Some(LongId(1L)),
startDate = Some(LocalDate.now().minus(2, ChronoUnit.DAYS))
)
val r = documentForOPNType.getRequiredType("Outpatient Physician Note", "Medical Oncology")
assert(r.contains(Document.RequiredType.OPN), s"document should have the requiredType=OPN, but:$r")
}
"getPNType" in {
val documentForPNType = sampleDocument.copy(
typeId = Some(LongId(6))
)
val r = documentForPNType.getRequiredType("Pathology Report", "")
assert(r.contains(Document.RequiredType.PN), s"document should have the requiredType=PN, but:$r")
}
"get None" in {
val document = sampleDocument.copy(
typeId = Some(LongId(1L)),
providerTypeId = Some(LongId(1L)),
startDate = Some(LocalDate.now().minus(7, ChronoUnit.MONTHS))
)
val r = document.getRequiredType("Outpatient Physician Note", "Medical Oncology")
assert(r.isEmpty, s"document should have the requiredType=None, but:$r")
}
}
private def sampleDocument = {
val lastUpdate = LocalDateTime.now()
Document(
id = LongId(2002),
status = Document.Status.New,
previousStatus = None,
assignee = None,
previousAssignee = None,
lastActiveUserId = None,
recordId = LongId(2003),
physician = None,
typeId = Some(LongId(123)),
providerName = Some("etst"),
providerTypeId = Some(LongId(123)),
requiredType = None,
institutionName = Some("institution name"),
startDate = Some(lastUpdate.toLocalDate.minusDays(2)),
endDate = None,
lastUpdate = lastUpdate,
meta = Some(TextJson(Document.Meta(1.1, 2.2)))
)
}
}
|