Skip to content

Commit

Permalink
Merge pull request #292 from navikt/signaturdatoinfuture
Browse files Browse the repository at this point in the history
Signaturdato in future
  • Loading branch information
MikAoJk authored Aug 24, 2023
2 parents 6a1789a + 78038b7 commit f00380a
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 14 deletions.
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "no.nav.syfo"
version = "1.0.0"
Expand All @@ -13,7 +12,7 @@ val jacksonVersion = "2.15.2"
val jaxbApiVersion = "2.4.0-b180830.0359"
val kafkaVersion = "3.4.0"
val ktorVersion = "2.3.3"
val logbackVersion = "1.4.9"
val logbackVersion = "1.4.11"
val logstashEncoderVersion = "7.4"
val prometheusVersion = "0.16.0"
val smCommonVersion = "1.0.12"
Expand All @@ -23,9 +22,9 @@ val javaxAnnotationApiVersion = "1.3.2"
val jaxwsToolsVersion = "2.3.2"
val jaxbRuntimeVersion = "2.4.0-b180830.0438"
val javaTimeAdapterVersion = "1.1.3"
val mockkVersion = "1.13.5"
val mockkVersion = "1.13.7"
val kotlinVersion = "1.9.0"
val googleCloudStorageVersion = "2.26.0"
val googleCloudStorageVersion = "2.26.1"
val junitJupiterVersion = "5.10.0"
val flywayVersion = "9.21.1"
val hikariVersion = "5.0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.syfo.application

import java.io.StringReader
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.UUID
import javax.jms.MessageConsumer
Expand All @@ -26,6 +27,7 @@ import no.nav.syfo.client.getHelsepersonellKategori
import no.nav.syfo.duplicationcheck.model.Duplicate
import no.nav.syfo.duplicationcheck.model.DuplicateCheck
import no.nav.syfo.handlestatus.handleDuplicateSM2013Content
import no.nav.syfo.handlestatus.handleSignaturDatoInTheFuture
import no.nav.syfo.handlestatus.handleStatusINVALID
import no.nav.syfo.handlestatus.handleStatusMANUALPROCESSING
import no.nav.syfo.handlestatus.handleStatusOK
Expand Down Expand Up @@ -116,7 +118,7 @@ class BlockingApplicationRunner(
is TextMessage -> message.text
else ->
throw RuntimeException(
"Incoming message needs to be a byte message or text message"
"Incoming message needs to be a byte message or text message",
)
}
INCOMING_MESSAGE_COUNTER.inc()
Expand Down Expand Up @@ -211,7 +213,7 @@ class BlockingApplicationRunner(
if (erVirksomhetSykmelding) {
logger.info(
"Mottatt virksomhetssykmelding, {}",
StructuredArguments.fields(loggingMeta)
StructuredArguments.fields(loggingMeta),
)
VIRKSOMHETSYKMELDING.inc()
val hpr = extractHpr(fellesformat)?.id
Expand Down Expand Up @@ -259,15 +261,15 @@ class BlockingApplicationRunner(
val identer =
pdlPersonService.getIdenter(
listOf(signaturFnr, originaltPasientFnr),
loggingMeta
loggingMeta,
)

val tssIdEmottak =
smtssClient.findBestTssIdEmottak(
signaturFnr,
legekontorOrgName,
loggingMeta,
sykmeldingId
sykmeldingId,
)
val tssIdInfotrygd =
if (!tssIdEmottak.isNullOrEmpty()) {
Expand All @@ -277,17 +279,17 @@ class BlockingApplicationRunner(
signaturFnr,
legekontorOrgName,
loggingMeta,
sykmeldingId
sykmeldingId,
)
}

logger.info(
"tssIdEmottak is $tssIdEmottak {}",
StructuredArguments.fields(loggingMeta)
StructuredArguments.fields(loggingMeta),
)
logger.info(
"tssIdInfotrygd is $tssIdInfotrygd {}",
StructuredArguments.fields(loggingMeta)
StructuredArguments.fields(loggingMeta),
)

handleEmottakSubscription(
Expand Down Expand Up @@ -355,7 +357,7 @@ class BlockingApplicationRunner(
val signerendeBehandler =
norskHelsenettClient.getByFnr(
fnr = signaturFnr,
loggingMeta = loggingMeta
loggingMeta = loggingMeta,
)

val behandlenedeBehandler =
Expand Down Expand Up @@ -433,6 +435,21 @@ class BlockingApplicationRunner(
}
}

if (sykmelding.signaturDato.isAfter(LocalDateTime.now())) {
handleSignaturDatoInTheFuture(
loggingMeta,
fellesformat,
ediLoggId,
msgId,
msgHead,
env,
kafkaproducerApprec,
duplicationService,
duplicateCheck,
)
continue@loop
}

val vedleggListe: List<String> =
if (vedlegg.isNotEmpty()) {
bucketUploadService.lastOppVedlegg(
Expand All @@ -459,7 +476,7 @@ class BlockingApplicationRunner(
personNrPasient = pasient.fnr!!,
tlfPasient =
extractTlfFromKontaktInfo(
healthInformation.pasient.kontaktInfo
healthInformation.pasient.kontaktInfo,
),
personNrLege = signaturFnr,
navLogId = ediLoggId,
Expand Down Expand Up @@ -499,7 +516,7 @@ class BlockingApplicationRunner(
val validationResult =
syfoSykemeldingRuleClient.executeRuleValidation(
receivedSykmelding,
loggingMeta
loggingMeta,
)

when (validationResult.status) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/no/nav/syfo/handlestatus/HandleStatusInvalid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,37 @@ fun handleVedleggContainsVirus(
sendApprec(apprec, env, kafkaproducerApprec, loggingMeta, duplicationService, duplicateCheck)
}

fun handleSignaturDatoInTheFuture(
loggingMeta: LoggingMeta,
fellesformat: XMLEIFellesformat,
ediLoggId: String,
msgId: String,
msgHead: XMLMsgHead,
env: EnvironmentVariables,
kafkaproducerApprec: KafkaProducer<String, Apprec>,
duplicationService: DuplicationService,
duplicateCheck: DuplicateCheck,
) {
logger.warn(
"Sykmeldingen er avvist fordi signaturdatoen(GenDate) er frem i tid {} {}",
fields(loggingMeta),
keyValue("avvistAv", env.applicationName),
)

val apprec =
fellesformatToAppprec(
fellesformat,
"Sykmeldingen kan ikke rettes, det må skrives en ny." +
"Pasienten har ikke fått beskjed, men venter på ny sykmelding fra deg. Grunnet følgende:" +
"Signaturdatoen(GenDate) er frem i tid. Kontakt din EPJ-leverandør",
ediLoggId,
msgId,
msgHead,
)

sendApprec(apprec, env, kafkaproducerApprec, loggingMeta, duplicationService, duplicateCheck)
}

private fun sendApprec(
apprec: Apprec,
env: EnvironmentVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,23 @@ internal class BlockingApplicationRunnerTest {
}
}
}

@Test
internal fun `Sykmelding med gendate frem i tid skal gi avvist apprec`() {
every { applicationState.ready } returns true andThen false
val stringInput =
getFileAsString(
"src/test/resources/sykemelding2013Regelsettversjon3gendatefremitid.xml"
)
val textMessage = mockk<TextMessage>(relaxed = true)
every { textMessage.text } returns stringInput
every { inputconsumer.receive(1000) } returns textMessage
runBlocking {
blockingApplicationRunner.run(inputconsumer, backoutProducer)

coVerify {
kafkaproducerApprec.send(match { it.value().apprecStatus == ApprecStatus.AVVIST })
}
}
}
}
Loading

0 comments on commit f00380a

Please sign in to comment.