From d82c93fef0fc0bb937220334f73c264fbb1082f2 Mon Sep 17 00:00:00 2001 From: kseniya Date: Wed, 20 Sep 2017 17:58:19 +0700 Subject: Common code for synchronizers --- .../synchronization/db/SlickDataSource.scala | 23 +++++++ .../synchronization/db/SlickDbAction.scala | 70 ++++++++++++++++++++++ .../synchronization/db/SlickDbDiff.scala | 52 ++++++++++++++++ .../synchronization/domain/FakeId.scala | 14 +++++ .../synchronization/utils/FakeIdGen.scala | 26 ++++++++ .../synchronization/utils/Refiner.scala | 12 ++++ .../synchronization/utils/package.scala | 64 ++++++++++++++++++++ 7 files changed, 261 insertions(+) create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDataSource.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbAction.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbDiff.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/domain/FakeId.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/FakeIdGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/Refiner.scala create mode 100644 src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/package.scala (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDataSource.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDataSource.scala new file mode 100644 index 0000000..63514ec --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDataSource.scala @@ -0,0 +1,23 @@ +package xyz.driver.pdsuicommon.synchronization.db + +import slick.dbio.DBIO + +import scalaz.OptionT + +trait SlickDataSource[T] { + + val isDictionary: Boolean = false + + /** + * @return New entity + */ + def create(x: T): DBIO[T] + + /** + * @return Updated entity + */ + def update(x: T): OptionT[DBIO, T] + + def delete(x: T): OptionT[DBIO, Unit] + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbAction.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbAction.scala new file mode 100644 index 0000000..57cc3d4 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbAction.scala @@ -0,0 +1,70 @@ +package xyz.driver.pdsuicommon.synchronization.db + +import slick.dbio.DBIO +import xyz.driver.pdsuicommon.logging._ +import xyz.driver.pdsuicommon.synchronization.utils.{FakeIdGen, FakeIdMap} + +import scala.concurrent.ExecutionContext +import scalaz.Monad + +trait SlickDbAction[+T] { + def entity: T +} + +object SlickDbAction { + + final case class Create[T](entity: T) extends SlickDbAction[T] + final case class Update[T](entity: T) extends SlickDbAction[T] + final case class Delete[T](entity: T) extends SlickDbAction[T] + + // Use it only inside of a transaction! + def unsafeRun[T](actions: List[SlickDbAction[T]], dataSource: SlickDataSource[T])( + implicit core: FakeIdGen[T], + executionContext: ExecutionContext, + dbioMonad: Monad[DBIO]): DBIO[FakeIdMap[T]] = { + unsafeRun(DBIO.successful(FakeIdMap.empty))(actions, dataSource) + } + + // Use it only inside of a transaction! + def unsafeRun[T](initial: DBIO[FakeIdMap[T]])(actions: List[SlickDbAction[T]], dataSource: SlickDataSource[T])( + implicit core: FakeIdGen[T], + executionContext: ExecutionContext, + dbioMonad: Monad[DBIO]): DBIO[FakeIdMap[T]] = { + // TODO Squash Updates and Delete to one operation, when bugs in repositories will be fixed + actions.foldLeft(initial) { + case (previousActions, Create(x)) => + for { + r <- previousActions + newArm <- dataSource.create(x) + } yield { + r + (core(newArm) -> newArm) + } + + case (previousActions, Update(x)) => + for { + r <- previousActions + updatedArm <- dataSource.update(x).getOrElse(x) + } yield { + r - core(updatedArm) + (core(updatedArm) -> updatedArm) + } + + case (previousActions, Delete(_)) if dataSource.isDictionary => + previousActions // We don't delete entities from dictionaries + + case (previousActions, Delete(x)) => + for { + r <- previousActions + _ <- dataSource.delete(x).run + } yield { + r - core(x) + } + } + } + + implicit def toPhiString[T](input: SlickDbAction[T])(implicit inner: T => PhiString): PhiString = input match { + case Create(x) => phi"Create($x)" + case Update(x) => phi"Update($x)" + case Delete(x) => phi"Delete($x)" + } + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbDiff.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbDiff.scala new file mode 100644 index 0000000..c226659 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/db/SlickDbDiff.scala @@ -0,0 +1,52 @@ +package xyz.driver.pdsuicommon.synchronization.db + +import xyz.driver.pdsuicommon.synchronization.domain.FakeId +import xyz.driver.pdsuicommon.synchronization.utils.{FakeIdGen, Refiner} + +import scala.annotation.tailrec +import scala.collection.breakOut +import scala.collection.immutable.SortedSet + +object SlickDbDiff { + + /** + * Calculates DB-actions to synchronize origEntities with draftEntities. + */ + def calc[DraftT, OrigT](origEntities: Iterable[OrigT], draftEntities: Iterable[DraftT])( + implicit draftFakeIdGen: FakeIdGen[DraftT], + origFakeIdGen: FakeIdGen[OrigT], + refiner: Refiner[DraftT, OrigT]): List[SlickDbAction[OrigT]] = { + val origMap: Map[FakeId, OrigT] = origEntities.map(x => origFakeIdGen(x) -> x)(breakOut) + val uniqueDraftEntities = SortedSet.newBuilder[DraftT](Ordering.by[DraftT, FakeId](draftFakeIdGen)) + uniqueDraftEntities ++= draftEntities + + loop(origMap, uniqueDraftEntities.result(), List.empty) + } + + @tailrec private def loop[DraftT, OrigT](origEntitiesMap: Map[FakeId, OrigT], + draftEntities: Iterable[DraftT], + actions: List[SlickDbAction[OrigT]])( + implicit draftFakeIdGen: FakeIdGen[DraftT], + refiner: Refiner[DraftT, OrigT]): List[SlickDbAction[OrigT]] = { + draftEntities.headOption match { + case None => + // The rest original entities are not a part of draft, so we will delete them + val toDelete: List[SlickDbAction[OrigT]] = origEntitiesMap.values.map(x => SlickDbAction.Delete(x))(breakOut) + actions ++ toDelete + + case Some(currRaw) => + val rawCore = draftFakeIdGen.getFor(currRaw) + val action: Option[SlickDbAction[OrigT]] = origEntitiesMap.get(rawCore) match { + // It is a new entity, because it doesn't exist among originals + case None => Some(SlickDbAction.Create(refiner.refine(currRaw))) + case Some(orig) => + val draft = refiner.refresh(orig, currRaw) + if (draft == orig) None + else Some(SlickDbAction.Update(draft)) + } + + loop(origEntitiesMap - rawCore, draftEntities.tail, action.map(_ :: actions).getOrElse(actions)) + } + } + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/domain/FakeId.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/domain/FakeId.scala new file mode 100644 index 0000000..38e442b --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/domain/FakeId.scala @@ -0,0 +1,14 @@ +package xyz.driver.pdsuicommon.synchronization.domain + +/* + It is like an Id for entities those haven't an Id, but should be unique. + For example, + RawArm has the name, the kind and the intervention fields. + It has not an Id, but should be identified by the name field. + So, the name field is a fake id for RawArm. + */ +final case class FakeId(value: String) + +object FakeId { + implicit val ordering: Ordering[FakeId] = Ordering.by(_.value) +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/FakeIdGen.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/FakeIdGen.scala new file mode 100644 index 0000000..196aab1 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/FakeIdGen.scala @@ -0,0 +1,26 @@ +package xyz.driver.pdsuicommon.synchronization.utils + +import xyz.driver.pdsuicommon.synchronization.domain.FakeId + +/** + * Used to generate a fake id from an entity. + * A fake id is used in comparison between entities with different types, + * for example, RawTrial and Trial. + * + * @see FakeId + */ +trait FakeIdGen[-T] extends (T => FakeId) { + + def getFor(x: T): FakeId + + override def apply(x: T): FakeId = getFor(x) + +} + +object FakeIdGen { + + def create[T](f: T => FakeId) = new FakeIdGen[T] { + override def getFor(x: T): FakeId = f(x) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/Refiner.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/Refiner.scala new file mode 100644 index 0000000..768b889 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/Refiner.scala @@ -0,0 +1,12 @@ +package xyz.driver.pdsuicommon.synchronization.utils + +/** + * Allows to extract a data from the From entity to convert/update in to the To entity. + */ +trait Refiner[-From, To] { + + def refine(raw: From): To + + def refresh(orig: To, update: From): To + +} diff --git a/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/package.scala b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/package.scala new file mode 100644 index 0000000..1b30158 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuicommon/synchronization/utils/package.scala @@ -0,0 +1,64 @@ +package xyz.driver.pdsuicommon.synchronization + +import java.net.URL +import java.nio.ByteBuffer +import java.util.UUID + +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuicommon.http.HttpFetcher +import xyz.driver.pdsuicommon.json.JsonSerializer +import xyz.driver.pdsuicommon.synchronization.domain.FakeId + +import scala.collection.breakOut +import scala.concurrent.{ExecutionContext, Future} +import scala.io.Codec + +package object utils { + + type FakeIdMap[T] = Map[FakeId, T] + + object FakeIdMap { + + def empty[T]: FakeIdMap[T] = Map.empty + + def create[T](xs: Seq[T])(implicit fakeIdExtractor: FakeIdGen[T]): FakeIdMap[T] = { + xs.map({ x => + fakeIdExtractor.getFor(x) -> x + })(breakOut) + } + + } + + /** + * Requests domain objects from the repository using + * ids of fetched dictionary entities + * + * @param getList repository access function + * @param xs sequence of entity objects + * @param id function that extracts id from the entity + * @tparam Id Type of Id (for example [[LongId]], [[UuidId]]) + * @tparam K Type parameter for Id + * @tparam D Domain object type name + * @tparam E Dictionary entity object type name + */ + def domainFromEntities[K, D, E, Id[_]](getList: Set[Id[K]] => Seq[D], xs: Seq[E])(id: E => Id[K]): Seq[D] = { + getList(xs.map(x => id(x)).toSet) + } + + /** Version of [[domainFromEntities]] for LongId */ + def domainFromEntitiesLong[K, D, E](getList: Set[LongId[K]] => Seq[D], xs: Seq[E])(id: E => Long): Seq[D] = { + domainFromEntities(getList, xs)(e => LongId(id(e))) + } + + /** Version of [[domainFromEntities]] for UuidId */ + def domainFromEntitiesUUID[K, D, E](getList: Set[UuidId[K]] => Seq[D], xs: Seq[E])(id: E => UUID): Seq[D] = { + domainFromEntities(getList, xs)(e => UuidId(id(e))) + } + + def fetch[T](httpFetcher: HttpFetcher, url: URL)(implicit m: Manifest[T], ec: ExecutionContext): Future[T] = { + httpFetcher(url).map { rawContent => + val content = Codec.UTF8.decoder.decode(ByteBuffer.wrap(rawContent)).toString + JsonSerializer.deserialize[T](content) + } + } +} -- cgit v1.2.3 From d8e71e0a9ee7db58032384d059403bc227a35138 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 13:31:21 +0700 Subject: Implemented some REP entities objects generators --- .../fakes/entities/RecordsProcessingApi.scala | 112 +++++++++++++++++++++ .../pdsuidomain/fakes/entities/rep/Common.scala | 35 +++++++ .../fakes/entities/rep/DocumentGen.scala | 68 +++++++++++++ .../fakes/entities/rep/ExtractedDataGen.scala | 74 ++++++++++++++ .../fakes/entities/rep/MedicalRecordMetaGen.scala | 63 ++++++++++++ 5 files changed, 352 insertions(+) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala new file mode 100644 index 0000000..93bfce6 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala @@ -0,0 +1,112 @@ +package xyz.driver.pdsuidomain.fakes.entities + + +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.core.generators +import xyz.driver.core.generators._ +import common._ +import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue +import xyz.driver.pdsuicommon.domain.{TextJson, User} +import xyz.driver.pdsuidomain.fakes.entities.rep.{DocumentGen, MedicalRecordMetaGen, Common} + + +object RecordsProcessingApi { + private val maxCollectionNumber = 5 + + private val maxAttemtsNumber = 100 + + private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] = + TextJson(nextMedicalRecordMetas(nextInt(maxCollectionNumber, minValue = 0))) + + private def nextDocuments: TextJson[List[Document]] = + TextJson(nextDocuments(nextInt(maxCollectionNumber, minValue = 0))) + + def nextMedicalRecordStatus: MedicalRecord.Status = + generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All) + + def nextMedicalRecordMeta: MedicalRecord.Meta = + MedicalRecordMetaGen.nextMedicalRecordMeta + + def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] = + List.fill(count)(nextMedicalRecordMeta) + + def nextMedicalRecordHistoryState: MedicalRecordHistory.State = + generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All) + + def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action = + generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) + + def nextDocument: Document = + DocumentGen.nextDocument + + def nextDocuments(count: Int): List[Document] = + List.fill(count)(nextDocument) + + def nextMedicalRecord() = { + MedicalRecord( + id = nextLongId[MedicalRecord], + status = nextMedicalRecordStatus, + previousStatus = nextOption(nextMedicalRecordStatus), + assignee = nextOption(nextStringId), + previousAssignee = nextOption(nextStringId), + lastActiveUserId = nextOption(nextStringId), + patientId = nextUuidId, + requestId = RecordRequestId(generators.nextUuid()), + disease = generators.nextString(), + caseId = nextOption(CaseId(generators.nextString())), + physician = nextOption(generators.nextString()), + meta = nextOption(nextMedicalRecordMetasJson), + predictedMeta = nextOption(nextMedicalRecordMetasJson), + predictedDocuments = nextOption(nextDocuments), + lastUpdate = nextLocalDateTime + ) + } + + def nextMedicalRecordHistory() = { + MedicalRecordHistory( + id = nextLongId[MedicalRecordHistory], + executor = nextStringId[User], + recordId = nextLongId[MedicalRecord], + state = nextMedicalRecordHistoryState, + action = nextMedicalRecordHistoryAction, + created = nextLocalDateTime + ) + } + + def nextMedicalRecordIssue(): MedicalRecordIssue = { + val pages = Common.genStartAndEndPages + + MedicalRecordIssue( + id = nextLongId[MedicalRecordIssue], + userId = nextStringId[User], + recordId = nextLongId[MedicalRecord], + startPage = pages._1, + endPage = pages._2, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + + def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = { + BridgeUploadQueue.Item( + kind = nextString(), + tag = nextString(), + created = nextLocalDateTime, + attempts = nextInt(maxAttemtsNumber, minValue = 0), + nextAttempt = nextLocalDateTime, + completed = nextBoolean(), + dependencyKind = nextOption(nextString()), + dependencyTag = nextOption(nextString()) + ) + } + + def nextProviderType(): ProviderType = { + ProviderType( + id = nextLongId[ProviderType], + name = nextString() + ) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala new file mode 100644 index 0000000..d09e09b --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala @@ -0,0 +1,35 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators._ + +object Common { + def genBoundedRange[T](from: T, + to: T) + (implicit ord: Ordering[T]): (T, T) = { + if (ord.compare(from, to) > 0) { + to -> from + } + else { + from -> to + } + } + + def genBoundedRangeOption[T](from: T, + to: T) + (implicit ord: Ordering[T]): (Option[T], Option[T]) = { + val ranges = nextOption(from) + .map(left => + genBoundedRange(left, to) + ) + .map { case (left, right) => + left -> nextOption(right) + } + + ranges.map(_._1) -> ranges.flatMap(_._2) + } + + def genStartAndEndPages: (Option[Double], Option[Double]) = { + genBoundedRangeOption[Double](nextDouble(), nextDouble()) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala new file mode 100644 index 0000000..1c77a78 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -0,0 +1,68 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + + +import java.time.LocalDate + +import xyz.driver.core.generators +import xyz.driver.core.generators.{nextBoolean, nextDouble, nextOption, nextString} +import xyz.driver.pdsuicommon.domain.{TextJson, User} +import xyz.driver.pdsuidomain.entities.{Document, DocumentType, MedicalRecord, ProviderType} +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} + +object DocumentGen { + implicit private class LocalDateOrdering(localData: LocalDate) + extends Ordered[LocalDate] { + + override def compare(that: LocalDate): Int = { + this.localData.compareTo(that) + } + } + + def nextDocumentStatus: Document.Status = + generators.oneOf[Document.Status](Document.Status.All) + + def nextDocumentRequiredType: Document.RequiredType = + generators.oneOf[Document.RequiredType](Document.RequiredType.All) + + def nextDocumentMeta: Document.Meta = { + val (startPage, endPage) = { + val startPage = nextDouble() + val endPage = nextDouble() + if (startPage > endPage) { + endPage -> startPage + } + else { + startPage -> endPage + } + } + + Document.Meta( + nextOption(nextBoolean()), startPage, endPage + ) + } + + def nextDocument: Document = { + val dates = Common + .genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + + Document( + id = nextLongId[Document], + status = nextDocumentStatus, + previousStatus = nextOption(nextDocumentStatus), + assignee = nextOption(nextStringId[User]), + previousAssignee = nextOption(nextStringId[User]), + lastActiveUserId = nextOption(nextStringId[User]), + recordId = nextLongId[MedicalRecord], + physician = nextOption(nextString()), + typeId = nextOption(nextLongId[DocumentType]), + providerName = nextOption(nextString()), + providerTypeId = nextOption(nextLongId[ProviderType]), + requiredType = nextOption(nextDocumentRequiredType), + meta = nextOption(TextJson(nextDocumentMeta)), + startDate = dates._1, + endDate = dates._2, + lastUpdate = nextLocalDateTime + ) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala new file mode 100644 index 0000000..48eaf79 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -0,0 +1,74 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators._ +import xyz.driver.pdsuidomain.entities.{Document, ExtractedData} +import xyz.driver.pdsuidomain.entities.ExtractedData.Meta +import xyz.driver.pdsuidomain.fakes.entities.common._ + + +object ExtractedDataGen { + private val maxPageNumber = 100 + private val maxIndexNumber = 100 + private val maxOffsetNumber = 10 + + implicit private class TextLayerPositionOrdering(textLayerPosition: ExtractedData.Meta.TextLayerPosition) + extends Ordered[ExtractedData.Meta.TextLayerPosition] { + override def compare(that: Meta.TextLayerPosition): Int = { + if (this.textLayerPosition.page < that.page) -1 + else if (this.textLayerPosition.page > that.page) 1 + else if (this.textLayerPosition.index < that.index) -1 + else if (this.textLayerPosition.index > that.index) 1 + else if (this.textLayerPosition.offset < that.offset) -1 + else if (this.textLayerPosition.offset > that.offset) 1 + else 0 + } + } + + def nextExtractedDataMetaKeyword(): Meta.Keyword = { + ExtractedData.Meta.Keyword( + page = nextInt(maxPageNumber, minValue = 0), + pageRatio = nextOption(nextDouble()), + index = nextInt(maxIndexNumber, minValue = 0), + sortIndex = nextString() + ) + } + + def nextExtractedDataMetaTextLayerPosition(): Meta.TextLayerPosition = { + ExtractedData.Meta.TextLayerPosition( + page = nextInt(maxPageNumber, minValue = 0), + index = nextInt(maxIndexNumber, minValue = 0), + offset = nextInt(maxOffsetNumber, minValue = 0) + ) + } + + def nextExtractedDataMetaEvidence(): Meta.Evidence = { + val layersPosition = + Common.genBoundedRange[ExtractedData.Meta.TextLayerPosition]( + nextExtractedDataMetaTextLayerPosition(), + nextExtractedDataMetaTextLayerPosition() + ) + + ExtractedData.Meta.Evidence( + pageRatio = nextDouble(), + start = layersPosition._1, + end = layersPosition._2 + ) + } + + def nextExtractedDataMeta(): Meta = { + ExtractedData.Meta( + nextExtractedDataMetaKeyword(), + nextExtractedDataMetaEvidence() + ) + } + + def nextExtractedData() = { + ExtractedData.apply( + id = nextLongId[ExtractedData], + documentId = nextLongId[Document], + keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]), + evidenceText = nextOption(nextString()), + ??? + ) + } +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala new file mode 100644 index 0000000..1536c65 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala @@ -0,0 +1,63 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.pdsuidomain.entities.MedicalRecord +import xyz.driver.core.generators +import xyz.driver.core.generators._ + +object MedicalRecordMetaGen { + private val maxItemsInCollectionNumber = 50 + private val pageMaxNumber = 1000 + + private val medicalRecordMetas = { + Set( + () => nextMedicalRecordMetaReorder, + () => nextMedicalRecordMetaDuplicate, + () => nextMedicalRecordMetaRotation + ) + } + + + def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = { + val itemsNumber = + maxItemsInCollectionNumber + val items = scala.util.Random + .shuffle(Seq.tabulate(itemsNumber)(identity)) + + MedicalRecord.Meta.Reorder( + predicted = nextOption(nextBoolean), + items = items + ) + } + + + def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = { + val startPageGen = + nextInt(pageMaxNumber, minValue = 0) + val endPageGen = + nextInt(pageMaxNumber, startPageGen) + + MedicalRecord.Meta.Duplicate( + predicted = nextOption(nextBoolean), + startPage = startPageGen.toDouble, + endPage = endPageGen.toDouble, + startOriginalPage = startPageGen.toDouble, + endOriginalPage = nextOption(endPageGen.toDouble) + ) + } + + def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = { + val items = + Array.tabulate(maxItemsInCollectionNumber)( + index => nextString() -> index + ).toMap + + MedicalRecord.Meta.Rotation( + predicted = nextOption(nextBoolean()), + items = items + ) + } + + def nextMedicalRecordMeta: MedicalRecord.Meta = { + generators.oneOf(medicalRecordMetas)() + } +} -- cgit v1.2.3 From 1f569ac1a31f88334c25976d94e7c495a7bbde80 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 14:32:21 +0700 Subject: Implemented all generator for REP's entities --- .../fakes/entities/RecordsProcessingApi.scala | 112 ---------------- .../fakes/entities/rep/BridgeUploadQueueGen.scala | 31 +++++ .../pdsuidomain/fakes/entities/rep/Common.scala | 10 +- .../fakes/entities/rep/DocumentGen.scala | 68 ++++++++-- .../fakes/entities/rep/ExportPatientGen.scala | 55 ++++++++ .../fakes/entities/rep/ExtractedDataGen.scala | 35 ++++- .../fakes/entities/rep/MedicalRecordGen.scala | 146 +++++++++++++++++++++ .../fakes/entities/rep/MedicalRecordMetaGen.scala | 63 --------- 8 files changed, 324 insertions(+), 196 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala deleted file mode 100644 index 93bfce6..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/RecordsProcessingApi.scala +++ /dev/null @@ -1,112 +0,0 @@ -package xyz.driver.pdsuidomain.fakes.entities - - -import xyz.driver.pdsuidomain.entities._ -import xyz.driver.core.generators -import xyz.driver.core.generators._ -import common._ -import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue -import xyz.driver.pdsuicommon.domain.{TextJson, User} -import xyz.driver.pdsuidomain.fakes.entities.rep.{DocumentGen, MedicalRecordMetaGen, Common} - - -object RecordsProcessingApi { - private val maxCollectionNumber = 5 - - private val maxAttemtsNumber = 100 - - private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] = - TextJson(nextMedicalRecordMetas(nextInt(maxCollectionNumber, minValue = 0))) - - private def nextDocuments: TextJson[List[Document]] = - TextJson(nextDocuments(nextInt(maxCollectionNumber, minValue = 0))) - - def nextMedicalRecordStatus: MedicalRecord.Status = - generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All) - - def nextMedicalRecordMeta: MedicalRecord.Meta = - MedicalRecordMetaGen.nextMedicalRecordMeta - - def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] = - List.fill(count)(nextMedicalRecordMeta) - - def nextMedicalRecordHistoryState: MedicalRecordHistory.State = - generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All) - - def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action = - generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) - - def nextDocument: Document = - DocumentGen.nextDocument - - def nextDocuments(count: Int): List[Document] = - List.fill(count)(nextDocument) - - def nextMedicalRecord() = { - MedicalRecord( - id = nextLongId[MedicalRecord], - status = nextMedicalRecordStatus, - previousStatus = nextOption(nextMedicalRecordStatus), - assignee = nextOption(nextStringId), - previousAssignee = nextOption(nextStringId), - lastActiveUserId = nextOption(nextStringId), - patientId = nextUuidId, - requestId = RecordRequestId(generators.nextUuid()), - disease = generators.nextString(), - caseId = nextOption(CaseId(generators.nextString())), - physician = nextOption(generators.nextString()), - meta = nextOption(nextMedicalRecordMetasJson), - predictedMeta = nextOption(nextMedicalRecordMetasJson), - predictedDocuments = nextOption(nextDocuments), - lastUpdate = nextLocalDateTime - ) - } - - def nextMedicalRecordHistory() = { - MedicalRecordHistory( - id = nextLongId[MedicalRecordHistory], - executor = nextStringId[User], - recordId = nextLongId[MedicalRecord], - state = nextMedicalRecordHistoryState, - action = nextMedicalRecordHistoryAction, - created = nextLocalDateTime - ) - } - - def nextMedicalRecordIssue(): MedicalRecordIssue = { - val pages = Common.genStartAndEndPages - - MedicalRecordIssue( - id = nextLongId[MedicalRecordIssue], - userId = nextStringId[User], - recordId = nextLongId[MedicalRecord], - startPage = pages._1, - endPage = pages._2, - lastUpdate = nextLocalDateTime, - isDraft = nextBoolean(), - text = nextString(), - archiveRequired = nextBoolean() - ) - } - - def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = { - BridgeUploadQueue.Item( - kind = nextString(), - tag = nextString(), - created = nextLocalDateTime, - attempts = nextInt(maxAttemtsNumber, minValue = 0), - nextAttempt = nextLocalDateTime, - completed = nextBoolean(), - dependencyKind = nextOption(nextString()), - dependencyTag = nextOption(nextString()) - ) - } - - def nextProviderType(): ProviderType = { - ProviderType( - id = nextLongId[ProviderType], - name = nextString() - ) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala new file mode 100644 index 0000000..fb1d3e3 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala @@ -0,0 +1,31 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators.{nextBoolean, nextInt, nextOption, nextString} +import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue +import xyz.driver.pdsuidomain.entities.ProviderType +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId} + +object BridgeUploadQueueGen { + private val maxAttemtsNumber = 100 + + def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = { + BridgeUploadQueue.Item( + kind = nextString(), + tag = nextString(), + created = nextLocalDateTime, + attempts = nextInt(maxAttemtsNumber, minValue = 0), + nextAttempt = nextLocalDateTime, + completed = nextBoolean(), + dependencyKind = nextOption(nextString()), + dependencyTag = nextOption(nextString()) + ) + } + + def nextProviderType(): ProviderType = { + ProviderType( + id = nextLongId[ProviderType], + name = nextString() + ) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala index d09e09b..337dc2b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala @@ -1,8 +1,10 @@ package xyz.driver.pdsuidomain.fakes.entities.rep +import xyz.driver.core.generators import xyz.driver.core.generators._ +import xyz.driver.pdsuicommon.domain.FuzzyValue -object Common { +private[rep] object Common { def genBoundedRange[T](from: T, to: T) (implicit ord: Ordering[T]): (T, T) = { @@ -28,7 +30,11 @@ object Common { ranges.map(_._1) -> ranges.flatMap(_._2) } - def genStartAndEndPages: (Option[Double], Option[Double]) = { + def nextFuzzyValue(): FuzzyValue = { + generators.oneOf[FuzzyValue](FuzzyValue.All) + } + + def nextStartAndEndPages: (Option[Double], Option[Double]) = { genBoundedRangeOption[Double](nextDouble(), nextDouble()) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 1c77a78..2f07f1d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -5,8 +5,8 @@ import java.time.LocalDate import xyz.driver.core.generators import xyz.driver.core.generators.{nextBoolean, nextDouble, nextOption, nextString} -import xyz.driver.pdsuicommon.domain.{TextJson, User} -import xyz.driver.pdsuidomain.entities.{Document, DocumentType, MedicalRecord, ProviderType} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} object DocumentGen { @@ -18,23 +18,30 @@ object DocumentGen { } } + private def nextDates = + Common.genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + + private def nextStartAndEndPagesOption = + Common.nextStartAndEndPages + + private def nextStartAndEndPage = + Common.genBoundedRange(nextDouble(),nextDouble()) + + def nextDocumentStatus: Document.Status = generators.oneOf[Document.Status](Document.Status.All) def nextDocumentRequiredType: Document.RequiredType = generators.oneOf[Document.RequiredType](Document.RequiredType.All) + def nextDocumentHistoryState: DocumentHistory.State = + generators.oneOf[DocumentHistory.State](DocumentHistory.State.All) + + def nextDocumentHistoryAction: DocumentHistory.Action = + generators.oneOf[DocumentHistory.Action](DocumentHistory.Action.All) + def nextDocumentMeta: Document.Meta = { - val (startPage, endPage) = { - val startPage = nextDouble() - val endPage = nextDouble() - if (startPage > endPage) { - endPage -> startPage - } - else { - startPage -> endPage - } - } + val (startPage, endPage) = nextStartAndEndPage Document.Meta( nextOption(nextBoolean()), startPage, endPage @@ -42,8 +49,7 @@ object DocumentGen { } def nextDocument: Document = { - val dates = Common - .genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + val dates = nextDates Document( id = nextLongId[Document], @@ -65,4 +71,38 @@ object DocumentGen { ) } + def nextDocumentType: DocumentType = { + DocumentType( + id = nextLongId[DocumentType], + name = nextString() + ) + } + + def nextDocumentIssue(documentId: LongId[Document]): DocumentIssue = { + val pages = nextStartAndEndPagesOption + + DocumentIssue( + id = nextLongId[DocumentIssue], + userId = nextStringId[User], + documentId = documentId, + startPage = pages._1, + endPage = pages._2, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + + + def nextDocumentHistory(documentId: LongId[Document]): DocumentHistory = { + DocumentHistory( + id = nextLongId[DocumentHistory], + executor = nextStringId[User], + documentId = documentId, + state = nextDocumentHistoryState, + action = nextDocumentHistoryAction, + created = nextLocalDateTime + ) + } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala new file mode 100644 index 0000000..4a4164a --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -0,0 +1,55 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators._ +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.entities.{Document, ExtractedData, Label, RecordRequestId} +import xyz.driver.pdsuidomain.entities.export.patient.{ +ExportPatientLabel, +ExportPatientLabelEvidence, +ExportPatientLabelEvidenceDocument, +ExportPatientWithLabels +} +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} + +object ExportPatientGen { + private val maxItemsInCollectionNumber = 3 + + def nextExportPatientLabelEvidenceDocument(documentId: LongId[Document]): ExportPatientLabelEvidenceDocument = { + ExportPatientLabelEvidenceDocument( + documentId = documentId, + requestId = RecordRequestId(nextUuid()), + documentType = nextString(), + providerType = nextString(), + date = nextLocalDate + ) + } + + def nextExportPatientLabelEvidence(documentId: LongId[Document]): ExportPatientLabelEvidence = { + ExportPatientLabelEvidence( + id = nextLongId[ExtractedData], + value = Common.nextFuzzyValue(), + evidenceText = nextString(), + document = nextExportPatientLabelEvidenceDocument(documentId) + ) + } + + def nextExportPatientLabel(documentId: LongId[Document]): ExportPatientLabel = { + ExportPatientLabel( + id = nextLongId[Label], + evidences = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExportPatientLabelEvidence(documentId)) + ) + } + + def nextExportPatientWithLabels(documentId: LongId[Document]): ExportPatientWithLabels = { + ExportPatientWithLabels( + patientId = UuidId[xyz.driver.pdsuidomain.entities.Patient](nextUuid()), + labelVersion = scala.util.Random.nextLong(), + labels = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExportPatientLabel(documentId)) + ) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 48eaf79..512e324 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -1,12 +1,17 @@ package xyz.driver.pdsuidomain.fakes.entities.rep + import xyz.driver.core.generators._ -import xyz.driver.pdsuidomain.entities.{Document, ExtractedData} +import xyz.driver.pdsuicommon.domain.{LongId, TextJson} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta import xyz.driver.pdsuidomain.fakes.entities.common._ +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData object ExtractedDataGen { + private val maxItemsInCollectionNumber = 50 + private val maxPageNumber = 100 private val maxIndexNumber = 100 private val maxOffsetNumber = 10 @@ -62,13 +67,33 @@ object ExtractedDataGen { ) } - def nextExtractedData() = { - ExtractedData.apply( + def nextExtractedData(documentId: LongId[Document]): ExtractedData = { + ExtractedData( id = nextLongId[ExtractedData], - documentId = nextLongId[Document], + documentId = documentId, keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]), evidenceText = nextOption(nextString()), - ??? + meta = nextOption(TextJson(nextExtractedDataMeta())) + ) + } + + + def nextExtractedDataLabel(): ExtractedDataLabel = { + ExtractedDataLabel( + id = nextLongId[ExtractedDataLabel], + dataId = nextLongId[ExtractedData], + labelId = nextOption(nextLongId[Label]), + categoryId = nextOption(nextLongId[Category]), + value = nextOption(Common.nextFuzzyValue()) + ) + } + + def nextRichExtractedData(documentId: LongId[Document]): RichExtractedData = { + RichExtractedData( + extractedData = nextExtractedData(documentId), + labels = List.fill( + nextInt(maxItemsInCollectionNumber, minValue = 0) + )(nextExtractedDataLabel()) ) } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala new file mode 100644 index 0000000..0ea3cdd --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -0,0 +1,146 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.pdsuidomain.entities._ +import xyz.driver.core.generators +import xyz.driver.core.generators._ +import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} +import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId, nextStringId, nextUuidId} + +object MedicalRecordGen { + private val maxItemsInCollectionNumber = 50 + + private val pageMaxNumber = 1000 + + private val medicalRecordMetas = { + Set( + () => nextMedicalRecordMetaReorder, + () => nextMedicalRecordMetaDuplicate, + () => nextMedicalRecordMetaRotation + ) + } + + def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] = + List.fill(count)(nextMedicalRecordMeta) + + private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] = + TextJson(nextMedicalRecordMetas(nextInt(maxItemsInCollectionNumber, minValue = 0))) + + private def nextDocument: Document = + DocumentGen.nextDocument + + private def nextDocuments(count: Int): List[Document] = + List.fill(count)(nextDocument) + + private def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { + val documents = nextDocuments( + nextInt(maxItemsInCollectionNumber, minValue = 0) + ) + + TextJson(documents.map(_.copy(recordId = recordId))) + } + + + def nextMedicalRecordStatus: MedicalRecord.Status = + generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All) + + def nextMedicalRecordHistoryState: MedicalRecordHistory.State = + generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All) + + def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action = + generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) + + + def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = { + val itemsNumber = + maxItemsInCollectionNumber + val items = scala.util.Random + .shuffle(Seq.tabulate(itemsNumber)(identity)) + + MedicalRecord.Meta.Reorder( + predicted = nextOption(nextBoolean), + items = items + ) + } + + + def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = { + val startPageGen = + nextInt(pageMaxNumber, minValue = 0) + val endPageGen = + nextInt(pageMaxNumber, startPageGen) + + MedicalRecord.Meta.Duplicate( + predicted = nextOption(nextBoolean), + startPage = startPageGen.toDouble, + endPage = endPageGen.toDouble, + startOriginalPage = startPageGen.toDouble, + endOriginalPage = nextOption(endPageGen.toDouble) + ) + } + + def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = { + val items = + Array.tabulate(maxItemsInCollectionNumber)( + index => nextString() -> index + ).toMap + + MedicalRecord.Meta.Rotation( + predicted = nextOption(nextBoolean()), + items = items + ) + } + + def nextMedicalRecordMeta: MedicalRecord.Meta = { + generators.oneOf(medicalRecordMetas)() + } + + + def nextMedicalRecord(): MedicalRecord = { + val id = nextLongId[MedicalRecord] + MedicalRecord( + id = nextLongId[MedicalRecord], + status = nextMedicalRecordStatus, + previousStatus = nextOption(nextMedicalRecordStatus), + assignee = nextOption(nextStringId), + previousAssignee = nextOption(nextStringId), + lastActiveUserId = nextOption(nextStringId), + patientId = nextUuidId, + requestId = RecordRequestId(generators.nextUuid()), + disease = generators.nextString(), + caseId = nextOption(CaseId(generators.nextString())), + physician = nextOption(generators.nextString()), + meta = nextOption(nextMedicalRecordMetasJson), + predictedMeta = nextOption(nextMedicalRecordMetasJson), + predictedDocuments = nextOption(nextDocuments(id)), + lastUpdate = nextLocalDateTime + ) + } + + def nextMedicalRecordHistory(): MedicalRecordHistory = { + MedicalRecordHistory( + id = nextLongId[MedicalRecordHistory], + executor = nextStringId[User], + recordId = nextLongId[MedicalRecord], + state = nextMedicalRecordHistoryState, + action = nextMedicalRecordHistoryAction, + created = nextLocalDateTime + ) + } + + def nextMedicalRecordIssue(): MedicalRecordIssue = { + val pages = Common.nextStartAndEndPages + + MedicalRecordIssue( + id = nextLongId[MedicalRecordIssue], + userId = nextStringId[User], + recordId = nextLongId[MedicalRecord], + startPage = pages._1, + endPage = pages._2, + lastUpdate = nextLocalDateTime, + isDraft = nextBoolean(), + text = nextString(), + archiveRequired = nextBoolean() + ) + } + +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala deleted file mode 100644 index 1536c65..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordMetaGen.scala +++ /dev/null @@ -1,63 +0,0 @@ -package xyz.driver.pdsuidomain.fakes.entities.rep - -import xyz.driver.pdsuidomain.entities.MedicalRecord -import xyz.driver.core.generators -import xyz.driver.core.generators._ - -object MedicalRecordMetaGen { - private val maxItemsInCollectionNumber = 50 - private val pageMaxNumber = 1000 - - private val medicalRecordMetas = { - Set( - () => nextMedicalRecordMetaReorder, - () => nextMedicalRecordMetaDuplicate, - () => nextMedicalRecordMetaRotation - ) - } - - - def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = { - val itemsNumber = - maxItemsInCollectionNumber - val items = scala.util.Random - .shuffle(Seq.tabulate(itemsNumber)(identity)) - - MedicalRecord.Meta.Reorder( - predicted = nextOption(nextBoolean), - items = items - ) - } - - - def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = { - val startPageGen = - nextInt(pageMaxNumber, minValue = 0) - val endPageGen = - nextInt(pageMaxNumber, startPageGen) - - MedicalRecord.Meta.Duplicate( - predicted = nextOption(nextBoolean), - startPage = startPageGen.toDouble, - endPage = endPageGen.toDouble, - startOriginalPage = startPageGen.toDouble, - endOriginalPage = nextOption(endPageGen.toDouble) - ) - } - - def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = { - val items = - Array.tabulate(maxItemsInCollectionNumber)( - index => nextString() -> index - ).toMap - - MedicalRecord.Meta.Rotation( - predicted = nextOption(nextBoolean()), - items = items - ) - } - - def nextMedicalRecordMeta: MedicalRecord.Meta = { - generators.oneOf(medicalRecordMetas)() - } -} -- cgit v1.2.3 From f8902d43cb189b408210ae7c80e2112346bdc037 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 18:26:36 +0700 Subject: Fixed generators of entities for ReP; Implemented json examples for swagger for ReP --- .../utils/CustomSwaggerJsonFormats.scala | 94 +++++++++++++++++++++- .../fakes/entities/rep/BridgeUploadQueueGen.scala | 15 +--- .../fakes/entities/rep/DocumentGen.scala | 48 ++++++----- .../fakes/entities/rep/ExtractedDataGen.scala | 14 +++- .../fakes/entities/rep/MedicalRecordGen.scala | 52 ++++++------ .../fakes/entities/rep/ProviderTypeGen.scala | 14 ++++ 6 files changed, 171 insertions(+), 66 deletions(-) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 6c87858..f2c6d94 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -4,7 +4,7 @@ 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.pdsuicommon.domain.{LongId, StringId, TextJson, UuidId} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.formats.json.sprayformats.arm._ import xyz.driver.pdsuidomain.formats.json.sprayformats.criterion._ @@ -15,25 +15,29 @@ 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.pdsuicommon.concurrent.BridgeUploadQueue import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion +import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData + +import scala.collection.immutable object CustomSwaggerJsonFormats { - val customCommonProperties = Map[Class[_], Property]( + val customCommonProperties = immutable.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]( + val customTrialCurationProperties = immutable.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]( + val customTrialCurationObjectsExamples = immutable.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( @@ -52,4 +56,86 @@ object CustomSwaggerJsonFormats { xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) ) + //records-processing-service + object Rep { + import xyz.driver.pdsuidomain.fakes.entities.rep + import xyz.driver.pdsuidomain.formats.json.sprayformats.document + import xyz.driver.pdsuidomain.formats.json.sprayformats.documentissue + import xyz.driver.pdsuidomain.formats.json.sprayformats.documenthistory + import xyz.driver.pdsuidomain.formats.json.sprayformats.providertype + import xyz.driver.pdsuidomain.formats.json.sprayformats.record + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordissue + import xyz.driver.pdsuidomain.formats.json.sprayformats.recordhistory + import xyz.driver.pdsuidomain.formats.json.sprayformats.bridgeuploadqueue + import xyz.driver.pdsuidomain.formats.json.sprayformats.extracteddata + + + val customRepObjectsExamples = immutable.Map[Class[_], JsValue]( + classOf[Document] -> + document.documentFormat.write(rep.DocumentGen.nextDocument()), + classOf[Document.Meta] -> + document.documentMetaFormat.write(rep.DocumentGen.nextDocumentMeta()), + classOf[TextJson[Document.Meta]] -> + document.fullDocumentMetaFormat.write(rep.DocumentGen.nextDocumentMetaJson()), + classOf[Document.RequiredType] -> + document.requiredTypeFormat.write(rep.DocumentGen.nextDocumentRequiredType()), + classOf[Document.Status] -> + document.documentStatusFormat.write(rep.DocumentGen.nextDocumentStatus()), + + classOf[DocumentIssue] -> + documentissue.documentIssueFormat.write(rep.DocumentGen.nextDocumentIssue()), + + classOf[DocumentHistory] -> + documenthistory.documentHistoryFormat.write(rep.DocumentGen.nextDocumentHistory()), + classOf[DocumentHistory.Action] -> + documenthistory.documentActionFormat.write(rep.DocumentGen.nextDocumentHistoryAction()), + classOf[DocumentHistory.State] -> + documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), + + classOf[ProviderType] -> + providertype.providerTypeFormat.write(rep.ProviderTypeGen.nextProviderType()), + + classOf[TextJson[List[MedicalRecord.Meta]]] -> + record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), + classOf[MedicalRecord] -> + record.recordFormat.write(rep.MedicalRecordGen.nextMedicalRecord()), + classOf[MedicalRecord.Meta] -> + record.recordMetaTypeFormat.write(rep.MedicalRecordGen.nextMedicalRecordMeta()), + classOf[MedicalRecord.Status] -> + record.recordStatusFormat.write(rep.MedicalRecordGen.nextMedicalRecordStatus()), + + classOf[MedicalRecordIssue] -> + recordissue.recordIssueFormat.write(rep.MedicalRecordGen.nextMedicalRecordIssue()), + + classOf[MedicalRecordHistory] -> + recordhistory.recordHistoryFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistory()), + classOf[MedicalRecordHistory.Action] -> + recordhistory.recordActionFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryAction()), + classOf[MedicalRecordHistory.State] -> + recordhistory.recordStateFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryState()), + + classOf[BridgeUploadQueue.Item] -> + bridgeuploadqueue.queueUploadItemFormat.write(rep.BridgeUploadQueueGen.nextBridgeUploadQueueItem()), + + classOf[ExtractedData.Meta] -> + extracteddata.extractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMeta()), + classOf[ExtractedData.Meta.Evidence] -> + extracteddata.metaEvidenceFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaEvidence()), + classOf[ExtractedData.Meta.Keyword] -> + extracteddata.metaKeywordFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaKeyword()), + classOf[ExtractedData.Meta.TextLayerPosition] -> + extracteddata.metaTextLayerPositionFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaTextLayerPosition()), + + classOf[TextJson[ExtractedData.Meta]] -> + extracteddata.fullExtractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaJson()), + + classOf[RichExtractedData] -> + extracteddata.extractedDataFormat.write(rep.ExtractedDataGen.nextRichExtractedData()), + + classOf[ExtractedDataLabel] -> + extracteddata.extractedDataLabelWriter.write(rep.ExtractedDataGen.nextExtractedDataLabel()) + ) + } + + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala index fb1d3e3..e7cbd19 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala @@ -2,30 +2,21 @@ package xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.core.generators.{nextBoolean, nextInt, nextOption, nextString} import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue -import xyz.driver.pdsuidomain.entities.ProviderType -import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId} +import xyz.driver.pdsuidomain.fakes.entities.common.nextLocalDateTime object BridgeUploadQueueGen { - private val maxAttemtsNumber = 100 + private val maxAttemptsNumber = 100 def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = { BridgeUploadQueue.Item( kind = nextString(), tag = nextString(), created = nextLocalDateTime, - attempts = nextInt(maxAttemtsNumber, minValue = 0), + attempts = nextInt(maxAttemptsNumber, minValue = 0), nextAttempt = nextLocalDateTime, completed = nextBoolean(), dependencyKind = nextOption(nextString()), dependencyTag = nextOption(nextString()) ) } - - def nextProviderType(): ProviderType = { - ProviderType( - id = nextLongId[ProviderType], - name = nextString() - ) - } - } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 2f07f1d..0d32495 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -18,43 +18,47 @@ object DocumentGen { } } - private def nextDates = + private def nextDates() = Common.genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) - private def nextStartAndEndPagesOption = + private def nextStartAndEndPagesOption() = Common.nextStartAndEndPages - private def nextStartAndEndPage = + private def nextStartAndEndPage() = Common.genBoundedRange(nextDouble(),nextDouble()) - def nextDocumentStatus: Document.Status = - generators.oneOf[Document.Status](Document.Status.All) + def nextDocumentStatus(): Document.Status = + Document.Status.New - def nextDocumentRequiredType: Document.RequiredType = + def nextDocumentRequiredType(): Document.RequiredType = generators.oneOf[Document.RequiredType](Document.RequiredType.All) - def nextDocumentHistoryState: DocumentHistory.State = + def nextDocumentHistoryState(): DocumentHistory.State = generators.oneOf[DocumentHistory.State](DocumentHistory.State.All) - def nextDocumentHistoryAction: DocumentHistory.Action = + def nextDocumentHistoryAction(): DocumentHistory.Action = generators.oneOf[DocumentHistory.Action](DocumentHistory.Action.All) - def nextDocumentMeta: Document.Meta = { - val (startPage, endPage) = nextStartAndEndPage + def nextDocumentMeta(): Document.Meta = { + val (startPage, endPage) = nextStartAndEndPage() Document.Meta( nextOption(nextBoolean()), startPage, endPage ) } - def nextDocument: Document = { - val dates = nextDates + def nextDocumentMetaJson(): TextJson[Document.Meta] = { + TextJson(nextDocumentMeta()) + } + + def nextDocument(): Document = { + val dates = nextDates() Document( id = nextLongId[Document], - status = nextDocumentStatus, - previousStatus = nextOption(nextDocumentStatus), + status = nextDocumentStatus(), + previousStatus = None, assignee = nextOption(nextStringId[User]), previousAssignee = nextOption(nextStringId[User]), lastActiveUserId = nextOption(nextStringId[User]), @@ -63,23 +67,23 @@ object DocumentGen { typeId = nextOption(nextLongId[DocumentType]), providerName = nextOption(nextString()), providerTypeId = nextOption(nextLongId[ProviderType]), - requiredType = nextOption(nextDocumentRequiredType), - meta = nextOption(TextJson(nextDocumentMeta)), + requiredType = nextOption(nextDocumentRequiredType()), + meta = nextOption(nextDocumentMetaJson()), startDate = dates._1, endDate = dates._2, lastUpdate = nextLocalDateTime ) } - def nextDocumentType: DocumentType = { + def nextDocumentType(): DocumentType = { DocumentType( id = nextLongId[DocumentType], name = nextString() ) } - def nextDocumentIssue(documentId: LongId[Document]): DocumentIssue = { - val pages = nextStartAndEndPagesOption + def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = { + val pages = nextStartAndEndPagesOption() DocumentIssue( id = nextLongId[DocumentIssue], @@ -95,13 +99,13 @@ object DocumentGen { } - def nextDocumentHistory(documentId: LongId[Document]): DocumentHistory = { + def nextDocumentHistory(documentId: LongId[Document] = nextLongId): DocumentHistory = { DocumentHistory( id = nextLongId[DocumentHistory], executor = nextStringId[User], documentId = documentId, - state = nextDocumentHistoryState, - action = nextDocumentHistoryAction, + state = nextDocumentHistoryState(), + action = nextDocumentHistoryAction(), created = nextLocalDateTime ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 512e324..0d99d19 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -67,13 +67,23 @@ object ExtractedDataGen { ) } + def nextExtractedDataMetaJson(): TextJson[Meta] = { + TextJson( + ExtractedData.Meta( + nextExtractedDataMetaKeyword(), + nextExtractedDataMetaEvidence() + ) + ) + } + + def nextExtractedData(documentId: LongId[Document]): ExtractedData = { ExtractedData( id = nextLongId[ExtractedData], documentId = documentId, keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]), evidenceText = nextOption(nextString()), - meta = nextOption(TextJson(nextExtractedDataMeta())) + meta = nextOption(nextExtractedDataMetaJson()) ) } @@ -88,7 +98,7 @@ object ExtractedDataGen { ) } - def nextRichExtractedData(documentId: LongId[Document]): RichExtractedData = { + def nextRichExtractedData(documentId: LongId[Document] = nextLongId): RichExtractedData = { RichExtractedData( extractedData = nextExtractedData(documentId), labels = List.fill( diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 0ea3cdd..90c98c3 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -7,31 +7,31 @@ import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId, nextStringId, nextUuidId} object MedicalRecordGen { - private val maxItemsInCollectionNumber = 50 + private val maxItemsInCollectionNumber: Int = 50 - private val pageMaxNumber = 1000 + private val pageMaxNumber: Int = 1000 - private val medicalRecordMetas = { + private val medicalRecordMetas: Set[() => MedicalRecord.Meta] = { Set( - () => nextMedicalRecordMetaReorder, - () => nextMedicalRecordMetaDuplicate, - () => nextMedicalRecordMetaRotation + () => nextMedicalRecordMetaReorder(), + () => nextMedicalRecordMetaDuplicate(), + () => nextMedicalRecordMetaRotation() ) } def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] = - List.fill(count)(nextMedicalRecordMeta) + List.fill(count)(nextMedicalRecordMeta()) - private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] = + def nextMedicalRecordMetasJson(): TextJson[List[MedicalRecord.Meta]] = TextJson(nextMedicalRecordMetas(nextInt(maxItemsInCollectionNumber, minValue = 0))) - private def nextDocument: Document = - DocumentGen.nextDocument + private def nextDocument(): Document = + DocumentGen.nextDocument() private def nextDocuments(count: Int): List[Document] = - List.fill(count)(nextDocument) + List.fill(count)(nextDocument()) - private def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { + def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { val documents = nextDocuments( nextInt(maxItemsInCollectionNumber, minValue = 0) ) @@ -40,17 +40,17 @@ object MedicalRecordGen { } - def nextMedicalRecordStatus: MedicalRecord.Status = - generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All) + def nextMedicalRecordStatus(): MedicalRecord.Status = + MedicalRecord.Status.New - def nextMedicalRecordHistoryState: MedicalRecordHistory.State = + def nextMedicalRecordHistoryState(): MedicalRecordHistory.State = generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All) - def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action = + def nextMedicalRecordHistoryAction(): MedicalRecordHistory.Action = generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) - def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = { + def nextMedicalRecordMetaReorder(): MedicalRecord.Meta.Reorder = { val itemsNumber = maxItemsInCollectionNumber val items = scala.util.Random @@ -63,7 +63,7 @@ object MedicalRecordGen { } - def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = { + def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { val startPageGen = nextInt(pageMaxNumber, minValue = 0) val endPageGen = @@ -78,7 +78,7 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = { + def nextMedicalRecordMetaRotation(): MedicalRecord.Meta.Rotation = { val items = Array.tabulate(maxItemsInCollectionNumber)( index => nextString() -> index @@ -90,7 +90,7 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMeta: MedicalRecord.Meta = { + def nextMedicalRecordMeta(): MedicalRecord.Meta = { generators.oneOf(medicalRecordMetas)() } @@ -99,8 +99,8 @@ object MedicalRecordGen { val id = nextLongId[MedicalRecord] MedicalRecord( id = nextLongId[MedicalRecord], - status = nextMedicalRecordStatus, - previousStatus = nextOption(nextMedicalRecordStatus), + status = nextMedicalRecordStatus(), + previousStatus = None, assignee = nextOption(nextStringId), previousAssignee = nextOption(nextStringId), lastActiveUserId = nextOption(nextStringId), @@ -109,8 +109,8 @@ object MedicalRecordGen { disease = generators.nextString(), caseId = nextOption(CaseId(generators.nextString())), physician = nextOption(generators.nextString()), - meta = nextOption(nextMedicalRecordMetasJson), - predictedMeta = nextOption(nextMedicalRecordMetasJson), + meta = nextOption(nextMedicalRecordMetasJson()), + predictedMeta = nextOption(nextMedicalRecordMetasJson()), predictedDocuments = nextOption(nextDocuments(id)), lastUpdate = nextLocalDateTime ) @@ -121,8 +121,8 @@ object MedicalRecordGen { id = nextLongId[MedicalRecordHistory], executor = nextStringId[User], recordId = nextLongId[MedicalRecord], - state = nextMedicalRecordHistoryState, - action = nextMedicalRecordHistoryAction, + state = nextMedicalRecordHistoryState(), + action = nextMedicalRecordHistoryAction(), created = nextLocalDateTime ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala new file mode 100644 index 0000000..168f7af --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala @@ -0,0 +1,14 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators.nextString +import xyz.driver.pdsuidomain.entities.ProviderType +import xyz.driver.pdsuidomain.fakes.entities.common.nextLongId + +object ProviderTypeGen { + def nextProviderType(): ProviderType = { + ProviderType( + id = nextLongId[ProviderType], + name = nextString() + ) + } +} -- cgit v1.2.3 From fa841b8902ff29dc3d3e8c7dccd93d7b5b2b827f Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 18:27:34 +0700 Subject: Formatted code by scalafmt --- .../pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 13 ------------- .../pdsuidomain/fakes/entities/rep/Common.scala | 20 +++++++------------- .../pdsuidomain/fakes/entities/rep/DocumentGen.scala | 12 +++++------- .../fakes/entities/rep/ExportPatientGen.scala | 8 ++++---- .../fakes/entities/rep/ExtractedDataGen.scala | 12 ++++-------- .../fakes/entities/rep/MedicalRecordGen.scala | 12 +++++------- 6 files changed, 25 insertions(+), 52 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index f2c6d94..538618b 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -69,7 +69,6 @@ object CustomSwaggerJsonFormats { import xyz.driver.pdsuidomain.formats.json.sprayformats.bridgeuploadqueue import xyz.driver.pdsuidomain.formats.json.sprayformats.extracteddata - val customRepObjectsExamples = immutable.Map[Class[_], JsValue]( classOf[Document] -> document.documentFormat.write(rep.DocumentGen.nextDocument()), @@ -81,20 +80,16 @@ object CustomSwaggerJsonFormats { document.requiredTypeFormat.write(rep.DocumentGen.nextDocumentRequiredType()), classOf[Document.Status] -> document.documentStatusFormat.write(rep.DocumentGen.nextDocumentStatus()), - classOf[DocumentIssue] -> documentissue.documentIssueFormat.write(rep.DocumentGen.nextDocumentIssue()), - classOf[DocumentHistory] -> documenthistory.documentHistoryFormat.write(rep.DocumentGen.nextDocumentHistory()), classOf[DocumentHistory.Action] -> documenthistory.documentActionFormat.write(rep.DocumentGen.nextDocumentHistoryAction()), classOf[DocumentHistory.State] -> documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), - classOf[ProviderType] -> providertype.providerTypeFormat.write(rep.ProviderTypeGen.nextProviderType()), - classOf[TextJson[List[MedicalRecord.Meta]]] -> record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), classOf[MedicalRecord] -> @@ -103,20 +98,16 @@ object CustomSwaggerJsonFormats { record.recordMetaTypeFormat.write(rep.MedicalRecordGen.nextMedicalRecordMeta()), classOf[MedicalRecord.Status] -> record.recordStatusFormat.write(rep.MedicalRecordGen.nextMedicalRecordStatus()), - classOf[MedicalRecordIssue] -> recordissue.recordIssueFormat.write(rep.MedicalRecordGen.nextMedicalRecordIssue()), - classOf[MedicalRecordHistory] -> recordhistory.recordHistoryFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistory()), classOf[MedicalRecordHistory.Action] -> recordhistory.recordActionFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryAction()), classOf[MedicalRecordHistory.State] -> recordhistory.recordStateFormat.write(rep.MedicalRecordGen.nextMedicalRecordHistoryState()), - classOf[BridgeUploadQueue.Item] -> bridgeuploadqueue.queueUploadItemFormat.write(rep.BridgeUploadQueueGen.nextBridgeUploadQueueItem()), - classOf[ExtractedData.Meta] -> extracteddata.extractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMeta()), classOf[ExtractedData.Meta.Evidence] -> @@ -125,17 +116,13 @@ object CustomSwaggerJsonFormats { extracteddata.metaKeywordFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaKeyword()), classOf[ExtractedData.Meta.TextLayerPosition] -> extracteddata.metaTextLayerPositionFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaTextLayerPosition()), - classOf[TextJson[ExtractedData.Meta]] -> extracteddata.fullExtractedDataMetaFormat.write(rep.ExtractedDataGen.nextExtractedDataMetaJson()), - classOf[RichExtractedData] -> extracteddata.extractedDataFormat.write(rep.ExtractedDataGen.nextRichExtractedData()), - classOf[ExtractedDataLabel] -> extracteddata.extractedDataLabelWriter.write(rep.ExtractedDataGen.nextExtractedDataLabel()) ) } - } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala index 337dc2b..9618eed 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala @@ -5,26 +5,20 @@ import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.FuzzyValue private[rep] object Common { - def genBoundedRange[T](from: T, - to: T) - (implicit ord: Ordering[T]): (T, T) = { + def genBoundedRange[T](from: T, to: T)(implicit ord: Ordering[T]): (T, T) = { if (ord.compare(from, to) > 0) { to -> from - } - else { + } else { from -> to } } - def genBoundedRangeOption[T](from: T, - to: T) - (implicit ord: Ordering[T]): (Option[T], Option[T]) = { + def genBoundedRangeOption[T](from: T, to: T)(implicit ord: Ordering[T]): (Option[T], Option[T]) = { val ranges = nextOption(from) - .map(left => - genBoundedRange(left, to) - ) - .map { case (left, right) => - left -> nextOption(right) + .map(left => genBoundedRange(left, to)) + .map { + case (left, right) => + left -> nextOption(right) } ranges.map(_._1) -> ranges.flatMap(_._2) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 0d32495..10349bb 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -1,6 +1,5 @@ package xyz.driver.pdsuidomain.fakes.entities.rep - import java.time.LocalDate import xyz.driver.core.generators @@ -10,8 +9,7 @@ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} object DocumentGen { - implicit private class LocalDateOrdering(localData: LocalDate) - extends Ordered[LocalDate] { + implicit private class LocalDateOrdering(localData: LocalDate) extends Ordered[LocalDate] { override def compare(that: LocalDate): Int = { this.localData.compareTo(that) @@ -25,8 +23,7 @@ object DocumentGen { Common.nextStartAndEndPages private def nextStartAndEndPage() = - Common.genBoundedRange(nextDouble(),nextDouble()) - + Common.genBoundedRange(nextDouble(), nextDouble()) def nextDocumentStatus(): Document.Status = Document.Status.New @@ -44,7 +41,9 @@ object DocumentGen { val (startPage, endPage) = nextStartAndEndPage() Document.Meta( - nextOption(nextBoolean()), startPage, endPage + nextOption(nextBoolean()), + startPage, + endPage ) } @@ -98,7 +97,6 @@ object DocumentGen { ) } - def nextDocumentHistory(documentId: LongId[Document] = nextLongId): DocumentHistory = { DocumentHistory( id = nextLongId[DocumentHistory], diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala index 4a4164a..7259d0c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -4,10 +4,10 @@ import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuidomain.entities.{Document, ExtractedData, Label, RecordRequestId} import xyz.driver.pdsuidomain.entities.export.patient.{ -ExportPatientLabel, -ExportPatientLabelEvidence, -ExportPatientLabelEvidenceDocument, -ExportPatientWithLabels + ExportPatientLabel, + ExportPatientLabelEvidence, + ExportPatientLabelEvidenceDocument, + ExportPatientWithLabels } import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 0d99d19..8ac07d0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -1,6 +1,5 @@ package xyz.driver.pdsuidomain.fakes.entities.rep - import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ @@ -8,16 +7,15 @@ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta import xyz.driver.pdsuidomain.fakes.entities.common._ import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - object ExtractedDataGen { private val maxItemsInCollectionNumber = 50 - private val maxPageNumber = 100 - private val maxIndexNumber = 100 + private val maxPageNumber = 100 + private val maxIndexNumber = 100 private val maxOffsetNumber = 10 implicit private class TextLayerPositionOrdering(textLayerPosition: ExtractedData.Meta.TextLayerPosition) - extends Ordered[ExtractedData.Meta.TextLayerPosition] { + extends Ordered[ExtractedData.Meta.TextLayerPosition] { override def compare(that: Meta.TextLayerPosition): Int = { if (this.textLayerPosition.page < that.page) -1 else if (this.textLayerPosition.page > that.page) 1 @@ -56,7 +54,7 @@ object ExtractedDataGen { ExtractedData.Meta.Evidence( pageRatio = nextDouble(), start = layersPosition._1, - end = layersPosition._2 + end = layersPosition._2 ) } @@ -76,7 +74,6 @@ object ExtractedDataGen { ) } - def nextExtractedData(documentId: LongId[Document]): ExtractedData = { ExtractedData( id = nextLongId[ExtractedData], @@ -87,7 +84,6 @@ object ExtractedDataGen { ) } - def nextExtractedDataLabel(): ExtractedDataLabel = { ExtractedDataLabel( id = nextLongId[ExtractedDataLabel], diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 90c98c3..7221e66 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -39,7 +39,6 @@ object MedicalRecordGen { TextJson(documents.map(_.copy(recordId = recordId))) } - def nextMedicalRecordStatus(): MedicalRecord.Status = MedicalRecord.Status.New @@ -49,7 +48,6 @@ object MedicalRecordGen { def nextMedicalRecordHistoryAction(): MedicalRecordHistory.Action = generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) - def nextMedicalRecordMetaReorder(): MedicalRecord.Meta.Reorder = { val itemsNumber = maxItemsInCollectionNumber @@ -62,7 +60,6 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { val startPageGen = nextInt(pageMaxNumber, minValue = 0) @@ -80,9 +77,11 @@ object MedicalRecordGen { def nextMedicalRecordMetaRotation(): MedicalRecord.Meta.Rotation = { val items = - Array.tabulate(maxItemsInCollectionNumber)( - index => nextString() -> index - ).toMap + Array + .tabulate(maxItemsInCollectionNumber)( + index => nextString() -> index + ) + .toMap MedicalRecord.Meta.Rotation( predicted = nextOption(nextBoolean()), @@ -94,7 +93,6 @@ object MedicalRecordGen { generators.oneOf(medicalRecordMetas)() } - def nextMedicalRecord(): MedicalRecord = { val id = nextLongId[MedicalRecord] MedicalRecord( -- cgit v1.2.3 From deba20326e3269fee3ef51f8e6841f17453b4155 Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 28 Sep 2017 13:12:32 -0700 Subject: Simplified Export entities for EVLS --- .../pdsuidomain/entities/RawPatientLabel.scala | 4 +- .../ExportPatientLabelEvidenceDocument.scala | 6 +- .../json/export/ApiExportPatientLabel.scala | 28 ------- .../export/ApiExportPatientLabelEvidence.scala | 38 --------- .../ApiExportPatientLabelEvidenceDocument.scala | 46 ---------- .../json/export/ApiExportPatientWithLabels.scala | 31 ------- .../formats/json/export/ApiExportTrialArm.scala | 27 ------ .../json/export/ApiExportTrialLabelCriterion.scala | 55 ------------ .../json/export/ApiExportTrialWithLabels.scala | 53 ------------ .../formats/json/sprayformats/document.scala | 2 + .../formats/json/sprayformats/export.scala | 97 ++++++++++++---------- .../formats/json/sprayformats/record.scala | 2 + .../services/rest/RestExtractedDataService.scala | 9 +- .../services/rest/RestTrialService.scala | 8 +- .../json/sprayformats/ExportFormatSuite.scala | 26 +++--- 15 files changed, 87 insertions(+), 345 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabel.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidence.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientLabelEvidenceDocument.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportPatientWithLabels.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala (limited to 'src/main/scala') 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) } - } -- cgit v1.2.3 From b7dfa70fdc49d0a47f8628139baebf27ad2ea746 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 29 Sep 2017 09:33:59 +0700 Subject: Corrected scala style errors --- .../scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 538618b..4ecf915 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -56,7 +56,7 @@ object CustomSwaggerJsonFormats { xyz.driver.pdsuidomain.fakes.entities.trialcuration.nextStudyDesign()) ) - //records-processing-service + // records-processing-service object Rep { import xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.pdsuidomain.formats.json.sprayformats.document -- cgit v1.2.3 From 642f98c2ddd8af6c83d3de5a51c643ba93b23f96 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 29 Sep 2017 13:48:22 +0700 Subject: Fixed ExportPatientGen class --- .../fakes/entities/rep/ExportPatientGen.scala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala index 7259d0c..c2909f3 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.{LongId, UuidId} -import xyz.driver.pdsuidomain.entities.{Document, ExtractedData, Label, RecordRequestId} +import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.export.patient.{ ExportPatientLabel, ExportPatientLabelEvidence, @@ -14,12 +14,26 @@ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} object ExportPatientGen { private val maxItemsInCollectionNumber = 3 + def nextDocumentType(documentTypeId: LongId[DocumentType] = nextLongId): DocumentType = { + DocumentType( + documentTypeId, + nextString() + ) + } + + def nextProviderType(providerTypeId: LongId[ProviderType] = nextLongId): ProviderType = { + ProviderType( + providerTypeId, + nextString() + ) + } + def nextExportPatientLabelEvidenceDocument(documentId: LongId[Document]): ExportPatientLabelEvidenceDocument = { ExportPatientLabelEvidenceDocument( documentId = documentId, requestId = RecordRequestId(nextUuid()), - documentType = nextString(), - providerType = nextString(), + documentType = nextDocumentType(), + providerType = nextProviderType(), date = nextLocalDate ) } -- cgit v1.2.3 From b5e0d5f91b52013bc11ef3ea586a54bb001577bc Mon Sep 17 00:00:00 2001 From: vlad Date: Sun, 1 Oct 2017 12:50:54 -0700 Subject: Fixing IN in filters, Model from EVLS added to common, Reusing domain model labels --- build.sbt | 4 +- .../pdsuicommon/db/SlickPostgresQueryBuilder.scala | 3 +- .../driver/pdsuicommon/db/SlickQueryBuilder.scala | 3 +- .../pdsuicommon/parsers/SearchFilterParser.scala | 23 +++-- .../utils/CustomSwaggerJsonFormats.scala | 2 +- .../driver/pdsuidomain/entities/Criterion.scala | 5 +- .../pdsuidomain/entities/ExtractedData.scala | 3 +- .../xyz/driver/pdsuidomain/entities/Keyword.scala | 3 +- .../xyz/driver/pdsuidomain/entities/Label.scala | 31 ------- .../driver/pdsuidomain/entities/PatientLabel.scala | 1 + .../entities/PatientLabelEvidenceView.scala | 1 + .../pdsuidomain/entities/RawPatientLabel.scala | 1 + .../pdsuidomain/entities/RawTrialLabel.scala | 1 + .../driver/pdsuidomain/entities/eligibility.scala | 63 +++++++++++++ .../export/patient/ExportPatientLabel.scala | 3 +- .../export/trial/ExportTrialLabelCriterion.scala | 3 +- .../driver/pdsuidomain/fakes/entities/common.scala | 41 +++++++-- .../pdsuidomain/fakes/entities/eligibility.scala | 72 +++++++++++++++ .../driver/pdsuidomain/fakes/entities/export.scala | 35 +++++++ .../pdsuidomain/fakes/entities/rep/Common.scala | 35 ------- .../fakes/entities/rep/DocumentGen.scala | 7 +- .../fakes/entities/rep/ExportPatientGen.scala | 11 +-- .../fakes/entities/rep/ExtractedDataGen.scala | 17 ++-- .../fakes/entities/rep/MedicalRecordGen.scala | 7 +- .../fakes/entities/rep/ProviderTypeGen.scala | 14 --- .../pdsuidomain/fakes/entities/trialcuration.scala | 3 +- .../formats/json/category/ApiCategory.scala | 23 ----- .../formats/json/keyword/ApiKeyword.scala | 23 ----- .../formats/json/label/ApiCriterionLabel.scala | 5 +- .../formats/json/label/ApiExtractedDataLabel.scala | 5 +- .../pdsuidomain/formats/json/label/ApiLabel.scala | 22 ----- .../json/patient/trial/ApiPatientCriterion.scala | 3 +- .../formats/json/sprayformats/criterion.scala | 3 +- .../formats/json/sprayformats/documenttype.scala | 1 - .../formats/json/sprayformats/eligibility.scala | 101 +++++++++++++++++++++ .../formats/json/sprayformats/export.scala | 3 +- .../formats/json/sprayformats/extracteddata.scala | 3 +- .../json/sprayformats/patientcriterion.scala | 1 + .../formats/json/sprayformats/providerttype.scala | 12 --- .../formats/json/sprayformats/providertype.scala | 12 +++ .../services/EligibilityVerificationService.scala | 18 ++++ .../services/PatientCriterionService.scala | 1 + .../services/PatientEligibleTrialService.scala | 1 + .../services/PatientLabelEvidenceService.scala | 1 + .../pdsuidomain/services/PatientLabelService.scala | 1 + .../fake/FakeEligibilityVerificationService.scala | 28 ++++++ .../services/fake/FakeTrialService.scala | 3 +- .../rest/RestEligibilityVerificationService.scala | 43 +++++++++ .../parsers/SearchFilterParserSuite.scala | 13 ++- 49 files changed, 494 insertions(+), 224 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/entities/Label.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/category/ApiCategory.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/keyword/ApiKeyword.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/label/ApiLabel.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/eligibility.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala create mode 100644 src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala (limited to 'src/main/scala') diff --git a/build.sbt b/build.sbt index 837a1f0..66c0f7b 100644 --- a/build.sbt +++ b/build.sbt @@ -18,8 +18,8 @@ lazy val core = (project in file(".")) "io.github.cloudify" %% "spdf" % "1.4.0", "org.davidbild" %% "tristate-core" % "0.2.0", "org.davidbild" %% "tristate-play" % "0.2.0" exclude ("com.typesafe.play", "play-json"), - "xyz.driver" %% "core" % "0.16.7", - "xyz.driver" %% "domain-model" % "0.12.26", + "xyz.driver" %% "core" % "1.2.1", + "xyz.driver" %% "domain-model" % "0.17.1", "ch.qos.logback" % "logback-classic" % "1.1.7", "com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.8.4", "com.github.spullara.mustache.java" % "scala-extensions-2.11" % "0.9.4", diff --git a/src/main/scala/xyz/driver/pdsuicommon/db/SlickPostgresQueryBuilder.scala b/src/main/scala/xyz/driver/pdsuicommon/db/SlickPostgresQueryBuilder.scala index f882441..a56ab9a 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/db/SlickPostgresQueryBuilder.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/db/SlickPostgresQueryBuilder.scala @@ -2,8 +2,7 @@ package xyz.driver.pdsuicommon.db import java.time.{LocalDateTime, ZoneOffset} -import slick.driver.JdbcProfile -import slick.jdbc.GetResult +import slick.jdbc.{JdbcProfile, GetResult} import xyz.driver.core.database.SlickDal import xyz.driver.pdsuicommon.logging._ diff --git a/src/main/scala/xyz/driver/pdsuicommon/db/SlickQueryBuilder.scala b/src/main/scala/xyz/driver/pdsuicommon/db/SlickQueryBuilder.scala index ab2757b..0daa84d 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/db/SlickQueryBuilder.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/db/SlickQueryBuilder.scala @@ -3,8 +3,7 @@ package xyz.driver.pdsuicommon.db import java.sql.PreparedStatement import java.time.LocalDateTime -import slick.driver.JdbcProfile -import slick.jdbc.{PositionedParameters, SQLActionBuilder, SetParameter} +import slick.jdbc.{JdbcProfile, PositionedParameters, SQLActionBuilder, SetParameter} import xyz.driver.pdsuicommon.db.Sorting.{Dimension, Sequential} import xyz.driver.pdsuicommon.db.SortingOrder.{Ascending, Descending} diff --git a/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala b/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala index e0adeb8..e46e11c 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala @@ -15,10 +15,7 @@ object SearchFilterParser { private object BinaryAtomFromTuple { def unapply(input: (SearchFilterExpr.Dimension, (String, Any))): Option[SearchFilterExpr.Atom.Binary] = { val (dimensionName, (strOperation, value)) = input - val updatedValue = value match { - case s: String => s.safeTrim - case a => a - } + val updatedValue = trimIfString(value) parseOperation(strOperation.toLowerCase).map { op => SearchFilterExpr.Atom.Binary(dimensionName, op, updatedValue.asInstanceOf[AnyRef]) @@ -30,15 +27,24 @@ object SearchFilterParser { // Compiler warning: unchecked since it is eliminated by erasure, if we user Seq[String] def unapply(input: (SearchFilterExpr.Dimension, (String, Seq[_]))): Option[SearchFilterExpr.Atom.NAry] = { val (dimensionName, (strOperation, xs)) = input + val updatedValues = xs.map(trimIfString) + if (strOperation.toLowerCase == "in") { - val values = xs.asInstanceOf[Seq[String]].map(_.safeTrim) - Some(SearchFilterExpr.Atom.NAry(dimensionName, SearchFilterNAryOperation.In, values)) + Some( + SearchFilterExpr.Atom + .NAry(dimensionName, SearchFilterNAryOperation.In, updatedValues.map(_.asInstanceOf[AnyRef]))) } else { None } } } + private def trimIfString(value: Any) = + value match { + case s: String => s.safeTrim + case a => a + } + private val operationsMapping = { import xyz.driver.pdsuicommon.db.SearchFilterBinaryOperation._ @@ -96,7 +102,7 @@ object SearchFilterParser { private val nAryValueParser: Parser[String] = P(CharPred(_ != ',').rep(min = 1).!) - private val longParser: Parser[Long] = P(CharIn('0' to '9').rep(1).!.map(_.toLong)) + private val longParser: Parser[Long] = P(CharIn('0' to '9').rep(min = 1).!.map(_.toLong)) private val binaryAtomParser: Parser[SearchFilterExpr.Atom.Binary] = P( dimensionParser ~ whitespaceParser ~ ( @@ -109,7 +115,8 @@ object SearchFilterParser { private val nAryAtomParser: Parser[SearchFilterExpr.Atom.NAry] = P( dimensionParser ~ whitespaceParser ~ ( - naryOperatorParser ~/ whitespaceParser ~/ nAryValueParser.!.rep(min = 1, sep = ",") + naryOperatorParser ~ whitespaceParser ~ + (longParser.rep(min = 1, sep = ",") | nAryValueParser.!.rep(min = 1, sep = ",")) ) ~ End ).map { case NAryAtomFromTuple(atom) => atom diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index 4ecf915..a3f48d1 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -89,7 +89,7 @@ object CustomSwaggerJsonFormats { classOf[DocumentHistory.State] -> documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), classOf[ProviderType] -> - providertype.providerTypeFormat.write(rep.ProviderTypeGen.nextProviderType()), + providertype.providerTypeFormat.write(rep.MedicalRecordGen.nextProviderType()), classOf[TextJson[List[MedicalRecord.Meta]]] -> record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), classOf[MedicalRecord] -> diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala index 0dfb33f..7f065d4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.entities +import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{LongId, StringId} import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.Criterion.Meta.Evidence @@ -10,7 +11,7 @@ final case class Criterion(id: LongId[Criterion], isCompound: Boolean, meta: String) { - def isValid(): Boolean = text.nonEmpty && Option(meta).isDefined + def isValid: Boolean = text.nonEmpty && Option(meta).isDefined } object Criterion { @@ -41,7 +42,7 @@ object CriterionArm { final case class CriterionLabel(id: LongId[CriterionLabel], labelId: Option[LongId[Label]], criterionId: LongId[Criterion], - categoryId: Option[LongId[Category]], + categoryId: Option[LongId[LabelCategory]], value: Option[Boolean], isDefining: Boolean) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala index 32258dc..fbd468f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/ExtractedData.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.entities +import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, TextJson} import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta @@ -43,5 +44,5 @@ object ExtractedDataLabel { final case class ExtractedDataLabel(id: LongId[ExtractedDataLabel], dataId: LongId[ExtractedData], labelId: Option[LongId[Label]], - categoryId: Option[LongId[Category]], + categoryId: Option[LongId[LabelCategory]], value: Option[FuzzyValue]) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Keyword.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Keyword.scala index 3683efc..a984f92 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Keyword.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Keyword.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.entities +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuicommon.logging._ @@ -17,7 +18,7 @@ final case class KeywordWithLabels(keyword: Keyword, labels: List[Label]) object KeywordWithLabels { implicit def toPhiString(x: KeywordWithLabels): PhiString = { import x._ - phi"KeywordWithLabels(keyword=$keyword, $labels)" + phi"KeywordWithLabels(keyword=$keyword, ${Unsafe(labels)}" } } diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Label.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Label.scala deleted file mode 100644 index eea39de..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Label.scala +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.driver.pdsuidomain.entities - -import xyz.driver.pdsuicommon.domain.LongId -import xyz.driver.pdsuicommon.logging._ - -final case class Category(id: LongId[Category], name: String) - -object Category { - implicit def toPhiString(x: Category): PhiString = { - import x._ - phi"Category(id=$id, name=${Unsafe(name)})" - } -} - -final case class Label(id: LongId[Label], categoryId: LongId[Category], name: String, description: String) - -object Label { - implicit def toPhiString(x: Label): PhiString = { - import x._ - phi"Label($id, categoryId=${Unsafe(categoryId)}, name=${Unsafe(name)}, description=${Unsafe(description)})" - } -} - -final case class CategoryWithLabels(category: Category, labels: List[Label]) - -object CategoryWithLabels { - implicit def toPhiString(x: CategoryWithLabels): PhiString = { - import x._ - phi"CategoryWithLabels(category=$category, labels=$labels)" - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala index 633a347..d10c7d2 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabel.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.entities +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} import xyz.driver.pdsuicommon.logging._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala index 34e3741..3311d96 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/PatientLabelEvidenceView.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDate +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala index 184782b..689eaa4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/RawPatientLabel.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDate +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, UuidId} import xyz.driver.pdsuicommon.logging._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala index 9e69c87..bdbc4ea 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/RawTrialLabel.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.entities import java.time.LocalDateTime +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} import xyz.driver.pdsuicommon.logging._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala new file mode 100644 index 0000000..aa7a7d2 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala @@ -0,0 +1,63 @@ +package xyz.driver.pdsuidomain.entities + +import xyz.driver.core.Id +import xyz.driver.core.date.Date +import xyz.driver.entities.assays.AssayType +import xyz.driver.entities.clinic.{ClinicalRecord, TestOrder} +import xyz.driver.entities.common.FullName +import xyz.driver.entities.labels.{Label, LabelValue} +import xyz.driver.entities.patient.CancerType +import xyz.driver.entities.process.ProcessStepExecutionStatus +import xyz.driver.entities.report.Report +import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels + +object eligibility { + + sealed trait EvidenceDocument { + val documentType: DocumentType + val providerType: ProviderType + val providerName: Option[String] + val date: Option[Date] + val isDriverDocument: Boolean + } + + final case class MolecularEvidenceDocument(documentType: DocumentType, + providerType: ProviderType, + providerName: Option[String], + date: Option[Date], + reportId: Id[Report], + reportType: AssayType, + isDriverDocument: Boolean = true) + extends EvidenceDocument + + final case class ClinicalEvidenceDocument(documentId: Id[ClinicalEvidenceDocument], + documentType: DocumentType, + providerType: ProviderType, + providerName: Option[String], + date: Option[Date], + requestId: Id[ClinicalRecord], + isDriverDocument: Boolean = false) + extends EvidenceDocument + + // Some fields are optional because they are not in the backend response + final case class Evidence(evidenceId: Option[Id[Evidence]], + evidenceText: String, + labelValue: LabelValue, + document: EvidenceDocument, + isPrimaryValue: Option[Boolean] = None) + + final case class LabelWithEvidence(label: Label, evidence: Seq[Evidence] = Seq.empty) + + final case class LabelMismatchRank(label: Label, + score: Int, + trials: Seq[ExportTrialWithLabels], + evidence: Seq[Evidence]) + final case class MismatchRankedLabels(data: Seq[LabelMismatchRank], labelVersion: Int) + + final case class MatchedPatient(patientId: Id[MatchedPatient], + name: FullName[MatchedPatient], + birthDate: Date, + orderId: Id[TestOrder], + disease: CancerType, + patientDataStatus: ProcessStepExecutionStatus) +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala index c69fc09..2edd707 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/patient/ExportPatientLabel.scala @@ -1,8 +1,9 @@ package xyz.driver.pdsuidomain.entities.export.patient +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{Label, RawPatientLabel} +import xyz.driver.pdsuidomain.entities.RawPatientLabel final case class ExportPatientLabel(id: LongId[Label], evidences: List[ExportPatientLabelEvidence]) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala index 7bff22c..1f06e0d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrialLabelCriterion.scala @@ -1,8 +1,9 @@ package xyz.driver.pdsuidomain.entities.export.trial +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label, RawTrialLabel} +import xyz.driver.pdsuidomain.entities.{Arm, Criterion, RawTrialLabel} final case class ExportTrialLabelCriterion(criterionId: LongId[Criterion], value: Option[Boolean], diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala index b259b07..7318ff6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala @@ -2,26 +2,28 @@ package xyz.driver.pdsuidomain.fakes.entities import java.time.{LocalDate, LocalDateTime, LocalTime} -import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} +import xyz.driver.core.generators.{nextDouble, nextOption} +import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId} import xyz.driver.pdsuidomain.entities.{Trial, TrialHistory} + import scala.util.Random object common { import xyz.driver.core.generators - def nextUuidId[T] = UuidId[T](generators.nextUuid()) + def nextUuidId[T]: UuidId[T] = UuidId[T](generators.nextUuid()) - def nextLongId[T] = LongId[T](generators.nextInt(Int.MaxValue).toLong) + def nextLongId[T]: LongId[T] = LongId[T](generators.nextInt(Int.MaxValue).toLong) - def nextStringId[T] = StringId[T](generators.nextString(maxLength = 20)) + def nextStringId[T]: StringId[T] = StringId[T](generators.nextString(maxLength = 20)) - def nextTrialStatus = generators.oneOf[Trial.Status](Trial.Status.All) + def nextTrialStatus: Trial.Status = generators.oneOf[Trial.Status](Trial.Status.All) - def nextPreviousTrialStatus = generators.oneOf[Trial.Status](Trial.Status.AllPrevious) + def nextPreviousTrialStatus: Trial.Status = generators.oneOf[Trial.Status](Trial.Status.AllPrevious) - def nextLocalDateTime = LocalDateTime.of(nextLocalDate, LocalTime.MIDNIGHT) + def nextLocalDateTime: LocalDateTime = LocalDateTime.of(nextLocalDate, LocalTime.MIDNIGHT) - def nextLocalDate = LocalDate.of( + def nextLocalDate: LocalDate = LocalDate.of( 1970 + Random.nextInt(68), 1 + Random.nextInt(12), 1 + Random.nextInt(28) // all months have at least 28 days @@ -33,4 +35,27 @@ object common { def nextTrialState = generators.oneOf[TrialHistory.State](TrialHistory.State.All) + def genBoundedRange[T](from: T, to: T)(implicit ord: Ordering[T]): (T, T) = { + if (ord.compare(from, to) > 0) { + to -> from + } else { + from -> to + } + } + + def genBoundedRangeOption[T](from: T, to: T)(implicit ord: Ordering[T]): (Option[T], Option[T]) = { + val ranges = nextOption(from).map { left => + val range = genBoundedRange(left, to) + range._1 -> nextOption(range._2) + } + + ranges.map(_._1) -> ranges.flatMap(_._2) + } + + def nextFuzzyValue(): FuzzyValue = + generators.oneOf[FuzzyValue](FuzzyValue.All) + + def nextStartAndEndPages: (Option[Double], Option[Double]) = + genBoundedRangeOption[Double](nextDouble(), nextDouble()) + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala new file mode 100644 index 0000000..7dc50be --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala @@ -0,0 +1,72 @@ +package xyz.driver.pdsuidomain.fakes.entities + +import xyz.driver.core.generators +import xyz.driver.entities.clinic.{ClinicalRecord, TestOrder} +import xyz.driver.entities.patient.CancerType +import xyz.driver.entities.report.Report +import xyz.driver.fakes +import xyz.driver.pdsuidomain.entities.eligibility._ + +object eligibility { + import xyz.driver.core.generators._ + + def nextMolecularEvidenceDocument(): MolecularEvidenceDocument = + MolecularEvidenceDocument( + documentType = xyz.driver.pdsuidomain.fakes.entities.rep.DocumentGen.nextDocumentType(), + providerType = xyz.driver.pdsuidomain.fakes.entities.rep.MedicalRecordGen.nextProviderType(), + providerName = nextOption(nextString(100)), + date = nextOption(nextDate()), + reportId = nextId[Report](), + reportType = fakes.entities.assays.nextAssayType(), + isDriverDocument = nextBoolean() + ) + + def nextClinicalEvidenceDocument(): ClinicalEvidenceDocument = + ClinicalEvidenceDocument( + documentType = xyz.driver.pdsuidomain.fakes.entities.rep.DocumentGen.nextDocumentType(), + providerType = xyz.driver.pdsuidomain.fakes.entities.rep.MedicalRecordGen.nextProviderType(), + providerName = nextOption(nextString(100)), + date = nextOption(nextDate()), + documentId = nextId[ClinicalEvidenceDocument](), + requestId = nextId[ClinicalRecord](), + isDriverDocument = nextBoolean() + ) + + def nextEvidenceDocument(): EvidenceDocument = + oneOf[EvidenceDocument](nextMolecularEvidenceDocument(), + nextClinicalEvidenceDocument(), + nextClinicalEvidenceDocument()) // For more clinical documents + + def nextEvidence(): Evidence = + Evidence( + evidenceId = Option(nextId[Evidence]()), + evidenceText = nextString(100), + labelValue = xyz.driver.fakes.entities.labels.nextLabelValue(), + nextEvidenceDocument(), + isPrimaryValue = nextOption(nextBoolean()) + ) + + def nextLabelWithEvidence(): LabelWithEvidence = + LabelWithEvidence(label = fakes.entities.labels.nextLabel(), evidence = Seq.empty) + + def nextLabelMismatchRank(): LabelMismatchRank = + LabelMismatchRank( + label = fakes.entities.labels.nextLabel(), + score = nextInt(100), + trials = seqOf(xyz.driver.pdsuidomain.fakes.entities.export.nextExportTrialWithLabels()), + evidence = seqOf(nextEvidence()) + ) + + def nextMismatchRankedLabels(): MismatchRankedLabels = + MismatchRankedLabels(data = seqOf(nextLabelMismatchRank()), labelVersion = nextInt(100)) + + def nextMatchedPatient(): MatchedPatient = + MatchedPatient( + patientId = nextId[MatchedPatient](), + name = fakes.entities.common.nextFullName[MatchedPatient](), + birthDate = nextDate(), + orderId = nextId[TestOrder](), + disease = generators.oneOf[CancerType](CancerType.Breast, CancerType.Lung, CancerType.Prostate), + patientDataStatus = fakes.entities.process.nextProcessStepExecutionStatus() + ) +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala new file mode 100644 index 0000000..7f3c410 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/export.scala @@ -0,0 +1,35 @@ +package xyz.driver.pdsuidomain.fakes.entities + +import xyz.driver.entities.labels.Label +import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Trial} +import xyz.driver.pdsuidomain.entities.export.trial._ + +object export { + import xyz.driver.core.generators._ + import common._ + + def nextExportTrialArm(): ExportTrialArm = + ExportTrialArm(armId = nextLongId[Arm], armName = nextString(100)) + + def nextExportTrialLabelCriterion(): ExportTrialLabelCriterion = + ExportTrialLabelCriterion( + criterionId = nextLongId[Criterion], + value = nextOption[Boolean](nextBoolean()), + labelId = nextLongId[Label], + armIds = setOf(nextLongId[Arm]), + criteria = nextString(100), + isCompound = nextBoolean(), + isDefining = nextBoolean() + ) + + def nextExportTrialWithLabels(): ExportTrialWithLabels = + ExportTrialWithLabels( + nctId = nextStringId[Trial], + trialId = nextUuidId[Trial], + condition = nextString(100), + lastReviewed = nextLocalDateTime, + labelVersion = nextInt(100).toLong, + arms = listOf(nextExportTrialArm()), + criteria = listOf(nextExportTrialLabelCriterion()) + ) +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala deleted file mode 100644 index 9618eed..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala +++ /dev/null @@ -1,35 +0,0 @@ -package xyz.driver.pdsuidomain.fakes.entities.rep - -import xyz.driver.core.generators -import xyz.driver.core.generators._ -import xyz.driver.pdsuicommon.domain.FuzzyValue - -private[rep] object Common { - def genBoundedRange[T](from: T, to: T)(implicit ord: Ordering[T]): (T, T) = { - if (ord.compare(from, to) > 0) { - to -> from - } else { - from -> to - } - } - - def genBoundedRangeOption[T](from: T, to: T)(implicit ord: Ordering[T]): (Option[T], Option[T]) = { - val ranges = nextOption(from) - .map(left => genBoundedRange(left, to)) - .map { - case (left, right) => - left -> nextOption(right) - } - - ranges.map(_._1) -> ranges.flatMap(_._2) - } - - def nextFuzzyValue(): FuzzyValue = { - generators.oneOf[FuzzyValue](FuzzyValue.All) - } - - def nextStartAndEndPages: (Option[Double], Option[Double]) = { - genBoundedRangeOption[Double](nextDouble(), nextDouble()) - } - -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 10349bb..6d5330e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -4,6 +4,7 @@ import java.time.LocalDate import xyz.driver.core.generators import xyz.driver.core.generators.{nextBoolean, nextDouble, nextOption, nextString} +import xyz.driver.pdsuidomain.fakes.entities.common._ import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLocalDateTime, nextLongId, nextStringId} @@ -17,13 +18,13 @@ object DocumentGen { } private def nextDates() = - Common.genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) private def nextStartAndEndPagesOption() = - Common.nextStartAndEndPages + nextStartAndEndPages private def nextStartAndEndPage() = - Common.genBoundedRange(nextDouble(), nextDouble()) + genBoundedRange(nextDouble(), nextDouble()) def nextDocumentStatus(): Document.Status = Document.Status.New diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala index c2909f3..e3ef6bc 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -1,14 +1,11 @@ package xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.core.generators._ +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.domain.{LongId, UuidId} +import xyz.driver.pdsuidomain.fakes.entities.common._ import xyz.driver.pdsuidomain.entities._ -import xyz.driver.pdsuidomain.entities.export.patient.{ - ExportPatientLabel, - ExportPatientLabelEvidence, - ExportPatientLabelEvidenceDocument, - ExportPatientWithLabels -} +import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} object ExportPatientGen { @@ -41,7 +38,7 @@ object ExportPatientGen { def nextExportPatientLabelEvidence(documentId: LongId[Document]): ExportPatientLabelEvidence = { ExportPatientLabelEvidence( id = nextLongId[ExtractedData], - value = Common.nextFuzzyValue(), + value = nextFuzzyValue(), evidenceText = nextString(), document = nextExportPatientLabelEvidenceDocument(documentId) ) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 8ac07d0..8e77445 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -1,6 +1,7 @@ package xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.core.generators._ +import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{LongId, TextJson} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.ExtractedData.Meta @@ -46,7 +47,7 @@ object ExtractedDataGen { def nextExtractedDataMetaEvidence(): Meta.Evidence = { val layersPosition = - Common.genBoundedRange[ExtractedData.Meta.TextLayerPosition]( + genBoundedRange[ExtractedData.Meta.TextLayerPosition]( nextExtractedDataMetaTextLayerPosition(), nextExtractedDataMetaTextLayerPosition() ) @@ -65,14 +66,8 @@ object ExtractedDataGen { ) } - def nextExtractedDataMetaJson(): TextJson[Meta] = { - TextJson( - ExtractedData.Meta( - nextExtractedDataMetaKeyword(), - nextExtractedDataMetaEvidence() - ) - ) - } + def nextExtractedDataMetaJson(): TextJson[Meta] = + TextJson(ExtractedData.Meta(nextExtractedDataMetaKeyword(), nextExtractedDataMetaEvidence())) def nextExtractedData(documentId: LongId[Document]): ExtractedData = { ExtractedData( @@ -89,8 +84,8 @@ object ExtractedDataGen { id = nextLongId[ExtractedDataLabel], dataId = nextLongId[ExtractedData], labelId = nextOption(nextLongId[Label]), - categoryId = nextOption(nextLongId[Category]), - value = nextOption(Common.nextFuzzyValue()) + categoryId = nextOption(nextLongId[LabelCategory]), + value = nextOption(nextFuzzyValue()) ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 7221e66..023dc00 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -4,7 +4,7 @@ import xyz.driver.pdsuidomain.entities._ import xyz.driver.core.generators import xyz.driver.core.generators._ import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} -import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId, nextStringId, nextUuidId} +import xyz.driver.pdsuidomain.fakes.entities.common._ object MedicalRecordGen { private val maxItemsInCollectionNumber: Int = 50 @@ -126,7 +126,7 @@ object MedicalRecordGen { } def nextMedicalRecordIssue(): MedicalRecordIssue = { - val pages = Common.nextStartAndEndPages + val pages = nextStartAndEndPages MedicalRecordIssue( id = nextLongId[MedicalRecordIssue], @@ -141,4 +141,7 @@ object MedicalRecordGen { ) } + def nextProviderType(): ProviderType = + ProviderType(id = nextLongId[ProviderType], name = nextString()) + } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala deleted file mode 100644 index 168f7af..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala +++ /dev/null @@ -1,14 +0,0 @@ -package xyz.driver.pdsuidomain.fakes.entities.rep - -import xyz.driver.core.generators.nextString -import xyz.driver.pdsuidomain.entities.ProviderType -import xyz.driver.pdsuidomain.fakes.entities.common.nextLongId - -object ProviderTypeGen { - def nextProviderType(): ProviderType = { - ProviderType( - id = nextLongId[ProviderType], - name = nextString() - ) - } -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala index fe5bf09..fcd833a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.fakes.entities +import xyz.driver.entities.labels.{Label, LabelCategory} import xyz.driver.pdsuicommon.domain.{LongId, User} import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion @@ -51,7 +52,7 @@ object trialcuration { id = nextLongId[CriterionLabel], labelId = Option(nextLongId[Label]), criterionId = criterionId, - categoryId = Option(nextLongId[Category]), + categoryId = Option(nextLongId[LabelCategory]), value = Option(generators.nextBoolean()), isDefining = generators.nextBoolean() ) 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/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..743f885 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") 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 index 8119d35..7ec6ef5 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala @@ -1,7 +1,6 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.DocumentType object documenttype { 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..30ceae2 --- /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[LabelWithEvidence] = jsonFormat2(LabelWithEvidence) + + 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 2a1fe46..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,7 +1,8 @@ package xyz.driver.pdsuidomain.formats.json.sprayformats import spray.json._ -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label} +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} 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/providertype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala new file mode 100644 index 0000000..385feb2 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala @@ -0,0 +1,12 @@ +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/services/EligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala new file mode 100644 index 0000000..d3e977e --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala @@ -0,0 +1,18 @@ +package xyz.driver.pdsuidomain.services + +import xyz.driver.core.Id +import xyz.driver.core.rest.ServiceRequestContext +import xyz.driver.entities.patient.CancerType +import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} +import xyz.driver.pdsuidomain.entities.{Arm, Patient} + +import scala.concurrent.Future +import scalaz.ListT + +trait EligibilityVerificationService { + + def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, MatchedPatient] + + def getMismatchRankedLabels(patientId: Id[Patient], cancerType: CancerType, excludedArms: Seq[Id[Arm]])( + implicit ctx: ServiceRequestContext): Future[MismatchRankedLabels] +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala index 9ff3879..6d85f85 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientCriterionService.scala @@ -2,6 +2,7 @@ package xyz.driver.pdsuidomain.services import java.time.LocalDateTime +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala index 2c17f74..abb3f8a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.services +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting} import xyz.driver.pdsuicommon.domain.{LongId, UuidId} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala index 56e2e3d..6871f3e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelEvidenceService.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.services +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.{LongId, UuidId} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala index 71b8bd4..2a4d7fc 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientLabelService.scala @@ -1,5 +1,6 @@ package xyz.driver.pdsuidomain.services +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala new file mode 100644 index 0000000..c5531f9 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala @@ -0,0 +1,28 @@ +package xyz.driver.pdsuidomain.services.fake + +import xyz.driver.core.rest.ServiceRequestContext +import xyz.driver.core.{Id, generators} +import xyz.driver.entities.patient +import xyz.driver.pdsuidomain.entities.eligibility.MismatchRankedLabels +import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} +import xyz.driver.pdsuidomain.services.EligibilityVerificationService + +import scala.concurrent.Future +import scalaz.ListT + +class FakeEligibilityVerificationService extends EligibilityVerificationService { + + override def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, eligibility.MatchedPatient] = + ListT.listT[Future]( + Future.successful(List(xyz.driver.pdsuidomain.fakes.entities.eligibility.nextMatchedPatient()))) + + override def getMismatchRankedLabels( + patientId: Id[Patient], + cancerType: patient.CancerType, + excludedArms: Seq[Id[Arm]])(implicit ctx: ServiceRequestContext): Future[eligibility.MismatchRankedLabels] = + Future.successful( + MismatchRankedLabels( + generators.seqOf(xyz.driver.pdsuidomain.fakes.entities.eligibility.nextLabelMismatchRank()), + labelVersion = generators.nextInt(10) + )) +} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala index 3793c1f..9aeb820 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeTrialService.scala @@ -6,10 +6,11 @@ import akka.NotUsed import akka.stream.scaladsl.Source import akka.util.ByteString import xyz.driver.core.generators +import xyz.driver.entities.labels.Label import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId} -import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Label, Trial} +import xyz.driver.pdsuidomain.entities.{Arm, Criterion, Trial} import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrialArm, ExportTrialLabelCriterion, ExportTrialWithLabels} import xyz.driver.pdsuidomain.services.TrialService diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala new file mode 100644 index 0000000..07757e3 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala @@ -0,0 +1,43 @@ +package xyz.driver.pdsuidomain.services.rest + +import akka.http.scaladsl.model.Uri +import akka.stream.Materializer +import spray.json.DefaultJsonProtocol +import xyz.driver.core.Id +import xyz.driver.core.rest.{RestService, ServiceRequestContext, ServiceTransport} +import xyz.driver.entities.patient +import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} +import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} +import xyz.driver.pdsuidomain.services.EligibilityVerificationService + +import scala.concurrent.{ExecutionContext, Future} +import scalaz.ListT +import scalaz.Scalaz.futureInstance + +class RestEligibilityVerificationService(transport: ServiceTransport, baseUri: Uri)( + implicit protected val materializer: Materializer, + protected val exec: ExecutionContext +) extends EligibilityVerificationService with RestService { + + import DefaultJsonProtocol._ + import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ + import xyz.driver.pdsuidomain.formats.json.sprayformats.eligibility._ + + override def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, eligibility.MatchedPatient] = { + val request = get(baseUri, s"/v1/patients") + listResponse[MatchedPatient](transport.sendRequest(ctx)(request)) + } + + override def getMismatchRankedLabels(patientId: Id[Patient], + cancerType: patient.CancerType, + excludedArms: Seq[Id[Arm]])( + implicit ctx: ServiceRequestContext): Future[eligibility.MismatchRankedLabels] = { + + val query = + Seq("disease" -> cancerType.toString.toUpperCase, "ineligible_arms" -> excludedArms.map(_.value).mkString(",")) + + val request = get(baseUri, s"/v1/patients/$patientId/labels", query) + optionalResponse[MismatchRankedLabels](transport.sendRequest(ctx)(request)) + .getOrElse(throw new Exception(s"The data of patient $patientId is not ready yet")) + } +} diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala index ba67d13..5deaecb 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParserSuite.scala @@ -14,7 +14,7 @@ import xyz.driver.pdsuicommon.db.SearchFilterNAryOperation.In import xyz.driver.pdsuicommon.utils.Utils import xyz.driver.pdsuicommon.utils.Utils._ -import scala.util.Success +import scala.util._ object SearchFilterParserSuite { @@ -133,6 +133,17 @@ class SearchFilterParserSuite extends FreeSpecLike with Checkers { } "n-ary" - { + "actual record Ids" - { + "should not be parsed with text values" in { + val filter = SearchFilterParser.parse(Seq("filters" -> "id IN 1,5")) + filter match { + case Success(_) => () + case Failure(t) => t.printStackTrace() + } + assert(filter === Success(SearchFilterExpr.Atom.NAry(Dimension(None, "id"), In, Seq(Long.box(1), Long.box(5))))) + } + } + "in" in check { val testQueryGen = queryGen( dimensionGen = Gen.identifier, -- cgit v1.2.3 From fb9b25e867287c485b1b3e97352d9d816147df36 Mon Sep 17 00:00:00 2001 From: vlad Date: Sun, 1 Oct 2017 13:05:15 -0700 Subject: Slight changes in naming --- src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala index aa7a7d2..0d0965b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala @@ -46,7 +46,7 @@ object eligibility { document: EvidenceDocument, isPrimaryValue: Option[Boolean] = None) - final case class LabelWithEvidence(label: Label, evidence: Seq[Evidence] = Seq.empty) + final case class LabelEvidence(label: Label, evidence: Seq[Evidence] = Seq.empty) final case class LabelMismatchRank(label: Label, score: Int, @@ -54,8 +54,8 @@ object eligibility { evidence: Seq[Evidence]) final case class MismatchRankedLabels(data: Seq[LabelMismatchRank], labelVersion: Int) - final case class MatchedPatient(patientId: Id[MatchedPatient], - name: FullName[MatchedPatient], + final case class MatchedPatient(patientId: Id[Patient], + name: FullName[Patient], birthDate: Date, orderId: Id[TestOrder], disease: CancerType, -- cgit v1.2.3 From c5b7f009479930b82f0fb839971eeb2c457dcef0 Mon Sep 17 00:00:00 2001 From: vlad Date: Sun, 1 Oct 2017 13:07:43 -0700 Subject: Slight changes in naming --- .../scala/xyz/driver/pdsuidomain/entities/eligibility.scala | 4 ++-- .../xyz/driver/pdsuidomain/fakes/entities/eligibility.scala | 10 +++++----- .../pdsuidomain/formats/json/sprayformats/eligibility.scala | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala index 0d0965b..1a900ac 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala @@ -54,8 +54,8 @@ object eligibility { evidence: Seq[Evidence]) final case class MismatchRankedLabels(data: Seq[LabelMismatchRank], labelVersion: Int) - final case class MatchedPatient(patientId: Id[Patient], - name: FullName[Patient], + final case class MatchedPatient(patientId: Id[xyz.driver.entities.patient.Patient], + name: FullName[xyz.driver.entities.patient.Patient], birthDate: Date, orderId: Id[TestOrder], disease: CancerType, diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala index 7dc50be..5f3321c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/eligibility.scala @@ -2,7 +2,7 @@ package xyz.driver.pdsuidomain.fakes.entities import xyz.driver.core.generators import xyz.driver.entities.clinic.{ClinicalRecord, TestOrder} -import xyz.driver.entities.patient.CancerType +import xyz.driver.entities.patient.{CancerType, Patient} import xyz.driver.entities.report.Report import xyz.driver.fakes import xyz.driver.pdsuidomain.entities.eligibility._ @@ -46,8 +46,8 @@ object eligibility { isPrimaryValue = nextOption(nextBoolean()) ) - def nextLabelWithEvidence(): LabelWithEvidence = - LabelWithEvidence(label = fakes.entities.labels.nextLabel(), evidence = Seq.empty) + def nextLabelEvidence(): LabelEvidence = + LabelEvidence(label = fakes.entities.labels.nextLabel(), evidence = Seq.empty) def nextLabelMismatchRank(): LabelMismatchRank = LabelMismatchRank( @@ -62,8 +62,8 @@ object eligibility { def nextMatchedPatient(): MatchedPatient = MatchedPatient( - patientId = nextId[MatchedPatient](), - name = fakes.entities.common.nextFullName[MatchedPatient](), + patientId = nextId[Patient](), + name = fakes.entities.common.nextFullName[Patient](), birthDate = nextDate(), orderId = nextId[TestOrder](), disease = generators.oneOf[CancerType](CancerType.Breast, CancerType.Lung, CancerType.Prostate), 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 30ceae2..b836e1c 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 @@ -92,7 +92,7 @@ object eligibility { } } - implicit def labelWithEvidenceJsonFormat: RootJsonFormat[LabelWithEvidence] = jsonFormat2(LabelWithEvidence) + implicit def labelWithEvidenceJsonFormat: RootJsonFormat[LabelEvidence] = jsonFormat2(LabelEvidence) implicit def labelRankingFormat: RootJsonFormat[LabelMismatchRank] = jsonFormat4(LabelMismatchRank) implicit def labelRankingsFormat: RootJsonFormat[MismatchRankedLabels] = jsonFormat2(MismatchRankedLabels) -- cgit v1.2.3 From d0482b45b6f9149f050c5e5a6dbab6f059229282 Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 2 Oct 2017 01:05:42 -0700 Subject: DocumentType and ProviderType as enums --- .../utils/CustomSwaggerJsonFormats.scala | 3 +- .../xyz/driver/pdsuidomain/entities/Document.scala | 364 +++++++++++++++------ .../fakes/entities/rep/DocumentGen.scala | 8 +- .../fakes/entities/rep/ExportPatientGen.scala | 16 +- .../fakes/entities/rep/MedicalRecordGen.scala | 2 +- .../formats/json/document/ApiDocumentType.scala | 9 +- .../formats/json/document/ApiProviderType.scala | 9 +- .../formats/json/sprayformats/document.scala | 19 +- .../formats/json/sprayformats/documenttype.scala | 12 - .../formats/json/sprayformats/providertype.scala | 12 - .../formats/json/sprayformats/record.scala | 19 +- .../json/sprayformats/ExportFormatSuite.scala | 16 +- 12 files changed, 326 insertions(+), 163 deletions(-) delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala delete mode 100644 src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala index a3f48d1..83c4e6f 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala @@ -62,7 +62,6 @@ object CustomSwaggerJsonFormats { import xyz.driver.pdsuidomain.formats.json.sprayformats.document import xyz.driver.pdsuidomain.formats.json.sprayformats.documentissue import xyz.driver.pdsuidomain.formats.json.sprayformats.documenthistory - import xyz.driver.pdsuidomain.formats.json.sprayformats.providertype import xyz.driver.pdsuidomain.formats.json.sprayformats.record import xyz.driver.pdsuidomain.formats.json.sprayformats.recordissue import xyz.driver.pdsuidomain.formats.json.sprayformats.recordhistory @@ -89,7 +88,7 @@ object CustomSwaggerJsonFormats { classOf[DocumentHistory.State] -> documenthistory.documentStateFormat.write(rep.DocumentGen.nextDocumentHistoryState()), classOf[ProviderType] -> - providertype.providerTypeFormat.write(rep.MedicalRecordGen.nextProviderType()), + record.providerTypeFormat.write(rep.MedicalRecordGen.nextProviderType()), classOf[TextJson[List[MedicalRecord.Meta]]] -> record.recordMetaFormat.write(rep.MedicalRecordGen.nextMedicalRecordMetasJson()), classOf[MedicalRecord] -> diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala index 839fead..eccb254 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Document.scala @@ -15,74 +15,195 @@ import xyz.driver.pdsuicommon.validation.Validators.Validator import xyz.driver.pdsuidomain.entities.Document.Meta import scalaz.Equal +import scalaz.syntax.equal._ +import scalaz.Scalaz.stringInstance -final case class ProviderType(id: LongId[ProviderType], name: String) +sealed trait ProviderType { + val id: LongId[ProviderType] + val name: String +} object ProviderType { - sealed trait ProviderTypeName - case object MedicalOncology extends ProviderTypeName - case object Surgery extends ProviderTypeName - case object Pathology extends ProviderTypeName - case object MolecularPathology extends ProviderTypeName - case object LaboratoryMedicine extends ProviderTypeName - case object Radiology extends ProviderTypeName - case object InterventionalRadiology extends ProviderTypeName - case object RadiationOncology extends ProviderTypeName - case object PrimaryCare extends ProviderTypeName - case object Cardiology extends ProviderTypeName - case object Dermatology extends ProviderTypeName - case object Ophthalmology extends ProviderTypeName - case object Gastroenterology extends ProviderTypeName - case object Neurology extends ProviderTypeName - case object Psychiatry extends ProviderTypeName - case object Gynecology extends ProviderTypeName - case object InfectiousDisease extends ProviderTypeName - case object Immunology extends ProviderTypeName - case object Nephrology extends ProviderTypeName - case object Rheumatology extends ProviderTypeName - case object Cytology extends ProviderTypeName - case object Otolaryngology extends ProviderTypeName - case object Anesthesiology extends ProviderTypeName - case object Urology extends ProviderTypeName - case object PalliativeCare extends ProviderTypeName - case object EmergencyMedicine extends ProviderTypeName - case object SocialWork extends ProviderTypeName - case object NA extends ProviderTypeName - case object Other extends ProviderTypeName - - def fromString(txt: String): Option[ProviderTypeName] = { - txt match { - case "Medical Oncology" => Some(MedicalOncology) - case "Surgery" => Some(Surgery) - case "Pathology" => Some(Pathology) - case "Molecular Pathology" => Some(MolecularPathology) - case "LaboratoryMedicine" => Some(LaboratoryMedicine) - case "Radiology" => Some(Radiology) - case "Interventional Radiology" => Some(InterventionalRadiology) - case "Radiation Oncology" => Some(RadiationOncology) - case "Primary Care" => Some(PrimaryCare) - case "Cardiology" => Some(Cardiology) - case "Dermatology" => Some(Dermatology) - case "Ophthalmology" => Some(Ophthalmology) - case "Gastroenterology" => Some(Gastroenterology) - case "Neurology" => Some(Neurology) - case "Psychiatry" => Some(Psychiatry) - case "Gynecology" => Some(Gynecology) - case "Infectious Disease" => Some(InfectiousDisease) - case "Immunology" => Some(Immunology) - case "Nephrology" => Some(Nephrology) - case "Rheumatology" => Some(Rheumatology) - case "Cytology" => Some(Cytology) - case "Otolaryngology" => Some(Otolaryngology) - case "Anesthesiology" => Some(Anesthesiology) - case "Urology" => Some(Urology) - case "Palliative Care" => Some(PalliativeCare) - case "Emergency Medicine" => Some(EmergencyMedicine) - case "Social Work" => Some(SocialWork) - case "N/A" => Some(NA) - case "Other" => Some(Other) - case _ => None - } + + case object MedicalOncology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](1) + val name: String = "Medical Oncology" + } + + case object Surgery extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](2) + val name: String = "Surgery" + } + + case object Pathology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](3) + val name: String = "Pathology" + } + + case object MolecularPathology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](4) + val name: String = "Molecular Pathology" + } + + case object LaboratoryMedicine extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](5) + val name: String = "Laboratory Medicine" + } + + case object Radiology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](6) + val name: String = "Radiology" + } + + case object InterventionalRadiology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](7) + val name: String = "Interventional Radiology" + } + + case object RadiationOncology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](8) + val name: String = "Radiation Oncology" + } + + case object PrimaryCare extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](9) + val name: String = "Primary Care" + } + + case object Cardiology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](10) + val name: String = "Cardiology" + } + + case object Dermatology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](11) + val name: String = "Dermatology" + } + + case object Ophthalmology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](12) + val name: String = "Ophthalmology" + } + + case object Gastroenterology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](13) + val name: String = "Gastroenterology" + } + + case object Neurology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](14) + val name: String = "Neurology" + } + + case object Psychiatry extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](15) + val name: String = "Psychiatry" + } + + case object Gynecology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](16) + val name: String = "Gynecology" + } + + case object InfectiousDisease extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](17) + val name: String = "Infectious Disease" + } + + case object Immunology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](18) + val name: String = "Immunology" + } + + case object Nephrology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](19) + val name: String = "Nephrology" + } + + case object Rheumatology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](20) + val name: String = "Rheumatology" + } + + case object Cytology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](21) + val name: String = "Cytology" + } + + case object Otolaryngology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](22) + val name: String = "Otolaryngology" + } + + case object Anesthesiology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](23) + val name: String = "Anesthesiology" + } + + case object Urology extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](24) + val name: String = "Urology" + } + + case object PalliativeCare extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](25) + val name: String = "Palliative Care" + } + + case object EmergencyMedicine extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](26) + val name: String = "Emergency Medicine" + } + + case object SocialWork extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](27) + val name: String = "Social Work" + } + + case object NA extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](28) + val name: String = "N/A" + } + + case object Other extends ProviderType { + val id: LongId[ProviderType] = LongId[ProviderType](29) + val name: String = "Other" + } + + val All = Seq[ProviderType]( + MedicalOncology, + Surgery, + Pathology, + MolecularPathology, + LaboratoryMedicine, + Radiology, + InterventionalRadiology, + RadiationOncology, + PrimaryCare, + Cardiology, + Dermatology, + Ophthalmology, + Gastroenterology, + Neurology, + Psychiatry, + Gynecology, + InfectiousDisease, + Immunology, + Nephrology, + Rheumatology, + Cytology, + Otolaryngology, + Anesthesiology, + Urology, + PalliativeCare, + EmergencyMedicine, + SocialWork, + NA, + Other + ) + + def fromString(txt: String): Option[ProviderType] = { + All.find(_.name === txt) } implicit def toPhiString(x: ProviderType): PhiString = { @@ -91,39 +212,90 @@ object ProviderType { } } -final case class DocumentType(id: LongId[DocumentType], name: String) +sealed trait DocumentType { + val id: LongId[DocumentType] + val name: String +} object DocumentType { - sealed trait DocumentTypeName - case object OutpatientPhysicianNote extends DocumentTypeName - case object DischargeNote extends DocumentTypeName - case object LaboratoryReport extends DocumentTypeName - case object MedicationList extends DocumentTypeName - case object HospitalizationNote extends DocumentTypeName - case object PathologyReport extends DocumentTypeName - case object RadiologyReport extends DocumentTypeName - case object OperativeProcedureReport extends DocumentTypeName - case object MedicationAdministration extends DocumentTypeName - case object SocialWorkCaseManagementNote extends DocumentTypeName - case object NonPhysicianProviderNote extends DocumentTypeName - case object Administrative extends DocumentTypeName - - def fromString(txt: String): Option[DocumentTypeName] = { - txt match { - case "Outpatient Physician Note" => Some(OutpatientPhysicianNote) - case "Discharge Note" => Some(DischargeNote) - case "Laboratory Report" => Some(LaboratoryReport) - case "Medication List" => Some(MedicationList) - case "Hospitalization Note" => Some(HospitalizationNote) - case "Pathology Report" => Some(PathologyReport) - case "Radiology Report" => Some(RadiologyReport) - case "Operative/Procedure Report" => Some(OperativeProcedureReport) - case "Medication Administration" => Some(MedicationAdministration) - case "Social Work/Case Management Note" => Some(SocialWorkCaseManagementNote) - case "Non-physician Provider Note" => Some(NonPhysicianProviderNote) - case "Administrative" => Some(Administrative) - case _ => None - } + + case object OutpatientPhysicianNote extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](1) + val name: String = "Outpatient Physician Note" + } + + case object DischargeNote extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](2) + val name: String = "Discharge Note" + } + + case object LaboratoryReport extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](3) + val name: String = "Laboratory Report" + } + + case object MedicationList extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](4) + val name: String = "Medication List" + } + + case object HospitalizationNote extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](5) + val name: String = "Hospitalization Note" + } + + case object PathologyReport extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](6) + val name: String = "Pathology Report" + } + + case object RadiologyReport extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](7) + val name: String = "Radiology Report" + } + + case object OperativeProcedureReport extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](8) + val name: String = "Operative/Procedure Report" + } + + case object MedicationAdministration extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](9) + val name: String = "Medication Administration" + } + + case object SocialWorkCaseManagementNote extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](10) + val name: String = "Social Work/Case Management Note" + } + + case object NonPhysicianProviderNote extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](11) + val name: String = "Non-physician Provider Note" + } + + case object Administrative extends DocumentType { + val id: LongId[DocumentType] = LongId[DocumentType](12) + val name: String = "Administrative" + } + + val All = Seq[DocumentType]( + OutpatientPhysicianNote, + DischargeNote, + LaboratoryReport, + MedicationList, + HospitalizationNote, + PathologyReport, + RadiologyReport, + OperativeProcedureReport, + MedicationAdministration, + SocialWorkCaseManagementNote, + NonPhysicianProviderNote, + Administrative + ) + + def fromString(txt: String): Option[DocumentType] = { + All.find(_.name === txt) } implicit def equal: Equal[DocumentType] = Equal.equal[DocumentType](_ == _) diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 6d5330e..1ac75ab 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -75,12 +75,8 @@ object DocumentGen { ) } - def nextDocumentType(): DocumentType = { - DocumentType( - id = nextLongId[DocumentType], - name = nextString() - ) - } + def nextDocumentType(): DocumentType = + generators.oneOf(DocumentType.All: _*) def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = { val pages = nextStartAndEndPagesOption() diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala index e3ef6bc..3fcc4cb 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExportPatientGen.scala @@ -7,24 +7,12 @@ import xyz.driver.pdsuidomain.fakes.entities.common._ import xyz.driver.pdsuidomain.entities._ import xyz.driver.pdsuidomain.entities.export.patient._ import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDate, nextLongId} +import xyz.driver.pdsuidomain.fakes.entities.rep.DocumentGen._ +import xyz.driver.pdsuidomain.fakes.entities.rep.MedicalRecordGen._ object ExportPatientGen { private val maxItemsInCollectionNumber = 3 - def nextDocumentType(documentTypeId: LongId[DocumentType] = nextLongId): DocumentType = { - DocumentType( - documentTypeId, - nextString() - ) - } - - def nextProviderType(providerTypeId: LongId[ProviderType] = nextLongId): ProviderType = { - ProviderType( - providerTypeId, - nextString() - ) - } - def nextExportPatientLabelEvidenceDocument(documentId: LongId[Document]): ExportPatientLabelEvidenceDocument = { ExportPatientLabelEvidenceDocument( documentId = documentId, diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 023dc00..2777116 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -142,6 +142,6 @@ object MedicalRecordGen { } def nextProviderType(): ProviderType = - ProviderType(id = nextLongId[ProviderType], name = nextString()) + generators.oneOf(ProviderType.All: _*) } 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/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index ff0603a..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,7 +28,24 @@ object document { implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply) - implicit val documentTypeFormat: RootJsonFormat[DocumentType] = jsonFormat2(DocumentType.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 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 7ec6ef5..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala +++ /dev/null @@ -1,12 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.sprayformats - -import spray.json._ -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/providertype.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.scala deleted file mode 100644 index 385feb2..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providertype.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 6b69873..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,7 +36,24 @@ object record { } } - implicit val providerTypeFormat = jsonFormat2(ProviderType.apply) + 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) 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 52c8c81..a451905 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 @@ -16,8 +16,8 @@ class ExportFormatSuite extends FlatSpec with Matchers { val document = ExportPatientLabelEvidenceDocument( documentId = LongId(101), requestId = RecordRequestId(UUID.fromString("7b54a75d-4197-4b27-9045-b9b6cb131be9")), - documentType = DocumentType(LongId[DocumentType](1), "document type"), - providerType = ProviderType(LongId[ProviderType](2), "provider type"), + documentType = DocumentType.OutpatientPhysicianNote, + providerType = ProviderType.Surgery, date = LocalDate.parse("2017-08-10") ) @@ -67,14 +67,14 @@ class ExportFormatSuite extends FlatSpec with Matchers { 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":{"id":1,"name":"document type"},"providerType":{"id":2,"name":"provider type"},"date":"2017-08-10"}}, + "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"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"}}]}, + "documentType":{"id":1,"name":"Outpatient Physician Note"},"providerType":{"id":2,"name":"Surgery"},"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":{"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) + {"documentId":101,"requestId":"7b54a75d-4197-4b27-9045-b9b6cb131be9","documentType":{"id":1,"name":"Outpatient Physician Note"}, + "providerType":{"id":2,"name":"Surgery"},"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":"Outpatient Physician Note"}, + "providerType":{"id":2,"name":"Surgery"},"date":"2017-08-10"}}]}]}""".parseJson) } "Json format for ApiExportTrialWithLabels" should "read and write correct JSON" in { -- cgit v1.2.3 From 14b460edbebb1d5c39809dbc591b786edec9fa8e Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 2 Oct 2017 15:21:58 +0700 Subject: TRIAL-17 Added 'inclusion' field to Criterion --- .../xyz/driver/pdsuidomain/entities/Criterion.scala | 3 ++- .../pdsuidomain/fakes/entities/trialcuration.scala | 3 ++- .../formats/json/criterion/ApiCriterion.scala | 12 ++++++++---- .../formats/json/criterion/ApiNewCriterion.scala | 9 ++++++--- .../formats/json/criterion/ApiUpdateCriterion.scala | 6 +++++- .../formats/json/sprayformats/criterion.scala | 19 ++++++++++++++++--- .../json/sprayformats/CriterionFormatSuite.scala | 17 ++++++++++++----- 7 files changed, 51 insertions(+), 18 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala index 7f065d4..2432251 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/Criterion.scala @@ -9,7 +9,8 @@ final case class Criterion(id: LongId[Criterion], trialId: StringId[Trial], text: Option[String], isCompound: Boolean, - meta: String) { + meta: String, + inclusion: Option[Boolean]) { def isValid: Boolean = text.nonEmpty && Option(meta).isDefined } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala index fcd833a..9a5022c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/trialcuration.scala @@ -45,7 +45,8 @@ object trialcuration { trialId = nextStringId[Trial], text = Option(generators.nextString()), isCompound = generators.nextBoolean(), - meta = generators.nextString() + meta = generators.nextString(), + inclusion = Option(generators.nextBoolean()) ) def nextCriterionLabel(criterionId: LongId[Criterion]): CriterionLabel = CriterionLabel( 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/sprayformats/criterion.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/criterion.scala index 743f885..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 @@ -73,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]])) @@ -88,7 +93,8 @@ object criterion { criterion = orig.criterion.copy( meta = meta, text = text, - isCompound = isCompound + isCompound = isCompound, + inclusion = inclusion ), armIds = arms, labels = labels @@ -106,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 { @@ -129,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]]]) @@ -146,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/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala index d24c4c1..708aed9 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatSuite.scala @@ -15,7 +15,8 @@ class CriterionFormatSuite extends FlatSpec with Matchers { trialId = StringId("NCT000001"), text = Some("text"), isCompound = false, - meta = "{}" + meta = "{}", + inclusion = None ) val labels = List( CriterionLabel( @@ -44,12 +45,12 @@ class CriterionFormatSuite extends FlatSpec with Matchers { val writtenJson = richCriterionFormat.write(richCriterion) writtenJson should be( - """{"text":"text","isCompound":false,"trialId":"NCT000001","arms":[20,21,21],"id":10,"meta":"{}", + """{"text":"text","isCompound":false,"trialId":"NCT000001","inclusion":null,"arms":[20,21,21],"id":10,"meta":"{}", "labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true}, {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson) val createCriterionJson = - """{"text":"text","isCompound":false,"trialId":"NCT000001", + """{"text":"text","isCompound":false,"trialId":"NCT000001","inclusion":null, "arms":[20,21,21],"meta":"{}","labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true}, {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson val parsedRichCriterion = richCriterionFormat.read(createCriterionJson) @@ -59,8 +60,14 @@ class CriterionFormatSuite extends FlatSpec with Matchers { ) parsedRichCriterion should be(expectedRichCriterion) - val updateCriterionJson = """{"meta":null,"text":"new text","isCompound":true}""".parseJson - val expectedUpdatedCriterion = richCriterion.copy(criterion = criterion.copy(text = Some("new text"), isCompound = true, meta = "{}")) + val updateCriterionJson = """{"meta":null,"text":"new text","isCompound":true,"inclusion":true}""".parseJson + val expectedUpdatedCriterion = richCriterion.copy( + criterion = criterion.copy( + text = Some("new text"), + isCompound = true, + meta = "{}", + inclusion = Some(true) + )) val parsedUpdateCriterion = applyUpdateToCriterion(updateCriterionJson, richCriterion) parsedUpdateCriterion should be(expectedUpdatedCriterion) } -- cgit v1.2.3 From 0dbf8df69b7bcdb1107a72d8cf077ce422bd1994 Mon Sep 17 00:00:00 2001 From: vlad Date: Tue, 3 Oct 2017 03:15:55 -0700 Subject: Making EligibilityVerificationService to accept AuthorizedServiceRequestContext --- .../services/EligibilityVerificationService.scala | 7 ++++--- .../services/fake/FakeEligibilityVerificationService.scala | 14 ++++++++------ .../services/rest/RestEligibilityVerificationService.scala | 8 +++++--- 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala index d3e977e..7cb1228 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala @@ -1,8 +1,9 @@ package xyz.driver.pdsuidomain.services import xyz.driver.core.Id -import xyz.driver.core.rest.ServiceRequestContext +import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.entities.patient.CancerType +import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} import xyz.driver.pdsuidomain.entities.{Arm, Patient} @@ -11,8 +12,8 @@ import scalaz.ListT trait EligibilityVerificationService { - def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, MatchedPatient] + def getMatchedPatients()(implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): ListT[Future, MatchedPatient] def getMismatchRankedLabels(patientId: Id[Patient], cancerType: CancerType, excludedArms: Seq[Id[Arm]])( - implicit ctx: ServiceRequestContext): Future[MismatchRankedLabels] + implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[MismatchRankedLabels] } diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala index c5531f9..3633c2d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala @@ -1,8 +1,9 @@ package xyz.driver.pdsuidomain.services.fake -import xyz.driver.core.rest.ServiceRequestContext +import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.core.{Id, generators} import xyz.driver.entities.patient +import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.MismatchRankedLabels import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService @@ -12,14 +13,15 @@ import scalaz.ListT class FakeEligibilityVerificationService extends EligibilityVerificationService { - override def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, eligibility.MatchedPatient] = + override def getMatchedPatients()( + implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): ListT[Future, eligibility.MatchedPatient] = ListT.listT[Future]( Future.successful(List(xyz.driver.pdsuidomain.fakes.entities.eligibility.nextMatchedPatient()))) - override def getMismatchRankedLabels( - patientId: Id[Patient], - cancerType: patient.CancerType, - excludedArms: Seq[Id[Arm]])(implicit ctx: ServiceRequestContext): Future[eligibility.MismatchRankedLabels] = + override def getMismatchRankedLabels(patientId: Id[Patient], + cancerType: patient.CancerType, + excludedArms: Seq[Id[Arm]])( + implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[eligibility.MismatchRankedLabels] = Future.successful( MismatchRankedLabels( generators.seqOf(xyz.driver.pdsuidomain.fakes.entities.eligibility.nextLabelMismatchRank()), diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala index 07757e3..5a5ede7 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala @@ -4,8 +4,9 @@ import akka.http.scaladsl.model.Uri import akka.stream.Materializer import spray.json.DefaultJsonProtocol import xyz.driver.core.Id -import xyz.driver.core.rest.{RestService, ServiceRequestContext, ServiceTransport} +import xyz.driver.core.rest.{AuthorizedServiceRequestContext, RestService, ServiceTransport} import xyz.driver.entities.patient +import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService @@ -23,7 +24,8 @@ class RestEligibilityVerificationService(transport: ServiceTransport, baseUri: U import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ import xyz.driver.pdsuidomain.formats.json.sprayformats.eligibility._ - override def getMatchedPatients()(implicit ctx: ServiceRequestContext): ListT[Future, eligibility.MatchedPatient] = { + override def getMatchedPatients()( + implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): ListT[Future, eligibility.MatchedPatient] = { val request = get(baseUri, s"/v1/patients") listResponse[MatchedPatient](transport.sendRequest(ctx)(request)) } @@ -31,7 +33,7 @@ class RestEligibilityVerificationService(transport: ServiceTransport, baseUri: U override def getMismatchRankedLabels(patientId: Id[Patient], cancerType: patient.CancerType, excludedArms: Seq[Id[Arm]])( - implicit ctx: ServiceRequestContext): Future[eligibility.MismatchRankedLabels] = { + implicit ctx: AuthorizedServiceRequestContext[AuthUserInfo]): Future[eligibility.MismatchRankedLabels] = { val query = Seq("disease" -> cancerType.toString.toUpperCase, "ineligible_arms" -> excludedArms.map(_.value).mkString(",")) -- cgit v1.2.3 From a321a978353439fc516b0f2016c28fb32ba1b7ae Mon Sep 17 00:00:00 2001 From: vlad Date: Tue, 3 Oct 2017 03:29:48 -0700 Subject: Making EligibilityVerificationService to accept AuthorizedServiceRequestContext --- .../driver/pdsuidomain/services/EligibilityVerificationService.scala | 4 ++-- .../services/fake/FakeEligibilityVerificationService.scala | 3 ++- .../services/rest/RestEligibilityVerificationService.scala | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala index 7cb1228..7395400 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilityVerificationService.scala @@ -2,10 +2,10 @@ package xyz.driver.pdsuidomain.services import xyz.driver.core.Id import xyz.driver.core.rest.AuthorizedServiceRequestContext -import xyz.driver.entities.patient.CancerType +import xyz.driver.entities.patient.{CancerType, Patient} import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} -import xyz.driver.pdsuidomain.entities.{Arm, Patient} +import xyz.driver.pdsuidomain.entities.Arm import scala.concurrent.Future import scalaz.ListT diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala index 3633c2d..1e1a3ea 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/fake/FakeEligibilityVerificationService.scala @@ -3,9 +3,10 @@ package xyz.driver.pdsuidomain.services.fake import xyz.driver.core.rest.AuthorizedServiceRequestContext import xyz.driver.core.{Id, generators} import xyz.driver.entities.patient +import xyz.driver.entities.patient.Patient import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.MismatchRankedLabels -import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} +import xyz.driver.pdsuidomain.entities.{Arm, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService import scala.concurrent.Future diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala index 5a5ede7..f6879d0 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilityVerificationService.scala @@ -6,9 +6,10 @@ import spray.json.DefaultJsonProtocol import xyz.driver.core.Id import xyz.driver.core.rest.{AuthorizedServiceRequestContext, RestService, ServiceTransport} import xyz.driver.entities.patient +import xyz.driver.entities.patient.Patient import xyz.driver.entities.users.AuthUserInfo import xyz.driver.pdsuidomain.entities.eligibility.{MatchedPatient, MismatchRankedLabels} -import xyz.driver.pdsuidomain.entities.{Arm, Patient, eligibility} +import xyz.driver.pdsuidomain.entities.{Arm, eligibility} import xyz.driver.pdsuidomain.services.EligibilityVerificationService import scala.concurrent.{ExecutionContext, Future} -- cgit v1.2.3