diff options
author | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
---|---|---|
committer | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
commit | 9968eaefa2a97ebe495fa51b640e31c78db61ac6 (patch) | |
tree | 4eed12a4ebb2829e336a3da673c7c8462e7ab845 /src/main/scala/xyz/driver/pdsuidomain/formats | |
parent | d5ecec043a3d70dd09bda8a79fcd188f411b47df (diff) | |
parent | d4b18efda238f506103dddbf3b400ae17c797276 (diff) | |
download | rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.gz rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.bz2 rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.zip |
Merge branch 'master' into slick-query-builder
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats')
8 files changed, 71 insertions, 50 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala index 39acbde..f306a71 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiIntervention.scala @@ -8,12 +8,12 @@ import play.api.libs.json.{Format, JsPath} final case class ApiIntervention(id: Long, name: String, typeId: Option[Long], - description: String, + dosage: String, isActive: Boolean, arms: List[Long], trialId: String, originalName: String, - originalDescription: String, + originalDosage: String, originalType: Option[String]) { def toDomain = { @@ -24,8 +24,8 @@ final case class ApiIntervention(id: Long, originalName = this.originalName, typeId = this.typeId.map(id => LongId(id)), originalType = this.originalType.map(id => id.toString), - description = this.description, - originalDescription = this.originalDescription, + dosage = this.dosage, + originalDosage = this.originalDosage, isActive = this.isActive ) @@ -43,12 +43,12 @@ object ApiIntervention { (JsPath \ "id").format[Long] and (JsPath \ "name").format[String] and (JsPath \ "typeId").formatNullable[Long] and - (JsPath \ "description").format[String] and + (JsPath \ "dosage").format[String] and (JsPath \ "isActive").format[Boolean] and (JsPath \ "arms").format[List[Long]] and (JsPath \ "trialId").format[String] and (JsPath \ "originalName").format[String] and - (JsPath \ "originalDescription").format[String] and + (JsPath \ "originalDosage").format[String] and (JsPath \ "originalType").formatNullable[String] )(ApiIntervention.apply, unlift(ApiIntervention.unapply)) @@ -60,12 +60,12 @@ object ApiIntervention { id = intervention.id.id, name = intervention.name, typeId = intervention.typeId.map(_.id), - description = intervention.description, + dosage = intervention.dosage, isActive = intervention.isActive, arms = arms.map(_.armId.id), trialId = intervention.trialId.id, originalName = intervention.originalName, - originalDescription = intervention.originalDescription, + originalDosage = intervention.originalDosage, originalType = intervention.originalType ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala index f67ba6b..aa55506 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/intervention/ApiPartialIntervention.scala @@ -6,7 +6,7 @@ import play.api.libs.functional.syntax._ import play.api.libs.json._ final case class ApiPartialIntervention(typeId: Option[Long], - description: Option[String], + dosage: Option[String], isActive: Option[Boolean], arms: Option[List[Long]]) { @@ -16,7 +16,7 @@ final case class ApiPartialIntervention(typeId: Option[Long], orig.copy( intervention = origIntervention.copy( typeId = typeId.map(LongId(_)).orElse(origIntervention.typeId), - description = description.getOrElse(origIntervention.description), + dosage = dosage.getOrElse(origIntervention.dosage), isActive = isActive.getOrElse(origIntervention.isActive) ), arms = draftArmList.getOrElse(orig.arms) @@ -28,14 +28,14 @@ object ApiPartialIntervention { private val reads: Reads[ApiPartialIntervention] = ( (JsPath \ "typeId").readNullable[Long] and - (JsPath \ "description").readNullable[String] and + (JsPath \ "dosage").readNullable[String] and (JsPath \ "isActive").readNullable[Boolean] and (JsPath \ "arms").readNullable[List[Long]] )(ApiPartialIntervention.apply _) private val writes: Writes[ApiPartialIntervention] = ( (JsPath \ "typeId").writeNullable[Long] and - (JsPath \ "description").writeNullable[String] and + (JsPath \ "dosage").writeNullable[String] and (JsPath \ "isActive").writeNullable[Boolean] and (JsPath \ "arms").writeNullable[List[Long]] )(unlift(ApiPartialIntervention.unapply)) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala index 28b2a5e..a658cfa 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documentissue.scala @@ -61,17 +61,6 @@ object documentissue { case _ => deserializationError(s"Expected Json Object as DocumentIssue, but got $json") } - implicit val documentIssueWriter = new JsonWriter[DocumentIssue] { - override def write(obj: DocumentIssue) = JsObject( - "id" -> obj.id.toJson, - "startPage" -> obj.startPage.toJson, - "endPage" -> obj.endPage.toJson, - "text" -> obj.text.toJson, - "lastUpdate" -> obj.lastUpdate.toJson, - "userId" -> obj.userId.toJson, - "isDraft" -> obj.isDraft.toJson, - "archiveRequired" -> obj.archiveRequired.toJson - ) - } + implicit val documentIssueFormat: RootJsonFormat[DocumentIssue] = jsonFormat9(DocumentIssue.apply) } 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 new file mode 100644 index 0000000..8119d35 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/documenttype.scala @@ -0,0 +1,13 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import xyz.driver.pdsuidomain.entities._ +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/intervention.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala index a8ce950..9314391 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/intervention.scala @@ -11,16 +11,16 @@ object intervention { implicit val interventionWriter: JsonWriter[InterventionWithArms] = new JsonWriter[InterventionWithArms] { override def write(obj: InterventionWithArms) = JsObject( - "id" -> obj.intervention.id.toJson, - "name" -> obj.intervention.name.toJson, - "typeId" -> obj.intervention.typeId.toJson, - "description" -> obj.intervention.description.toJson, - "isActive" -> obj.intervention.isActive.toJson, - "arms" -> obj.arms.map(_.armId).toJson, - "trialId" -> obj.intervention.trialId.toJson, - "originalName" -> obj.intervention.originalName.toJson, - "originalDescription" -> obj.intervention.originalDescription.toJson, - "originalType" -> obj.intervention.originalType.toJson + "id" -> obj.intervention.id.toJson, + "name" -> obj.intervention.name.toJson, + "typeId" -> obj.intervention.typeId.toJson, + "dosage" -> obj.intervention.dosage.toJson, + "isActive" -> obj.intervention.isActive.toJson, + "arms" -> obj.arms.map(_.armId).toJson, + "trialId" -> obj.intervention.trialId.toJson, + "originalName" -> obj.intervention.originalName.toJson, + "originalDosage" -> obj.intervention.originalDosage.toJson, + "originalType" -> obj.intervention.originalType.toJson ) } @@ -30,8 +30,8 @@ object intervention { .get("typeId") .map(_.convertTo[LongId[InterventionType]]) - val description = fields - .get("description") + val dosage = fields + .get("dosage") .map(_.convertTo[String]) val isActive = fields @@ -46,7 +46,7 @@ object intervention { orig.copy( intervention = origIntervention.copy( typeId = typeId.orElse(origIntervention.typeId), - description = description.getOrElse(origIntervention.description), + dosage = dosage.getOrElse(origIntervention.dosage), isActive = isActive.getOrElse(origIntervention.isActive) ), arms = arms.getOrElse(orig.arms) 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 new file mode 100644 index 0000000..385feb2 --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/providerttype.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/formats/json/sprayformats/recordissue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala index 4ae04d0..4ac5f6d 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/recordissue.scala @@ -63,17 +63,6 @@ object recordissue { case _ => deserializationError(s"Expected Json Object as MedicalRecordIssue, but got $json") } - implicit val recordIssueWriter = new JsonWriter[MedicalRecordIssue] { - override def write(obj: MedicalRecordIssue) = JsObject( - "id" -> obj.id.toJson, - "startPage" -> obj.startPage.toJson, - "endPage" -> obj.endPage.toJson, - "text" -> obj.text.toJson, - "lastUpdate" -> obj.lastUpdate.toJson, - "userId" -> obj.userId.toJson, - "isDraft" -> obj.isDraft.toJson, - "archiveRequired" -> obj.archiveRequired.toJson - ) - } + implicit val recordIssueFormat = jsonFormat9(MedicalRecordIssue.apply) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala index 852c4f6..c9475c6 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/trialissue/ApiTrialIssue.scala @@ -4,20 +4,37 @@ import java.time.{ZoneId, ZonedDateTime} import play.api.libs.functional.syntax._ import play.api.libs.json._ +import xyz.driver.pdsuicommon.domain._ import xyz.driver.pdsuidomain.entities.TrialIssue final case class ApiTrialIssue(id: Long, + trialId: String, text: String, lastUpdate: ZonedDateTime, userId: String, isDraft: Boolean, evidence: String, archiveRequired: Boolean, - meta: String) + meta: String) { + + def toDomain = TrialIssue( + id = LongId(this.id), + trialId = StringId(this.trialId), + text = this.text, + userId = StringId(this.userId), + lastUpdate = this.lastUpdate.toLocalDateTime, + isDraft = this.isDraft, + evidence = this.evidence, + archiveRequired = this.archiveRequired, + meta = this.meta + ) + +} object ApiTrialIssue { implicit val format: Format[ApiTrialIssue] = ( (JsPath \ "id").format[Long] and + (JsPath \ "trialId").format[String] and (JsPath \ "text").format[String] and (JsPath \ "lastUpdate").format[ZonedDateTime] and (JsPath \ "userId").format[String] and @@ -31,6 +48,7 @@ object ApiTrialIssue { def fromDomain(x: TrialIssue) = ApiTrialIssue( id = x.id.id, + trialId = x.trialId.id, text = x.text, lastUpdate = ZonedDateTime.of(x.lastUpdate, ZoneId.of("Z")), userId = x.userId.id, |