aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-09-28 13:12:32 -0700
committervlad <vlad@driver.xyz>2017-09-28 13:12:32 -0700
commitdeba20326e3269fee3ef51f8e6841f17453b4155 (patch)
tree29aac6bf4d0cd679a39ab1e1b84aef8ce1328b3f
parentc24679f1ae7d7ccc4e6693535b0aa3ac0e1ca225 (diff)
downloadrest-query-0.4.1.tar.gz
rest-query-0.4.1.tar.bz2
rest-query-0.4.1.zip
Simplified Export entities for EVLSv0.4.1
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala4
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala6
-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/sprayformats/document.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala97
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestExtractedDataService.scala9
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala8
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala26
15 files changed, 87 insertions, 345 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
index 6114661..184782b 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala
@@ -13,8 +13,8 @@ final case class RawPatientLabel(patientId: UuidId[Patient],
disease: String,
documentId: LongId[Document],
requestId: RecordRequestId,
- documentType: String,
- providerType: String,
+ documentType: DocumentType,
+ providerType: ProviderType,
startDate: LocalDate,
endDate: Option[LocalDate])
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
index 99912bc..7003615 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabelEvidenceDocument.scala
@@ -4,12 +4,12 @@ import java.time.LocalDate
import xyz.driver.pdsuicommon.domain._
import xyz.driver.pdsuicommon.logging._
-import xyz.driver.pdsuidomain.entities.{Document, RawPatientLabel, RecordRequestId}
+import xyz.driver.pdsuidomain.entities._
final case class ExportPatientLabelEvidenceDocument(documentId: LongId[Document],
requestId: RecordRequestId,
- documentType: String,
- providerType: String,
+ documentType: DocumentType,
+ providerType: ProviderType,
date: LocalDate)
object ExportPatientLabelEvidenceDocument extends PhiLogging {
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/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala
index baf1b4e..ff0603a 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,8 @@ object document {
implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply)
+ implicit val documentTypeFormat: RootJsonFormat[DocumentType] = jsonFormat2(DocumentType.apply)
+
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/export.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/export.scala
index 20b6ed0..2a1fe46 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,7 @@
package xyz.driver.pdsuidomain.formats.json.sprayformats
import spray.json._
+import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label}
import xyz.driver.pdsuidomain.entities.export.patient._
import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels}
@@ -8,42 +9,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 +43,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/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala
index e378dbd..6b69873 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,8 @@ object record {
}
}
+ implicit val providerTypeFormat = jsonFormat2(ProviderType.apply)
+
implicit val caseIdFormat = new RootJsonFormat[CaseId] {
override def write(caseId: CaseId): JsString = JsString(caseId.toString)
override def read(json: JsValue): CaseId = json match {
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestExtractedDataService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestExtractedDataService.scala
index 53b9f38..a65e1f4 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestExtractedDataService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestExtractedDataService.scala
@@ -1,7 +1,6 @@
package xyz.driver.pdsuidomain.services.rest
import scala.concurrent.{ExecutionContext, Future}
-
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.stream.Materializer
@@ -10,10 +9,12 @@ import xyz.driver.pdsuicommon.auth._
import xyz.driver.pdsuicommon.db._
import xyz.driver.pdsuicommon.domain._
import xyz.driver.pdsuidomain.entities._
+import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels
import xyz.driver.pdsuidomain.formats.json.ListResponse
-import xyz.driver.pdsuidomain.formats.json.export.ApiExportPatientWithLabels
import xyz.driver.pdsuidomain.formats.json.extracteddata.ApiExtractedData
import xyz.driver.pdsuidomain.services.ExtractedDataService
+import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.export._
class RestExtractedDataService(transport: ServiceTransport, baseUri: Uri)(
implicit protected val materializer: Materializer,
@@ -88,9 +89,9 @@ class RestExtractedDataService(transport: ServiceTransport, baseUri: Uri)(
val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/patient/$id"))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[ApiExportPatientWithLabels](response)
+ reply <- apiResponse[ExportPatientWithLabels](response)
} yield {
- GetPatientLabelsReply.Entity(reply.toDomain)
+ GetPatientLabelsReply.Entity(reply)
}
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala
index b77e6df..7e33919 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala
@@ -12,10 +12,12 @@ import xyz.driver.pdsuicommon.auth._
import xyz.driver.pdsuicommon.db._
import xyz.driver.pdsuicommon.domain._
import xyz.driver.pdsuidomain.entities._
+import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels
import xyz.driver.pdsuidomain.formats.json.ListResponse
-import xyz.driver.pdsuidomain.formats.json.export.ApiExportTrialWithLabels
import xyz.driver.pdsuidomain.formats.json.trial.ApiTrial
import xyz.driver.pdsuidomain.services.TrialService
+import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.export._
class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit protected val materializer: Materializer,
protected val exec: ExecutionContext)
@@ -39,9 +41,9 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote
val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$disease/$trialId"))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[ApiExportTrialWithLabels](response)
+ reply <- apiResponse[ExportTrialWithLabels](response)
} yield {
- GetTrialWithLabelsReply.Entity(reply.toDomain)
+ GetTrialWithLabelsReply.Entity(reply)
}
}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
index d0d4d1a..52c8c81 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ExportFormatSuite.scala
@@ -6,7 +6,7 @@ import java.util.UUID
import spray.json._
import org.scalatest.{FlatSpec, Matchers}
import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId}
-import xyz.driver.pdsuidomain.entities.RecordRequestId
+import xyz.driver.pdsuidomain.entities.{DocumentType, ProviderType, RecordRequestId}
class ExportFormatSuite extends FlatSpec with Matchers {
import export._
@@ -16,10 +16,11 @@ class ExportFormatSuite extends FlatSpec with Matchers {
val document = ExportPatientLabelEvidenceDocument(
documentId = LongId(101),
requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")),
- documentType = "document type",
- providerType = "provider type",
+ documentType = DocumentType(LongId[DocumentType](1), "document type"),
+ providerType = ProviderType(LongId[ProviderType](2), "provider type"),
date = LocalDate.parse("2017-08-10")
)
+
val labels = List(
ExportPatientLabel(
id = LongId(1),
@@ -62,18 +63,18 @@ class ExportFormatSuite extends FlatSpec with Matchers {
labels = labels
)
- val writtenJson = patientWithLabelsWriter.write(patientWithLabels)
+ val writtenJson = patientWithLabelsFormat.write(patientWithLabels)
writtenJson should be(
"""{"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","labelVersion":1,"labels":[{"labelId":1,"evidence":[{"evidenceId":11,
"labelValue":"Yes","evidenceText":"evidence text 11","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
- "documentType":"document type","providerType":"provider type","date":"2017-08-10"}},{"evidenceId":12,"labelValue":"No",
- "evidenceText":"evidence text 12","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
- "documentType":"document type","providerType":"provider type","date":"2017-08-10"}}]},
+ "documentType":{"id":1,"name":"document type"},"providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}},
+ {"evidenceId":12,"labelValue":"No","evidenceText":"evidence text 12","document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9",
+ "documentType":{"id":1,"name":"document type"},"providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}}]},
{"labelId":2,"evidence":[{"evidenceId":12,"labelValue":"Yes","evidenceText":"evidence text 12","document":
- {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":"document type",
- "providerType":"provider type","date":"2017-08-10"}},{"evidenceId":13,"labelValue":"Yes","evidenceText":"evidence text 13",
- "document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":"document type",
- "providerType":"provider type","date":"2017-08-10"}}]}]}""".parseJson)
+ {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"document type"},
+ "providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}},{"evidenceId":13,"labelValue":"Yes","evidenceText":"evidence text 13",
+ "document":{"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"document type"},
+ "providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}}]}]}""".parseJson)
}
"Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in {
@@ -112,7 +113,7 @@ class ExportFormatSuite extends FlatSpec with Matchers {
criteria = criteriaList
)
- val writtenJson = trialWithLabelsWriter.write(trialWithLabels)
+ val writtenJson = trialWithLabelsFormat.write(trialWithLabels)
writtenJson should be(
"""{"nctId":"NCT000001","trialId":"40892a07-c638-49d2-9795-1edfefbbcc7c","disease":"Breast","lastReviewed":"2017-08-10T18:00Z",
"labelVersion":1,"arms":[{"armId":1,"armName":"arm 1"},{"armId":2,"armName":"arm 2"}],"criteria":[
@@ -120,5 +121,4 @@ class ExportFormatSuite extends FlatSpec with Matchers {
{"value":"Unknown","labelId":21,"criterionId":11,"criterionText":"criteria 11 text","armIds":[2],"isCompound":true,"isDefining":false}]}""".parseJson)
}
-
}