Skip to content

Commit

Permalink
Add juridisk henvisning for flerre regler (#188)
Browse files Browse the repository at this point in the history
* Add juridisk henvisning for pasienter under 13 år

* use github commit sha for versjon

* change to sourceVersionURL

* Legg inn manglende juridiske henvisninger

* add test to show that all rules are run
  • Loading branch information
andreasDev authored Sep 29, 2023
1 parent 9041d57 commit 78a011b
Show file tree
Hide file tree
Showing 32 changed files with 841 additions and 512 deletions.
116 changes: 65 additions & 51 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ plugins {

application {
mainClass.set("no.nav.syfo.ApplicationKt")

val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
Expand Down Expand Up @@ -107,6 +106,7 @@ tasks {
}
}


test {
useJUnitPlatform {
}
Expand Down
2 changes: 2 additions & 0 deletions naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ spec:
value: https://smgcp-proxy.dev-fss-pub.nais.io
- name: LEGE_SUSPENSJON_PROXY_SCOPE
value: api://dev-fss.teamsykmelding.smgcp-proxy/.default
- name: SOURCE_VERSION_URL
value: {{ sourceVersionURL }}
2 changes: 2 additions & 0 deletions naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ spec:
value: https://smgcp-proxy.prod-fss-pub.nais.io
- name: LEGE_SUSPENSJON_PROXY_SCOPE
value: api://prod-fss.teamsykmelding.smgcp-proxy/.default
- name: SOURCE_VERSION_URL
value: {{ sourceVersionURL }}
2 changes: 2 additions & 0 deletions src/main/kotlin/no/nav/syfo/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fun Application.configureRouting(
applicationState: ApplicationState,
jwkProviderAad: JwkProvider,
) {

setupAuth(
environmentVariables = env,
jwkProviderAadV2 = jwkProviderAad,
Expand Down Expand Up @@ -224,6 +225,7 @@ fun Application.module() {
JuridiskVurderingService(
KafkaProducer(kafkaProperties),
environmentVariables.etterlevelsesTopic,
environmentVariables.sourceVersionURL
)
val ruleService =
RuleService(
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/no/nav/syfo/EnvironmentVariables.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data class EnvironmentVariables(
val etterlevelsesTopic: String = "teamsykmelding.paragraf-i-kode",
val jwtIssuer: String = getEnvVar("AZURE_OPENID_CONFIG_ISSUER"),
val jwkKeysUrl: String = getEnvVar("AZURE_OPENID_CONFIG_JWKS_URI"),
val sourceVersionURL: String = getEnvVar("SOURCE_VERSION_URL"),
)

fun getEnvVar(varName: String, defaultValue: String? = null) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package no.nav.syfo.rules.arbeidsuforhet
import no.nav.syfo.logger
import no.nav.syfo.model.RuleMetadata
import no.nav.syfo.model.Sykmelding
import no.nav.syfo.model.juridisk.JuridiskHenvisning
import no.nav.syfo.model.juridisk.Lovverk
import no.nav.syfo.rules.common.MedJuridisk
import no.nav.syfo.rules.common.RuleExecution
import no.nav.syfo.rules.common.RuleResult
import no.nav.syfo.rules.common.UtenJuridisk
import no.nav.syfo.rules.dsl.ResultNode
import no.nav.syfo.rules.dsl.RuleNode
import no.nav.syfo.rules.dsl.TreeNode
Expand All @@ -24,7 +26,17 @@ class ArbeidsuforhetRulesExecution(
override fun runRules(sykmelding: Sykmelding, ruleMetadata: RuleMetadataSykmelding) =
rootNode.evaluate(sykmelding, ruleMetadata.ruleMetadata).also { validationRulePath ->
logger.info("Rules ${sykmelding.id}, ${validationRulePath.printRulePath()}")
} to UtenJuridisk
} to
MedJuridisk(
JuridiskHenvisning(
lovverk = Lovverk.FOLKETRYGDLOVEN,
paragraf = "8-4",
ledd = 1,
punktum = null,
bokstav = null,
rundskriv = "R08-00"
),
)
}

private fun TreeNode<ArbeidsuforhetRules, RuleResult>.evaluate(
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/no/nav/syfo/rules/common/GenerateMermaid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import no.nav.syfo.rules.gradert.gradertRuleTree
import no.nav.syfo.rules.hpr.hprRuleTree
import no.nav.syfo.rules.legesuspensjon.legeSuspensjonRuleTree
import no.nav.syfo.rules.patientageover70.patientAgeOver70RuleTree
import no.nav.syfo.rules.periodlogic.periodLogicRuleTree
import no.nav.syfo.rules.patientunder13.patientAgeUnder13RuleTree
import no.nav.syfo.rules.periode.periodeRuleTree
import no.nav.syfo.rules.periodvalidering.periodLogicRuleTree
import no.nav.syfo.rules.tilbakedatering.tilbakedateringRuleTree
import no.nav.syfo.rules.validation.validationRuleTree

fun main() {
val ruleTrees =
listOf(
"Lege suspensjon" to legeSuspensjonRuleTree,
"Validation" to validationRuleTree,
"Periode validering" to periodLogicRuleTree,
"HPR" to hprRuleTree,
"Arbeidsuforhet" to arbeidsuforhetRuleTree,
"Validation" to validationRuleTree,
"Pasient under 13" to patientAgeUnder13RuleTree,
"Pasient over 70" to patientAgeOver70RuleTree,
"Periode" to periodLogicRuleTree,
"Tilbakedatering" to tilbakedateringRuleTree,
"Periode" to periodeRuleTree,
"Gradert" to gradertRuleTree,
"Tilbakedatering" to tilbakedateringRuleTree,
)

ruleTrees.forEach {
Expand Down
16 changes: 14 additions & 2 deletions src/main/kotlin/no/nav/syfo/rules/hpr/HPRRulesExecution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package no.nav.syfo.rules.hpr

import no.nav.syfo.logger
import no.nav.syfo.model.Sykmelding
import no.nav.syfo.model.juridisk.JuridiskHenvisning
import no.nav.syfo.model.juridisk.Lovverk
import no.nav.syfo.rules.common.MedJuridisk
import no.nav.syfo.rules.common.RuleExecution
import no.nav.syfo.rules.common.RuleResult
import no.nav.syfo.rules.common.UtenJuridisk
import no.nav.syfo.rules.dsl.ResultNode
import no.nav.syfo.rules.dsl.RuleNode
import no.nav.syfo.rules.dsl.TreeNode
Expand All @@ -22,7 +24,17 @@ class HPRRulesExecution(private val rootNode: HPRTreeNode = hprRuleTree) : RuleE
override fun runRules(sykmelding: Sykmelding, ruleMetadata: RuleMetadataSykmelding) =
rootNode.evaluate(sykmelding, ruleMetadata.behandlerOgStartdato).also { hprRulePath ->
logger.info("Rules ${sykmelding.id}, ${hprRulePath.printRulePath()}")
} to UtenJuridisk
} to
MedJuridisk(
JuridiskHenvisning(
lovverk = Lovverk.HELSEPERSONELLOVEN,
paragraf = "3",
ledd = null,
punktum = null,
bokstav = null,
rundskriv = null
)
)
}

private fun TreeNode<HPRRules, RuleResult>.evaluate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package no.nav.syfo.rules.patientunder13

import no.nav.syfo.model.Status
import no.nav.syfo.rules.common.RuleHit

enum class PatientAgeUnder13RuleHit(
val ruleHit: RuleHit,
) {
PASIENT_YNGRE_ENN_13(
ruleHit =
RuleHit(
rule = "PASIENT_YNGRE_ENN_13",
status = Status.INVALID,
messageForSender = "Pasienten er under 13 år. Sykmelding kan ikke benyttes.",
messageForUser = "Pasienten er under 13 år. Sykmelding kan ikke benyttes.",
),
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package no.nav.syfo.rules.patientunder13

import no.nav.syfo.model.Status
import no.nav.syfo.model.Status.INVALID
import no.nav.syfo.model.Status.OK
import no.nav.syfo.rules.common.RuleResult
import no.nav.syfo.rules.dsl.RuleNode
import no.nav.syfo.rules.dsl.tree

enum class PatientAgeUnder13Rules {
PASIENT_YNGRE_ENN_13,
}

val patientAgeUnder13RuleTree =
tree<PatientAgeUnder13Rules, RuleResult>(PatientAgeUnder13Rules.PASIENT_YNGRE_ENN_13) {
yes(INVALID, PatientAgeUnder13RuleHit.PASIENT_YNGRE_ENN_13)
no(OK)
}

internal fun RuleNode<PatientAgeUnder13Rules, RuleResult>.yes(
status: Status,
ruleHit: PatientAgeUnder13RuleHit? = null
) {
yes(RuleResult(status, ruleHit?.ruleHit))
}

internal fun RuleNode<PatientAgeUnder13Rules, RuleResult>.no(
status: Status,
ruleHit: PatientAgeUnder13RuleHit? = null
) {
no(RuleResult(status, ruleHit?.ruleHit))
}

fun getRule(rules: PatientAgeUnder13Rules): Rule<PatientAgeUnder13Rules> {
return when (rules) {
PatientAgeUnder13Rules.PASIENT_YNGRE_ENN_13 -> pasientUnder13Aar
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package no.nav.syfo.rules.patientunder13

import no.nav.syfo.logger
import no.nav.syfo.model.Sykmelding
import no.nav.syfo.model.juridisk.JuridiskHenvisning
import no.nav.syfo.model.juridisk.Lovverk
import no.nav.syfo.rules.common.MedJuridisk
import no.nav.syfo.rules.common.RuleExecution
import no.nav.syfo.rules.common.RuleResult
import no.nav.syfo.rules.dsl.ResultNode
import no.nav.syfo.rules.dsl.RuleNode
import no.nav.syfo.rules.dsl.TreeNode
import no.nav.syfo.rules.dsl.TreeOutput
import no.nav.syfo.rules.dsl.join
import no.nav.syfo.rules.dsl.printRulePath
import no.nav.syfo.services.RuleMetadataSykmelding

typealias PatientAgeUnder13TreeOutput = TreeOutput<PatientAgeUnder13Rules, RuleResult>

class PatientAgeUnder13RulesExecution(
val rootNode: TreeNode<PatientAgeUnder13Rules, RuleResult> = patientAgeUnder13RuleTree
) : RuleExecution<PatientAgeUnder13Rules> {
override fun runRules(sykmelding: Sykmelding, ruleMetadata: RuleMetadataSykmelding) =
rootNode.evaluate(sykmelding, ruleMetadata).also { patientAgeUnder13 ->
logger.info("Rules ${sykmelding.id}, ${patientAgeUnder13.printRulePath()}")
} to
MedJuridisk(
JuridiskHenvisning(
lovverk = Lovverk.FOLKETRYGDLOVEN,
paragraf = "8-3",
ledd = 1,
punktum = null,
bokstav = null,
),
)
}

private fun TreeNode<PatientAgeUnder13Rules, RuleResult>.evaluate(
sykmelding: Sykmelding,
ruleMetadata: RuleMetadataSykmelding,
): PatientAgeUnder13TreeOutput =
when (this) {
is ResultNode -> PatientAgeUnder13TreeOutput(treeResult = result)
is RuleNode -> {
val rule = getRule(rule)
val result = rule(sykmelding, ruleMetadata)
val childNode = if (result.ruleResult) yes else no
result join childNode.evaluate(sykmelding, ruleMetadata)
}
}
24 changes: 24 additions & 0 deletions src/main/kotlin/no/nav/syfo/rules/patientunder13/Rules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no.nav.syfo.rules.patientunder13

import no.nav.syfo.model.Sykmelding
import no.nav.syfo.rules.dsl.RuleResult
import no.nav.syfo.services.RuleMetadataSykmelding
import no.nav.syfo.services.sortedTOMDate

typealias Rule<T> =
(sykmelding: Sykmelding, ruleMetadataSykmelding: RuleMetadataSykmelding) -> RuleResult<T>

typealias PatientAgeOver70Rule = Rule<PatientAgeUnder13Rules>

val pasientUnder13Aar: PatientAgeOver70Rule = { sykmelding, ruleMetadata ->
val sisteTomDato = sykmelding.perioder.sortedTOMDate().last()
val pasientFodselsdato = ruleMetadata.ruleMetadata.pasientFodselsdato

val pasientUnder13Aar = sisteTomDato < pasientFodselsdato.plusYears(13)

RuleResult(
ruleInputs = mapOf("pasientUnder13Aar" to pasientUnder13Aar),
rule = PatientAgeUnder13Rules.PASIENT_YNGRE_ENN_13,
ruleResult = pasientUnder13Aar,
)
}
43 changes: 43 additions & 0 deletions src/main/kotlin/no/nav/syfo/rules/periode/PeriodeRuleHit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package no.nav.syfo.rules.periode

import no.nav.syfo.model.Status
import no.nav.syfo.rules.common.RuleHit

enum class PeriodeRuleHit(val ruleHit: RuleHit) {
FREMDATERT_MER_ENN_30_DAGER(
ruleHit =
RuleHit(
rule = "FREMDATERT",
status = Status.INVALID,
messageForSender =
"Sykmeldingen kan ikke rettes, det må skrives en ny. " +
"Pasienten har fått beskjed om å vente på ny sykmelding fra deg. Grunnet følgende:" +
"Hvis sykmeldingen er fremdatert mer enn 30 dager etter behandletDato avvises meldingen.",
messageForUser = "Sykmeldingen er datert mer enn 30 dager fram i tid.",
),
),
TILBAKEDATERT_MER_ENN_3_AR(
ruleHit =
RuleHit(
rule = "TILBAKEDATERT_MER_ENN_3_AR",
status = Status.INVALID,
messageForSender =
"Sykmeldingen kan ikke rettes, det må skrives en ny. " +
"Pasienten har fått beskjed om å vente på ny sykmelding fra deg. Grunnet følgende: " +
"Sykmeldinges fom-dato er mer enn 3 år tilbake i tid.",
messageForUser = "Startdatoen er mer enn tre år tilbake.",
),
),
TOTAL_VARIGHET_OVER_ETT_AAR(
ruleHit =
RuleHit(
rule = "TOTAL_VARIGHET_OVER_ETT_AAR",
status = Status.INVALID,
messageForSender =
"Sykmeldingen kan ikke rettes, det må skrives en ny. " +
"Pasienten har fått beskjed om å vente på ny sykmelding fra deg. Grunnet følgende:" +
"Sykmeldingen første fom og siste tom har ein varighet som er over 1 år",
messageForUser = "Den kan ikke ha en varighet på over ett år.",
),
),
}
50 changes: 50 additions & 0 deletions src/main/kotlin/no/nav/syfo/rules/periode/PeriodeRuleTree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package no.nav.syfo.rules.periode

import no.nav.syfo.model.Status
import no.nav.syfo.model.Status.INVALID
import no.nav.syfo.model.Status.OK
import no.nav.syfo.rules.common.RuleResult
import no.nav.syfo.rules.dsl.RuleNode
import no.nav.syfo.rules.dsl.tree
import no.nav.syfo.rules.periode.PeriodeRuleHit.*
import no.nav.syfo.rules.periodvalidering.PeriodLogicRuleHit

enum class PeriodeRules {
FREMDATERT_MER_ENN_30_DAGER,
TILBAKEDATERT_MER_ENN_3_AR,
TOTAL_VARIGHET_OVER_ETT_AAR,
}

val periodeRuleTree =
tree<PeriodeRules, RuleResult>(PeriodeRules.FREMDATERT_MER_ENN_30_DAGER) {
yes(INVALID, FREMDATERT_MER_ENN_30_DAGER)
no(PeriodeRules.TILBAKEDATERT_MER_ENN_3_AR) {
yes(INVALID, TILBAKEDATERT_MER_ENN_3_AR)
no(PeriodeRules.TOTAL_VARIGHET_OVER_ETT_AAR) {
yes(INVALID, TOTAL_VARIGHET_OVER_ETT_AAR)
no(OK)
}
}
}

internal fun RuleNode<PeriodeRules, RuleResult>.yes(
status: Status,
ruleHit: PeriodeRuleHit? = null
) {
yes(RuleResult(status, ruleHit?.ruleHit))
}

internal fun RuleNode<PeriodeRules, RuleResult>.no(
status: Status,
ruleHit: PeriodLogicRuleHit? = null
) {
no(RuleResult(status, ruleHit?.ruleHit))
}

fun getRule(rules: PeriodeRules): Rule<PeriodeRules> {
return when (rules) {
PeriodeRules.FREMDATERT_MER_ENN_30_DAGER -> fremdatertOver30Dager
PeriodeRules.TILBAKEDATERT_MER_ENN_3_AR -> tilbakeDatertOver3Ar
PeriodeRules.TOTAL_VARIGHET_OVER_ETT_AAR -> varighetOver1AAr
}
}
Loading

0 comments on commit 78a011b

Please sign in to comment.