1
0
mirror of https://github.com/pcvolkmer/mv64e-etl-processor synced 2025-09-13 09:02:50 +00:00

refactor: simple code cleanups (#125)

This commit is contained in:
2025-07-23 22:45:04 +02:00
committed by GitHub
parent dfc9de78ce
commit e5693736d8
2 changed files with 33 additions and 58 deletions

View File

@@ -35,7 +35,8 @@ import org.springframework.web.bind.annotation.*
@RestController @RestController
@RequestMapping(path = ["mtbfile", "mtb"]) @RequestMapping(path = ["mtbfile", "mtb"])
class MtbFileRestController( 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) private val logger = LoggerFactory.getLogger(MtbFileRestController::class.java)
@@ -54,7 +55,6 @@ class MtbFileRestController(
logger.debug("Accepted MTB File (bwHC V1) for processing") logger.debug("Accepted MTB File (bwHC V1) for processing")
requestProcessor.processMtbFile(mtbFile) requestProcessor.processMtbFile(mtbFile)
} else { } else {
logger.debug("Accepted MTB File (bwHC V1) and process deletion") logger.debug("Accepted MTB File (bwHC V1) and process deletion")
val patientId = PatientId(mtbFile.patient.id) val patientId = PatientId(mtbFile.patient.id)
requestProcessor.processDeletion(patientId, ttpConsentStatus) requestProcessor.processDeletion(patientId, ttpConsentStatus)
@@ -62,21 +62,6 @@ class MtbFileRestController(
return ResponseEntity.accepted().build() 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]) @PostMapping(consumes = [CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE])
fun mtbFile(@RequestBody mtbFile: Mtb): ResponseEntity<Unit> { fun mtbFile(@RequestBody mtbFile: Mtb): ResponseEntity<Unit> {
logger.debug("Accepted MTB File (DNPM V2) for processing") logger.debug("Accepted MTB File (DNPM V2) for processing")
@@ -91,4 +76,17 @@ class MtbFileRestController(
return ResponseEntity.accepted().build() 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)
}
} }

View File

@@ -43,7 +43,6 @@ import org.mockito.kotlin.anyValueClass
import org.mockito.kotlin.whenever import org.mockito.kotlin.whenever
import org.springframework.core.io.ClassPathResource import org.springframework.core.io.ClassPathResource
import org.springframework.http.MediaType import org.springframework.http.MediaType
import org.springframework.test.context.TestPropertySource
import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.delete import org.springframework.test.web.servlet.delete
import org.springframework.test.web.servlet.post import org.springframework.test.web.servlet.post
@@ -67,7 +66,8 @@ class MtbFileRestControllerTest {
@Mock requestProcessor: RequestProcessor @Mock requestProcessor: RequestProcessor
) { ) {
this.requestProcessor = requestProcessor this.requestProcessor = requestProcessor
val controller = MtbFileRestController(requestProcessor, val controller = MtbFileRestController(
requestProcessor,
ConsentByMtbFile() ConsentByMtbFile()
) )
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -90,8 +90,7 @@ class MtbFileRestControllerTest {
@Test @Test
fun shouldProcessPostRequestWithRejectedConsent() { fun shouldProcessPostRequestWithRejectedConsent() {
mockMvc.post("/mtbfile") { mockMvc.post("/mtbfile") {
content = content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
contentType = MediaType.APPLICATION_JSON contentType = MediaType.APPLICATION_JSON
}.andExpect { }.andExpect {
status { 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 @Nested
inner class BwhcRequestsCheckConsentViaTtp { inner class BwhcRequestsCheckConsentViaTtp {
@@ -142,7 +137,6 @@ class MtbFileRestControllerTest {
val controller = MtbFileRestController(requestProcessor, gicsConsentService) val controller = MtbFileRestController(requestProcessor, gicsConsentService)
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
this.gicsConsentService = gicsConsentService this.gicsConsentService = gicsConsentService
} }
@ParameterizedTest @ParameterizedTest
@@ -152,8 +146,7 @@ class MtbFileRestControllerTest {
whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_GIVEN) whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_GIVEN)
mockMvc.post("/mtbfile") { mockMvc.post("/mtbfile") {
content = content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
contentType = MediaType.APPLICATION_JSON contentType = MediaType.APPLICATION_JSON
}.andExpect { }.andExpect {
status { status {
@@ -172,8 +165,7 @@ class MtbFileRestControllerTest {
whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED) whenever(gicsConsentService.getTtpBroadConsentStatus(any())).thenReturn(TtpConsentStatus.BROAD_CONSENT_MISSING_OR_REJECTED)
mockMvc.post("/mtbfile") { mockMvc.post("/mtbfile") {
content = content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
objectMapper.writeValueAsString(bwhcMtbFileContent(Status.valueOf(status)))
contentType = MediaType.APPLICATION_JSON contentType = MediaType.APPLICATION_JSON
}.andExpect { }.andExpect {
status { status {
@@ -219,7 +211,8 @@ class MtbFileRestControllerTest {
@Mock requestProcessor: RequestProcessor @Mock requestProcessor: RequestProcessor
) { ) {
this.requestProcessor = requestProcessor this.requestProcessor = requestProcessor
val controller = MtbFileRestController(requestProcessor, val controller = MtbFileRestController(
requestProcessor,
ConsentByMtbFile() ConsentByMtbFile()
) )
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -242,8 +235,7 @@ class MtbFileRestControllerTest {
@Test @Test
fun shouldProcessPostRequestWithRejectedConsent() { fun shouldProcessPostRequestWithRejectedConsent() {
mockMvc.post("/mtb") { mockMvc.post("/mtb") {
content = content = objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
objectMapper.writeValueAsString(bwhcMtbFileContent(Status.REJECTED))
contentType = MediaType.APPLICATION_JSON contentType = MediaType.APPLICATION_JSON
}.andExpect { }.andExpect {
status { status {
@@ -287,7 +279,8 @@ class MtbFileRestControllerTest {
@Mock gicsConsentService: GicsConsentService @Mock gicsConsentService: GicsConsentService
) { ) {
this.requestProcessor = requestProcessor this.requestProcessor = requestProcessor
val controller = MtbFileRestController(requestProcessor, val controller = MtbFileRestController(
requestProcessor,
gicsConsentService gicsConsentService
) )
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build() this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
@@ -296,8 +289,7 @@ class MtbFileRestControllerTest {
@Test @Test
fun shouldRespondPostRequest() { fun shouldRespondPostRequest() {
val mtbFileContent = val mtbFileContent =
ClassPathResource("mv64e-mtb-fake-patient.json").inputStream.readAllBytes() ClassPathResource("mv64e-mtb-fake-patient.json").inputStream.readAllBytes().toString(Charsets.UTF_8)
.toString(Charsets.UTF_8)
mockMvc.post("/mtb") { mockMvc.post("/mtb") {
content = mtbFileContent content = mtbFileContent
@@ -314,28 +306,13 @@ class MtbFileRestControllerTest {
} }
companion object { companion object {
fun bwhcMtbFileContent(consentStatus: Status) = MtbFile.builder() fun bwhcMtbFileContent(consentStatus: Status) = MtbFile.builder().withPatient(
.withPatient( Patient.builder().withId("TEST_12345678").withBirthDate("2000-08-08").withGender(Patient.Gender.MALE)
Patient.builder()
.withId("TEST_12345678")
.withBirthDate("2000-08-08")
.withGender(Patient.Gender.MALE)
.build() .build()
) ).withConsent(
.withConsent( Consent.builder().withId("1").withStatus(consentStatus).withPatient("TEST_12345678").build()
Consent.builder() ).withEpisode(
.withId("1") Episode.builder().withId("1").withPatient("TEST_12345678").withPeriod(PeriodStart("2023-08-08")).build()
.withStatus(consentStatus) ).build()
.withPatient("TEST_12345678")
.build()
)
.withEpisode(
Episode.builder()
.withId("1")
.withPatient("TEST_12345678")
.withPeriod(PeriodStart("2023-08-08"))
.build()
)
.build()
} }
} }