From 0cb9b1fb20e38dc8858e1f24b17ec247b8a5a4fc Mon Sep 17 00:00:00 2001 From: Tuncay NAMLI Date: Thu, 20 May 2021 11:31:53 +0300 Subject: [PATCH] :bugs: fix: Fix document operation handler with missing timestamp and identifier --- .../operation/DocumentOperationHandler.scala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/onfhir-operations/src/main/scala/io/onfhir/operation/DocumentOperationHandler.scala b/onfhir-operations/src/main/scala/io/onfhir/operation/DocumentOperationHandler.scala index 4bc72383..77b36ee4 100644 --- a/onfhir-operations/src/main/scala/io/onfhir/operation/DocumentOperationHandler.scala +++ b/onfhir-operations/src/main/scala/io/onfhir/operation/DocumentOperationHandler.scala @@ -8,8 +8,10 @@ import io.onfhir.api.model.{FHIROperationRequest, FHIROperationResponse} import io.onfhir.api.parsers.FHIRSearchParameterValueParser import io.onfhir.api.service.{FHIRCreateService, FHIROperationHandlerService, FHIRSearchService} import io.onfhir.api.util.FHIRUtil +import io.onfhir.config.OnfhirConfig import io.onfhir.db.ResourceManager import io.onfhir.exception.InternalServerException +import io.onfhir.util.DateTimeUtil import io.onfhir.util.JsonFormatter.formats import org.json4s.JString import org.json4s.JsonAST.{JField, JObject, JValue} @@ -65,13 +67,21 @@ class DocumentOperationHandler extends FHIROperationHandlerService { } ) } + //Add document time and identifier + result = result merge JObject( + "timestamp" -> JString(DateTimeUtil.serializeInstant(Instant.now())), + "identifier" -> JObject( + "system" -> JString(OnfhirConfig.fhirRootUrl), + "value" -> JString(FHIRUtil.generateResourceId()) + ) + ) - val persist = operationRequest.extractParamValue[String]("persist") + val persist = operationRequest.extractParamValue[Boolean]("persist") val generatedBundle = persist match { - case Some("true") => + case Some(true) => ResourceManager.createResource((bundle \ "resourceType").extract[String], result.asInstanceOf[JObject], generatedId = (result \ "id").extractOpt[String]) - bundle + result.asInstanceOf[JObject] case _ => { val newVersion = 1L //new version is always 1 for create operation val lastModified = Instant.now()