summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2025-07-23 22:45:04 +0200
committerGitHub2025-07-23 22:45:04 +0200
commite5693736d8149f692a11e59971fd57f8bda8e305 (patch)
treef4a4389edb5f5800b7a9303f27631a0ca1c9af8c /src
parentdfc9de78ceb8753392aac16e99dfc25346634ac9 (diff)
refactor: simple code cleanups (#125)
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt32
-rw-r--r--src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt59
2 files changed, 33 insertions, 58 deletions
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt
index 44c74e3..ca64fc9 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt
@@ -35,7 +35,8 @@ import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping(path = ["mtbfile", "mtb"])
class MtbFileRestController(
- private val requestProcessor: RequestProcessor, private val iGetConsent: IGetConsent
+ private val requestProcessor: RequestProcessor,
+ private val iGetConsent: IGetConsent
) {
private val logger = LoggerFactory.getLogger(MtbFileRestController::class.java)
@@ -54,7 +55,6 @@ class MtbFileRestController(
logger.debug("Accepted MTB File (bwHC V1) for processing")
requestProcessor.processMtbFile(mtbFile)
} else {
-
logger.debug("Accepted MTB File (bwHC V1) and process deletion")
val patientId = PatientId(mtbFile.patient.id)
requestProcessor.processDeletion(patientId, ttpConsentStatus)
@@ -62,21 +62,6 @@ class MtbFileRestController(
return ResponseEntity.accepted().build()
}
- private fun checkConsentStatus(mtbFile: MtbFile): Pair<TtpConsentStatus, Boolean> {
- var ttpConsentStatus = iGetConsent.getTtpBroadConsentStatus(mtbFile.patient.id)
-
- val isConsentOK =
- (ttpConsentStatus.equals(TtpConsentStatus.UNKNOWN_CHECK_FILE) && mtbFile.consent.status == Consent.Status.ACTIVE) ||
- ttpConsentStatus.equals(
- TtpConsentStatus.BROAD_CONSENT_GIVEN
- )
- if (ttpConsentStatus.equals(TtpConsentStatus.UNKNOWN_CHECK_FILE) && mtbFile.consent.status == Consent.Status.REJECTED) {
- // in case ttp check is disabled - we propagate rejected status anyway
- ttpConsentStatus = TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED
- }
- return Pair(ttpConsentStatus, isConsentOK)
- }
-
@PostMapping(consumes = [CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE])
fun mtbFile(@RequestBody mtbFile: Mtb): ResponseEntity<Unit> {
logger.debug("Accepted MTB File (DNPM V2) for processing")
@@ -91,4 +76,17 @@ class MtbFileRestController(
return ResponseEntity.accepted().build()
}
+ private fun checkConsentStatus(mtbFile: MtbFile): Pair<TtpConsentStatus, Boolean> {
+ var ttpConsentStatus = iGetConsent.getTtpBroadConsentStatus(mtbFile.patient.id)
+
+ val isConsentOK = (ttpConsentStatus == TtpConsentStatus.UNKNOWN_CHECK_FILE && mtbFile.consent.status == Consent.Status.ACTIVE)
+ || ttpConsentStatus == TtpConsentStatus.BROAD_CONSENT_GIVEN
+
+ if (ttpConsentStatus == TtpConsentStatus.UNKNOWN_CHECK_FILE && mtbFile.consent.status == Consent.Status.REJECTED) {
+ // in case ttp check is disabled - we propagate rejected status anyway
+ ttpConsentStatus = TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED
+ }
+ return Pair(ttpConsentStatus, isConsentOK)
+ }
+
}
diff --git a/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt
index eb7e0b6..7a91ed1 100644
--- a/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt
+++ b/src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt
@@ -43,7 +43,6 @@ import org.mockito.kotlin.anyValueClass
import org.mockito.kotlin.whenever
import org.springframework.core.io.ClassPathResource
import org.springframework.http.MediaType
-import org.springframework.test.context.TestPropertySource
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.delete
import org.springframework.test.web.servlet.post
@@ -67,7 +66,8 @@ class MtbFileRestControllerTest {
@Mock requestProcessor: RequestProcessor
) {
this.requestProcessor = requestProcessor
- val controller = MtbFileRestController(requestProcessor,
+ val controller = MtbFileRestController(
+ requestProcessor,
ConsentByMtbFile()
)
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -90,8 +90,7 @@ class MtbFileRestControllerTest {
@Test
fun shouldProcessPostRequestWithRejectedConsent() {
mockMvc.post("/mtbfile") {
- content =
- objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
+ content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
contentType = MediaType.APPLICATION_JSON
}.andExpect {
status {
@@ -120,10 +119,6 @@ class MtbFileRestControllerTest {
}
}
- @TestPropertySource(
- properties = ["app.consent.gics.enabled=true",
- "app.consent.gics.gIcsBaseUri=http://localhost:8090/ttp-fhir/fhir/gics"]
- )
@Nested
inner class BwhcRequestsCheckConsentViaTtp {
@@ -142,7 +137,6 @@ class MtbFileRestControllerTest {
val controller = MtbFileRestController(requestProcessor, gicsConsentService)
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
this.gicsConsentService = gicsConsentService
-
}
@ParameterizedTest
@@ -152,8 +146,7 @@ class MtbFileRestControllerTest {
whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_GIVEN)
mockMvc.post("/mtbfile") {
- content =
- objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
+ content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
contentType = MediaType.APPLICATION_JSON
}.andExpect {
status {
@@ -172,8 +165,7 @@ class MtbFileRestControllerTest {
whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED)
mockMvc.post("/mtbfile") {
- content =
- objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
+ content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
contentType = MediaType.APPLICATION_JSON
}.andExpect {
status {
@@ -219,7 +211,8 @@ class MtbFileRestControllerTest {
@Mock requestProcessor: RequestProcessor
) {
this.requestProcessor = requestProcessor
- val controller = MtbFileRestController(requestProcessor,
+ val controller = MtbFileRestController(
+ requestProcessor,
ConsentByMtbFile()
)
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -242,8 +235,7 @@ class MtbFileRestControllerTest {
@Test
fun shouldProcessPostRequestWithRejectedConsent() {
mockMvc.post("/mtb") {
- content =
- objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
+ content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
contentType = MediaType.APPLICATION_JSON
}.andExpect {
status {
@@ -287,7 +279,8 @@ class MtbFileRestControllerTest {
@Mock gicsConsentService: GicsConsentService
) {
this.requestProcessor = requestProcessor
- val controller = MtbFileRestController(requestProcessor,
+ val controller = MtbFileRestController(
+ requestProcessor,
gicsConsentService
)
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -296,8 +289,7 @@ class MtbFileRestControllerTest {
@Test
fun shouldRespondPostRequest() {
val mtbFileContent =
- ClassPathResource("mv64e-mtb-fake-patient.json").inputStream.readAllBytes()
- .toString(Charsets.UTF_8)
+ ClassPathResource("mv64e-mtb-fake-patient.json").inputStream.readAllBytes().toString(Charsets.UTF_8)
mockMvc.post("/mtb") {
content = mtbFileContent
@@ -314,28 +306,13 @@ class MtbFileRestControllerTest {
}
companion object {
- fun bwhcMtbFileContent(consentStatus: Status) = MtbFile.builder()
- .withPatient(
- Patient.builder()
- .withId("TEST_12345678")
- .withBirthDate("2000-08-08")
- .withGender(Patient.Gender.MALE)
- .build()
- )
- .withConsent(
- Consent.builder()
- .withId("1")
- .withStatus(consentStatus)
- .withPatient("TEST_12345678")
+ fun bwhcMtbFileContent(consentStatus: Status) = MtbFile.builder().withPatient(
+ Patient.builder().withId("TEST_12345678").withBirthDate("2000-08-08").withGender(Patient.Gender.MALE)
.build()
- )
- .withEpisode(
- Episode.builder()
- .withId("1")
- .withPatient("TEST_12345678")
- .withPeriod(PeriodStart("2023-08-08"))
- .build()
- )
- .build()
+ ).withConsent(
+ Consent.builder().withId("1").withStatus(consentStatus).withPatient("TEST_12345678").build()
+ ).withEpisode(
+ Episode.builder().withId("1").withPatient("TEST_12345678").withPeriod(PeriodStart("2023-08-08")).build()
+ ).build()
}
}