Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed May 22, 2024
1 parent 51b68b6 commit 2537833
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 18 deletions.
46 changes: 36 additions & 10 deletions src/main/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarService.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package no.nav.syfo.dialogmotesvar

import io.micrometer.core.instrument.Counter
import no.nav.syfo.dialogmotestatusendring.domain.didFinishDialogmote
import no.nav.syfo.dialogmotestatusendring.getDialogmoteStatusendring
import no.nav.syfo.dialogmotestatusendring.kafka.log
import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED
import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED_KOMMER
import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED
import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER
import no.nav.syfo.dialogmotesvar.domain.*
import no.nav.syfo.metric.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED
import no.nav.syfo.metric.METRICS_NS
import no.nav.syfo.metric.METRICS_REGISTRY
import no.nav.syfo.personoppgave.*
import no.nav.syfo.personoppgave.domain.*
import no.nav.syfo.util.toLocalDateTimeOslo
Expand All @@ -17,7 +23,7 @@ fun processDialogmotesvar(
cutoffDate: LocalDate,
) {
log.info("Received dialogmotesvar! ${dialogmotesvar.moteuuid}")
if (isIrrelevantDialogmotesvar(connection, dialogmotesvar, cutoffDate)) return
if (dialogmotesvar.isIrrelevant(cutoffDate) || isDialogmoteClosed(connection, dialogmotesvar)) return

val personOppgave = connection
.getPersonOppgaverByReferanseUuid(dialogmotesvar.moteuuid)
Expand All @@ -26,6 +32,10 @@ fun processDialogmotesvar(

if (personOppgave == null) {
connection.createPersonOppgave(dialogmotesvar)
COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED.increment()
if (dialogmotesvar.svarType == DialogmoteSvartype.KOMMER) {
COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED_KOMMER.increment()
}
} else {
if (dialogmotesvar happenedAfter personOppgave) {
val updatedOppgave = personOppgave.copy(
Expand All @@ -36,6 +46,9 @@ fun processDialogmotesvar(
)
connection.updatePersonoppgaveSetBehandlet(updatedOppgave)
COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED.increment()
if (dialogmotesvar.svarType == DialogmoteSvartype.KOMMER) {
COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER.increment()
}
}
}
}
Expand All @@ -54,12 +67,25 @@ fun isDialogmoteClosed(connection: Connection, dialogmotesvar: Dialogmotesvar):
return latestStatusEndring != null && latestStatusEndring.didFinishDialogmote()
}

fun isIrrelevantDialogmotesvar(
connection: Connection,
dialogmotesvar: Dialogmotesvar,
cutoffDate: LocalDate
): Boolean {
return dialogmotesvar.svarType == DialogmoteSvartype.KOMMER ||
!(dialogmotesvar happenedAfter cutoffDate) ||
isDialogmoteClosed(connection, dialogmotesvar)
private object Metrics {
const val DIALOGMOTESVAR_OPPGAVE_CREATED = "${METRICS_NS}_dialogmotesvar_oppgave_created_count"
val COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED: Counter =
Counter.builder(DIALOGMOTESVAR_OPPGAVE_CREATED)
.description("Counts the number of PERSON_OPPGAVE created from a KDialogmotesvar")
.register(METRICS_REGISTRY)
const val DIALOGMOTESVAR_OPPGAVE_UPDATED = "${METRICS_NS}_dialogmotesvar_oppgave_updated_count"
val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED: Counter =
Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED)
.description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar")
.register(METRICS_REGISTRY)
const val DIALOGMOTESVAR_OPPGAVE_CREATED_KOMMER = "${METRICS_NS}_dialogmotesvar_oppgave_created_kommer_count"
val COUNT_DIALOGMOTESVAR_OPPGAVE_CREATED_KOMMER: Counter =
Counter.builder(DIALOGMOTESVAR_OPPGAVE_CREATED_KOMMER)
.description("Counts the number of PERSON_OPPGAVE created from a KDialogmotesvar KOMMER med tekst")
.register(METRICS_REGISTRY)
const val DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER = "${METRICS_NS}_dialogmotesvar_oppgave_updated_kommer_count"
val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER: Counter =
Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER)
.description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar KOMMER med tekst")
.register(METRICS_REGISTRY)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ data class Dialogmotesvar(
val senderType: SenderType,
val brevSentAt: OffsetDateTime,
val svarReceivedAt: OffsetDateTime,
val svarTekst: String?,
)

fun Dialogmotesvar.isIrrelevant(cutoffDate: LocalDate): Boolean =
!(this happenedAfter cutoffDate) || (svarType == DialogmoteSvartype.KOMMER && svarTekst.isNullOrBlank())

infix fun Dialogmotesvar.happenedAfter(
date: LocalDate,
) = LocalDate.from(svarReceivedAt).isAfter(date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fun KDialogmotesvar.toDialogmotesvar(moteuuid: UUID): Dialogmotesvar = Dialogmot
senderType = this.senderType,
brevSentAt = this.brevSentAt,
svarReceivedAt = this.svarReceivedAt,
svarTekst = this.svarTekst,
)

enum class SenderType {
Expand Down
6 changes: 0 additions & 6 deletions src/main/kotlin/no/nav/syfo/metric/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ val COUNT_CALL_TILGANGSKONTROLL_PERSON_FORBIDDEN: Counter = Counter.builder(CALL
.description("Counts the number of forbidden calls to istilgangskontroll - person")
.register(METRICS_REGISTRY)

const val DIALOGMOTESVAR_OPPGAVE_UPDATED = "${METRICS_NS}_dialogmotesvar_oppgave_updated_count"
val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED: Counter =
Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED)
.description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar")
.register(METRICS_REGISTRY)

const val PERSONOPPGAVEHENDELSE_DIALOGMELDING_SVAR_MOTTATT =
"${METRICS_NS}_personoppgavehendelse_dialogmelding_svar_mottatt_count"
val COUNT_PERSONOPPGAVEHENDELSE_DIALOGMELDING_SVAR_MOTTATT: Counter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.mockk.*
import no.nav.syfo.dialogmotestatusendring.domain.DialogmoteStatusendringType
import no.nav.syfo.dialogmotestatusendring.getDialogmoteStatusendring
import no.nav.syfo.dialogmotesvar.domain.DialogmoteSvartype
import no.nav.syfo.dialogmotesvar.domain.SenderType
import no.nav.syfo.personoppgave.*
import no.nav.syfo.testutil.generators.generateDialogmotesvar
import no.nav.syfo.testutil.generators.generatePDialogmotestatusendring
Expand Down Expand Up @@ -83,7 +84,44 @@ class DialogmotesvarServiceSpek : Spek({
verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) }
}

it("does not create an oppgave if arbeidstaker confirms attendance to dialogmote") {
it("creates an oppgave if behandler confirms attendance to dialogmote and svarTekst is not empty") {
val dialogmotesvar = generateDialogmotesvar(
svartype = DialogmoteSvartype.KOMMER,
svarTekst = "Passer bra, men kan vi endre tidspunkt?",
senderType = SenderType.BEHANDLER,
)

every { connection.createPersonOppgave(dialogmotesvar) } returns UUID.randomUUID()

processDialogmotesvar(
connection = connection,
dialogmotesvar = dialogmotesvar,
cutoffDate = CUTOFF_DATE,
)

verify(exactly = 1) { connection.getPersonOppgaverByReferanseUuid(dialogmotesvar.moteuuid) }
verify(exactly = 1) { connection.createPersonOppgave(dialogmotesvar) }
verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) }
}

it("does not create an oppgave if behandler confirms attendance to dialogmote and svarTekst is empty") {
val dialogmotesvar = generateDialogmotesvar(
svartype = DialogmoteSvartype.KOMMER,
senderType = SenderType.BEHANDLER,
)

processDialogmotesvar(
connection = connection,
dialogmotesvar = dialogmotesvar,
cutoffDate = CUTOFF_DATE,
)

verify(exactly = 0) { connection.getPersonOppgaverByReferanseUuid(any()) }
verify(exactly = 0) { connection.createBehandletPersonoppgave(any(), any()) }
verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) }
}

it("does not create an oppgave if arbeidstaker confirms attendance to dialogmote and svarTekst is empty") {
val dialogmotesvar = generateDialogmotesvar(
svartype = DialogmoteSvartype.KOMMER,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ fun generateDialogmotesvar(
moteuuid: UUID = UUID.randomUUID(),
svartype: DialogmoteSvartype = DialogmoteSvartype.KOMMER,
svarReceivedAt: OffsetDateTime = OffsetDateTime.now(),
senderType: SenderType = SenderType.ARBEIDSTAKER,
svarTekst: String? = null,
) = Dialogmotesvar(
uuid = UUID.randomUUID(),
moteuuid = moteuuid,
arbeidstakerIdent = UserConstants.ARBEIDSTAKER_FNR,
svarType = svartype,
senderType = SenderType.ARBEIDSTAKER,
senderType = senderType,
brevSentAt = OffsetDateTime.now(),
svarReceivedAt = svarReceivedAt,
svarTekst = svarTekst,
)

fun generateKDialogmotesvar() = KDialogmotesvar(
Expand Down

0 comments on commit 2537833

Please sign in to comment.