diff options
| author | Paul-Christian Volkmer | 2026-05-21 16:57:26 +0200 |
|---|---|---|
| committer | GitHub | 2026-05-21 14:57:26 +0000 |
| commit | 0e64b9a6ba69a829c231ab2c04c81d277d73f5c3 (patch) | |
| tree | aa374e5d70b1f2cf19139155799a0ab27846e89c /src/main/kotlin | |
| parent | 81c0c247df395ff420b591724236d8a3bea47016 (diff) | |
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
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt | 32 |
1 files changed, 29 insertions, 3 deletions
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 && |
