-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
311 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletion
28
src/main/kotlin/no/nav/sykdig/digitalisering/papirsykmelding/api/RegelClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
package no.nav.sykdig.digitalisering.papirsykmelding.api | ||
|
||
import net.logstash.logback.argument.StructuredArguments.kv | ||
import no.nav.sykdig.applog | ||
import no.nav.sykdig.digitalisering.papirsykmelding.db.model.ReceivedSykmeldingNasjonal | ||
import no.nav.sykdig.digitalisering.sykmelding.ValidationResult | ||
import no.nav.sykdig.securelog | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.HttpClientErrorException | ||
import org.springframework.web.client.RestTemplate | ||
import org.springframework.web.client.exchange | ||
|
||
|
||
@Component | ||
class RegelClient( | ||
@Value("\$regel.url") private val regelUrl: String, | ||
private val regelRestTemplate: RestTemplate | ||
private val regeltM2mRestTemplate: RestTemplate | ||
){ | ||
val log = applog() | ||
val securelog = securelog() | ||
|
||
fun valider(sykmelding: ReceivedSykmeldingNasjonal, msgId: String): ValidationResult { | ||
log.info("validating against rules {}", kv("sykmeldingId", sykmelding.sykmelding.id)) | ||
val headers = HttpHeaders() | ||
headers["Nav-CallId"] = msgId | ||
|
||
val response = regeltM2mRestTemplate.exchange( | ||
"$regelUrl/api/v2/rules/validate", | ||
HttpMethod.POST, | ||
HttpEntity(sykmelding, headers), | ||
ValidationResult::class.java | ||
) | ||
return response.body ?: throw HttpClientErrorException(HttpStatus.NOT_FOUND, "regelvalidering feilet for sykmeldingId ${sykmelding.sykmelding.id}") | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../kotlin/no/nav/sykdig/digitalisering/papirsykmelding/api/model/FerdigstillRegistrering.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package no.nav.sykdig.digitalisering.papirsykmelding.api.model | ||
|
||
import no.nav.sykdig.oppgavemottak.Oppgave | ||
|
||
|
||
data class FerdigstillRegistrering( | ||
val oppgaveId: Int?, | ||
val journalpostId: String, | ||
val dokumentInfoId: String?, | ||
val pasientFnr: String, | ||
val sykmeldingId: String, | ||
val sykmelder: Sykmelder, | ||
val navEnhet: String, | ||
val veileder: Veileder, | ||
val avvist: Boolean, | ||
val oppgave: Oppgave?, | ||
) | ||
|
||
class Veileder( | ||
val veilederIdent: String, | ||
) | ||
|
180 changes: 180 additions & 0 deletions
180
src/main/kotlin/no/nav/sykdig/digitalisering/papirsykmelding/api/model/ValidationRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
package no.nav.sykdig.digitalisering.papirsykmelding.api.model | ||
|
||
import java.time.LocalDate | ||
import no.nav.sykdig.digitalisering.exceptions.ValidationException | ||
import no.nav.sykdig.digitalisering.sykmelding.RuleInfo | ||
import no.nav.sykdig.digitalisering.sykmelding.Status | ||
import no.nav.sykdig.digitalisering.sykmelding.ValidationResult | ||
|
||
fun checkValidState( | ||
smRegistreringManuell: SmRegistreringManuell, | ||
sykmelder: Sykmelder, | ||
validationResult: ValidationResult, | ||
) { | ||
when { | ||
smRegistreringManuell.perioder.isEmpty() -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = "periodeValidation", | ||
messageForSender = | ||
"Sykmeldingen må ha minst én periode oppgitt for å være gyldig", | ||
messageForUser = | ||
"Sykmelder har gjort en feil i utfyllingen av sykmeldingen.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
harOverlappendePerioder(smRegistreringManuell.perioder) -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = "overlappendePeriodeValidation", | ||
messageForSender = "Sykmeldingen har overlappende perioder", | ||
messageForUser = | ||
"Sykmelder har gjort en feil i utfyllingen av sykmeldingen.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
harUlovligKombinasjonMedReisetilskudd(smRegistreringManuell.perioder) -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = "reisetilskuddValidation", | ||
messageForSender = | ||
"Sykmeldingen inneholder periode som kombinerer reisetilskudd med annen sykmeldingstype", | ||
messageForUser = | ||
"Sykmelder har gjort en feil i utfyllingen av sykmeldingen.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
erFremtidigDato(smRegistreringManuell.behandletDato) -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = "behandletDatoValidation", | ||
messageForSender = "Behandletdato kan ikke være frem i tid.", | ||
messageForUser = | ||
"Sykmelder har gjort en feil i utfyllingen av sykmeldingen.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
studentBehandlerUtenAutorisasjon(validationResult, sykmelder) -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = | ||
RuleHitCustomError.BEHANDLER_MANGLER_AUTORISASJON_I_HPR.name, | ||
messageForSender = | ||
"Studenter har ikke lov til å skrive sykmelding. Sykmelding må avvises.", | ||
messageForUser = "Studenter har ikke lov til å skrive sykmelding.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
suspendertBehandler(validationResult) -> { | ||
val vr = | ||
ValidationResult( | ||
status = Status.MANUAL_PROCESSING, | ||
ruleHits = | ||
listOf( | ||
RuleInfo( | ||
ruleName = RuleHitCustomError.BEHANDLER_SUSPENDERT.name, | ||
messageForSender = | ||
"Legen har mistet retten til å skrive sykmelding.", | ||
messageForUser = "Legen har mistet retten til å skrive sykmelding.", | ||
ruleStatus = Status.MANUAL_PROCESSING, | ||
), | ||
), | ||
) | ||
throw ValidationException(vr) | ||
} | ||
} | ||
} | ||
|
||
fun suspendertBehandler(validationResult: ValidationResult): Boolean { | ||
return validationResult.ruleHits.any { | ||
it.ruleName == RuleHitCustomError.BEHANDLER_SUSPENDERT.name | ||
} | ||
} | ||
|
||
fun studentBehandlerUtenAutorisasjon( | ||
validationResult: ValidationResult, | ||
sykmelder: Sykmelder | ||
): Boolean { | ||
val behandlerManglerAutorisasjon = | ||
validationResult.ruleHits.any { | ||
it.ruleName == RuleHitCustomError.BEHANDLER_MANGLER_AUTORISASJON_I_HPR.name | ||
} | ||
|
||
val erStudent = | ||
sykmelder.godkjenninger?.any { | ||
it.autorisasjon?.aktiv == true && | ||
it.autorisasjon.oid == 7704 && | ||
it.autorisasjon.verdi == "3" | ||
} | ||
|
||
return behandlerManglerAutorisasjon && erStudent == true | ||
} | ||
|
||
fun harOverlappendePerioder(perioder: List<Periode>): Boolean { | ||
return harIdentiskePerioder(perioder) || | ||
perioder.any { periodA -> | ||
perioder | ||
.filter { periodB -> periodB != periodA } | ||
.any { periodB -> periodA.fom in periodB.range() || periodA.tom in periodB.range() } | ||
} | ||
} | ||
|
||
private fun harIdentiskePerioder(perioder: List<Periode>): Boolean { | ||
return perioder.distinct().count() != perioder.size | ||
} | ||
|
||
fun harUlovligKombinasjonMedReisetilskudd(perioder: List<Periode>): Boolean { | ||
perioder.forEach { | ||
if ( | ||
it.reisetilskudd && | ||
(it.aktivitetIkkeMulig != null || | ||
it.gradert != null || | ||
it.avventendeInnspillTilArbeidsgiver != null || | ||
it.behandlingsdager != null) | ||
) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
fun Periode.range(): ClosedRange<LocalDate> = fom.rangeTo(tom) | ||
|
||
fun erFremtidigDato(dato: LocalDate): Boolean { | ||
return dato.isAfter(LocalDate.now()) | ||
} |
Oops, something went wrong.