diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats')
17 files changed, 146 insertions, 129 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala new file mode 100644 index 0000000..2a670c4 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ListResponse.scala @@ -0,0 +1,39 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import java.time.LocalDateTime + +import spray.json.{RootJsonFormat, _} +import xyz.driver.pdsuicommon.db.Pagination +import xyz.driver.pdsuidomain.formats.json.sprayformats.common._ + +final case class ListResponse[+T](items: Seq[T], meta: ListResponse.Meta) + +object ListResponse extends DefaultJsonProtocol { + private val itemsField = "items" + private val metaField = "meta" + + final case class Meta(itemsCount: Int, pageNumber: Int, pageSize: Int, lastUpdate: Option[LocalDateTime]) + + object Meta { + def apply(itemsCount: Int, pagination: Pagination, lastUpdate: Option[LocalDateTime]): Meta = { + Meta( + itemsCount, + pagination.pageNumber, + pagination.pageSize, + lastUpdate + ) + } + } + + implicit val listResponseMetaFormat: RootJsonFormat[Meta] = jsonFormat4(Meta.apply) + + implicit def listResponseMetaWriter[T: JsonWriter]: RootJsonWriter[ListResponse[T]] = + new RootJsonWriter[ListResponse[T]] { + override def write(listResponse: ListResponse[T]): JsValue = { + JsObject( + itemsField -> listResponse.items.map(_.toJson).toJson, + metaField -> listResponse.meta.toJson + ) + } + } +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala index dbd0a43..61e0e7f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/common.scala @@ -3,7 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import java.time.{LocalDate, LocalDateTime, ZoneId, ZonedDateTime} import spray.json._ -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} +import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} object common { @@ -55,14 +55,6 @@ object common { } } - implicit def fuzzyValueFormat: RootJsonFormat[FuzzyValue] = new RootJsonFormat[FuzzyValue] { - override def write(value: FuzzyValue): JsString = JsString(FuzzyValue.valueToString(value)) - override def read(json: JsValue): FuzzyValue = json match { - case JsString(value) => FuzzyValue.fromString(value) - case _ => deserializationError(s"Expected value as FuzzyValue, but got $json") - } - } - implicit val integerFormat: RootJsonFormat[Integer] = new RootJsonFormat[Integer] { override def write(obj: Integer): JsNumber = JsNumber(obj.intValue()) override def read(json: JsValue): Integer = json match { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala index 7526d9c..a43e92a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala @@ -10,7 +10,7 @@ object criterion { import DefaultJsonProtocol._ import common._ - implicit val criterionLabelWriter = new JsonWriter[CriterionLabel] { + implicit val criterionLabelWriter = new RootJsonWriter[CriterionLabel] { override def write(obj: CriterionLabel) = JsObject( "labelId" -> obj.labelId.toJson, "categoryId" -> obj.categoryId.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index e3f6a9c..69e8b75 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala @@ -26,7 +26,7 @@ object document { "PN" -> RequiredType.PN ) - implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply) + implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat2(Meta.apply) implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] { override def read(json: JsValue): DocumentType = json match { @@ -40,7 +40,7 @@ object document { .fromString(name) .getOrElse(deserializationError(s"Unknown document type: $name")) - case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") + case _ => deserializationError(s"Expected Json Object as Document type, but got $json") } override def write(obj: DocumentType) = @@ -73,6 +73,11 @@ object document { .map(_.convertTo[Option[LongId[ProviderType]]]) .getOrElse(orig.providerTypeId) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[Option[String]]) + .getOrElse(orig.institutionName) + val meta = fields .get("meta") .map(_.convertTo[Option[TextJson[Meta]]]) @@ -93,6 +98,7 @@ object document { typeId = typeId, providerName = provider, providerTypeId = providerTypeId, + institutionName = institutionName, meta = meta, startDate = startDate, endDate = endDate @@ -111,6 +117,7 @@ object document { "provider" -> document.providerName.toJson, "providerTypeId" -> document.providerTypeId.toJson, "requiredType" -> document.requiredType.toJson, + "institutionName" -> document.institutionName.toJson, "startDate" -> document.startDate.toJson, "endDate" -> document.endDate.toJson, "status" -> document.status.toJson, @@ -145,6 +152,10 @@ object document { .get("providerTypeId") .map(_.convertTo[LongId[ProviderType]]) + val institutionName = fields + .get("institutionName") + .map(_.convertTo[String]) + val meta = fields .get("meta") .map(_.convertTo[TextJson[Meta]]) @@ -168,6 +179,7 @@ object document { providerName = provider, providerTypeId = providerTypeId, requiredType = None, + institutionName = institutionName, meta = meta, previousStatus = None, assignee = None, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala index b836e1c..3c2465f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala @@ -21,7 +21,7 @@ object eligibility { implicit val clinicalDocumentFormat: RootJsonFormat[ClinicalEvidenceDocument] = jsonFormat7(ClinicalEvidenceDocument) implicit val evidenceDocumentFormat: RootJsonFormat[EvidenceDocument] = - GadtJsonFormat.create[EvidenceDocument]("documentType") { + GadtJsonFormat.create[EvidenceDocument]("evidenceDocumentType") { case _: MolecularEvidenceDocument => "Molecular" case _: ClinicalEvidenceDocument => "Clinical" } { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala index 39d5c59..1c4b6b4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala @@ -2,15 +2,16 @@ 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.formats.json.labels._ import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} +import xyz.driver.pdsuidomain.entities.{Criterion, EligibilityArm} object export { import DefaultJsonProtocol._ import common._ - import record._ import document._ + import record._ implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5(ExportPatientLabelEvidenceDocument.apply) @@ -67,7 +68,7 @@ object export { longIdFormat[Criterion].read(criterionId), value, longIdFormat[Label].read(labelId), - armIdsVector.map(longIdFormat[Arm].read).toSet, + armIdsVector.map(longIdFormat[EligibilityArm].read).toSet, criterionText, isCompound, isDefining @@ -81,12 +82,5 @@ object export { } implicit val trialWithLabelsFormat: RootJsonFormat[ExportTrialWithLabels] = - jsonFormat(ExportTrialWithLabels.apply, - "nctId", - "trialId", - "disease", - "lastReviewed", - "labelVersion", - "arms", - "criteria") + jsonFormat(ExportTrialWithLabels.apply, "nctId", "trialId", "lastReviewed", "labelVersion", "arms", "criteria") } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala index d6eadbd..5d5585a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala @@ -1,10 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.entities.labels.{Label, LabelCategory} -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} +import xyz.driver.entities.labels.{Label, LabelCategory, LabelValue} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData +import xyz.driver.formats.json.labels._ object extracteddata { import DefaultJsonProtocol._ @@ -44,7 +45,7 @@ object extracteddata { val value = fields .get("value") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) ExtractedDataLabel( id = LongId(0), diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala index 724c391..2b0dfe5 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patient.scala @@ -3,6 +3,8 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.core.json.EnumJsonFormat import xyz.driver.pdsuidomain.entities._ +import xyz.driver.formats.json.common._ +import xyz.driver.formats.json.patient._ object patient { import DefaultJsonProtocol._ @@ -26,7 +28,7 @@ object patient { } } - implicit val patientWriter: JsonWriter[Patient] = new JsonWriter[Patient] { + implicit val patientWriter: RootJsonWriter[Patient] = new RootJsonWriter[Patient] { override def write(patient: Patient): JsValue = JsObject( "id" -> patient.id.toJson, @@ -38,7 +40,7 @@ object patient { "previousAssignee" -> patient.previousAssignee.toJson, "lastActiveUser" -> patient.lastActiveUserId.toJson, "lastUpdate" -> patient.lastUpdate.toJson, - "condition" -> patient.condition.toJson, + "disease" -> patient.disease.toJson, "orderId" -> patient.orderId.toJson ) } 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 index b091746..7e8c220 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala @@ -1,10 +1,10 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.entities.labels.Label -import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId} +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion +import xyz.driver.pdsuidomain.services.PatientCriterionService.{DraftPatientCriterion, RichPatientCriterion} +import xyz.driver.formats.json.labels._ object patientcriterion { import DefaultJsonProtocol._ @@ -15,13 +15,13 @@ object patientcriterion { val eligibilityStatus = if (fields.contains("eligibilityStatus")) { fields .get("eligibilityStatus") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) } else orig.eligibilityStatus val verifiedEligibilityStatus = if (fields.contains("verifiedEligibilityStatus")) { fields .get("verifiedEligibilityStatus") - .map(_.convertTo[FuzzyValue]) + .map(_.convertTo[LabelValue]) } else orig.verifiedEligibilityStatus orig.copy( @@ -38,30 +38,27 @@ object patientcriterion { override def read(json: JsValue) = json.convertTo[List[JsValue]].map(_.convertTo[DraftPatientCriterion]) } - 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 + implicit val patientCriterionWriter: RootJsonWriter[RichPatientCriterion] = + new RootJsonWriter[RichPatientCriterion] { + override def write(obj: RichPatientCriterion): JsValue = { JsObject( - "id" -> criterion.id.toJson, - "labelId" -> labelId.toJson, - "nctId" -> criterion.nctId.toJson, - "criterionId" -> criterion.criterionId.toJson, - "criterionText" -> criterion.criterionText.toJson, - "criterionValue" -> criterion.criterionValue.map { + "id" -> obj.patientCriterion.id.toJson, + "labelId" -> obj.labelId.toJson, + "nctId" -> obj.patientCriterion.nctId.toJson, + "criterionId" -> obj.patientCriterion.criterionId.toJson, + "criterionText" -> obj.patientCriterion.criterionText.toJson, + "criterionValue" -> obj.patientCriterion.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 + "criterionIsDefining" -> obj.patientCriterion.criterionIsDefining.toJson, + "criterionIsCompound" -> obj.patientCriterion.criterionValue.isEmpty.toJson, + "arms" -> obj.armList.map(_.armName).toJson, + "eligibilityStatus" -> obj.patientCriterion.eligibilityStatus.toJson, + "verifiedEligibilityStatus" -> obj.patientCriterion.verifiedEligibilityStatus.toJson, + "isVerified" -> obj.patientCriterion.isVerified.toJson, + "isVisible" -> obj.patientCriterion.isVisible.toJson, + "lastUpdate" -> obj.patientCriterion.lastUpdate.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala index b97570a..746c7b4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientdefiningcriteria.scala @@ -2,12 +2,13 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities.PatientLabel +import xyz.driver.formats.json.labels._ object patientdefiningcriteria { import DefaultJsonProtocol._ import common._ - implicit val patientLabelDefiningCriteriaWriter: JsonWriter[PatientLabel] = new JsonWriter[PatientLabel] { + implicit val patientLabelDefiningCriteriaWriter: RootJsonWriter[PatientLabel] = new RootJsonWriter[PatientLabel] { override def write(obj: PatientLabel) = JsObject( "id" -> obj.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala index 894e453..342d3a8 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienteligibletrial.scala @@ -3,6 +3,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEligibleTrial +import xyz.driver.formats.json.labels._ object patienteligibletrial { import DefaultJsonProtocol._ @@ -21,8 +22,8 @@ object patienteligibletrial { case _ => deserializationError(s"Expected Json Object as partial PatientTrialArmGroupView, but got $json") } - implicit val patientEligibleTrialWriter: JsonWriter[RichPatientEligibleTrial] = - new JsonWriter[RichPatientEligibleTrial] { + implicit val patientEligibleTrialWriter: RootJsonWriter[RichPatientEligibleTrial] = + new RootJsonWriter[RichPatientEligibleTrial] { override def write(obj: RichPatientEligibleTrial) = JsObject( "id" -> obj.group.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala index 4f2783c..b8c0058 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patienthypothesis.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.PatientHypothesisService.RichPatientHypothesis object patienthypothesis { import DefaultJsonProtocol._ @@ -18,18 +19,29 @@ object patienthypothesis { case _ => deserializationError(s"Expected Json Object as partial PatientHypothesis, but got $json") } - implicit val patientHypothesisWriter: JsonWriter[(PatientHypothesis, Boolean)] = - new JsonWriter[(PatientHypothesis, Boolean)] { - override def write(obj: (PatientHypothesis, Boolean)): JsValue = { - val patientHypothesis = obj._1 - val isRationaleRequired = obj._2 + implicit val richPatientHypothesisWriter: RootJsonWriter[RichPatientHypothesis] = + new RootJsonWriter[RichPatientHypothesis] { + override def write(obj: RichPatientHypothesis): JsValue = { JsObject( - "id" -> patientHypothesis.id.toJson, - "patientId" -> patientHypothesis.patientId.toJson, - "hypothesisId" -> patientHypothesis.hypothesisId.toJson, - "matchedTrials" -> patientHypothesis.matchedTrials.toJson, - "rationale" -> patientHypothesis.rationale.toJson, - "isRationaleRequired" -> isRationaleRequired.toJson + "id" -> obj.patientHypothesis.id.toJson, + "patientId" -> obj.patientHypothesis.patientId.toJson, + "hypothesisId" -> obj.patientHypothesis.hypothesisId.toJson, + "matchedTrials" -> obj.patientHypothesis.matchedTrials.toJson, + "rationale" -> obj.patientHypothesis.rationale.toJson, + "isRationaleRequired" -> obj.isRequired.toJson + ) + } + } + + implicit val patientHypothesisWriter: RootJsonWriter[PatientHypothesis] = + new RootJsonWriter[PatientHypothesis] { + override def write(obj: PatientHypothesis): JsValue = { + JsObject( + "id" -> obj.id.toJson, + "patientId" -> obj.patientId.toJson, + "hypothesisId" -> obj.hypothesisId.toJson, + "matchedTrials" -> obj.matchedTrials.toJson, + "rationale" -> obj.rationale.toJson ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala index 7d35bd1..d325a53 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientissue.scala @@ -40,7 +40,7 @@ object patientissue { } - implicit val patientIssueWriter = new JsonWriter[PatientIssue] { + implicit val patientIssueWriter = new RootJsonWriter[PatientIssue] { override def write(obj: PatientIssue) = JsObject( "id" -> obj.id.toJson, "text" -> obj.text.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala index 3b52833..57dca1e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientlabel.scala @@ -1,8 +1,12 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.pdsuicommon.domain.FuzzyValue +import xyz.driver.entities.labels.LabelValue import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.services.PatientLabelService.RichPatientLabel +import xyz.driver.formats.json.labels._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.record._ +import xyz.driver.pdsuidomain.formats.json.sprayformats.document._ object patientlabel { import DefaultJsonProtocol._ @@ -12,12 +16,12 @@ object patientlabel { case JsObject(fields) => val primaryValue = fields .get("primaryValue") - .map(_.convertTo[Option[FuzzyValue]]) + .map(_.convertTo[Option[LabelValue]]) .getOrElse(orig.primaryValue) val verifiedPrimaryValue = fields .get("verifiedPrimaryValue") - .map(_.convertTo[Option[FuzzyValue]]) + .map(_.convertTo[Option[LabelValue]]) .getOrElse(orig.verifiedPrimaryValue) orig.copy( @@ -28,25 +32,23 @@ object patientlabel { case _ => deserializationError(s"Expected Json Object as PatientLabel, but got $json") } - implicit val patientLabelWriter: JsonWriter[(PatientLabel, Boolean)] = new JsonWriter[(PatientLabel, Boolean)] { - override def write(obj: (PatientLabel, Boolean)): JsValue = { - val patientLabel = obj._1 - val isVerified = obj._2 + implicit val richPatientLabelWriter: RootJsonWriter[RichPatientLabel] = new RootJsonWriter[RichPatientLabel] { + override def write(obj: RichPatientLabel): JsValue = { JsObject( - "id" -> patientLabel.id.toJson, - "labelId" -> patientLabel.labelId.toJson, - "primaryValue" -> patientLabel.primaryValue.toJson, - "verifiedPrimaryValue" -> patientLabel.verifiedPrimaryValue.toJson, - "score" -> patientLabel.score.toJson, - "isImplicitMatch" -> patientLabel.isImplicitMatch.toJson, - "isVisible" -> patientLabel.isVisible.toJson, - "isVerified" -> isVerified.toJson + "id" -> obj.patientLabel.id.toJson, + "labelId" -> obj.patientLabel.labelId.toJson, + "primaryValue" -> obj.patientLabel.primaryValue.toJson, + "verifiedPrimaryValue" -> obj.patientLabel.verifiedPrimaryValue.toJson, + "score" -> obj.patientLabel.score.toJson, + "isImplicitMatch" -> obj.patientLabel.isImplicitMatch.toJson, + "isVisible" -> obj.patientLabel.isVisible.toJson, + "isVerified" -> obj.isVerified.toJson ) } } - implicit val patientLabelEvidenceWriter: JsonWriter[PatientLabelEvidenceView] = - new JsonWriter[PatientLabelEvidenceView] { + implicit val patientLabelEvidenceWriter: RootJsonWriter[PatientLabelEvidenceView] = + new RootJsonWriter[PatientLabelEvidenceView] { override def write(evidence: PatientLabelEvidenceView): JsValue = JsObject( "id" -> evidence.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala index 8eef44a..65687c1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala @@ -67,7 +67,6 @@ object record { override def write(obj: Duplicate) = JsObject( "type" -> "duplicate".toJson, - "predicted" -> obj.predicted.toJson, "startPage" -> obj.startPage.toJson, "endPage" -> obj.endPage.toJson, "startOriginalPage" -> obj.startOriginalPage.toJson, @@ -76,10 +75,6 @@ object record { override def read(json: JsValue): Duplicate = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val startPage = fields .get("startPage") .map(_.convertTo[Double]) @@ -101,7 +96,6 @@ object record { .map(_.convertTo[Double]) Duplicate( - predicted = predicted, startPage = startPage, endPage = endPage, startOriginalPage = startOriginalPage, @@ -114,27 +108,16 @@ object record { implicit val reorderMetaFormat: RootJsonFormat[Reorder] = new RootJsonFormat[Reorder] { override def write(obj: Reorder) = - JsObject( - "type" -> "reorder".toJson, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) + JsObject("type" -> "reorder".toJson, "items" -> obj.items.toJson) override def read(json: JsValue): Reorder = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val items = fields .get("items") .map(_.convertTo[Seq[Int]]) .getOrElse(deserializationError(s"Reorder meta json object does not contain `items` field: $json")) - Reorder( - predicted = predicted, - items = items - ) + Reorder(items) case _ => deserializationError(s"Expected JsObject as Reorder meta of medical record, but got $json") } @@ -142,27 +125,16 @@ object record { implicit val rotateMetaFormat: RootJsonFormat[Rotation] = new RootJsonFormat[Rotation] { override def write(obj: Rotation) = - JsObject( - "type" -> "rotation".toJson, - "predicted" -> obj.predicted.toJson, - "items" -> obj.items.toJson - ) + JsObject("type" -> "rotation".toJson, "items" -> obj.items.toJson) override def read(json: JsValue): Rotation = json match { case JsObject(fields) => - val predicted = fields - .get("predicted") - .map(_.convertTo[Boolean]) - val items = fields .get("items") .map(_.convertTo[Map[String, Int]]) .getOrElse(deserializationError(s"Rotation meta json object does not contain `items` field: $json")) - Rotation( - predicted = predicted, - items = items - ) + Rotation(items = items) case _ => deserializationError(s"Expected JsObject as Rotation meta of medical record, but got $json") } @@ -233,8 +205,6 @@ object record { caseId = None, physician = None, meta = None, - predictedMeta = None, - predictedDocuments = None, lastUpdate = LocalDateTime.now() ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala index a778000..b25ed1d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trial.scala @@ -9,8 +9,8 @@ import xyz.driver.pdsuidomain.entities._ object trial { import DefaultJsonProtocol._ - import common._ import Trial._ + import common._ implicit val trialStatusFormat = new EnumJsonFormat[Status]( "New" -> Status.New, @@ -24,13 +24,7 @@ object trial { "Archived" -> Status.Archived ) - implicit val conditionFormat = new EnumJsonFormat[Condition]( - "Breast" -> Condition.Breast, - "Lung" -> Condition.Lung, - "Prostate" -> Condition.Prostate - ) - - implicit val trialWriter: JsonWriter[Trial] = new JsonWriter[Trial] { + implicit val trialWriter: RootJsonWriter[Trial] = new RootJsonWriter[Trial] { override def write(obj: Trial) = JsObject( "id" -> obj.id.toJson, diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala index 572f44d..d1ca191 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/trialissue.scala @@ -44,7 +44,7 @@ object trialissue { } - implicit val trialIssueWriter = new JsonWriter[TrialIssue] { + implicit val trialIssueWriter = new RootJsonWriter[TrialIssue] { override def write(obj: TrialIssue) = JsObject( "id" -> obj.id.toJson, "text" -> obj.text.toJson, |