1
0
mirror of https://github.com/pcvolkmer/etl-processor.git synced 2025-07-03 23:12:54 +00:00

Add RequestService to handle access to requests

This commit is contained in:
2023-08-08 14:50:12 +02:00
parent 1fc09d691e
commit bcc23f6b14
4 changed files with 402 additions and 7 deletions

View File

@ -21,7 +21,10 @@ package dev.dnpm.etl.processor.services
import com.fasterxml.jackson.databind.ObjectMapper
import de.ukw.ccc.bwhc.dto.MtbFile
import dev.dnpm.etl.processor.monitoring.*
import dev.dnpm.etl.processor.monitoring.Report
import dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
import dev.dnpm.etl.processor.output.MtbFileSender
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
import org.apache.commons.codec.binary.Base32
@ -35,7 +38,7 @@ import java.util.*
class RequestProcessor(
private val pseudonymizeService: PseudonymizeService,
private val senders: List<MtbFileSender>,
private val requestRepository: RequestRepository,
private val requestService: RequestService,
private val objectMapper: ObjectMapper,
private val statisticsUpdateProducer: Sinks.Many<Any>
) {
@ -46,7 +49,7 @@ class RequestProcessor(
val pid = mtbFile.patient.id
val pseudonymized = pseudonymizeService.pseudonymize(mtbFile)
val allRequests = requestRepository.findAllByPatientIdOrderByProcessedAtDesc(pseudonymized.patient.id)
val allRequests = requestService.allRequestsByPatientPseudonym(pseudonymized.patient.id)
val lastMtbFileRequestForPatient = allRequests
.filter { it.type == RequestType.MTB_FILE }
@ -55,7 +58,7 @@ class RequestProcessor(
val isLastRequestDeletion = allRequests.firstOrNull()?.type == RequestType.DELETE
if (null != lastMtbFileRequestForPatient && lastMtbFileRequestForPatient.fingerprint == fingerprint(mtbFile) && !isLastRequestDeletion) {
requestRepository.save(
requestService.save(
Request(
patientId = pseudonymized.patient.id,
pid = pid,
@ -99,7 +102,7 @@ class RequestProcessor(
RequestStatus.UNKNOWN
}
requestRepository.save(
requestService.save(
Request(
uuid = request.requestId,
patientId = request.mtbFile.patient.id,
@ -165,7 +168,7 @@ class RequestProcessor(
RequestStatus.UNKNOWN
}
requestRepository.save(
requestService.save(
Request(
uuid = requestId,
patientId = patientPseudonym,
@ -181,7 +184,7 @@ class RequestProcessor(
)
)
} catch (e: Exception) {
requestRepository.save(
requestService.save(
Request(
uuid = requestId,
patientId = "???",

View File

@ -0,0 +1,56 @@
/*
* 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 dev.dnpm.etl.processor.monitoring.Request
import dev.dnpm.etl.processor.monitoring.RequestRepository
import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
import org.springframework.stereotype.Service
@Service
class RequestService(
private val requestRepository: RequestRepository
) {
fun save(request: Request) = requestRepository.save(request)
fun allRequestsByPatientPseudonym(patientPseudonym: String) = requestRepository
.findAllByPatientIdOrderByProcessedAtDesc(patientPseudonym)
fun lastMtbFileRequestForPatientPseudonym(patientPseudonym: String) =
Companion.lastMtbFileRequestForPatientPseudonym(allRequestsByPatientPseudonym(patientPseudonym))
fun isLastRequestDeletion(patientPseudonym: String) =
Companion.isLastRequestDeletion(allRequestsByPatientPseudonym(patientPseudonym))
companion object {
fun lastMtbFileRequestForPatientPseudonym(allRequests: List<Request>) = allRequests
.filter { it.type == RequestType.MTB_FILE }
.sortedByDescending { it.processedAt }
.firstOrNull { it.status == RequestStatus.SUCCESS || it.status == RequestStatus.WARNING }
fun isLastRequestDeletion(allRequests: List<Request>) = allRequests
.maxByOrNull { it.processedAt }?.type == RequestType.DELETE
}
}