From e2e0b4ed409fa9ebaddebc86d7f284c3787716d2 Mon Sep 17 00:00:00 2001 From: Anders Rognstad Date: Mon, 30 Oct 2023 13:42:26 +0100 Subject: [PATCH] Refactor create LoggingMeta --- .../application/BlockingApplicationRunner.kt | 10 ++--- .../application/DialogmeldingProcessor.kt | 10 ++--- .../services/ArenaDialogmeldingService.kt | 44 +++++++------------ .../kotlin/no/nav/syfo/util/LoggingMeta.kt | 22 +++++++++- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/main/kotlin/no/nav/syfo/application/BlockingApplicationRunner.kt b/src/main/kotlin/no/nav/syfo/application/BlockingApplicationRunner.kt index 13f94a32..dd28f12a 100644 --- a/src/main/kotlin/no/nav/syfo/application/BlockingApplicationRunner.kt +++ b/src/main/kotlin/no/nav/syfo/application/BlockingApplicationRunner.kt @@ -79,7 +79,6 @@ class BlockingApplicationRunner( val fellesformat = safeUnmarshal(inputMessageText) val msgHead: XMLMsgHead = fellesformat.get() val emottakblokk = fellesformat.get() - val ediLoggId = emottakblokk.ediLoggId val dialogmeldingXml = extractDialogmelding(fellesformat) val patientXml = extractPatient(fellesformat) val vedlegg = extractValidVedlegg(fellesformat) @@ -89,11 +88,10 @@ class BlockingApplicationRunner( val sha256String = sha256hashstring(dialogmeldingXml, patientXml, vedlegg) val innbyggerIdent = extractInnbyggerident(fellesformat) - val legekontorOrgNr = extractOrganisationNumberFromSender(fellesformat)?.id - val loggingMeta = LoggingMeta( - mottakId = ediLoggId, - orgNr = legekontorOrgNr, - msgId = msgHead.msgInfo.msgId, + val loggingMeta = LoggingMeta.create( + emottakBlokk = emottakblokk, + fellesformatXml = fellesformat, + msgHead = msgHead, ) logger.info("Received message, {}", StructuredArguments.fields(loggingMeta)) if (innbyggerIdent.isNullOrEmpty() || !elevenDigits.matches(innbyggerIdent)) { diff --git a/src/main/kotlin/no/nav/syfo/application/DialogmeldingProcessor.kt b/src/main/kotlin/no/nav/syfo/application/DialogmeldingProcessor.kt index 71df8f23..7fd9b2ad 100644 --- a/src/main/kotlin/no/nav/syfo/application/DialogmeldingProcessor.kt +++ b/src/main/kotlin/no/nav/syfo/application/DialogmeldingProcessor.kt @@ -84,20 +84,18 @@ class DialogmeldingProcessor( val fellesformat = safeUnmarshal(inputMessageText) val msgHead: XMLMsgHead = fellesformat.get() val emottakblokk = fellesformat.get() - val ediLoggId = emottakblokk.ediLoggId val msgId = msgHead.msgInfo.msgId val dialogmeldingXml = extractDialogmelding(fellesformat) val patientXml = extractPatient(fellesformat) val dialogmeldingType = findDialogmeldingType(emottakblokk.ebService, emottakblokk.ebAction) val xmlVedlegg = extractValidVedlegg(fellesformat) val sha256String = sha256hashstring(dialogmeldingXml, patientXml, xmlVedlegg) - val legekontorOrgNr = extractOrganisationNumberFromSender(fellesformat)?.id val pasientNavn = extractPasientNavn(fellesformat) - val loggingMeta = LoggingMeta( - mottakId = ediLoggId, - orgNr = legekontorOrgNr, - msgId = msgHead.msgInfo.msgId, + val loggingMeta = LoggingMeta.create( + emottakBlokk = emottakblokk, + fellesformatXml = fellesformat, + msgHead = msgHead, ) val starttime = System.currentTimeMillis() diff --git a/src/main/kotlin/no/nav/syfo/services/ArenaDialogmeldingService.kt b/src/main/kotlin/no/nav/syfo/services/ArenaDialogmeldingService.kt index f356c107..1e780c83 100644 --- a/src/main/kotlin/no/nav/syfo/services/ArenaDialogmeldingService.kt +++ b/src/main/kotlin/no/nav/syfo/services/ArenaDialogmeldingService.kt @@ -24,7 +24,17 @@ class ArenaDialogmeldingService( ) { val msgHead: XMLMsgHead = fellesformatXml.get() val emottakBlokk = fellesformatXml.get() - val tssId = getTssId(receivedDialogmelding, fellesformatXml) + val loggingMeta = LoggingMeta.create( + emottakBlokk = emottakBlokk, + fellesformatXml = fellesformatXml, + msgHead = msgHead, + ) + val tssId = getTssId( + receivedDialogmelding = receivedDialogmelding, + loggingMeta = loggingMeta, + msgHead = msgHead, + emottakBlokk = emottakBlokk, + ) val arenaDialogNotat = createArenaDialogNotat( fellesformat = fellesformatXml, tssid = tssId, @@ -38,11 +48,7 @@ class ArenaDialogmeldingService( sendArenaDialogNotat( mqSender = mqSender, arenaDialogNotat = arenaDialogNotat, - loggingMeta = getLoggingMeta( - emottakBlokk = emottakBlokk, - fellesformatXml = fellesformatXml, - msgHead = msgHead, - ) + loggingMeta = loggingMeta ) } @@ -52,7 +58,9 @@ class ArenaDialogmeldingService( private suspend fun getTssId( receivedDialogmelding: ReceivedDialogmelding, - fellesformatXml: XMLEIFellesformat, + msgHead: XMLMsgHead, + emottakBlokk: XMLMottakenhetBlokk, + loggingMeta: LoggingMeta, ): String { val tssId = smtssClient.findBestTss( legePersonIdent = PersonIdent(receivedDialogmelding.personNrLege), @@ -61,35 +69,15 @@ class ArenaDialogmeldingService( ) if (tssId != null && tssId.tssid.isNotBlank()) { - val msgHead: XMLMsgHead = fellesformatXml.get() - val emottakBlokk = fellesformatXml.get() emottakService.registerEmottakSubscription( tssId = tssId, partnerReferanse = emottakBlokk.partnerReferanse, sender = msgHead.msgInfo.sender, msgId = msgHead.msgInfo.msgId, - loggingMeta = getLoggingMeta( - emottakBlokk = emottakBlokk, - fellesformatXml = fellesformatXml, - msgHead = msgHead, - ), + loggingMeta = loggingMeta, ) } return tssId?.tssid ?: "" } - - private fun getLoggingMeta( - emottakBlokk: XMLMottakenhetBlokk, - fellesformatXml: XMLEIFellesformat, - msgHead: XMLMsgHead, - ): LoggingMeta { - val ediLoggId = emottakBlokk.ediLoggId - val legekontorOrgNr = extractOrganisationNumberFromSender(fellesformatXml)?.id - return LoggingMeta( - mottakId = ediLoggId, - orgNr = legekontorOrgNr, - msgId = msgHead.msgInfo.msgId, - ) - } } diff --git a/src/main/kotlin/no/nav/syfo/util/LoggingMeta.kt b/src/main/kotlin/no/nav/syfo/util/LoggingMeta.kt index a6b42739..c6ec1285 100644 --- a/src/main/kotlin/no/nav/syfo/util/LoggingMeta.kt +++ b/src/main/kotlin/no/nav/syfo/util/LoggingMeta.kt @@ -1,5 +1,9 @@ package no.nav.syfo.util +import no.nav.helse.eiFellesformat2.XMLEIFellesformat +import no.nav.helse.eiFellesformat2.XMLMottakenhetBlokk +import no.nav.helse.msgHead.XMLMsgHead + enum class LogType { INVALID_MESSAGE, TEST_FNR_IN_PRODUCTION @@ -35,7 +39,23 @@ data class LoggingMeta( val orgNr: String?, val msgId: String, val dialogmeldingId: String = "" -) +) { + companion object { + fun create( + emottakBlokk: XMLMottakenhetBlokk, + fellesformatXml: XMLEIFellesformat, + msgHead: XMLMsgHead + ): LoggingMeta { + val ediLoggId = emottakBlokk.ediLoggId + val legekontorOrgNr = extractOrganisationNumberFromSender(fellesformatXml)?.id + return LoggingMeta( + mottakId = ediLoggId, + orgNr = legekontorOrgNr, + msgId = msgHead.msgInfo.msgId, + ) + } + } +} class TrackableException(override val cause: Throwable) : RuntimeException()