aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
blob: d719c5c194c570fe8362b9ae96248747c0495bac (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
package xyz.driver.pdsuidomain.formats.json

import spray.json._
import xyz.driver.formats.json.labels._
import xyz.driver.pdsuidomain.entities._

object patienteligibletrial {
  import DefaultJsonProtocol._
  import common._

  def applyUpdateToTrialArmGroup(json: JsValue, orig: PatientTrialArmGroupView): PatientTrialArmGroupView =
    json match {
      case JsObject(fields) =>
        val isVerified = fields
          .get("isVerified")
          .map(_.convertTo[Boolean])
          .getOrElse(orig.isVerified)

        orig.copy(isVerified = isVerified)

      case _ => deserializationError(s"Expected Json Object as partial PatientTrialArmGroupView, but got $json")
    }

  implicit val patientEligibleTrialWriter: RootJsonWriter[RichPatientEligibleTrial] =
    new RootJsonWriter[RichPatientEligibleTrial] {
      override def write(obj: RichPatientEligibleTrial) =
        JsObject(
          "id"                        -> obj.group.id.toJson,
          "patientId"                 -> obj.group.patientId.toJson,
          "trialId"                   -> obj.group.trialId.toJson,
          "trialTitle"                -> obj.trial.title.toJson,
          "arms"                      -> obj.arms.map(_.armName).toJson,
          "hypothesisId"              -> obj.trial.hypothesisId.toJson,
          "verifiedEligibilityStatus" -> obj.group.verifiedEligibilityStatus.toJson,
          "isVerified"                -> obj.group.isVerified.toJson
        )
    }

}