diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-02 18:37:52 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-02 18:37:52 +0700 |
commit | d0e3c6f37347142a3ef5eab871dde47ea70af304 (patch) | |
tree | a87d24b1b5d6489576f00fe446f05b5110d62cc0 /src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala | |
parent | 283ca02360949143ffe7ee8ad87d51902426b450 (diff) | |
parent | 1913870abec9e31d080f6858d0fc296445852cc6 (diff) | |
download | rest-query-d0e3c6f37347142a3ef5eab871dde47ea70af304.tar.gz rest-query-d0e3c6f37347142a3ef5eab871dde47ea70af304.tar.bz2 rest-query-d0e3c6f37347142a3ef5eab871dde47ea70af304.zip |
Merge branch 'master' into synch-refactor
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala | 107 |
1 files changed, 107 insertions, 0 deletions
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..1ac75ab --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -0,0 +1,107 @@ +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.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} + +object DocumentGen { + implicit private class LocalDateOrdering(localData: LocalDate) extends Ordered[LocalDate] { + + override def compare(that: LocalDate): Int = { + this.localData.compareTo(that) + } + } + + private def nextDates() = + genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) + + private def nextStartAndEndPagesOption() = + nextStartAndEndPages + + private def nextStartAndEndPage() = + genBoundedRange(nextDouble(), nextDouble()) + + def nextDocumentStatus(): Document.Status = + Document.Status.New + + 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) = nextStartAndEndPage() + + Document.Meta( + nextOption(nextBoolean()), + startPage, + endPage + ) + } + + def nextDocumentMetaJson(): TextJson[Document.Meta] = { + TextJson(nextDocumentMeta()) + } + + def nextDocument(): Document = { + val dates = nextDates() + + Document( + id = nextLongId[Document], + status = nextDocumentStatus(), + previousStatus = None, + 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(nextDocumentMetaJson()), + startDate = dates._1, + endDate = dates._2, + lastUpdate = nextLocalDateTime + ) + } + + def nextDocumentType(): DocumentType = + generators.oneOf(DocumentType.All: _*) + + def nextDocumentIssue(documentId: LongId[Document] = nextLongId): 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] = nextLongId): DocumentHistory = { + DocumentHistory( + id = nextLongId[DocumentHistory], + executor = nextStringId[User], + documentId = documentId, + state = nextDocumentHistoryState(), + action = nextDocumentHistoryAction(), + created = nextLocalDateTime + ) + } +} |