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

}