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

import spray.json._
import xyz.driver.formats.json.labels._
import xyz.driver.pdsuidomain.entities._
import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial

object patienteligibletrial {
  import DefaultJsonProtocol._
  import common._
  import xyz.driver.pdsuidomain.formats.json.trial._
  import xyz.driver.pdsuidomain.formats.json.patientcriterion._

  def applyUpdateToTrialArmGroup(json: JsValue, orig: PatientTrialArmGroupView): PatientTrialArmGroupView =
    json match {
      case JsObject(fields) =>
        val isVerified = fields.get("group").map(_.asJsObject)
          .flatMap(_.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 patientEligibleArmGroupView: RootJsonFormat[PatientTrialArmGroupView] =
    jsonFormat7(PatientTrialArmGroupView.apply)

  implicit val patientEligibleTrialFormat: RootJsonFormat[RichPatientEligibleTrial] =
    jsonFormat3(RichPatientEligibleTrial.apply)

}