aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-12-14 10:26:44 +0700
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-12-14 10:26:44 +0700
commited1ad48ac9f5a03839bbe176b363af6c84220e6b (patch)
treef6bb6ff1fc22f5d204d6e9e5f5d330d027048be1 /src
parent7c3feb9b3bf7a1cc12e54c1d994649d03e70e14c (diff)
parent51d5d1ddba83f539405c6d395933e1f8a456c871 (diff)
downloadrest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.tar.gz
rest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.tar.bz2
rest-query-ed1ad48ac9f5a03839bbe176b363af6c84220e6b.zip
Merge branch 'master' into support-service-exceptions
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala2
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala12
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/TrialHistory.scala32
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala26
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala5
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala10
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala88
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala16
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala10
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala34
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala84
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala103
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala2
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientEligibleTrialFormatSuite.scala14
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/TrialIssueFormatSuite.scala1
18 files changed, 297 insertions, 154 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
index 1d843e4..6987100 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/acl/ACL.scala
@@ -126,7 +126,7 @@ object ACL extends PhiLogging {
object Trial
extends BaseACL(
label = "trial",
- read = TcRoles + RoutesCurator + TreatmentMatchingAdmin + ResearchOncologist + AdministratorRole,
+ read = TcRoles ++ TreatmentMatchingRoles + ResearchOncologist + AdministratorRole,
update = TcRoles
)
diff --git a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
index 62c9690..f617a20 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/utils/CustomSwaggerJsonFormats.scala
@@ -197,7 +197,7 @@ object CustomSwaggerJsonFormats {
classOf[RichPatientCriterion] -> richPatientCriterionFormat.write(nextRichPatientCriterion()),
classOf[DraftPatientCriterion] -> draftPatientCriterionFormat.write(nextDraftPatientCriterion()),
classOf[PatientLabelEvidenceView] -> patientLabelEvidenceWriter.write(nextPatientLabelEvidenceView()),
- classOf[RichPatientEligibleTrial] -> patientEligibleTrialFormat.write(nextRichPatientEligibleTrial()),
+ classOf[RichPatientEligibleTrial] -> patientEligibleTrialWriter.write(nextRichPatientEligibleTrial()),
classOf[PatientHypothesis] -> patientHypothesisWriter.write(nextPatientHypothesis()),
classOf[PatientHistory] -> patientHistoryFormat.write(nextPatientHistory()),
classOf[PatientIssue] -> patientIssueWriter.write(nextPatientIssue()),
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala
index d3bc56e..cf13d1a 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/MedicalRecord.scala
@@ -85,12 +85,8 @@ object MedicalRecord {
}
object Status {
- case object Unprocessed extends Status
- case object PreCleaning extends Status
case object New extends Status
case object Cleaned extends Status
- case object PreOrganized extends Status
- case object PreOrganizing extends Status
case object Reviewed extends Status
case object Organized extends Status
case object Done extends Status
@@ -98,12 +94,8 @@ object MedicalRecord {
case object Archived extends Status
def fromString(status: String): Option[Status] = status match {
- case "Unprocessed" => Some(Unprocessed)
- case "PreCleaning" => Some(PreCleaning)
case "New" => Some(New)
case "Cleaned" => Some(Cleaned)
- case "PreOrganized" => Some(PreOrganized)
- case "PreOrganizing" => Some(PreOrganizing)
case "Reviewed" => Some(Reviewed)
case "Organized" => Some(Organized)
case "Done" => Some(Done)
@@ -113,12 +105,8 @@ object MedicalRecord {
}
val All: Set[Status] = Set[Status](
- Unprocessed,
- PreCleaning,
New,
Cleaned,
- PreOrganized,
- PreOrganizing,
Reviewed,
Organized,
Done,
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/TrialHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/TrialHistory.scala
index cc96cbd..9210742 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/TrialHistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/TrialHistory.scala
@@ -17,25 +17,31 @@ object TrialHistory {
sealed trait State
object State {
- case object Summarize extends State
- case object Criteriarize extends State
- case object Review extends State
- case object Flag extends State
+ case object Summarize extends State
+ case object Criteriarize extends State
+ case object Review extends State
+ case object ReviewSummary extends State
+ case object ReviewCriteria extends State
+ case object Flag extends State
- val All: Set[State] = Set[State](Summarize, Criteriarize, Review, Flag)
+ val All: Set[State] = Set[State](Summarize, Criteriarize, Review, ReviewSummary, ReviewCriteria, Flag)
val fromString: PartialFunction[String, State] = {
- case "Summarize" => State.Summarize
- case "Criteriarize" => State.Criteriarize
- case "Review" => State.Review
- case "Flag" => State.Flag
+ case "Summarize" => State.Summarize
+ case "Criteriarize" => State.Criteriarize
+ case "Review" => State.Review
+ case "ReviewSummary" => State.ReviewSummary
+ case "ReviewCriteria" => State.ReviewCriteria
+ case "Flag" => State.Flag
}
def stateToString(x: State): String = x match {
- case State.Summarize => "Summarize"
- case State.Criteriarize => "Criteriarize"
- case State.Review => "Review"
- case State.Flag => "Flag"
+ case State.Summarize => "Summarize"
+ case State.Criteriarize => "Criteriarize"
+ case State.Review => "Review"
+ case State.ReviewSummary => "ReviewSummary"
+ case State.ReviewCriteria => "ReviewCriteria"
+ case State.Flag => "Flag"
}
implicit def toPhiString(x: State): PhiString =
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala
index 1a900ac..9362a0c 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/entities/eligibility.scala
@@ -60,4 +60,9 @@ object eligibility {
orderId: Id[TestOrder],
disease: CancerType,
patientDataStatus: ProcessStepExecutionStatus)
+
+ final case class EligibleTrial(nctId: String, arms: Seq[EligibleArm])
+ final case class EligibleArm(title: String, criteria: Seq[EligibleCriterion])
+ final case class EligibleCriterion(text: String, eligibilityStatus: LabelValue)
+
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala
index 571cbde..925ba65 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/eligibility.scala
@@ -100,4 +100,9 @@ object eligibility {
implicit def labelRankingsFormat: RootJsonFormat[MismatchRankedLabels] = jsonFormat2(MismatchRankedLabels)
implicit def matchedPatientFormat: RootJsonFormat[MatchedPatient] = jsonFormat6(MatchedPatient)
+
+ implicit lazy val eligibleTrialFormat: RootJsonFormat[EligibleTrial] = jsonFormat2(EligibleTrial.apply)
+ implicit lazy val eligibleArmFormat: RootJsonFormat[EligibleArm] = jsonFormat2(EligibleArm.apply)
+ implicit lazy val eligibleCriterionFormat: RootJsonFormat[EligibleCriterion] = jsonFormat2(EligibleCriterion.apply)
+
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
index f21b0cb..4c006f9 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/patienteligibletrial.scala
@@ -8,14 +8,13 @@ import xyz.driver.pdsuidomain.services.PatientEligibleTrialService.RichPatientEl
object patienteligibletrial {
import DefaultJsonProtocol._
import common._
- import xyz.driver.pdsuidomain.formats.json.trial._
- import xyz.driver.pdsuidomain.formats.json.patientcriterion._
def applyUpdateToTrialArmGroup(json: JsValue, orig: PatientTrialArmGroupView): PatientTrialArmGroupView =
json match {
case JsObject(fields) =>
- val isVerified = fields.get("group").map(_.asJsObject)
- .flatMap(_.fields.get("isVerified")).map(_.convertTo[Boolean])
+ val isVerified = fields
+ .get("isVerified")
+ .map(_.convertTo[Boolean])
.getOrElse(orig.isVerified)
orig.copy(isVerified = isVerified)
@@ -23,10 +22,19 @@ object patienteligibletrial {
case _ => deserializationError(s"Expected Json Object as partial PatientTrialArmGroupView, but got $json")
}
- implicit val patientEligibleArmGroupView: RootJsonFormat[PatientTrialArmGroupView] =
- jsonFormat7(PatientTrialArmGroupView.apply)
-
- implicit val patientEligibleTrialFormat: RootJsonFormat[RichPatientEligibleTrial] =
- jsonFormat3(RichPatientEligibleTrial.apply)
+ implicit val patientEligibleTrialWriter: RootJsonWriter[RichPatientEligibleTrial] =
+ new RootJsonWriter[RichPatientEligibleTrial] {
+ override def write(obj: RichPatientEligibleTrial) =
+ JsObject(
+ "id" -> obj.group.id.toJson,
+ "patientId" -> obj.group.patientId.toJson,
+ "trialId" -> obj.group.trialId.toJson,
+ "trialTitle" -> obj.trial.title.toJson,
+ "arms" -> obj.arms.map(_.armName).toJson,
+ "hypothesisId" -> obj.trial.hypothesisId.toJson,
+ "verifiedEligibilityStatus" -> obj.group.verifiedEligibilityStatus.toJson,
+ "isVerified" -> obj.group.isVerified.toJson
+ )
+ }
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala
index cbe4951..d3fe2c9 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/record.scala
@@ -16,13 +16,8 @@ object record {
import common._
implicit val recordStatusFormat: EnumJsonFormat[Status] = new EnumJsonFormat[Status](
- "PreCleaning" -> Status.PreCleaning,
- "Unprocessed" -> Status.Unprocessed,
- "PreOrganized" -> Status.PreOrganized,
"New" -> Status.New,
"Cleaned" -> Status.Cleaned,
- "PreOrganized" -> Status.PreOrganized,
- "PreOrganizing" -> Status.PreOrganizing,
"Reviewed" -> Status.Reviewed,
"Organized" -> Status.Organized,
"Done" -> Status.Done,
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala
index c8df1d8..f71ec12 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialhistory.scala
@@ -10,10 +10,12 @@ object trialhistory {
import common._
implicit val trialStateFormat = new EnumJsonFormat[State](
- "Summarize" -> State.Summarize,
- "Criteriarize" -> State.Criteriarize,
- "Review" -> State.Review,
- "Flag" -> State.Flag
+ "Summarize" -> State.Summarize,
+ "Criteriarize" -> State.Criteriarize,
+ "Review" -> State.Review,
+ "ReviewSummary" -> State.ReviewSummary,
+ "ReviewCriteria" -> State.ReviewCriteria,
+ "Flag" -> State.Flag
)
implicit val trialActionFormat = new EnumJsonFormat[Action](
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala
index f9bb0b6..79882c2 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue.scala
@@ -2,16 +2,26 @@ package xyz.driver.pdsuidomain.formats.json
import java.time.LocalDateTime
-import spray.json._
+import spray.json.{RootJsonReader, _}
+import xyz.driver.core.{Id, auth}
import xyz.driver.core.auth.User
import xyz.driver.core.json._
import xyz.driver.pdsuicommon.domain.{LongId, StringId}
import xyz.driver.pdsuidomain.entities._
object trialissue {
+
import DefaultJsonProtocol._
import common._
+ private def deserializationErrorFieldMessage(field: String, json: JsValue)(implicit className: String) = {
+ deserializationError(s"$className json object do not contain '$field' field: $json")
+ }
+
+ private def deserializationErrorEntityMessage(json: JsValue)(implicit className: String) = {
+ deserializationError(s"Expected Json Object as $className, but got $json")
+ }
+
def applyUpdateToTrialIssue(json: JsValue, orig: TrialIssue): TrialIssue = {
json.asJsObject.getFields("text", "evidence", "archiveRequired", "meta") match {
case Seq(text, evidence, archiveRequired, meta) =>
@@ -48,15 +58,77 @@ object trialissue {
implicit val trialIssueWriter = new RootJsonWriter[TrialIssue] {
override def write(obj: TrialIssue) = JsObject(
- "id" -> obj.id.toJson,
- "text" -> obj.text.toJson,
- "lastUpdate" -> obj.lastUpdate.toJson,
- "userId" -> obj.userId.toJson,
- "isDraft" -> obj.isDraft.toJson,
- "evidence" -> obj.evidence.toJson,
+ "id" -> obj.id.toJson,
+ "text" -> obj.text.toJson,
+ "lastUpdate" -> obj.lastUpdate.toJson,
+ "userId" -> obj.userId.toJson,
+ "isDraft" -> obj.isDraft.toJson,
+ "evidence" -> obj.evidence.toJson,
"archiveRequired" -> obj.archiveRequired.toJson,
- "meta" -> obj.meta.toJson
+ "meta" -> obj.meta.toJson
)
}
+ def trialIssueReader(trialId: StringId[Trial]): RootJsonReader[TrialIssue] =
+ new RootJsonReader[TrialIssue] {
+ implicit val className: String = "TrialIssue"
+
+ override def read(json: JsValue): TrialIssue = json match {
+ case JsObject(fields) =>
+ val id = fields
+ .get("id")
+ .map(_.convertTo[LongId[TrialIssue]])
+ .getOrElse(deserializationErrorFieldMessage("id", json))
+
+ val text = fields
+ .get("text")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationErrorFieldMessage("text", json))
+
+ val lastUpdate = fields
+ .get("lastUpdate")
+ .map(_.convertTo[LocalDateTime])
+ .getOrElse(deserializationErrorFieldMessage("lastUpdate", json))
+
+ val userId = fields
+ .get("userId")
+ .map(_.convertTo[Id[auth.User]])
+ .getOrElse(deserializationErrorFieldMessage("userId", json))
+
+ val isDraft = fields
+ .get("isDraft")
+ .map(_.convertTo[Boolean])
+ .getOrElse(deserializationErrorFieldMessage("isDraft", json))
+
+ val evidence = fields
+ .get("evidence")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationErrorFieldMessage("evidence", json))
+
+ val archiveRequired = fields
+ .get("archiveRequired")
+ .map(_.convertTo[Boolean])
+ .getOrElse(deserializationErrorFieldMessage("archiveRequired", json))
+
+ val meta = fields
+ .get("meta")
+ .map(_.convertTo[String])
+ .getOrElse(deserializationErrorFieldMessage("meta", json))
+
+ TrialIssue(
+ id = id,
+ userId = userId,
+ trialId = trialId,
+ lastUpdate = lastUpdate,
+ isDraft = isDraft,
+ text = text,
+ evidence = evidence,
+ archiveRequired = archiveRequired,
+ meta = meta
+ )
+
+ case _ => deserializationErrorEntityMessage(json)
+ }
+ }
+
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala
new file mode 100644
index 0000000..b3e6673
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/EligibilitySnapshotService.scala
@@ -0,0 +1,16 @@
+package xyz.driver.pdsuidomain.services
+
+import xyz.driver.core.rest.AuthorizedServiceRequestContext
+import xyz.driver.entities.users.AuthUserInfo
+import xyz.driver.pdsuicommon.domain.UuidId
+import xyz.driver.pdsuidomain.entities.{Patient => PdsuiPatient}
+import xyz.driver.pdsuidomain.entities.eligibility.EligibleTrial
+
+import scala.concurrent.Future
+
+trait EligibilitySnapshotService {
+
+ def eligibilitySnapshot(patientId: UuidId[PdsuiPatient])(
+ implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[Seq[EligibleTrial]]
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala
index f07f6fa..8d1288a 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientEligibleTrialService.scala
@@ -96,11 +96,9 @@ object PatientEligibleTrialService {
case object NotFoundError extends UpdateReply with DefaultNotFoundError with DomainError.NotFoundError
- case object PatientNotFoundError
- extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
+ case object PatientNotFoundError extends UpdateReply with DefaultPatientNotFoundError with DomainError.NotFoundError
- case object AuthorizationError
- extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError
+ case object AuthorizationError extends UpdateReply with DomainError.AuthorizationError with DefaultAccessDeniedError
final case class CommonError(userMessage: String) extends UpdateReply with DomainError
@@ -127,7 +125,7 @@ trait PatientEligibleTrialService {
def getCriterionListByGroupId(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])(
implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetCriterionListOfGroupReply]
- def update(origEligibleTrialWithTrial: RichPatientEligibleTrial,
- draftPatientTrialArmGroup: PatientTrialArmGroupView)(
+ def update(origEligibleTrialWithTrial: RichPatientEligibleTrial, draftPatientTrialArmGroup: PatientTrialArmGroupView)(
implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply]
+
}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala
new file mode 100644
index 0000000..2187ec2
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestEligibilitySnapshotService.scala
@@ -0,0 +1,34 @@
+package xyz.driver.pdsuidomain.services.rest
+
+import akka.http.scaladsl.model.{HttpMethods, HttpRequest, Uri}
+import akka.stream.Materializer
+import xyz.driver.core.rest.{AuthorizedServiceRequestContext, ServiceTransport}
+import xyz.driver.entities.users.AuthUserInfo
+import xyz.driver.pdsuicommon.domain.UuidId
+import xyz.driver.pdsuidomain.entities.eligibility.EligibleTrial
+import xyz.driver.pdsuidomain.entities.{Patient, eligibility}
+import xyz.driver.pdsuidomain.services.EligibilitySnapshotService
+
+import scala.concurrent.{ExecutionContext, Future}
+
+class RestEligibilitySnapshotService(transport: ServiceTransport, baseUrl: Uri)(
+ implicit protected val materializer: Materializer,
+ protected val exec: ExecutionContext) extends EligibilitySnapshotService with RestHelper {
+
+ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+ import spray.json.DefaultJsonProtocol._
+ import xyz.driver.pdsuidomain.formats.json.eligibility._
+
+ override def eligibilitySnapshot(patientId: UuidId[Patient])
+ (implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]):
+ Future[Seq[eligibility.EligibleTrial]] = {
+ val request = HttpRequest(HttpMethods.GET, endpointUri(baseUrl, s"/v1/patient/$patientId/eligibilitySnapshot"))
+ for {
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[Seq[EligibleTrial]](response)
+ } yield {
+ reply
+ }
+ }
+
+}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala
deleted file mode 100644
index 06aa6d0..0000000
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestPatientEligibleTrialService.scala
+++ /dev/null
@@ -1,84 +0,0 @@
-package xyz.driver.pdsuidomain.services.rest
-
-import akka.http.scaladsl.marshalling.Marshal
-import akka.http.scaladsl.model._
-import akka.stream.Materializer
-import xyz.driver.core.rest.{Pagination => _, _}
-import xyz.driver.entities.users.AuthUserInfo
-import xyz.driver.pdsuicommon.db._
-import xyz.driver.pdsuicommon.domain._
-import xyz.driver.pdsuidomain.ListResponse
-import xyz.driver.pdsuidomain.entities._
-import xyz.driver.pdsuidomain.services.PatientCriterionService.RichPatientCriterion
-import xyz.driver.pdsuidomain.services.PatientEligibleTrialService
-
-import scala.concurrent.{ExecutionContext, Future}
-
-class RestPatientEligibleTrialService(transport: ServiceTransport, baseUri: Uri)(
- implicit protected val materializer: Materializer,
- protected val exec: ExecutionContext)
- extends PatientEligibleTrialService with RestHelper {
-
- import PatientEligibleTrialService._
- import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
- import xyz.driver.pdsuidomain.formats.json.listresponse._
- import xyz.driver.pdsuidomain.formats.json.patientcriterion._
- import xyz.driver.pdsuidomain.formats.json.patienteligibletrial._
-
- def getAll(patientId: UuidId[Patient],
- filter: SearchFilterExpr = SearchFilterExpr.Empty,
- sorting: Option[Sorting] = None,
- pagination: Option[Pagination] = None)(
- implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetListReply] = {
- val request = HttpRequest(HttpMethods.GET,
- endpointUri(baseUri,
- s"/v1/patient/$patientId/trial",
- filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination)))
- for {
- response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[ListResponse[RichPatientEligibleTrial]](response)
- } yield {
- GetListReply.EntityList(reply.items, reply.meta.itemsCount)
- }
- }
-
-
- def getById(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])(
- implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetByIdReply] = {
- val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/trial/$id"))
- for {
- response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[RichPatientEligibleTrial](response)
- } yield {
- GetByIdReply.Entity(reply)
- }
- }
-
- def getCriterionListByGroupId(patientId: UuidId[Patient], id: LongId[PatientTrialArmGroup])(
- implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[GetCriterionListOfGroupReply] = {
- val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/patient/$patientId/trial/$id/criterion"))
- for {
- response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[ListResponse[RichPatientCriterion]](response)
- } yield {
- GetCriterionListOfGroupReply.EntityList(reply.items, reply.meta.itemsCount)
- }
- }
-
- def update(origEligibleTrialWithTrial: RichPatientEligibleTrial,
- draftPatientTrialArmGroup: PatientTrialArmGroupView)(
- implicit requestContext: AuthorizedServiceRequestContext[AuthUserInfo]): Future[UpdateReply] = {
- for {
- entity <- Marshal(draftPatientTrialArmGroup).to[RequestEntity]
- request = HttpRequest(
- HttpMethods.PATCH,
- endpointUri(baseUri, s"/v1/patient/${origEligibleTrialWithTrial.group.patientId}/trial/${origEligibleTrialWithTrial.group.id}"))
- .withEntity(entity)
- response <- transport.sendRequestGetResponse(requestContext)(request)
- reply <- apiResponse[RichPatientEligibleTrial](response)
- } yield {
- UpdateReply.Updated(reply)
- }
- }
-
-}
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala
new file mode 100644
index 0000000..b14d35b
--- /dev/null
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialIssueService.scala
@@ -0,0 +1,103 @@
+package xyz.driver.pdsuidomain.services.rest
+
+import akka.http.scaladsl.marshalling.Marshal
+import akka.http.scaladsl.model._
+import akka.stream.Materializer
+import spray.json.RootJsonReader
+import xyz.driver.core.rest.{AuthorizedServiceRequestContext, ServiceTransport}
+import xyz.driver.entities.users
+import xyz.driver.pdsuicommon.db.{Pagination, SearchFilterExpr, Sorting}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.ListResponse
+import xyz.driver.pdsuidomain.entities.{Trial, TrialIssue}
+import xyz.driver.pdsuidomain.services.TrialIssueService
+
+import scala.concurrent.ExecutionContext
+
+class RestTrialIssueService(transport: ServiceTransport, baseUri: Uri)
+ (implicit
+ protected val materializer: Materializer,
+ protected val exec: ExecutionContext)
+ extends TrialIssueService with RestHelper{
+
+ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+ import xyz.driver.pdsuidomain.formats.json.listresponse._
+ import xyz.driver.pdsuidomain.formats.json.trialissue._
+ import xyz.driver.pdsuidomain.services.TrialIssueService._
+
+ override def create(draft: TrialIssue)
+ (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = {
+ val trialId = draft.trialId
+
+ implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId)
+
+ for {
+ entity <- Marshal(draft).to[RequestEntity]
+ request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, s"/v1/trial/$trialId/issue")).withEntity(entity)
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[TrialIssue](response)
+ } yield {
+ CreateReply.Created(reply)
+ }
+ }
+
+ override def getListByTrialId(trialId: StringId[Trial],
+ filter: SearchFilterExpr,
+ sorting: Option[Sorting],
+ pagination: Option[Pagination])
+ (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = {
+ implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId)
+
+ val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$trialId/issue",
+ filterQuery(filter) ++ sortingQuery(sorting) ++ paginationQuery(pagination))
+ )
+ for {
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[ListResponse[TrialIssue]](response)
+ } yield {
+ GetListByTrialIdReply.EntityList(reply.items, reply.meta.itemsCount, reply.meta.lastUpdate)
+ }
+ }
+
+ override def getById(trialId: StringId[Trial], id: LongId[TrialIssue])
+ (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = {
+ implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId)
+
+ val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id"))
+ for {
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[TrialIssue](response)
+ } yield {
+ GetByIdReply.Entity(reply)
+ }
+ }
+
+ override def update(orig: TrialIssue, draft: TrialIssue)
+ (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = {
+ val trialId = draft.trialId
+ val id = orig.id.id
+
+ implicit val jsonReader: RootJsonReader[TrialIssue] = trialIssueReader(trialId)
+
+ for {
+ entity <- Marshal(draft).to[RequestEntity]
+ request = HttpRequest(HttpMethods.PATCH, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id")).withEntity(entity)
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ reply <- apiResponse[TrialIssue](response)
+ } yield {
+ UpdateReply.Updated(reply)
+ }
+ }
+
+ override def delete(trialId: StringId[Trial], id: LongId[TrialIssue])
+ (implicit requestContext: AuthorizedServiceRequestContext[users.AuthUserInfo]) = {
+ val request = HttpRequest(HttpMethods.DELETE, endpointUri(baseUri, s"/v1/trial/$trialId/issue/$id"))
+ for {
+ response <- transport.sendRequestGetResponse(requestContext)(request)
+ _ <- apiResponse[HttpEntity](response)
+ } yield {
+ DeleteReply.Deleted
+ }
+ }
+
+}
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 4654c2e..6650d51 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala
@@ -110,7 +110,7 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote
}
val id = origTrial.id.id
- val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/trial/$id/$action", query))
+ val request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, s"/v1/trial/$id/$action", query))
for {
response <- transport.sendRequestGetResponse(requestContext)(request)
reply <- apiResponse[Trial](response)
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientEligibleTrialFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientEligibleTrialFormatSuite.scala
index 9695c2d..faef0f6 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientEligibleTrialFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientEligibleTrialFormatSuite.scala
@@ -47,19 +47,13 @@ class PatientEligibleTrialFormatSuite extends FlatSpec with Matchers {
PatientCriterionArm(patientCriterionId = LongId(1), armId = LongId(32), armName = "arm 32")
)
val orig = RichPatientEligibleTrial(trial, group, arms)
- val writtenJson = patientEligibleTrialFormat.write(orig)
+ val writtenJson = patientEligibleTrialWriter.write(orig)
writtenJson should be(
- """{"trial":{"isPartner":false,"assignee":null,"lastUpdate":"2017-08-10T18:16:19Z","previousStatus":null,
- "isUpdated":false,"overviewTemplate":"","phase":"","originalStudyDesignId":null,
- "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","originalTitle":"orig trial title","studyDesignId":321,
- "lastActiveUser":null,"externalid":"40892a07-c638-49d2-9795-1edfefbbcc7c","id":"NCT000001","status":"Done",
- "overview":null,"previousAssignee":null,"title":"trial title"},"group":{"isVerified":false
- ,"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4",
- "verifiedEligibilityStatus":"Yes","trialId":"NCT000001","eligibilityStatus":"Yes","id":1},
- "arms":[{"patientCriterionId":1,"armId":31,"armName":"arm 31"},{"patientCriterionId":1,"armId":32,"armName":"arm 32"}]}""".parseJson)
+ """{"id":1,"patientId":"748b5884-3528-4cb9-904b-7a8151d6e343","trialId":"NCT000001","trialTitle":"trial title",
+ "hypothesisId":"e76e2fc4-a29c-44fb-a81b-8856d06bb1d4","verifiedEligibilityStatus":"Yes","isVerified":false,"arms":["arm 31","arm 32"]}""".parseJson)
- val updatePatientEligibleTrialJson = """{"group":{"isVerified":true}}""".parseJson
+ val updatePatientEligibleTrialJson = """{"isVerified":true}""".parseJson
val expectedUpdatedPatientTrialArmGroup = group.copy(isVerified = true)
val parsedUpdatePatientTrialArmGroup = applyUpdateToTrialArmGroup(updatePatientEligibleTrialJson, group)
parsedUpdatePatientTrialArmGroup should be(expectedUpdatedPatientTrialArmGroup)
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/TrialIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/TrialIssueFormatSuite.scala
index a3b5931..a13e097 100644
--- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/TrialIssueFormatSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/TrialIssueFormatSuite.scala
@@ -26,6 +26,7 @@ class TrialIssueFormatSuite extends FlatSpec with Matchers {
writtenJson should be("""{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false,
"text":"message text","evidence":"evidence","archiveRequired":false,"meta":"{}"}""".parseJson)
+ trialIssueReader(StringId("NCT000001")).read(writtenJson) shouldBe trialIssue
val createTrialIssueJson = """{"text":"message text","evidence":"evidence","meta":"{}"}""".parseJson
val expectedCreatedTrialIssue = trialIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true)