From 7440fe1e23e730fd526a814cfde7cc86e105cf70 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 5 Oct 2023 10:51:49 +0200 Subject: Issue #12: Basic implementation of transformation service --- .../services/TransformationServiceTest.kt | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt (limited to 'src/test/kotlin/dev') diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt new file mode 100644 index 0000000..c6cd645 --- /dev/null +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt @@ -0,0 +1,83 @@ +package dev.dnpm.etl.processor.services + +import com.fasterxml.jackson.databind.ObjectMapper +import de.ukw.ccc.bwhc.dto.Consent +import de.ukw.ccc.bwhc.dto.Diagnosis +import de.ukw.ccc.bwhc.dto.Icd10 +import de.ukw.ccc.bwhc.dto.MtbFile +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +class TransformationServiceTest { + + private lateinit var service: TransformationService + + @BeforeEach + fun setup() { + this.service = TransformationService(ObjectMapper()) + } + + @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 { + it.version = "2013" + }).build() + ) + ).build() + + val actual = this.service.transform(mtbFile, *transformations) + + assertThat(actual).isNotNull + assertThat(actual.diagnoses[0].icd10.version).isEqualTo("2014") + } + + @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 { + it.version = "2013" + }).build(), + Diagnosis.builder().withId("5678").withIcd10(Icd10("F79.8").also { + it.version = "2019" + }).build() + ) + ).build() + + val actual = this.service.transform(mtbFile, *transformations) + + assertThat(actual).isNotNull + assertThat(actual.diagnoses[0].icd10.code).isEqualTo("F79.9") + assertThat(actual.diagnoses[0].icd10.version).isEqualTo("2014") + assertThat(actual.diagnoses[1].icd10.code).isEqualTo("F79.8") + assertThat(actual.diagnoses[1].icd10.version).isEqualTo("2019") + } + + @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) + + assertThat(actual.consent).isNotNull + assertThat(actual.consent.status).isEqualTo(Consent.Status.REJECTED) + } + +} \ No newline at end of file -- cgit v1.2.3 From 1e1db1c4d9cf0810056287c8895b1662c16daf2c Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 5 Oct 2023 11:37:10 +0200 Subject: Issue #12: Add application config for transformation configuration --- .../processor/services/TransformationServiceTest.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/test/kotlin/dev') diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt index c6cd645..5b34562 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt @@ -1,3 +1,22 @@ +/* + * This file is part of ETL-Processor + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package dev.dnpm.etl.processor.services import com.fasterxml.jackson.databind.ObjectMapper -- cgit v1.2.3 From 4196664060e879c6159d7986a145f28be3c1798a Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 5 Oct 2023 12:09:56 +0200 Subject: Issue #12: Transform MTBFile objects by using transformation rules --- .../etl/processor/services/RequestProcessorTest.kt | 21 ++++++++++++++++++ .../services/TransformationServiceTest.kt | 25 ++++++++-------------- 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src/test/kotlin/dev') diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt index 7856833..9aaa091 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt @@ -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() diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt index 5b34562..487b502 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt @@ -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) -- cgit v1.2.3