diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain')
12 files changed, 91 insertions, 141 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala deleted file mode 100644 index 1aed121..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/export/trial/ExportTrial.scala +++ /dev/null @@ -1,27 +0,0 @@ -package xyz.driver.pdsuidomain.entities.export.trial - -import java.time.LocalDateTime - -import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.logging._ -import xyz.driver.pdsuidomain.entities.Trial - -final case class ExportTrial(nctId: StringId[Trial], - trialId: UuidId[Trial], - condition: Trial.Condition, - lastReviewed: LocalDateTime) - -object ExportTrial { - - implicit def toPhiString(x: ExportTrial): PhiString = { - import x._ - phi"ExportTrial(nctId=$nctId, trialId=$trialId, condition=${Unsafe(condition)}, lastReviewed=$lastReviewed)" - } - - def fromDomain(x: Trial) = ExportTrial( - nctId = x.id, - trialId = x.externalId, - condition = x.condition, - lastReviewed = x.lastUpdate - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala deleted file mode 100644 index 0c9cb71..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrial.scala +++ /dev/null @@ -1,26 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import java.time.ZoneId - -import play.api.libs.functional.syntax._ -import play.api.libs.json.{Format, JsPath} -import xyz.driver.pdsuidomain.entities.export.trial.ExportTrial - -final case class ApiExportTrial(nctId: String, trialId: String, disease: String, lastReviewed: Long) - -object ApiExportTrial { - - implicit val format: Format[ApiExportTrial] = ( - (JsPath \ "nctId").format[String] and - (JsPath \ "trialId").format[String] and - (JsPath \ "disease").format[String] and - (JsPath \ "lastReviewed").format[Long] - )(ApiExportTrial.apply, unlift(ApiExportTrial.unapply)) - - def fromDomain(trial: ExportTrial): ApiExportTrial = ApiExportTrial( - nctId = trial.nctId.id, - trialId = trial.trialId.toString, - disease = trial.condition.toString.toUpperCase, - lastReviewed = trial.lastReviewed.atZone(ZoneId.of("Z")).toEpochSecond - ) -} 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 index b2b02eb..ea96f58 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialArm.scala @@ -2,9 +2,16 @@ 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) +final case class ApiExportTrialArm(armId: String, armName: String) { + + def toDomain: ExportTrialArm = { + ExportTrialArm(LongId[Arm](armId.toLong), armName) + } +} object ApiExportTrialArm { 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 index 2564efe..df1ebb4 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialLabelCriterion.scala @@ -1,9 +1,10 @@ package xyz.driver.pdsuidomain.formats.json.export -import xyz.driver.pdsuicommon.domain.FuzzyValue 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, @@ -11,7 +12,20 @@ final case class ApiExportTrialLabelCriterion(value: String, criterionText: String, armIds: List[String], isCompound: Boolean, - isDefining: 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 { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala deleted file mode 100644 index 93ee42e..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialList.scala +++ /dev/null @@ -1,15 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.export - -import play.api.libs.json.{Format, Json} -import xyz.driver.pdsuidomain.entities.export.trial.ExportTrial - -final case class ApiExportTrialList(trials: Seq[ApiExportTrial]) - -object ApiExportTrialList { - - implicit val format: Format[ApiExportTrialList] = Json.format - - def fromDomain(trialList: Seq[ExportTrial]) = ApiExportTrialList( - trials = trialList.map(ApiExportTrial.fromDomain) - ) -} 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 index de76ac0..e383a1f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/export/ApiExportTrialWithLabels.scala @@ -1,9 +1,11 @@ package xyz.driver.pdsuidomain.formats.json.export -import java.time.ZoneId +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, @@ -12,7 +14,20 @@ final case class ApiExportTrialWithLabels(nctId: String, lastReviewed: Long, labelVersion: Long, arms: List[ApiExportTrialArm], - criteria: List[ApiExportTrialLabelCriterion]) + 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 { diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala index f59836e..51bd03f 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trial/ApiTrial.scala @@ -36,7 +36,7 @@ final case class ApiTrial(id: String, previousStatus = this.previousStatus.map(s => TrialStatus.statusFromString(s)), previousAssignee = this.previousAssignee.map(id => StringId(id)), lastActiveUserId = this.lastActiveUser.map(id => StringId(id)), - lastUpdate = this.lastUpdate.toLocalDateTime(), + lastUpdate = this.lastUpdate.toLocalDateTime, condition = Trial.Condition .fromString(this.condition) .getOrElse( diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala deleted file mode 100644 index a313703..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/services/ExportService.scala +++ /dev/null @@ -1,63 +0,0 @@ -package xyz.driver.pdsuidomain.services - -import java.time.LocalDateTime - -import xyz.driver.pdsuicommon.auth.AnonymousRequestContext -import xyz.driver.pdsuicommon.db.SearchFilterExpr -import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.error.DomainError -import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels -import xyz.driver.pdsuidomain.entities.export.trial.{ExportTrial, ExportTrialWithLabels} -import xyz.driver.pdsuidomain.entities.{MedicalRecord, Patient, Trial} - -import scala.concurrent.Future - -object ExportService { - - sealed trait GetPatientReply - object GetPatientReply { - type Error = GetPatientReply with DomainError - - final case class Entity(x: ExportPatientWithLabels) extends GetPatientReply - - case object NotFoundError extends GetPatientReply with DomainError.NotFoundError { - def userMessage: String = "Patient not found" - } - } - - sealed trait GetTrialListReply - object GetTrialListReply { - final case class EntityList(xs: Seq[ExportTrial], totalFound: Int, lastUpdate: Option[LocalDateTime]) - extends GetTrialListReply - } - - sealed trait GetTrialReply - object GetTrialReply { - type Error = GetTrialReply with DomainError - - final case class Entity(x: ExportTrialWithLabels) extends GetTrialReply - - case object NotFoundError extends GetTrialReply with DomainError.NotFoundError { - def userMessage: String = "Trial not found" - } - } -} - -trait ExportService { - - import ExportService._ - - def getPatient(id: UuidId[Patient])(implicit requestContext: AnonymousRequestContext): Future[GetPatientReply] - - def getTrialList(filter: SearchFilterExpr = SearchFilterExpr.Empty)( - implicit requestContext: AnonymousRequestContext): Future[GetTrialListReply] - - def getTrial(trialId: StringId[Trial], condition: String)( - implicit requestContext: AnonymousRequestContext): Future[GetTrialReply] - - def getRecords(patientId: UuidId[Patient])( - implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetListReply] - - def getRecordPdf(recordId: LongId[MedicalRecord])( - implicit requestContext: AnonymousRequestContext): Future[MedicalRecordService.GetPdfSourceReply] -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/MedicalRecordService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/MedicalRecordService.scala index b2fc9f9..cfdb2b1 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/MedicalRecordService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/MedicalRecordService.scala @@ -4,7 +4,7 @@ import java.time.LocalDateTime import xyz.driver.pdsuicommon.auth.AuthenticatedRequestContext import xyz.driver.pdsuicommon.db._ -import xyz.driver.pdsuicommon.domain.LongId +import xyz.driver.pdsuicommon.domain.{LongId, UuidId} import xyz.driver.pdsuicommon.error._ import xyz.driver.pdsuidomain.entities.MedicalRecord.PdfSource import xyz.driver.pdsuidomain.entities._ @@ -93,6 +93,9 @@ trait MedicalRecordService { def getById(recordId: LongId[MedicalRecord])( implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply] + def getPatientRecords(patientId: UuidId[Patient])( + implicit requestContext: AuthenticatedRequestContext): Future[GetListReply] + def getPdfSource(recordId: LongId[MedicalRecord])( implicit requestContext: AuthenticatedRequestContext): Future[GetPdfSourceReply] diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala index ce70934..b2a140c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/PatientService.scala @@ -8,6 +8,7 @@ import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuicommon.error.DomainError import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities._ +import xyz.driver.pdsuidomain.entities.export.patient.ExportPatientWithLabels import scala.concurrent.Future @@ -50,6 +51,17 @@ object PatientService { } } + sealed trait GetPatientWithLabelsReply + object GetPatientWithLabelsReply { + type Error = GetPatientWithLabelsReply with DomainError + + final case class Entity(x: ExportPatientWithLabels) extends GetPatientWithLabelsReply + + case object NotFoundError extends GetPatientWithLabelsReply with DomainError.NotFoundError { + def userMessage: String = "Patient not found" + } + } + sealed trait UpdateReply object UpdateReply { type Error = UpdateReply with DomainError @@ -76,6 +88,9 @@ trait PatientService { def getById(id: UuidId[Patient])(implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply] + def getExportPatient(id: UuidId[Patient])( + implicit requestContext: AuthenticatedRequestContext): Future[GetPatientWithLabelsReply] + def getAll(filter: SearchFilterExpr = SearchFilterExpr.Empty, sorting: Option[Sorting] = None, pagination: Option[Pagination] = None)( diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala index 3148842..d140d27 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/TrialService.scala @@ -9,6 +9,7 @@ import xyz.driver.pdsuicommon.error.DomainError import xyz.driver.pdsuicommon.logging._ import xyz.driver.pdsuidomain.entities.Trial import xyz.driver.pdsuidomain.entities.Trial.PdfSource +import xyz.driver.pdsuidomain.entities.export.trial.ExportTrialWithLabels import scala.concurrent.Future @@ -51,6 +52,20 @@ object TrialService { } } + sealed trait GetTrialWithLabelsReply + object GetTrialWithLabelsReply { + type Error = GetTrialWithLabelsReply with DomainError + + final case class Entity(x: ExportTrialWithLabels) extends GetTrialWithLabelsReply + + case object NotFoundError extends GetTrialWithLabelsReply with DomainError.NotFoundError { + def userMessage: String = "Trial not found" + } + + case object AuthorizationError + extends GetTrialWithLabelsReply with DomainError.AuthorizationError with DefaultAccessDeniedError + } + sealed trait GetPdfSourceReply object GetPdfSourceReply { type Error = GetPdfSourceReply with DomainError @@ -95,6 +110,9 @@ trait TrialService { def getById(id: StringId[Trial])(implicit requestContext: AuthenticatedRequestContext): Future[GetByIdReply] + def getTrialWithLabels(trialId: StringId[Trial], condition: String)( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] + def getPdfSource(trialId: StringId[Trial])( implicit requestContext: AuthenticatedRequestContext): Future[GetPdfSourceReply] 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 54f5f2e..9f72760 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestTrialService.scala @@ -1,8 +1,6 @@ package xyz.driver.pdsuidomain.services.rest -import scala.NotImplementedError import scala.concurrent.{ExecutionContext, Future} - import akka.http.scaladsl.marshalling.Marshal import akka.http.scaladsl.model._ import akka.stream.Materializer @@ -12,6 +10,7 @@ import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuidomain.entities._ 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 @@ -32,6 +31,17 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote } } + def getTrialWithLabels(trialId: StringId[Trial], condition: String)( + implicit requestContext: AuthenticatedRequestContext): Future[GetTrialWithLabelsReply] = { + val request = HttpRequest(HttpMethods.GET, endpointUri(baseUri, s"/v1/export/trial/$trialId")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[ApiExportTrialWithLabels](response) + } yield { + GetTrialWithLabelsReply.Entity(reply.toDomain) + } + } + def getPdfSource(trialId: StringId[Trial])( implicit requestContext: AuthenticatedRequestContext): Future[GetPdfSourceReply] = Future.failed(new NotImplementedError("Streaming PDF over network is not supported.")) @@ -90,5 +100,4 @@ class RestTrialService(transport: ServiceTransport, baseUri: Uri)(implicit prote singleAction(origTrial, "archive") def unassign(origTrial: Trial)(implicit requestContext: AuthenticatedRequestContext): Future[UpdateReply] = singleAction(origTrial, "unassign") - } |