aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-28 15:27:40 +0700
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-29 13:11:39 +0700
commit7bf2da3afbde1b4cec0d68cb4899e51a63e8a9b1 (patch)
treec31407bbe1a09918fc73b64484466f8b38244176
parent116c78627fd22c4a6b70d5343d6e89fa9ab9e7ad (diff)
downloadrest-query-7bf2da3afbde1b4cec0d68cb4899e51a63e8a9b1.tar.gz
rest-query-7bf2da3afbde1b4cec0d68cb4899e51a63e8a9b1.tar.bz2
rest-query-7bf2da3afbde1b4cec0d68cb4899e51a63e8a9b1.zip
Created custom formats of TriC for swagger
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala55
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala34
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala137
3 files changed, 226 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
new file mode 100644
index 0000000..c1a2c7c
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
@@ -0,0 +1,55 @@
+package xyz.driver.pdsuicommon.utils
+
+import java.time.{LocalDate, LocalDateTime}
+
+import io.swagger.models.properties.Property
+import spray.json.JsValue
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
+import xyz.driver.pdsuidomain.entities._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.intervention._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.hypothesis._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.studydesign._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.trial._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.trialhistory._
+import xyz.driver.pdsuidomain.formats.json.sprayformats.trialissue._
+import xyz.driver.core.swagger.CustomSwaggerJsonConverter._
+import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion
+
+object CustomSwaggerJsonFormats {
+
+ val customCommonProperties = Map[Class[_], Property](
+ classOf[LocalDateTime] -> stringProperty(example = Some("2010-12-31'T'18:59:59Z")),
+ classOf[LocalDate] -> stringProperty(example = Some("2010-12-31")),
+ classOf[UuidId[_]] -> stringProperty(example = Some("370b0450-35cb-4aab-ba74-0145be75add5")),
+ classOf[StringId[_]] -> stringProperty(),
+ classOf[LongId[_]] -> stringProperty()
+ )
+ val customTrialCurationProperties = Map[Class[_], Property](
+ classOf[Trial.Status] -> stringProperty(),
+ classOf[Trial.Condition] -> stringProperty(),
+ classOf[TrialHistory.Action] -> stringProperty(),
+ classOf[TrialHistory.State] -> stringProperty()
+ ) ++ customCommonProperties
+
+ val customTrialCurationObjectsExamples = Map[Class[_], JsValue](
+ classOf[Trial] -> trialWriter.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrial()),
+ classOf[Arm] -> armFormat.write(xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextArm()),
+ classOf[TrialHistory] -> trialHistoryFormat.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialHistory()),
+ classOf[TrialIssue] -> trialIssueWriter.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextTrialIssue()),
+ classOf[RichCriterion] -> richCriterionFormat.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextRichCriterion()),
+ classOf[InterventionWithArms] -> interventionWriter.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionWithArms()),
+ classOf[InterventionType] -> interventionTypeFormat.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextInterventionType()),
+ classOf[Hypothesis] -> hypothesisFormat.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextHypothesis()),
+ classOf[StudyDesign] -> studyDesignFormat.write(
+ xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign())
+ )
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
new file mode 100644
index 0000000..fbab2ce
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
@@ -0,0 +1,34 @@
+package xyz.driver.pdsuidomain.fakes.entities
+
+import java.time.{LocalDate, LocalDateTime, LocalTime}
+
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
+import xyz.driver.pdsuidomain.entities.{Trial, TrialHistory}
+
+object common {
+ import xyz.driver.core.generators
+
+ def nextUuidId[T] = UuidId[T](generators.nextUuid())
+
+ def nextLongId[T] = LongId[T](generators.nextInt(Int.MaxValue).toLong)
+
+ def nextStringId[T] = StringId[T](generators.nextString(maxLength = 20))
+
+ def nextTrialStatus = generators.oneOf[Trial.Status](Trial.Status.All)
+
+ def nextPreviousTrialStatus = generators.oneOf[Trial.Status](Trial.Status.AllPrevious)
+
+ def nextLocalDateTime = LocalDateTime.of(nextLocalDate, LocalTime.MIDNIGHT)
+
+ def nextLocalDate = {
+ val date = generators.nextDate()
+ LocalDate.of(date.year, date.month, date.day)
+ }
+
+ def nextCondition = generators.oneOf[Trial.Condition](Trial.Condition.All)
+
+ def nextTrialAction = generators.oneOf[TrialHistory.Action](TrialHistory.Action.All)
+
+ def nextTrialState = generators.oneOf[TrialHistory.State](TrialHistory.State.All)
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala
new file mode 100644
index 0000000..caa6bca
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala
@@ -0,0 +1,137 @@
+package xyz.driver.pdsuidomain.fakes.entities
+
+import xyz.driver.pdsuicommon.domain.{LongId, User}
+import xyz.driver.pdsuidomain.entities._
+import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion
+
+object trialcuration {
+ import xyz.driver.core.generators
+ import common._
+
+ def nextTrial(): Trial = Trial(
+ id = nextStringId[Trial],
+ externalId = nextUuidId[Trial],
+ status = nextTrialStatus,
+ assignee = Option(nextStringId[User]),
+ previousStatus = Option(nextPreviousTrialStatus),
+ previousAssignee = Option(nextStringId[User]),
+ lastActiveUserId = Option(nextStringId[User]),
+ lastUpdate = nextLocalDateTime,
+ condition = nextCondition,
+ phase = generators.nextString(),
+ hypothesisId = Option(nextUuidId[Hypothesis]),
+ studyDesignId = Option(nextLongId[StudyDesign]),
+ originalStudyDesign = Option(generators.nextString()),
+ isPartner = generators.nextBoolean(),
+ overview = Option(generators.nextString()),
+ overviewTemplate = generators.nextString(),
+ isUpdated = generators.nextBoolean(),
+ title = generators.nextString(),
+ originalTitle = generators.nextString()
+ )
+
+ def nextArm(): Arm = Arm(
+ id = nextLongId[Arm],
+ name = generators.nextString(),
+ originalName = generators.nextString(),
+ trialId = nextStringId[Trial],
+ deleted = Option(nextLocalDateTime)
+ )
+
+ def nextCriterion(): Criterion = Criterion(
+ id = nextLongId[Criterion],
+ trialId = nextStringId[Trial],
+ text = Option(generators.nextString()),
+ isCompound = generators.nextBoolean(),
+ meta = generators.nextString()
+ )
+
+ def nextCriterionLabel(criterionId: LongId[Criterion]): CriterionLabel = CriterionLabel(
+ id = nextLongId[CriterionLabel],
+ labelId = Option(nextLongId[Label]),
+ criterionId = criterionId,
+ categoryId = Option(nextLongId[Category]),
+ value = Option(generators.nextBoolean()),
+ isDefining = generators.nextBoolean()
+ )
+
+ def nextRichCriterion(): RichCriterion = {
+ val criterion = nextCriterion()
+ RichCriterion(
+ criterion = criterion,
+ armIds = Seq(nextLongId[Arm], nextLongId[Arm]),
+ labels = Seq(
+ nextCriterionLabel(criterion.id),
+ nextCriterionLabel(criterion.id)
+ )
+ )
+ }
+
+ def nextIntervention(): Intervention = Intervention(
+ id = nextLongId[Intervention],
+ trialId = nextStringId[Trial],
+ name = generators.nextString(),
+ originalName = generators.nextString(),
+ typeId = Option(nextLongId[InterventionType]),
+ originalType = Option(generators.nextString()),
+ description = generators.nextString(),
+ originalDescription = generators.nextString(),
+ isActive = generators.nextBoolean()
+ )
+
+ def nextInterventionArm(interventionId: LongId[Intervention]): InterventionArm = InterventionArm(
+ interventionId = interventionId,
+ armId = nextLongId[Arm]
+ )
+
+ def nextInterventionWithArms(): InterventionWithArms = {
+ val intervention = nextIntervention()
+ InterventionWithArms(
+ intervention = intervention,
+ arms = List(
+ nextInterventionArm(intervention.id),
+ nextInterventionArm(intervention.id),
+ nextInterventionArm(intervention.id)
+ )
+ )
+ }
+
+ def nextTrialIssue(): TrialIssue = TrialIssue(
+ id = nextLongId[TrialIssue],
+ userId = nextStringId[User],
+ trialId = nextStringId[Trial],
+ lastUpdate = nextLocalDateTime,
+ isDraft = generators.nextBoolean(),
+ text = generators.nextString(),
+ evidence = generators.nextString(),
+ archiveRequired = generators.nextBoolean(),
+ meta = generators.nextString()
+ )
+
+ def nextTrialHistory(): TrialHistory = TrialHistory(
+ id = nextLongId[TrialHistory],
+ executor = nextStringId[User],
+ trialId = nextStringId[Trial],
+ state = nextTrialState,
+ action = nextTrialAction,
+ created = nextLocalDateTime
+ )
+
+ def nextHypothesis(): Hypothesis = Hypothesis(
+ id = nextUuidId[Hypothesis],
+ name = generators.nextString(),
+ treatmentType = generators.nextString(),
+ description = generators.nextString()
+ )
+
+ def nextStudyDesign(): StudyDesign = StudyDesign(
+ id = nextLongId[StudyDesign],
+ name = generators.nextString()
+ )
+
+ def nextInterventionType(): InterventionType = InterventionType(
+ id = nextLongId[InterventionType],
+ name = generators.nextString()
+ )
+
+}