mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-17 12:52:54 +00:00
fix: serialization issue with fhir consent and embedding research consent
This commit is contained in:
@ -8,7 +8,6 @@ import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.model.BooleanType;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Coding;
|
||||
@ -185,7 +184,7 @@ public class GicsConsentService implements ICheckConsent {
|
||||
throw new IllegalStateException(
|
||||
"consent data request failed - stopping processing! - try again or fix other problems first.");
|
||||
}
|
||||
IBaseResource iBaseResource = fhirContext.newXmlParser()
|
||||
var iBaseResource = fhirContext.newJsonParser()
|
||||
.parseResource(consentDataSerialized);
|
||||
if (iBaseResource instanceof OperationOutcome) {
|
||||
// log error - very likely a configuration error
|
||||
|
@ -1,20 +1,18 @@
|
||||
package dev.dnpm.etl.processor.config
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext
|
||||
import com.fasterxml.jackson.core.JsonParser
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationContext
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource
|
||||
import org.hl7.fhir.r4.model.Consent
|
||||
|
||||
class IBaseResourceDeserializer : JsonDeserializer<IBaseResource>() {
|
||||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): IBaseResource {
|
||||
val fhirContext = FhirContext.forR4()
|
||||
class ConsentResourceDeserializer : JsonDeserializer<Consent>() {
|
||||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Consent {
|
||||
|
||||
val jsonNode = p?.readValueAsTree<JsonNode>()
|
||||
val json = jsonNode?.toString()
|
||||
|
||||
return fhirContext.newJsonParser().parseResource(json) as IBaseResource
|
||||
return JacksonConfig.fhirContext().newJsonParser().parseResource(json) as Consent
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package dev.dnpm.etl.processor.config
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator
|
||||
import com.fasterxml.jackson.databind.JsonSerializer
|
||||
import com.fasterxml.jackson.databind.SerializerProvider
|
||||
import org.hl7.fhir.r4.model.Consent
|
||||
|
||||
class ConsentResourceSerializer : JsonSerializer<Consent>() {
|
||||
override fun serialize(
|
||||
value: Consent, gen: JsonGenerator, serializers: SerializerProvider
|
||||
) {
|
||||
val json = JacksonConfig.fhirContext().newJsonParser().encodeResourceToString(value)
|
||||
gen.writeRawValue(json)
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@ package dev.dnpm.etl.processor.config
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource
|
||||
import org.hl7.fhir.r4.model.Consent
|
||||
|
||||
class FhirResourceModule : SimpleModule() {
|
||||
init {
|
||||
addSerializer(IBaseResource::class.java, IBaseResourceSerializer())
|
||||
addDeserializer(IBaseResource::class.java, IBaseResourceDeserializer())
|
||||
addSerializer(Consent::class.java, ConsentResourceSerializer())
|
||||
addDeserializer(Consent::class.java, ConsentResourceDeserializer())
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package dev.dnpm.etl.processor.config
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext
|
||||
import com.fasterxml.jackson.core.JsonGenerator
|
||||
import com.fasterxml.jackson.databind.JsonSerializer
|
||||
import com.fasterxml.jackson.databind.SerializerProvider
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource
|
||||
|
||||
class IBaseResourceSerializer : JsonSerializer<IBaseResource>() {
|
||||
override fun serialize(
|
||||
value: IBaseResource,
|
||||
gen: JsonGenerator,
|
||||
serializers: SerializerProvider
|
||||
) {
|
||||
val fhirContext = FhirContext.forR4()
|
||||
val json = fhirContext.newJsonParser().encodeResourceToString(value)
|
||||
gen.writeRawValue(json)
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package dev.dnpm.etl.processor.config
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
@ -9,11 +10,18 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
@Configuration
|
||||
class JacksonConfig {
|
||||
|
||||
companion object {
|
||||
var fhirContext: FhirContext = FhirContext.forR4()
|
||||
|
||||
@JvmStatic
|
||||
fun fhirContext(): FhirContext {
|
||||
return fhirContext
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun objectMapper(): ObjectMapper =
|
||||
ObjectMapper()
|
||||
.registerModule(FhirResourceModule())
|
||||
fun objectMapper(): ObjectMapper = ObjectMapper().registerModule(FhirResourceModule())
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).registerModule(
|
||||
JavaTimeModule()
|
||||
);
|
||||
)
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ class GPasConnectionCheckService(
|
||||
fun check() {
|
||||
result = try {
|
||||
val uri = UriComponentsBuilder.fromUriString(
|
||||
gPasConfigProperties.uri?.replace("/\$\$pseudonymizeAllowCreate", "/metadata").toString()
|
||||
gPasConfigProperties.uri?.replace("/\$pseudonymizeAllowCreate", "/metadata").toString()
|
||||
).build().toUri()
|
||||
|
||||
val headers = HttpHeaders()
|
||||
|
@ -42,7 +42,6 @@ import dev.pcvolkmer.mv64e.mtb.MvhMetadata
|
||||
import dev.pcvolkmer.mv64e.mtb.Provision
|
||||
import org.apache.commons.codec.binary.Base32
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource
|
||||
import org.hl7.fhir.r4.model.Bundle
|
||||
import org.hl7.fhir.r4.model.Consent
|
||||
import org.slf4j.Logger
|
||||
@ -53,7 +52,6 @@ import java.io.IOException
|
||||
import java.lang.RuntimeException
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.util.*
|
||||
|
||||
@Service
|
||||
@ -107,7 +105,7 @@ class RequestProcessor(
|
||||
initMetaDataAtMtbFile(mtbFile)
|
||||
|
||||
val personIdentifierValue = extractPatientIdentifier(mtbFile)
|
||||
val requestDate = Date.from(Instant.now(Clock.system(ZoneId.of("ECT"))))
|
||||
val requestDate = Date.from(Instant.now(Clock.systemUTC()))
|
||||
|
||||
// 1. Broad consent Entry exists?
|
||||
// 1.1. -> yes and research consent is given -> send mtb file
|
||||
@ -192,7 +190,7 @@ class RequestProcessor(
|
||||
mtbFile: Mtb, broadConsent: Bundle
|
||||
) {
|
||||
broadConsent.entry.forEach { it ->
|
||||
mtbFile.metadata.researchConsents.add(mapOf(it.resource.id to it as IBaseResource))
|
||||
mtbFile.metadata.researchConsents.add(mapOf(it.resource.id to it.resource as Consent))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user