aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala23
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala6
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala28
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala38
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala46
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala31
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala27
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala55
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala53
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala23
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala22
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala22
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala19
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala13
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala101
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala98
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/extracteddata.scala3
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/patientcriterion.scala1
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala19
27 files changed, 251 insertions, 441 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala
deleted file mode 100644
index f1e15f3..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.category
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuidomain.entities.CategoryWithLabels
-import xyz.driver.pdsuidomain.formats.json.label.ApiLabel
-
-final case class ApiCategory(id: Long, name: String, labels: List[ApiLabel])
-
-object ApiCategory {
-
- implicit val format: Format[ApiCategory] = (
- (JsPath \ "id").format[Long] and
- (JsPath \ "name").format[String] and
- (JsPath \ "labels").format[List[ApiLabel]]
- )(ApiCategory.apply, unlift(ApiCategory.unapply))
-
- def fromDomain(categoryWithLabels: CategoryWithLabels) = ApiCategory(
- id = categoryWithLabels.category.id.id,
- name = categoryWithLabels.category.name,
- labels = categoryWithLabels.labels.map(x => ApiLabel(x.id.id, x.name, x.categoryId.id))
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala
index 4986b17..43b5494 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiCriterion.scala
@@ -14,7 +14,8 @@ final case class ApiCriterion(id: Long,
text: Option[String],
isCompound: Boolean,
labels: Seq[ApiCriterionLabel],
- trialId: String) {
+ trialId: String,
+ inclusion: Option[Boolean]) {
def toDomain = RichCriterion(
criterion = Criterion(
@@ -22,7 +23,8 @@ final case class ApiCriterion(id: Long,
trialId = StringId[Trial](trialId),
text,
isCompound,
- meta.getOrElse("")
+ meta.getOrElse(""),
+ inclusion
),
armIds = arms.map(LongId[Arm]),
labels = labels.map(_.toDomain(LongId[Criterion](id)))
@@ -40,7 +42,8 @@ object ApiCriterion {
(JsPath \ "text").formatNullable[String] and
(JsPath \ "isCompound").format[Boolean] and
(JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and
- (JsPath \ "trialId").format[String]
+ (JsPath \ "trialId").format[String] and
+ (JsPath \ "inclusion").formatNullable[Boolean]
)(ApiCriterion.apply, unlift(ApiCriterion.unapply))
def fromDomain(richCriterion: RichCriterion) = ApiCriterion(
@@ -50,6 +53,7 @@ object ApiCriterion {
text = richCriterion.criterion.text,
isCompound = richCriterion.criterion.isCompound,
labels = richCriterion.labels.map(ApiCriterionLabel.fromDomain),
- trialId = richCriterion.criterion.trialId.id
+ trialId = richCriterion.criterion.trialId.id,
+ inclusion = richCriterion.criterion.inclusion
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala
index ab7641f..d72a9b4 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiNewCriterion.scala
@@ -13,7 +13,8 @@ final case class ApiNewCriterion(meta: Option[String],
text: Option[String],
isCompound: Option[Boolean],
labels: Seq[ApiCriterionLabel],
- trialId: String) {
+ trialId: String,
+ inclusion: Option[Boolean]) {
def toDomain = RichCriterion(
criterion = Criterion(
@@ -21,7 +22,8 @@ final case class ApiNewCriterion(meta: Option[String],
meta = meta.getOrElse(""),
trialId = StringId(trialId),
isCompound = isCompound.getOrElse(false),
- text = text
+ text = text,
+ inclusion = inclusion
),
armIds = arms.getOrElse(Seq.empty).map(LongId[Arm]),
labels = labels.map(_.toDomain(LongId(Long.MaxValue))) // A developer should specify right criterionId himself
@@ -38,6 +40,7 @@ object ApiNewCriterion {
(JsPath \ "text").formatNullable[String] and
(JsPath \ "isCompound").formatNullable[Boolean] and
(JsPath \ "labels").format(seqJsonFormat[ApiCriterionLabel]) and
- (JsPath \ "trialId").format[String]
+ (JsPath \ "trialId").format[String] and
+ (JsPath \ "inclusion").formatNullable[Boolean]
)(ApiNewCriterion.apply, unlift(ApiNewCriterion.unapply))
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala
index 2bcda56..77989f0 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/criterion/ApiUpdateCriterion.scala
@@ -14,6 +14,7 @@ final case class ApiUpdateCriterion(meta: Tristate[String],
arms: Tristate[Seq[Long]],
text: Option[String],
isCompound: Option[Boolean],
+ inclusion: Tristate[Boolean],
labels: Tristate[Seq[ApiCriterionLabel]]) {
def applyTo(orig: RichCriterion): RichCriterion = RichCriterion(
@@ -27,7 +28,8 @@ final case class ApiUpdateCriterion(meta: Tristate[String],
meta = meta.cata(identity, "{}", orig.meta),
text = text.orElse(orig.text),
isCompound = isCompound.getOrElse(orig.isCompound),
- trialId = orig.trialId
+ trialId = orig.trialId,
+ inclusion = inclusion.cata(x => Some(x), None, orig.inclusion)
)
}
@@ -45,6 +47,7 @@ object ApiUpdateCriterion {
(JsPath \ "arms").readTristate(seqJsonFormat[Long]) and
(JsPath \ "text").readNullable[String] and
(JsPath \ "isCompound").readNullable[Boolean] and
+ (JsPath \ "inclusion").readTristate[Boolean] and
(JsPath \ "labels").readTristate(seqJsonFormat[ApiCriterionLabel])
)(ApiUpdateCriterion.apply _)
@@ -53,6 +56,7 @@ object ApiUpdateCriterion {
(JsPath \ "arms").writeTristate(seqJsonFormat[Long]) and
(JsPath \ "text").writeNullable[String] and
(JsPath \ "isCompound").writeNullable[Boolean] and
+ (JsPath \ "inclusion").writeTristate[Boolean] and
(JsPath \ "labels").writeTristate(seqJsonFormat[ApiCriterionLabel])
)(unlift(ApiUpdateCriterion.unapply))
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
index 8b4974f..22bea6b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiDocumentType.scala
@@ -2,15 +2,14 @@ package xyz.driver.pdsuidomain.formats.json.document
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.DocumentType
final case class ApiDocumentType(id: Long, name: String) {
- def toDomain = DocumentType(
- id = LongId(this.id),
- name = this.name
- )
+ def toDomain: DocumentType =
+ DocumentType
+ .fromString(name)
+ .getOrElse(throw new IllegalArgumentException(s"Unknown document type name $name"))
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
index c0eddad..9c0c216 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/document/ApiProviderType.scala
@@ -2,15 +2,14 @@ package xyz.driver.pdsuidomain.formats.json.document
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
import xyz.driver.pdsuidomain.entities.ProviderType
final case class ApiProviderType(id: Long, name: String) {
- def toDomain = ProviderType(
- id = LongId(this.id),
- name = this.name
- )
+ def toDomain: ProviderType =
+ ProviderType
+ .fromString(name)
+ .getOrElse(throw new IllegalArgumentException(s"Unknown provider type name $name"))
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala
deleted file mode 100644
index 0ef1c68..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabel
-
-final case class ApiExportPatientLabel(id: String, evidences: List[ApiExportPatientLabelEvidence]) {
-
- def toDomain = ExportPatientLabel(
- id = LongId(this.id.toLong),
- evidences = this.evidences.map(_.toDomain)
- )
-
-}
-
-object ApiExportPatientLabel {
-
- implicit val format: Format[ApiExportPatientLabel] = (
- (JsPath \ "labelId").format[String] and
- (JsPath \ "evidence").format[List[ApiExportPatientLabelEvidence]]
- )(ApiExportPatientLabel.apply, unlift(ApiExportPatientLabel.unapply))
-
- def fromDomain(label: ExportPatientLabel) = ApiExportPatientLabel(
- id = label.id.toString,
- evidences = label.evidences.map(ApiExportPatientLabelEvidence.fromDomain)
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala
deleted file mode 100644
index d141762..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala
+++ /dev/null
@@ -1,38 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
-import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidence
-
-final case class ApiExportPatientLabelEvidence(evidenceId: String,
- labelValue: String,
- evidenceText: String,
- document: ApiExportPatientLabelEvidenceDocument) {
-
- def toDomain = ExportPatientLabelEvidence(
- id = LongId(this.evidenceId.toLong),
- value = FuzzyValue.fromString
- .applyOrElse(this.labelValue, (s: String) => throw new NoSuchElementException(s"Unknown fuzzy value $s")),
- evidenceText = this.evidenceText,
- document = this.document.toDomain
- )
-
-}
-
-object ApiExportPatientLabelEvidence {
-
- implicit val format: Format[ApiExportPatientLabelEvidence] = (
- (JsPath \ "evidenceId").format[String] and
- (JsPath \ "labelValue").format[String](Writes[String](x => JsString(x.toUpperCase))) and
- (JsPath \ "evidenceText").format[String] and
- (JsPath \ "document").format[ApiExportPatientLabelEvidenceDocument]
- )(ApiExportPatientLabelEvidence.apply, unlift(ApiExportPatientLabelEvidence.unapply))
-
- def fromDomain(evidence: ExportPatientLabelEvidence) = ApiExportPatientLabelEvidence(
- evidenceId = evidence.id.toString,
- labelValue = FuzzyValue.valueToString(evidence.value),
- evidenceText = evidence.evidenceText,
- document = ApiExportPatientLabelEvidenceDocument.fromDomain(evidence.document)
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala
deleted file mode 100644
index 6999301..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala
+++ /dev/null
@@ -1,46 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import java.time.LocalDate
-import java.util.UUID
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities.RecordRequestId
-import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientLabelEvidenceDocument
-
-final case class ApiExportPatientLabelEvidenceDocument(documentId: String,
- requestId: String,
- documentType: String,
- providerType: String,
- date: LocalDate) {
-
- def toDomain = ExportPatientLabelEvidenceDocument(
- documentId = LongId(this.documentId.toLong),
- requestId = RecordRequestId(UUID.fromString(this.requestId)),
- documentType = this.documentType,
- providerType = this.providerType,
- date = this.date
- )
-
-}
-
-object ApiExportPatientLabelEvidenceDocument {
-
- implicit val format: Format[ApiExportPatientLabelEvidenceDocument] = (
- (JsPath \ "documentId").format[String] and
- (JsPath \ "requestId").format[String] and
- (JsPath \ "documentType").format[String] and
- (JsPath \ "providerType").format[String] and
- (JsPath \ "date").format[LocalDate]
- )(ApiExportPatientLabelEvidenceDocument.apply, unlift(ApiExportPatientLabelEvidenceDocument.unapply))
-
- def fromDomain(document: ExportPatientLabelEvidenceDocument) =
- ApiExportPatientLabelEvidenceDocument(
- documentId = document.documentId.toString,
- requestId = document.requestId.toString,
- documentType = document.documentType,
- providerType = document.providerType,
- date = document.date
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala
deleted file mode 100644
index fc9bab7..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.UuidId
-import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels
-
-final case class ApiExportPatientWithLabels(patientId: String, labelVersion: Long, labels: List[ApiExportPatientLabel]) {
-
- def toDomain = ExportPatientWithLabels(
- patientId = UuidId(this.patientId),
- labelVersion = this.labelVersion,
- labels = this.labels.map(_.toDomain)
- )
-
-}
-
-object ApiExportPatientWithLabels {
-
- implicit val format: Format[ApiExportPatientWithLabels] = (
- (JsPath \ "patientId").format[String] and
- (JsPath \ "labelVersion").format[Long] and
- (JsPath \ "labels").format[List[ApiExportPatientLabel]]
- )(ApiExportPatientWithLabels.apply, unlift(ApiExportPatientWithLabels.unapply))
-
- def fromDomain(patient: ExportPatientWithLabels) = ApiExportPatientWithLabels(
- patientId = patient.patientId.toString,
- labelVersion = patient.labelVersion,
- labels = patient.labels.map(ApiExportPatientLabel.fromDomain)
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala
deleted file mode 100644
index ea96f58..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.LongId
-import xyz.driver.pdsuidomain.entities.Arm
-import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialArm
-
-final case class ApiExportTrialArm(armId: String, armName: String) {
-
- def toDomain: ExportTrialArm = {
- ExportTrialArm(LongId[Arm](armId.toLong), armName)
- }
-}
-
-object ApiExportTrialArm {
-
- implicit val format: Format[ApiExportTrialArm] = (
- (JsPath \ "armId").format[String] and
- (JsPath \ "armName").format[String]
- )(ApiExportTrialArm.apply, unlift(ApiExportTrialArm.unapply))
-
- def fromDomain(arm: ExportTrialArm) = ApiExportTrialArm(
- armId = arm.armId.toString,
- armName = arm.armName
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala
deleted file mode 100644
index df1ebb4..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala
+++ /dev/null
@@ -1,55 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json._
-import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
-import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialLabelCriterion
-import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label}
-
-final case class ApiExportTrialLabelCriterion(value: String,
- labelId: String,
- criterionId: String,
- criterionText: String,
- armIds: List[String],
- isCompound: Boolean,
- isDefining: Boolean) {
-
- def toDomain: ExportTrialLabelCriterion = {
- ExportTrialLabelCriterion(
- LongId[Criterion](criterionId.toLong),
- FuzzyValue.fromString.lift(value).map(_ == FuzzyValue.Yes),
- LongId[Label](labelId.toLong),
- armIds.map(armId => LongId[Arm](armId.toLong)).toSet,
- criterionText,
- isCompound,
- isDefining
- )
- }
-}
-
-object ApiExportTrialLabelCriterion {
-
- implicit val format: Format[ApiExportTrialLabelCriterion] = (
- (JsPath \ "value").format[String](Writes[String](x => JsString(x.toUpperCase))) and
- (JsPath \ "labelId").format[String] and
- (JsPath \ "criterionId").format[String] and
- (JsPath \ "criterionText").format[String] and
- (JsPath \ "armIds").format[List[String]] and
- (JsPath \ "isCompound").format[Boolean] and
- (JsPath \ "isDefining").format[Boolean]
- )(ApiExportTrialLabelCriterion.apply, unlift(ApiExportTrialLabelCriterion.unapply))
-
- def fromDomain(x: ExportTrialLabelCriterion) = ApiExportTrialLabelCriterion(
- value = x.value
- .map { x =>
- FuzzyValue.valueToString(FuzzyValue.fromBoolean(x))
- }
- .getOrElse("Unknown"),
- labelId = x.labelId.toString,
- criterionId = x.criterionId.toString,
- criterionText = x.criteria,
- armIds = x.armIds.map(_.toString).toList,
- isCompound = x.isCompound,
- isDefining = x.isDefining
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala
deleted file mode 100644
index e383a1f..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala
+++ /dev/null
@@ -1,53 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.export
-
-import java.time.{Instant, ZoneId}
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuicommon.domain.{StringId, UuidId}
-import xyz.driver.pdsuidomain.entities.Trial
-import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels
-
-final case class ApiExportTrialWithLabels(nctId: String,
- trialId: String,
- condition: String,
- lastReviewed: Long,
- labelVersion: Long,
- arms: List[ApiExportTrialArm],
- criteria: List[ApiExportTrialLabelCriterion]) {
-
- def toDomain: ExportTrialWithLabels = {
- ExportTrialWithLabels(
- StringId[Trial](nctId),
- UuidId[Trial](trialId),
- condition,
- lastReviewed = Instant.ofEpochMilli(lastReviewed).atZone(ZoneId.of("Z")).toLocalDateTime,
- labelVersion,
- arms.map(_.toDomain),
- criteria.map(_.toDomain)
- )
- }
-}
-
-object ApiExportTrialWithLabels {
-
- implicit val format: Format[ApiExportTrialWithLabels] = (
- (JsPath \ "nctId").format[String] and
- (JsPath \ "trialId").format[String] and
- (JsPath \ "disease").format[String] and
- (JsPath \ "lastReviewed").format[Long] and
- (JsPath \ "labelVersion").format[Long] and
- (JsPath \ "arms").format[List[ApiExportTrialArm]] and
- (JsPath \ "criteria").format[List[ApiExportTrialLabelCriterion]]
- )(ApiExportTrialWithLabels.apply, unlift(ApiExportTrialWithLabels.unapply))
-
- def fromDomain(x: ExportTrialWithLabels) = ApiExportTrialWithLabels(
- nctId = x.nctId.id,
- trialId = x.trialId.toString,
- condition = x.condition,
- lastReviewed = x.lastReviewed.atZone(ZoneId.of("Z")).toEpochSecond,
- labelVersion = x.labelVersion,
- arms = x.arms.map(ApiExportTrialArm.fromDomain),
- criteria = x.criteria.map(ApiExportTrialLabelCriterion.fromDomain)
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala
deleted file mode 100644
index a9d02fc..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.keyword
-
-import xyz.driver.pdsuidomain.entities.KeywordWithLabels
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuidomain.formats.json.label.ApiLabel
-
-final case class ApiKeyword(id: Long, keyword: String, labels: List[ApiLabel])
-
-object ApiKeyword {
-
- implicit val format: Format[ApiKeyword] = (
- (JsPath \ "id").format[Long] and
- (JsPath \ "keyword").format[String] and
- (JsPath \ "labels").format[List[ApiLabel]]
- )(ApiKeyword.apply, unlift(ApiKeyword.unapply))
-
- def fromDomain(keywordWithLabels: KeywordWithLabels) = ApiKeyword(
- id = keywordWithLabels.keyword.id.id,
- keyword = keywordWithLabels.keyword.keyword,
- labels = keywordWithLabels.labels.map(x => ApiLabel(x.id.id, x.name, x.categoryId.id))
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala
index 7a65af8..d486749 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiCriterionLabel.scala
@@ -1,10 +1,11 @@
package xyz.driver.pdsuidomain.formats.json.label
import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
-import xyz.driver.pdsuidomain.entities.{Category, Criterion, CriterionLabel, Label}
+import xyz.driver.pdsuidomain.entities.{Criterion, CriterionLabel}
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
+import xyz.driver.entities.labels.{Label, LabelCategory}
/**
* @param value Yes|No
@@ -18,7 +19,7 @@ final case class ApiCriterionLabel(labelId: Option[Long],
id = LongId(0L),
labelId = labelId.map(LongId[Label]),
criterionId = criterionId,
- categoryId = categoryId.map(LongId[Category]),
+ categoryId = categoryId.map(LongId[LabelCategory]),
value = value.map {
case "Yes" => true
case "No" => false
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala
index cb45025..f8161af 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiExtractedDataLabel.scala
@@ -1,10 +1,11 @@
package xyz.driver.pdsuidomain.formats.json.label
import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
-import xyz.driver.pdsuidomain.entities.{Category, ExtractedData, ExtractedDataLabel, Label}
+import xyz.driver.pdsuidomain.entities.{ExtractedData, ExtractedDataLabel}
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json._
+import xyz.driver.entities.labels.{Label, LabelCategory}
final case class ApiExtractedDataLabel(id: Option[Long], categoryId: Option[Long], value: Option[String]) {
@@ -12,7 +13,7 @@ final case class ApiExtractedDataLabel(id: Option[Long], categoryId: Option[Long
id = LongId(0),
dataId = dataId,
labelId = id.map(LongId[Label]),
- categoryId = categoryId.map(LongId[Category]),
+ categoryId = categoryId.map(LongId[LabelCategory]),
value = value.map(FuzzyValue.fromString)
)
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala
deleted file mode 100644
index 042b380..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala
+++ /dev/null
@@ -1,22 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.label
-
-import play.api.libs.functional.syntax._
-import play.api.libs.json.{Format, JsPath}
-import xyz.driver.pdsuidomain.entities.Label
-
-final case class ApiLabel(id: Long, name: String, categoryId: Long)
-
-object ApiLabel {
-
- implicit val format: Format[ApiLabel] = (
- (JsPath \ "id").format[Long] and
- (JsPath \ "name").format[String] and
- (JsPath \ "categoryId").format[Long]
- )(ApiLabel.apply, unlift(ApiLabel.unapply))
-
- def fromDomain(x: Label) = ApiLabel(
- id = x.id.id,
- name = x.name,
- categoryId = x.categoryId.id
- )
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
index 75347f4..6eeb40b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patient/trial/ApiPatientCriterion.scala
@@ -3,10 +3,11 @@ package xyz.driver.pdsuidomain.formats.json.patient.trial
import java.time.{ZoneId, ZonedDateTime}
import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId}
-import xyz.driver.pdsuidomain.entities.{Label, PatientCriterion, PatientCriterionArm}
+import xyz.driver.pdsuidomain.entities.{PatientCriterion, PatientCriterionArm}
import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath, Reads, Writes}
+import xyz.driver.entities.labels.Label
final case class ApiPatientCriterion(id: Long,
labelId: Long,
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 732bcad..8da719c 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
@@ -1,6 +1,7 @@
package xyz.driver.pdsuidomain.formats.json.sprayformats
import spray.json._
+import xyz.driver.entities.labels.{Label, LabelCategory}
import xyz.driver.pdsuicommon.domain.{LongId, StringId}
import xyz.driver.pdsuidomain.entities._
import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion
@@ -29,7 +30,7 @@ object criterion {
val categoryId = fields
.get("categoryId")
- .map(_.convertTo[LongId[Category]])
+ .map(_.convertTo[LongId[LabelCategory]])
val value = fields
.get("value")
@@ -72,6 +73,11 @@ object criterion {
.map(_.convertTo[Option[String]].getOrElse("{}"))
.getOrElse(orig.criterion.meta)
+ val inclusion = fields
+ .get("inclusion")
+ .map(_.convertTo[Option[Boolean]])
+ .getOrElse(orig.criterion.inclusion)
+
val arms = fields
.get("arms")
.map(_.convertTo[Option[List[LongId[Arm]]]].getOrElse(List.empty[LongId[Arm]]))
@@ -87,7 +93,8 @@ object criterion {
criterion = orig.criterion.copy(
meta = meta,
text = text,
- isCompound = isCompound
+ isCompound = isCompound,
+ inclusion = inclusion
),
armIds = arms,
labels = labels
@@ -105,7 +112,8 @@ object criterion {
"text" -> obj.criterion.text.toJson,
"isCompound" -> obj.criterion.isCompound.toJson,
"labels" -> obj.labels.map(_.toJson).toJson,
- "trialId" -> obj.criterion.trialId.toJson
+ "trialId" -> obj.criterion.trialId.toJson,
+ "inclusion" -> obj.criterion.inclusion.toJson
)
override def read(json: JsValue): RichCriterion = json match {
@@ -128,6 +136,11 @@ object criterion {
.map(_.convertTo[String])
.getOrElse("")
+ val inclusion = fields
+ .get("inclusion")
+ .map(_.convertTo[Option[Boolean]])
+ .getOrElse(None)
+
val arms = fields
.get("arms")
.map(_.convertTo[List[LongId[Arm]]])
@@ -145,7 +158,8 @@ object criterion {
trialId = trialId,
text = text,
isCompound = isCompound,
- meta = meta
+ meta = meta,
+ inclusion = inclusion
),
armIds = arms,
labels = labels
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 baf1b4e..e3f6a9c 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
@@ -28,6 +28,25 @@ object document {
implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply)
+ implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] {
+ override def read(json: JsValue): DocumentType = json match {
+ case JsObject(fields) =>
+ val name = fields
+ .get("name")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json"))
+
+ DocumentType
+ .fromString(name)
+ .getOrElse(deserializationError(s"Unknown document type: $name"))
+
+ case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json")
+ }
+
+ override def write(obj: DocumentType) =
+ JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
+ }
+
implicit val fullDocumentMetaFormat = new RootJsonFormat[TextJson[Meta]] {
override def write(obj: TextJson[Meta]): JsValue = obj.content.toJson
override def read(json: JsValue) = TextJson(documentMetaFormat.read(json))
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala
deleted file mode 100644
index 8119d35..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala
+++ /dev/null
@@ -1,13 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.sprayformats
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities._
-import xyz.driver.pdsuidomain.entities.DocumentType
-
-object documenttype {
- import DefaultJsonProtocol._
- import common._
-
- implicit val format: RootJsonFormat[DocumentType] = jsonFormat2(DocumentType.apply)
-
-}
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
new file mode 100644
index 0000000..b836e1c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala
@@ -0,0 +1,101 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import DefaultJsonProtocol._
+import xyz.driver.core.Id
+import xyz.driver.core.json._
+import xyz.driver.entities.labels.LabelValue
+import xyz.driver.pdsuidomain.entities.eligibility._
+
+object eligibility {
+ import xyz.driver.formats.json.assay._
+ import xyz.driver.formats.json.common._
+ import xyz.driver.formats.json.labels._
+ import xyz.driver.formats.json.process._
+ import xyz.driver.pdsuidomain.formats.json.sprayformats.document._
+ import xyz.driver.pdsuidomain.formats.json.sprayformats.record._
+ import xyz.driver.pdsuidomain.formats.json.sprayformats.export._
+
+ implicit val molecularDocumentFormat: RootJsonFormat[MolecularEvidenceDocument] = jsonFormat7(
+ MolecularEvidenceDocument)
+ implicit val clinicalDocumentFormat: RootJsonFormat[ClinicalEvidenceDocument] = jsonFormat7(ClinicalEvidenceDocument)
+
+ implicit val evidenceDocumentFormat: RootJsonFormat[EvidenceDocument] =
+ GadtJsonFormat.create[EvidenceDocument]("documentType") {
+ case _: MolecularEvidenceDocument => "Molecular"
+ case _: ClinicalEvidenceDocument => "Clinical"
+ } {
+ case "Molecular" => molecularDocumentFormat
+ case "Clinical" => clinicalDocumentFormat
+ }
+
+ implicit object evidenceFormat extends RootJsonFormat[Evidence] {
+
+ override def write(evidence: Evidence): JsValue = {
+ JsObject(
+ "evidenceId" -> evidence.evidenceId.toJson,
+ "evidenceText" -> evidence.evidenceText.toJson,
+ "labelValue" -> evidence.labelValue.toJson,
+ "document" -> evidence.document.toJson,
+ "isPrimaryValue" -> evidence.isPrimaryValue.toJson
+ )
+ }
+
+ override def read(json: JsValue): Evidence = {
+ json match {
+ case JsObject(fields) =>
+ val evidenceId = fields
+ .get("evidenceId")
+ .map(_.convertTo[Id[Evidence]])
+
+ val evidenceText = fields
+ .get("evidenceText")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"Evidence json object do not contain 'evidenceText' field: $json"))
+
+ val labelValue = fields
+ .get("labelValue")
+ .map(_.convertTo[LabelValue])
+ .getOrElse(deserializationError(s"Evidence json object do not contain 'labelValue' field: $json"))
+
+ val isDriverDocument = fields
+ .get("document")
+ .flatMap {
+ case JsObject(fieldMap) =>
+ fieldMap
+ .get("isDriverDocument")
+ .map(_.convertTo[Boolean])
+ case _ => deserializationError(s"Expected Json Object as 'isDriverDocument', but got $json")
+ }
+ .getOrElse(deserializationError(s"Evidence json object do not contain 'document' field: $json"))
+
+ val document = customDocumentParser(isDriverDocument, fields, json)
+
+ val isPrimaryValue = fields
+ .get("isPrimaryValue")
+ .map(_.convertTo[Option[Boolean]])
+ .getOrElse(deserializationError(s"Evidence json object do not contain 'isPrimaryValue' field: $json"))
+
+ Evidence(evidenceId, evidenceText, labelValue, document, isPrimaryValue)
+ case _ => deserializationError(s"Expected Json Object as 'Evidence', but got $json")
+ }
+ }
+
+ def customDocumentParser(isDriverDocument: Boolean,
+ fields: Map[String, JsValue],
+ json: JsValue): EvidenceDocument = {
+ fields.get("document").fold { deserializationError(s"Expected Json Object as 'Document', but got $json") } {
+ document =>
+ if (isDriverDocument) document.convertTo[MolecularEvidenceDocument]
+ else document.convertTo[ClinicalEvidenceDocument]
+ }
+ }
+ }
+
+ implicit def labelWithEvidenceJsonFormat: RootJsonFormat[LabelEvidence] = jsonFormat2(LabelEvidence)
+
+ implicit def labelRankingFormat: RootJsonFormat[LabelMismatchRank] = jsonFormat4(LabelMismatchRank)
+ implicit def labelRankingsFormat: RootJsonFormat[MismatchRankedLabels] = jsonFormat2(MismatchRankedLabels)
+
+ implicit def matchedPatientFormat: RootJsonFormat[MatchedPatient] = jsonFormat6(MatchedPatient)
+}
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 20b6ed0..39d5c59 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
@@ -1,6 +1,8 @@
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.pdsuidomain.entities.export.patient._
import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels}
@@ -8,42 +10,24 @@ object export {
import DefaultJsonProtocol._
import common._
import record._
+ import document._
- implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] = jsonFormat5(
- ExportPatientLabelEvidenceDocument.apply)
+ implicit val patientLabelEvidenceDocumentFormat: RootJsonFormat[ExportPatientLabelEvidenceDocument] =
+ jsonFormat5(ExportPatientLabelEvidenceDocument.apply)
- implicit val patientLabelEvidenceWriter: JsonWriter[ExportPatientLabelEvidence] =
- new JsonWriter[ExportPatientLabelEvidence] {
- override def write(obj: ExportPatientLabelEvidence): JsValue =
- JsObject(
- "evidenceId" -> obj.id.toJson,
- "labelValue" -> obj.value.toJson,
- "evidenceText" -> obj.evidenceText.toJson,
- "document" -> obj.document.toJson
- )
- }
+ implicit val patientLabelEvidenceFormat: RootJsonFormat[ExportPatientLabelEvidence] =
+ jsonFormat(ExportPatientLabelEvidence.apply, "evidenceId", "labelValue", "evidenceText", "document")
- implicit val patientLabelWriter: JsonWriter[ExportPatientLabel] = new JsonWriter[ExportPatientLabel] {
- override def write(obj: ExportPatientLabel): JsValue =
- JsObject(
- "labelId" -> obj.id.toJson,
- "evidence" -> obj.evidences.map(_.toJson).toJson
- )
- }
+ implicit val patientLabelFormat: RootJsonFormat[ExportPatientLabel] =
+ jsonFormat(ExportPatientLabel.apply, "labelId", "evidence")
- implicit val patientWithLabelsWriter: JsonWriter[ExportPatientWithLabels] = new JsonWriter[ExportPatientWithLabels] {
- override def write(obj: ExportPatientWithLabels): JsValue =
- JsObject(
- "patientId" -> obj.patientId.toJson,
- "labelVersion" -> obj.labelVersion.toJson,
- "labels" -> obj.labels.map(_.toJson).toJson
- )
- }
+ implicit val patientWithLabelsFormat: RootJsonFormat[ExportPatientWithLabels] =
+ jsonFormat(ExportPatientWithLabels.apply, "patientId", "labelVersion", "labels")
implicit val trialArmFormat: RootJsonFormat[ExportTrialArm] = jsonFormat2(ExportTrialArm.apply)
- implicit val trialLabelCriterionWriter: JsonWriter[ExportTrialLabelCriterion] =
- new JsonWriter[ExportTrialLabelCriterion] {
+ implicit val trialLabelCriterionFormat: RootJsonFormat[ExportTrialLabelCriterion] =
+ new RootJsonFormat[ExportTrialLabelCriterion] {
override def write(obj: ExportTrialLabelCriterion): JsValue =
JsObject(
"value" -> obj.value
@@ -60,19 +44,49 @@ object export {
"isCompound" -> obj.isCompound.toJson,
"isDefining" -> obj.isDefining.toJson
)
- }
- implicit val trialWithLabelsWriter: JsonWriter[ExportTrialWithLabels] = new JsonWriter[ExportTrialWithLabels] {
- override def write(obj: ExportTrialWithLabels) =
- JsObject(
- "nctId" -> obj.nctId.toJson,
- "trialId" -> obj.trialId.toJson,
- "disease" -> obj.condition.toJson,
- "lastReviewed" -> obj.lastReviewed.toJson,
- "labelVersion" -> obj.labelVersion.toJson,
- "arms" -> obj.arms.toJson,
- "criteria" -> obj.criteria.map(_.toJson).toJson
- )
- }
+ override def read(json: JsValue): ExportTrialLabelCriterion = {
+
+ val fields = Seq("value", "labelId", "criterionId", "criterionText", "armIds", "isCompound", "isDefining")
+
+ json.asJsObject.getFields(fields: _*) match {
+ case Seq(JsString(valueString),
+ labelId,
+ criterionId,
+ JsString(criterionText),
+ JsArray(armIdsVector),
+ JsBoolean(isCompound),
+ JsBoolean(isDefining)) =>
+ val value = valueString match {
+ case "Yes" => Option(true)
+ case "No" => Option(false)
+ case "Unknown" => Option.empty[Boolean]
+ }
+
+ ExportTrialLabelCriterion(
+ longIdFormat[Criterion].read(criterionId),
+ value,
+ longIdFormat[Label].read(labelId),
+ armIdsVector.map(longIdFormat[Arm].read).toSet,
+ criterionText,
+ isCompound,
+ isDefining
+ )
+
+ case _ =>
+ deserializationError(
+ s"Cannot find required fields ${fields.mkString(", ")} in ExportTrialLabelCriterion object!")
+ }
+ }
+ }
+ implicit val trialWithLabelsFormat: RootJsonFormat[ExportTrialWithLabels] =
+ jsonFormat(ExportTrialWithLabels.apply,
+ "nctId",
+ "trialId",
+ "disease",
+ "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 42473bc..d6eadbd 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,6 +1,7 @@
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.pdsuidomain.entities._
import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData
@@ -39,7 +40,7 @@ object extracteddata {
val categoryId = fields
.get("categoryId")
- .map(_.convertTo[LongId[Category]])
+ .map(_.convertTo[LongId[LabelCategory]])
val value = fields
.get("value")
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 53e927d..b091746 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,6 +1,7 @@
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.pdsuidomain.entities._
import xyz.driver.pdsuidomain.services.PatientCriterionService.DraftPatientCriterion
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.scala
deleted file mode 100644
index 385feb2..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-package xyz.driver.pdsuidomain.formats.json.sprayformats
-
-import spray.json._
-import xyz.driver.pdsuidomain.entities.ProviderType
-
-object providertype {
- import DefaultJsonProtocol._
- import common._
-
- implicit val providerTypeFormat: RootJsonFormat[ProviderType] = jsonFormat2(ProviderType.apply)
-
-}
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 e378dbd..8eef44a 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
@@ -36,6 +36,25 @@ object record {
}
}
+ implicit val providerTypeFormat: RootJsonFormat[ProviderType] = new RootJsonFormat[ProviderType] {
+ override def read(json: JsValue): ProviderType = json match {
+ case JsObject(fields) =>
+ val name = fields
+ .get("name")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json"))
+
+ ProviderType
+ .fromString(name)
+ .getOrElse(deserializationError(s"Unknown provider type: $name"))
+
+ case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json")
+ }
+
+ override def write(obj: ProviderType) =
+ JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson)
+ }
+
implicit val caseIdFormat = new RootJsonFormat[CaseId] {
override def write(caseId: CaseId): JsString = JsString(caseId.toString)
override def read(json: JsValue): CaseId = json match {