diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-08-04 17:57:12 +0600 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-08-11 14:41:17 +0600 |
commit | ef9517e1b8f599fbdd15c474cf7dfea61e803c2f (patch) | |
tree | c31a139d35dab0c10c70bb7afef2bca8e48f0fee /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala | |
parent | 5519c219e2404cb19b6116dee90b40b5e5e2a720 (diff) | |
download | rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.gz rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.tar.bz2 rest-query-ef9517e1b8f599fbdd15c474cf7dfea61e803c2f.zip |
PDSUI-2188 Created and fixed spray json formats for tric and rep
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala new file mode 100644 index 0000000..ff7593f --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala @@ -0,0 +1,64 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion + +object patientcriterion { + import DefaultJsonProtocol._ + import common._ + + def applyUpdateToPatientCriterion(json: JsValue, orig: PatientCriterion): PatientCriterion = json match { + case JsObject(fields) => + val eligibilityStatus = if (fields.contains("eligibilityStatus")) { + fields + .get("eligibilityStatus") + .map(_.convertTo[FuzzyValue]) + } else orig.eligibilityStatus + + val verifiedEligibilityStatus = if (fields.contains("verifiedEligibilityStatus")) { + fields + .get("verifiedEligibilityStatus") + .map(_.convertTo[FuzzyValue]) + } else orig.verifiedEligibilityStatus + + orig.copy( + eligibilityStatus = eligibilityStatus, + verifiedEligibilityStatus = verifiedEligibilityStatus + ) + + case _ => deserializationError(s"Expected Json Object as partial PatientCriterion, but got $json") + } + + implicit val patientCriterionFormat: RootJsonFormat[DraftPatientCriterion] = jsonFormat3(DraftPatientCriterion.apply) + + implicit val patientCriterionWriter: JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] = + new JsonWriter[(PatientCriterion, LongId[Label], List[PatientCriterionArm])] { + override def write(obj: (PatientCriterion, LongId[Label], List[PatientCriterionArm])): JsValue = { + val criterion = obj._1 + val labelId = obj._2 + val arms = obj._3 + JsObject( + "id" -> criterion.id.toJson, + "labelId" -> labelId.toJson, + "nctId" -> criterion.nctId.toJson, + "criterionId" -> criterion.criterionId.toJson, + "criterionText" -> criterion.criterionText.toJson, + "criterionValue" -> criterion.criterionValue.map { + case true => "Yes" + case false => "No" + }.toJson, + "criterionIsDefining" -> criterion.criterionIsDefining.toJson, + "criterionIsCompound" -> criterion.criterionValue.isEmpty.toJson, + "arms" -> arms.map(_.armName).toJson, + "eligibilityStatus" -> criterion.eligibilityStatus.toJson, + "verifiedEligibilityStatus" -> criterion.verifiedEligibilityStatus.toJson, + "isVerified" -> criterion.isVerified.toJson, + "isVisible" -> criterion.isVisible.toJson, + "lastUpdate" -> criterion.lastUpdate.toJson + ) + } + } + +} |