Skip to content

Commit

Permalink
Refactor create LoggingMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed Oct 30, 2023
1 parent 4cbc7c3 commit e2e0b4e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class BlockingApplicationRunner(
val fellesformat = safeUnmarshal(inputMessageText)
val msgHead: XMLMsgHead = fellesformat.get()
val emottakblokk = fellesformat.get<XMLMottakenhetBlokk>()
val ediLoggId = emottakblokk.ediLoggId
val dialogmeldingXml = extractDialogmelding(fellesformat)
val patientXml = extractPatient(fellesformat)
val vedlegg = extractValidVedlegg(fellesformat)
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ class DialogmeldingProcessor(
val fellesformat = safeUnmarshal(inputMessageText)
val msgHead: XMLMsgHead = fellesformat.get()
val emottakblokk = fellesformat.get<XMLMottakenhetBlokk>()
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()

Expand Down
44 changes: 16 additions & 28 deletions src/main/kotlin/no/nav/syfo/services/ArenaDialogmeldingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ class ArenaDialogmeldingService(
) {
val msgHead: XMLMsgHead = fellesformatXml.get()
val emottakBlokk = fellesformatXml.get<XMLMottakenhetBlokk>()
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,
Expand All @@ -38,11 +48,7 @@ class ArenaDialogmeldingService(
sendArenaDialogNotat(
mqSender = mqSender,
arenaDialogNotat = arenaDialogNotat,
loggingMeta = getLoggingMeta(
emottakBlokk = emottakBlokk,
fellesformatXml = fellesformatXml,
msgHead = msgHead,
)
loggingMeta = loggingMeta
)
}

Expand All @@ -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),
Expand All @@ -61,35 +69,15 @@ class ArenaDialogmeldingService(
)

if (tssId != null && tssId.tssid.isNotBlank()) {
val msgHead: XMLMsgHead = fellesformatXml.get()
val emottakBlokk = fellesformatXml.get<XMLMottakenhetBlokk>()
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,
)
}
}
22 changes: 21 additions & 1 deletion src/main/kotlin/no/nav/syfo/util/LoggingMeta.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit e2e0b4e

Please sign in to comment.