mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
Issue #12: Transform MTBFile objects by using transformation rules
This commit is contained in:
parent
2824951e5e
commit
4196664060
@ -26,6 +26,7 @@ import dev.dnpm.etl.processor.pseudonym.Generator
|
||||
import dev.dnpm.etl.processor.pseudonym.GpasPseudonymGenerator
|
||||
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
||||
import dev.dnpm.etl.processor.services.Transformation
|
||||
import dev.dnpm.etl.processor.services.TransformationService
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
@ -73,10 +74,13 @@ class AppConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun transformations(configProperties: AppConfigProperties): List<Transformation> {
|
||||
return configProperties.transformations.map {
|
||||
fun transformationService(
|
||||
objectMapper: ObjectMapper,
|
||||
configProperties: AppConfigProperties
|
||||
): TransformationService {
|
||||
return TransformationService(objectMapper, configProperties.transformations.map {
|
||||
Transformation.of(it.path) from it.from to it.to
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.util.*
|
||||
@Service
|
||||
class RequestProcessor(
|
||||
private val pseudonymizeService: PseudonymizeService,
|
||||
private val transformationService: TransformationService,
|
||||
private val sender: MtbFileSender,
|
||||
private val requestService: RequestService,
|
||||
private val objectMapper: ObjectMapper,
|
||||
@ -50,7 +51,7 @@ class RequestProcessor(
|
||||
|
||||
mtbFile pseudonymizeWith pseudonymizeService
|
||||
|
||||
val request = MtbFileSender.MtbFileRequest(requestId, mtbFile)
|
||||
val request = MtbFileSender.MtbFileRequest(requestId, transformationService.transform(mtbFile))
|
||||
|
||||
requestService.save(
|
||||
Request(
|
||||
|
@ -24,8 +24,8 @@ import com.jayway.jsonpath.JsonPath
|
||||
import com.jayway.jsonpath.PathNotFoundException
|
||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||
|
||||
class TransformationService(private val objectMapper: ObjectMapper) {
|
||||
fun transform(mtbFile: MtbFile, vararg transformations: Transformation): MtbFile {
|
||||
class TransformationService(private val objectMapper: ObjectMapper, private val transformations: List<Transformation>) {
|
||||
fun transform(mtbFile: MtbFile): MtbFile {
|
||||
var json = objectMapper.writeValueAsString(mtbFile)
|
||||
|
||||
transformations.forEach { transformation ->
|
||||
|
@ -37,6 +37,7 @@ import org.mockito.Mockito.*
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.argumentCaptor
|
||||
import org.mockito.kotlin.whenever
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
@ -46,6 +47,7 @@ import java.util.*
|
||||
class RequestProcessorTest {
|
||||
|
||||
private lateinit var pseudonymizeService: PseudonymizeService
|
||||
private lateinit var transformationService: TransformationService
|
||||
private lateinit var sender: MtbFileSender
|
||||
private lateinit var requestService: RequestService
|
||||
private lateinit var applicationEventPublisher: ApplicationEventPublisher
|
||||
@ -55,11 +57,13 @@ class RequestProcessorTest {
|
||||
@BeforeEach
|
||||
fun setup(
|
||||
@Mock pseudonymizeService: PseudonymizeService,
|
||||
@Mock transformationService: TransformationService,
|
||||
@Mock sender: RestMtbFileSender,
|
||||
@Mock requestService: RequestService,
|
||||
@Mock applicationEventPublisher: ApplicationEventPublisher
|
||||
) {
|
||||
this.pseudonymizeService = pseudonymizeService
|
||||
this.transformationService = transformationService
|
||||
this.sender = sender
|
||||
this.requestService = requestService
|
||||
this.applicationEventPublisher = applicationEventPublisher
|
||||
@ -68,6 +72,7 @@ class RequestProcessorTest {
|
||||
|
||||
requestProcessor = RequestProcessor(
|
||||
pseudonymizeService,
|
||||
transformationService,
|
||||
sender,
|
||||
requestService,
|
||||
objectMapper,
|
||||
@ -98,6 +103,10 @@ class RequestProcessorTest {
|
||||
it.arguments[0] as String
|
||||
}.`when`(pseudonymizeService).patientPseudonym(any())
|
||||
|
||||
doAnswer {
|
||||
it.arguments[0]
|
||||
}.whenever(transformationService).transform(any())
|
||||
|
||||
val mtbFile = MtbFile.builder()
|
||||
.withPatient(
|
||||
Patient.builder()
|
||||
@ -153,6 +162,10 @@ class RequestProcessorTest {
|
||||
it.arguments[0] as String
|
||||
}.`when`(pseudonymizeService).patientPseudonym(any())
|
||||
|
||||
doAnswer {
|
||||
it.arguments[0]
|
||||
}.whenever(transformationService).transform(any())
|
||||
|
||||
val mtbFile = MtbFile.builder()
|
||||
.withPatient(
|
||||
Patient.builder()
|
||||
@ -212,6 +225,10 @@ class RequestProcessorTest {
|
||||
it.arguments[0] as String
|
||||
}.`when`(pseudonymizeService).patientPseudonym(any())
|
||||
|
||||
doAnswer {
|
||||
it.arguments[0]
|
||||
}.whenever(transformationService).transform(any())
|
||||
|
||||
val mtbFile = MtbFile.builder()
|
||||
.withPatient(
|
||||
Patient.builder()
|
||||
@ -271,6 +288,10 @@ class RequestProcessorTest {
|
||||
it.arguments[0] as String
|
||||
}.`when`(pseudonymizeService).patientPseudonym(any())
|
||||
|
||||
doAnswer {
|
||||
it.arguments[0]
|
||||
}.whenever(transformationService).transform(any())
|
||||
|
||||
val mtbFile = MtbFile.builder()
|
||||
.withPatient(
|
||||
Patient.builder()
|
||||
|
@ -34,15 +34,16 @@ class TransformationServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
this.service = TransformationService(ObjectMapper())
|
||||
this.service = TransformationService(
|
||||
ObjectMapper(), listOf(
|
||||
Transformation.of("consent.status") from Consent.Status.ACTIVE to Consent.Status.REJECTED,
|
||||
Transformation.of("diagnoses[*].icd10.version") from "2013" to "2014",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldTransformMtbFile() {
|
||||
val transformations = arrayOf(
|
||||
Transformation.of("diagnoses[*].icd10.version") from "2013" to "2014",
|
||||
)
|
||||
|
||||
val mtbFile = MtbFile.builder().withDiagnoses(
|
||||
listOf(
|
||||
Diagnosis.builder().withId("1234").withIcd10(Icd10("F79.9").also {
|
||||
@ -51,7 +52,7 @@ class TransformationServiceTest {
|
||||
)
|
||||
).build()
|
||||
|
||||
val actual = this.service.transform(mtbFile, *transformations)
|
||||
val actual = this.service.transform(mtbFile)
|
||||
|
||||
assertThat(actual).isNotNull
|
||||
assertThat(actual.diagnoses[0].icd10.version).isEqualTo("2014")
|
||||
@ -59,10 +60,6 @@ class TransformationServiceTest {
|
||||
|
||||
@Test
|
||||
fun shouldOnlyTransformGivenValues() {
|
||||
val transformations = arrayOf(
|
||||
Transformation.of("diagnoses[*].icd10.version") from "2013" to "2014",
|
||||
)
|
||||
|
||||
val mtbFile = MtbFile.builder().withDiagnoses(
|
||||
listOf(
|
||||
Diagnosis.builder().withId("1234").withIcd10(Icd10("F79.9").also {
|
||||
@ -74,7 +71,7 @@ class TransformationServiceTest {
|
||||
)
|
||||
).build()
|
||||
|
||||
val actual = this.service.transform(mtbFile, *transformations)
|
||||
val actual = this.service.transform(mtbFile)
|
||||
|
||||
assertThat(actual).isNotNull
|
||||
assertThat(actual.diagnoses[0].icd10.code).isEqualTo("F79.9")
|
||||
@ -85,15 +82,11 @@ class TransformationServiceTest {
|
||||
|
||||
@Test
|
||||
fun shouldTransformMtbFileWithConsentEnum() {
|
||||
val transformations = arrayOf(
|
||||
Transformation.of("consent.status") from Consent.Status.ACTIVE to Consent.Status.REJECTED,
|
||||
)
|
||||
|
||||
val mtbFile = MtbFile.builder().withConsent(
|
||||
Consent("123", "456", Consent.Status.ACTIVE)
|
||||
).build()
|
||||
|
||||
val actual = this.service.transform(mtbFile, *transformations)
|
||||
val actual = this.service.transform(mtbFile)
|
||||
|
||||
assertThat(actual.consent).isNotNull
|
||||
assertThat(actual.consent.status).isEqualTo(Consent.Status.REJECTED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user