mirror of
https://github.com/pcvolkmer/mv64e-etl-processor
synced 2025-09-13 01:02:50 +00:00
refactor: simple code cleanups (#125)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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)
|
||||
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")
|
||||
.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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user