From 0e64b9a6ba69a829c231ab2c04c81d277d73f5c3 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 21 May 2026 16:57:26 +0200 Subject: feat: send submission as a follow-up (#290) This identifies follow-up submissions: * if the initial submission has been accepted * if the most recent follow-up is later than the patients last submission If these criteria are not met, the submission will be sent as an addition--- .../etl/processor/services/RequestProcessor.kt | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/dev') diff --git a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt index b94fbbc..4b7afff 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt @@ -139,11 +139,19 @@ class RequestProcessor( hasSuccessfulInitialSubmission(request.patientPseudonym()) && !hasUnacceptedSuccessfulInitialSubmission(request.patientPseudonym()) ) { - // Use "addition" after "intial" with "Meldebestaetigung" + // Use "addition" or "followup" depending on existing follow-ups after "intial" with "Meldebestaetigung" request.content.metadata?.let { logger.warn("Override submission type using 'addition' after first initial submission!") - it.type = MvhSubmissionType.ADDITION - submissionType = SubmissionType.ADDITION + it.type = if (hasFollowUpAfterLastSuccessfulSubmission(request)) { + MvhSubmissionType.FOLLOWUP + } else { + MvhSubmissionType.ADDITION + } + submissionType = if (hasFollowUpAfterLastSuccessfulSubmission(request)) { + SubmissionType.FOLLOWUP + } else { + SubmissionType.ADDITION + } } } @@ -184,6 +192,24 @@ class RequestProcessor( ) } + private fun hasFollowUpAfterLastSuccessfulSubmission(request: DnpmV2MtbFileRequest): Boolean { + val lastSuccessfulSubmission = this.requestService.allRequestsByPatientPseudonym(request.patientPseudonym()) + .sortedBy { it.processedAt } + .filterNot { + it.submissionType == SubmissionType.INITIAL && + (it.status == RequestStatus.SUCCESS || it.status == RequestStatus.WARNING) && + !(it.submissionAccepted || it.status == RequestStatus.BLOCKED_INITIAL) + } + .lastOrNull() ?: return false + + val lastFollowUp = request.content.followUps + ?.filterNot { it.date == null } + ?.sortedBy { it.date } + ?.lastOrNull { it.date != null } ?: return false + + return lastSuccessfulSubmission.processedAt.isBefore( lastFollowUp.date.toInstant()) + } + private fun hasSuccessfulInitialSubmission(patientPseudonym: PatientPseudonym): Boolean { return this.requestService.allRequestsByPatientPseudonym(patientPseudonym).any { it.submissionType == SubmissionType.INITIAL && -- cgit v1.2.3