diff options
| author | Paul-Christian Volkmer | 2023-10-05 12:41:49 +0200 |
|---|---|---|
| committer | GitHub | 2023-10-05 12:41:49 +0200 |
| commit | 0eee1908df1a975824f002cff548456286e9a22a (patch) | |
| tree | a92fd2f24f155efdc1ebd924d103641f9b8c4c35 /src/test/kotlin/dev/dnpm/etl | |
| parent | 3f5c5e28fafa4aa35cb0744c28743074346e0a9c (diff) | |
| parent | ffea9343c87f15357e83167af4a4a2f7a03d71fc (diff) | |
Merge pull request #13 from CCC-MF/issue_12
Transformation of MTBFile data based on rules
Diffstat (limited to 'src/test/kotlin/dev/dnpm/etl')
| -rw-r--r-- | src/test/kotlin/dev/dnpm/etl/processor/services/RequestProcessorTest.kt | 21 | ||||
| -rw-r--r-- | src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt | 95 |
2 files changed, 116 insertions, 0 deletions
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 new file mode 100644 index 0000000..487b502 --- /dev/null +++ b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt @@ -0,0 +1,95 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +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(), 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 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) + + assertThat(actual).isNotNull + assertThat(actual.diagnoses[0].icd10.version).isEqualTo("2014") + } + + @Test + fun shouldOnlyTransformGivenValues() { + 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) + + 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 mtbFile = MtbFile.builder().withConsent( + Consent("123", "456", Consent.Status.ACTIVE) + ).build() + + val actual = this.service.transform(mtbFile) + + assertThat(actual.consent).isNotNull + assertThat(actual.consent.status).isEqualTo(Consent.Status.REJECTED) + } + +}
\ No newline at end of file |
