Skip to content

Commit

Permalink
IS-1896: Create/update dialogmotesvar-oppgave if kommer with tekst
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed May 22, 2024
1 parent 4a1ff97 commit 0719c2e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 19 deletions.
30 changes: 20 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,14 @@
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_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 +21,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 @@ -36,6 +40,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 +61,15 @@ 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_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_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")
.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 @@ -10,6 +10,7 @@ data class KDialogmotesvar(
val senderType: SenderType,
val brevSentAt: OffsetDateTime,
val svarReceivedAt: OffsetDateTime,
val svarTekst: String?,
)

fun KDialogmotesvar.toDialogmotesvar(moteuuid: UUID): Dialogmotesvar = Dialogmotesvar(
Expand All @@ -20,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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class KafkaDialogmotesvarConsumer(
validRecords.forEach { record ->
val kDialogmotesvar = record.value()
val moteUuid = UUID.fromString(record.key())
log.info("Received dialogmotesvar with key/moteuuid : $moteUuid of svar type ${kDialogmotesvar.svarType}")
log.info("Received dialogmotesvar with key/moteuuid : $moteUuid of svar type ${kDialogmotesvar.svarType} and tekst ${kDialogmotesvar.svarTekst}")

val dialogmotesvar = kDialogmotesvar.toDialogmotesvar(moteUuid)
storeDialogmotesvar(
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 All @@ -25,4 +28,5 @@ fun generateKDialogmotesvar() = KDialogmotesvar(
senderType = SenderType.ARBEIDSTAKER,
brevSentAt = OffsetDateTime.now(),
svarReceivedAt = OffsetDateTime.now(),
svarTekst = null,
)

0 comments on commit 0719c2e

Please sign in to comment.