Skip to content

Commit

Permalink
Chore: added functionality for send and avvis sykmelding
Browse files Browse the repository at this point in the history
chore: Added functionality for send and avvis sykmelding to this app. Korrigere sykmelding endpoint will save the updated object in the DB as well as smregistrering until the functionality is moved.
  • Loading branch information
helehar authored Dec 9, 2024
1 parent ac25481 commit 9a0166a
Show file tree
Hide file tree
Showing 67 changed files with 3,155 additions and 602 deletions.
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ val prometheusVersion = "0.16.0"
val mockkVersion = "1.13.10"
val kluentVersion = "1.73"
val coroutinesVersion = "1.8.1"
val coroutineReactorVersion = "1.9.0"
val hibernateVersion = "6.2.6.Final"
val jacksonDatatypeJsr310Version = "2.18.0"

val mockitoKotlinVersion = "5.4.0"
dependencies {
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:$graphqlDgsPlatformDependenciesVersion"))
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")
implementation("com.netflix.graphql.dgs:graphql-dgs-extended-scalars")
implementation("com.graphql-java:graphql-java:$graphqlVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:$coroutinesVersion")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$coroutineReactorVersion")
// implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.fasterxml.jackson.module:jackson-module-jaxb-annotations")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonDatatypeJsr310Version")
Expand Down Expand Up @@ -109,11 +111,13 @@ dependencies {
testImplementation("org.testcontainers:kafka:$testContainersVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("org.amshove.kluent:kluent:$kluentVersion")
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion")
constraints {
testImplementation("org.apache.commons:commons-compress:$commonsCompressVersion") {
because("overstyrer sårbar dependency fra com.opentable.components:otj-pg-embedded")
}
}
testImplementation(kotlin("test"))
}

tasks {
Expand Down
14 changes: 14 additions & 0 deletions naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ spec:
- application: syfohelsenettproxy
namespace: teamsykmelding
cluster: dev-gcp
- application: smtss
namespace: teamsykmelding
cluster: dev-gcp
- application: syfosmpapirregler
namespace: teamsykmelding
cluster: dev-gcp
external:
- host: kodeverk-api.nav.no
- host: oppgave-q1.dev-fss-pub.nais.io
Expand Down Expand Up @@ -127,3 +133,11 @@ spec:
value: http://syfohelsenettproxy
- name: HELSENETT_CLIENT_ID
value: dev-gcp.teamsykmelding.syfohelsenettproxy
- name: SMTSS_URL
value: http://smtss
- name: SMTSS_CLIENT_ID
value: dev-gcp.teamsykmelding.smtss
- name: SYFOSMPAPIRREGLER_URL
value: http://syfosmpapirregler
- name: SYFOSMPAPIRREGLER_CLIENT_ID
value: dev-gcp.teamsykmelding.syfosmpapirregler
14 changes: 14 additions & 0 deletions naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ spec:
- application: syfohelsenettproxy
namespace: teamsykmelding
cluster: prod-gcp
- application: smtss
namespace: teamsykmelding
cluster: prod-gcp
- application: syfosmpapirregler
namespace: teamsykmelding
cluster: prod-gcp
external:
- host: saf.prod-fss-pub.nais.io
- host: pdl-api.prod-fss-pub.nais.io
Expand Down Expand Up @@ -124,3 +130,11 @@ spec:
value: http://syfohelsenettproxy
- name: HELSENETT_CLIENT_ID
value: prod-gcp.teamsykmelding.syfohelsenettproxy
- name: SMTSS_URL
value: http://smtss
- name: SMTSS_CLIENT_ID
value: prod-gcp.teamsykmelding.smtss
- name: SYFOSMPAPIRREGLER_URL
value: http://syfosmpapirregler
- name: SYFOSMPAPIRREGLER_CLIENT_ID
value: prod-gcp.teamsykmelding.syfosmpapirregler
8 changes: 8 additions & 0 deletions src/main/kotlin/no/nav/sykdig/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ inline fun <reified T> T.securelog(): Logger {
inline fun <reified T> T.auditlog(): Logger {
return LoggerFactory.getLogger("auditLogger")
}

data class LoggingMeta(
val mottakId: String,
val journalpostId: String?,
val dokumentInfoId: String?,
val msgId: String,
val sykmeldingId: String,
)
14 changes: 14 additions & 0 deletions src/main/kotlin/no/nav/sykdig/config/M2MRestTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ class M2MRestTemplate(
.build()
}

@Bean
fun smtssM2mRestTemplate(): RestTemplate {
return restTemplateBuilder
.additionalInterceptors(bearerTokenInterceptor("smtss-m2m"))
.build()
}

@Bean
fun regeltM2mRestTemplate(): RestTemplate {
return restTemplateBuilder
.additionalInterceptors(bearerTokenInterceptor("regel-m2m"))
.build()
}

private fun bearerTokenInterceptor(type: String): ClientHttpRequestInterceptor {
return ClientHttpRequestInterceptor { request: HttpRequest, body: ByteArray, execution: ClientHttpRequestExecution ->
val token = m2mTokenService.getM2MToken(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
import org.springframework.security.web.SecurityFilterChain

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ class AivenKafkaConfig(
}

const val SYK_DIG_OPPGAVE_TOPIC = "teamsykmelding.syk-dig-oppgave"
const val OK_SYKMLEDING_TOPIC = "teamsykmelding.ok-sykmelding"
const val OK_SYKMELDING_TOPIC = "teamsykmelding.ok-sykmelding"
10 changes: 5 additions & 5 deletions src/main/kotlin/no/nav/sykdig/db/OppgaveRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package no.nav.sykdig.db
import com.fasterxml.jackson.module.kotlin.readValue
import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.model.RegisterOppgaveValues
import no.nav.sykdig.digitalisering.sykmelding.AktivitetIkkeMulig
import no.nav.sykdig.digitalisering.sykmelding.Diagnose
import no.nav.sykdig.digitalisering.sykmelding.Gradert
import no.nav.sykdig.digitalisering.sykmelding.MedisinskVurdering
import no.nav.sykdig.digitalisering.sykmelding.Periode
import no.nav.sykdig.digitalisering.felles.AktivitetIkkeMulig
import no.nav.sykdig.digitalisering.felles.Diagnose
import no.nav.sykdig.digitalisering.felles.Gradert
import no.nav.sykdig.digitalisering.felles.MedisinskVurdering
import no.nav.sykdig.digitalisering.felles.Periode
import no.nav.sykdig.digitalisering.sykmelding.UtenlandskSykmelding
import no.nav.sykdig.generated.types.Avvisingsgrunn
import no.nav.sykdig.generated.types.PeriodeInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package no.nav.sykdig.digitalisering

import no.nav.sykdig.digitalisering.pdl.toFormattedNameString
import no.nav.sykdig.digitalisering.sykmelding.Periode
import no.nav.sykdig.generated.DgsConstants.QUERY.DigitalisertSykmelding
import no.nav.sykdig.digitalisering.felles.Periode
import no.nav.sykdig.generated.types.Bostedsadresse
import no.nav.sykdig.generated.types.DiagnoseValue
import no.nav.sykdig.generated.types.Digitaliseringsoppgave
Expand Down
112 changes: 65 additions & 47 deletions src/main/kotlin/no/nav/sykdig/digitalisering/SykDigOppgaveService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import no.nav.sykdig.digitalisering.ferdigstilling.oppgave.OppgaveClient
import no.nav.sykdig.digitalisering.model.FerdistilltRegisterOppgaveValues
import no.nav.sykdig.digitalisering.model.RegisterOppgaveValues
import no.nav.sykdig.digitalisering.pdl.Person
import no.nav.sykdig.digitalisering.saf.graphql.DokumentInfo
import no.nav.sykdig.digitalisering.saf.graphql.SafJournalpost
import no.nav.sykdig.digitalisering.tilgangskontroll.OppgaveSecurityService
import no.nav.sykdig.digitalisering.tilgangskontroll.getNavEmail
import no.nav.sykdig.generated.types.Avvisingsgrunn
import no.nav.sykdig.model.DokumentDbModel
import no.nav.sykdig.model.OppgaveDbModel
Expand All @@ -35,59 +34,28 @@ class SykDigOppgaveService(
private val log = applog()
private val securelog = securelog()

private fun createOppgave(oppgaveId: String, fnr: String, journalpostId: String, journalpost: SafJournalpost, dokumentInfoId: String, source: String = "syk-dig"): OppgaveDbModel {
val dokumenter = journalpost.dokumenter.map {
val oppdatertTittel = if (it.tittel == "Utenlandsk sykmelding") {
"Digitalisert utenlandsk sykmelding"
} else {
it.tittel ?: "Mangler Tittel"
}
DokumentDbModel(it.dokumentInfoId, oppdatertTittel)
}

return OppgaveDbModel(
oppgaveId = oppgaveId,
fnr = fnr,
journalpostId = journalpostId,
dokumentInfoId = dokumentInfoId,
dokumenter = dokumenter,
opprettet = OffsetDateTime.now(ZoneOffset.UTC),
ferdigstilt = null,
tilbakeTilGosys = false,
avvisingsgrunn = null,
sykmeldingId = UUID.randomUUID(),
type = UTLAND,
sykmelding = null,
endretAv = getNavEmail(),
timestamp = OffsetDateTime.now(ZoneOffset.UTC),
source = source,
)
}

fun opprettOgLagreOppgave(
journalpost: SafJournalpost,
journalpostId: String,
fnr: String,
aktoerId: String,
navEpost: String,
): String {
val response =
oppgaveClient.opprettOppgave(
journalpostId = journalpostId,
aktoerId = aktoerId,
)
val opprettetOppgave = oppgaveClient.opprettOppgave(
journalpostId = journalpostId,
aktoerId = aktoerId,
)
val oppgaveId = opprettetOppgave.id.toString()

val oppgaveId = response.id.toString()
val dokumentInfoId = journalpost.dokumenter.first().dokumentInfoId
val tittel = journalpost.tittel.lowercase().contains("egenerklæring")
securelog.info("is egenarklaring: $tittel journalpostId: $journalpostId")
val oppgave = createOppgave(
val oppgave = buildOppgaveModel(
oppgaveId = oppgaveId,
fnr = fnr,
journalpostId = journalpostId,
journalpost = journalpost,
dokumentInfoId = dokumentInfoId,
source = if (journalpost.kanal == "NAV_NO" || tittel) "navno" else if (journalpost.kanal == "RINA") "rina" else "syk-dig"
journalpostId = journalpostId,
fnr = fnr,
navEpost = navEpost,
)

oppgaveRepository.lagreOppgave(oppgave)
log.info("Oppgave med id $oppgaveId lagret")
return oppgaveId
Expand Down Expand Up @@ -211,7 +179,7 @@ class SykDigOppgaveService(
) {
val sykmelding = oppgaveRepository.getLastSykmelding(oppgave.oppgaveId)
oppgaveRepository.ferdigstillAvvistOppgave(oppgave, navEpost, sykmelding, avvisningsgrunn)
ferdigstillingService.ferdigstillAvvistJournalpost(
ferdigstillingService.ferdigstillUtenlandskAvvistJournalpost(
enhet = enhetId,
oppgave = oppgave,
sykmeldt = sykmeldt,
Expand All @@ -220,7 +188,7 @@ class SykDigOppgaveService(
}

@Transactional
fun ferdigstillOppgave(
fun ferdigstillUtenlandskAvvistOppgave(
oppgave: OppgaveDbModel,
navEpost: String,
values: FerdistilltRegisterOppgaveValues,
Expand All @@ -230,7 +198,7 @@ class SykDigOppgaveService(
val sykmelding = toSykmelding(oppgave, values)

oppgaveRepository.updateOppgave(oppgave, sykmelding, navEpost, true)
ferdigstillingService.ferdigstill(
ferdigstillingService.ferdigstillUtenlandskOppgave(
enhet = enhetId,
oppgave = oppgave,
sykmeldt = sykmeldt,
Expand All @@ -247,6 +215,56 @@ class SykDigOppgaveService(
ferdigstillingService.sendUpdatedSykmelding(oppgave, sykmeldt, navEmail, values)
}

private fun buildOppgaveModel(
oppgaveId: String,
journalpost: SafJournalpost,
journalpostId: String,
fnr: String,
navEpost: String,
): OppgaveDbModel {
val dokumentInfoId = journalpost.dokumenter.first().dokumentInfoId
val dokumenter = buildDokumenter(journalpost.dokumenter)
val source = determineSource(journalpost)

return OppgaveDbModel(
oppgaveId = oppgaveId,
fnr = fnr,
journalpostId = journalpostId,
dokumentInfoId = dokumentInfoId,
dokumenter = dokumenter,
opprettet = OffsetDateTime.now(ZoneOffset.UTC),
ferdigstilt = null,
tilbakeTilGosys = false,
avvisingsgrunn = null,
sykmeldingId = UUID.randomUUID(),
type = UTLAND,
sykmelding = null,
endretAv = navEpost,
timestamp = OffsetDateTime.now(ZoneOffset.UTC),
source = source,
)
}

private fun buildDokumenter(dokumenter: List<DokumentInfo>): List<DokumentDbModel> {
return dokumenter.map {
val oppdatertTittel = if (it.tittel == "Utenlandsk sykmelding") {
"Digitalisert utenlandsk sykmelding"
} else {
it.tittel ?: "Mangler Tittel"
}
DokumentDbModel(it.dokumentInfoId, oppdatertTittel)
}
}

private fun determineSource(journalpost: SafJournalpost): String {
val isEgenerklaering = journalpost.tittel.lowercase().contains("egenerklæring")
return when {
journalpost.kanal == "NAV_NO" || isEgenerklaering -> "navno"
journalpost.kanal == "RINA" -> "rina"
else -> "syk-dig"
}
}

companion object {
private const val UTLAND = "UTLAND"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import no.nav.sykdig.digitalisering.model.FerdistilltRegisterOppgaveValues
import no.nav.sykdig.digitalisering.model.RegisterOppgaveValues
import no.nav.sykdig.digitalisering.pdl.PersonService
import no.nav.sykdig.digitalisering.regelvalidering.RegelvalideringService
import no.nav.sykdig.digitalisering.sykmelding.Sykmelding
import no.nav.sykdig.generated.types.Avvisingsgrunn
import no.nav.sykdig.generated.types.DigitaliseringsoppgaveStatus
import no.nav.sykdig.generated.types.DigitaliseringsoppgaveStatusEnum
import no.nav.sykdig.generated.types.OppdatertSykmeldingStatus
import no.nav.sykdig.generated.types.OppdatertSykmeldingStatusEnum
import no.nav.sykdig.generated.types.SykmeldingUnderArbeidValues
import no.nav.sykdig.metrics.MetricRegister
import no.nav.sykdig.model.OppgaveDbModel
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -83,7 +79,7 @@ class UtenlandskOppgaveService(
throw ClientException(valideringsresultat.joinToString())
}

sykDigOppgaveService.ferdigstillOppgave(oppgave, navEpost, values, enhetId, sykmeldt)
sykDigOppgaveService.ferdigstillUtenlandskAvvistOppgave(oppgave, navEpost, values, enhetId, sykmeldt)
metricRegister.ferdigstiltOppgave.increment()
}

Expand Down
Loading

0 comments on commit 9a0166a

Please sign in to comment.