Skip to content

Commit

Permalink
Remove send to arena code which is always toggled off (#223)
Browse files Browse the repository at this point in the history
Remove tss and emottaksubscription code from processing

Refactor create LoggingMeta

Lint fix
  • Loading branch information
andersrognstad authored Oct 31, 2023
1 parent a25c3f7 commit ce9c4b9
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 162 deletions.
2 changes: 0 additions & 2 deletions .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,3 @@ spec:
value: "dev-gcp.teamsykefravr.isbehandlerdialog"
- name: ISBEHANDLERDIALOG_ENDPOINT_URL
value: "http://isbehandlerdialog"
- name: USE_CRONJOB_TO_PUBLISH_TO_ARENA
value: "true"
2 changes: 0 additions & 2 deletions .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,3 @@ spec:
value: "prod-gcp.teamsykefravr.isbehandlerdialog"
- name: ISBEHANDLERDIALOG_ENDPOINT_URL
value: "http://isbehandlerdialog"
- name: USE_CRONJOB_TO_PUBLISH_TO_ARENA
value: "true"
3 changes: 0 additions & 3 deletions src/main/kotlin/no/nav/syfo/Bootstrap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ fun launchListeners(
mqSender = mqSender,
dialogmeldingProducer = dialogmeldingProducer,
azureAdV2Client = azureAdV2Client,
smtssClient = smtssClient,
emottakService = emottakService,
)

val behandlerdialogClient = BehandlerdialogClient(
Expand Down Expand Up @@ -172,7 +170,6 @@ fun launchListeners(
launchCronjobs(
applicationState = applicationState,
database = database,
environment = env,
dialogmeldingProcessor = dialogmeldingProcessor,
arenaDialogmeldingService = arenaDialogmeldingService,
)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/no/nav/syfo/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ data class Environment(
val smgcpProxyClientId: String = getEnvVar("SMGCP_PROXY_CLIENT_ID"),
val isbehandlerdialogClientId: String = getEnvVar("ISBEHANDLERDIALOG_CLIENT_ID"),
val isbehandlerdialogUrl: String = getEnvVar("ISBEHANDLERDIALOG_ENDPOINT_URL"),
val useCronjobToPublishToArena: Boolean = getEnvVar("USE_CRONJOB_TO_PUBLISH_TO_ARENA").toBoolean(),
) : MqConfig {
fun jdbcUrl(): String {
return "jdbc:postgresql://$databaseHost:$databasePort/$databaseName"
Expand Down
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
33 changes: 4 additions & 29 deletions src/main/kotlin/no/nav/syfo/application/DialogmeldingProcessor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.syfo.application

import io.ktor.client.*
import net.logstash.logback.argument.StructuredArguments
import no.nav.helse.dialogmelding.XMLDialogmelding
import no.nav.helse.eiFellesformat2.XMLMottakenhetBlokk
Expand All @@ -10,7 +9,6 @@ import no.nav.syfo.application.mq.MQSenderInterface
import no.nav.syfo.client.*
import no.nav.syfo.client.azuread.v2.AzureAdV2Client
import no.nav.syfo.client.pdl.PdlClient
import no.nav.syfo.client.SmtssClient
import no.nav.syfo.db.DatabaseInterface
import no.nav.syfo.domain.PersonIdent
import no.nav.syfo.handlestatus.*
Expand All @@ -31,8 +29,6 @@ class DialogmeldingProcessor(
val mqSender: MQSenderInterface,
val dialogmeldingProducer: DialogmeldingProducer,
val azureAdV2Client: AzureAdV2Client,
val smtssClient: SmtssClient,
val emottakService: EmottakService,
) {
val pdfgenClient = PdfgenClient(
url = env.syfopdfgen,
Expand Down Expand Up @@ -88,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 All @@ -114,22 +108,6 @@ class DialogmeldingProcessor(
val innbyggerOK = pdlClient.personEksisterer(PersonIdent(receivedDialogmelding.personNrPasient))
val legeOK = pdlClient.personEksisterer(PersonIdent(receivedDialogmelding.personNrLege))

val tssId = smtssClient.findBestTss(
legePersonIdent = PersonIdent(receivedDialogmelding.personNrLege),
legekontorOrgName = receivedDialogmelding.legekontorOrgName,
dialogmeldingId = receivedDialogmelding.msgId,
)

if (tssId != null && tssId.tssid.isNotBlank()) {
emottakService.registerEmottakSubscription(
tssId = tssId,
partnerReferanse = emottakblokk.partnerReferanse,
sender = msgHead.msgInfo.sender,
msgId = msgHead.msgInfo.msgId,
loggingMeta = loggingMeta,
)
}

val navnSignerendeLege = signerendeLegeService.signerendeLegeNavn(
signerendeLegeFnr = receivedDialogmelding.personNrLege,
msgId = msgId,
Expand Down Expand Up @@ -160,11 +138,8 @@ class DialogmeldingProcessor(
validationResult = validationResult,
vedleggListe = vedleggListe,
msgHead = msgHead,
emottakblokk = emottakblokk,
pasientNavn = pasientNavn,
navnSignerendeLege = navnSignerendeLege,
tssId = tssId?.tssid ?: "",
useCronjobToPublishToArena = env.useCronjobToPublishToArena,
)

Status.INVALID -> handleStatusINVALID(
Expand Down
18 changes: 6 additions & 12 deletions src/main/kotlin/no/nav/syfo/application/cronjob/CronjobLauncher.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package no.nav.syfo.application.cronjob

import no.nav.syfo.Environment
import no.nav.syfo.application.*
import no.nav.syfo.db.DatabaseInterface
import no.nav.syfo.services.ArenaDialogmeldingService

fun launchCronjobs(
applicationState: ApplicationState,
database: DatabaseInterface,
environment: Environment,
dialogmeldingProcessor: DialogmeldingProcessor,
arenaDialogmeldingService: ArenaDialogmeldingService,
) {
Expand All @@ -18,19 +16,15 @@ fun launchCronjobs(
database = database,
dialogmeldingProcessor = dialogmeldingProcessor,
)

val allCronjobs = mutableListOf<Cronjob>(
val sendDialogmeldingArenaCronjob = SendDialogmeldingArenaCronjob(
database = database,
arenaDialogmeldingService = arenaDialogmeldingService,
)
val allCronjobs = mutableListOf(
rerunCronJob,
sendDialogmeldingArenaCronjob,
)

if (environment.useCronjobToPublishToArena) {
val sendDialogmeldingArenaCronjob = SendDialogmeldingArenaCronjob(
database = database,
arenaDialogmeldingService = arenaDialogmeldingService,
)
allCronjobs.add(sendDialogmeldingArenaCronjob)
}

allCronjobs.forEach {
launchBackgroundTask(applicationState) {
cronjobRunner.start(cronjob = it)
Expand Down
24 changes: 0 additions & 24 deletions src/main/kotlin/no/nav/syfo/handlestatus/HandleStatusOK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.syfo.handlestatus

import net.logstash.logback.argument.StructuredArguments
import no.nav.helse.eiFellesformat2.XMLEIFellesformat
import no.nav.helse.eiFellesformat2.XMLMottakenhetBlokk
import no.nav.helse.msgHead.XMLMsgHead
import no.nav.syfo.application.mq.MQSenderInterface
import no.nav.syfo.apprec.ApprecStatus
Expand All @@ -29,11 +28,8 @@ suspend fun handleStatusOK(
validationResult: ValidationResult,
vedleggListe: List<Vedlegg>?,
msgHead: XMLMsgHead,
emottakblokk: XMLMottakenhetBlokk,
pasientNavn: String,
navnSignerendeLege: String,
tssId: String,
useCronjobToPublishToArena: Boolean,
) {
val journalpostId = journalService.onJournalRequest(
receivedDialogmelding,
Expand All @@ -44,26 +40,6 @@ suspend fun handleStatusOK(
navnSignerendeLege
)

if (!useCronjobToPublishToArena && !database.erDialogmeldingOpplysningerSendtArena(receivedDialogmelding.dialogmelding.id)) {
sendArenaDialogNotat(
mqSender,
createArenaDialogNotat(
fellesformat,
tssId,
receivedDialogmelding.personNrLege,
receivedDialogmelding.personNrPasient,
msgHead,
emottakblokk,
receivedDialogmelding.dialogmelding,
),
loggingMeta
)
database.lagreSendtArena(
dialogmeldingid = receivedDialogmelding.dialogmelding.id,
isSent = true,
)
}

if (!database.erDialogmeldingOpplysningerSendtKafka(receivedDialogmelding.dialogmelding.id)) {
dialogmeldingProducer.sendDialogmelding(
receivedDialogmelding = receivedDialogmelding,
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
1 change: 0 additions & 1 deletion src/test/kotlin/no/nav/syfo/TestEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ fun testEnvironment(
smgcpProxyUrl = smgcpUrl,
isbehandlerdialogClientId = "isbehandlerdialog",
isbehandlerdialogUrl = isbehandlerdialogUrl,
useCronjobToPublishToArena = true,
)

fun testAppState() = ApplicationState(
Expand Down
6 changes: 0 additions & 6 deletions src/test/kotlin/no/nav/syfo/api/VedleggSystemApiSpek.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import no.nav.syfo.application.api.VedleggDTO
import no.nav.syfo.application.api.vedleggSystemApiV1Path
import no.nav.syfo.application.mq.MQSenderInterface
import no.nav.syfo.client.azuread.v2.AzureAdV2Client
import no.nav.syfo.client.SmtssClient
import no.nav.syfo.kafka.DialogmeldingProducer
import no.nav.syfo.services.EmottakService
import no.nav.syfo.util.*
import org.amshove.kluent.shouldBeEqualTo
import org.spekframework.spek2.Spek
Expand All @@ -36,17 +34,13 @@ class VedleggSystemApiSpek : Spek({
val dialogmeldingProducer = mockk<DialogmeldingProducer>(relaxed = true)
val incomingMessage = mockk<TextMessage>(relaxed = true)
val azureAdV2Client = mockk<AzureAdV2Client>(relaxed = true)
val emottakService = mockk<EmottakService>(relaxed = true)
val smtssClient = mockk<SmtssClient>(relaxed = true)

val dialogmeldingProcessor = DialogmeldingProcessor(
database = database,
env = externalMockEnvironment.environment,
mqSender = mqSender,
dialogmeldingProducer = dialogmeldingProducer,
azureAdV2Client = azureAdV2Client,
smtssClient = smtssClient,
emottakService = emottakService,
)

val blockingApplicationRunner = BlockingApplicationRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class BlockingApplicationRunnerSpek : Spek({
mqSender = mqSender,
dialogmeldingProducer = dialogmeldingProducer,
azureAdV2Client = azureAdV2Client,
smtssClient = smtssClient,
emottakService = emottakService,
)
val blockingApplicationRunner = BlockingApplicationRunner(
applicationState = externalMockEnvironment.applicationState,
Expand Down
Loading

0 comments on commit ce9c4b9

Please sign in to comment.