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
|
package xyz.driver.pdsuidomain.formats.json.sprayformats
import spray.json._
import xyz.driver.entities.labels.Label
import xyz.driver.pdsuidomain.entities.{Arm, Criterion}
import xyz.driver.pdsuidomain.entities.export.patient._
import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels}
import xyz.driver.formats.json.labels._
object export {
import DefaultJsonProtocol._
import common._
import record._
import document._
implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] =
jsonFormat5(ExportPatientLabelEvidenceDocument.apply)
implicit val patientLabelEvidenceFormat: RootJsonFormat[ExportPatientLabelEvidence] =
jsonFormat(ExportPatientLabelEvidence.apply, "evidenceId", "labelValue", "evidenceText", "document")
implicit val patientLabelFormat: RootJsonFormat[ExportPatientLabel] =
jsonFormat(ExportPatientLabel.apply, "labelId", "evidence")
implicit val patientWithLabelsFormat: RootJsonFormat[ExportPatientWithLabels] =
jsonFormat(ExportPatientWithLabels.apply, "patientId", "labelVersion", "labels")
implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat2(ExportTrialArm.apply)
implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] =
new RootJsonFormat[ExportTrialLabelCriterion] {
override def write(obj: ExportTrialLabelCriterion): JsValue =
JsObject(
"value" -> obj.value
.map {
case true => "Yes"
case false => "No"
}
.getOrElse("Unknown")
.toJson,
"labelId" -> obj.labelId.toJson,
"criterionId" -> obj.criterionId.toJson,
"criterionText" -> obj.criteria.toJson,
"armIds" -> obj.armIds.toJson,
"isCompound" -> obj.isCompound.toJson,
"isDefining" -> obj.isDefining.toJson
)
override def read(json: JsValue): ExportTrialLabelCriterion = {
val fields = Seq("value", "labelId", "criterionId", "criterionText", "armIds", "isCompound", "isDefining")
json.asJsObject.getFields(fields: _*) match {
case Seq(JsString(valueString),
labelId,
criterionId,
JsString(criterionText),
JsArray(armIdsVector),
JsBoolean(isCompound),
JsBoolean(isDefining)) =>
val value = valueString match {
case "Yes" => Option(true)
case "No" => Option(false)
case "Unknown" => Option.empty[Boolean]
}
ExportTrialLabelCriterion(
longIdFormat[Criterion].read(criterionId),
value,
longIdFormat[Label].read(labelId),
armIdsVector.map(longIdFormat[Arm].read).toSet,
criterionText,
isCompound,
isDefining
)
case _ =>
deserializationError(
s"Cannot find required fields ${fields.mkString(", ")} in ExportTrialLabelCriterion object!")
}
}
}
implicit val trialWithLabelsFormat: RootJsonFormat[ExportTrialWithLabels] =
jsonFormat(ExportTrialWithLabels.apply,
"nctId",
"trialId",
"disease",
"lastReviewed",
"labelVersion",
"arms",
"criteria")
}
|