Skip to content

Commit

Permalink
Merge pull request #346 from statisticsnorway/bugfix_testperiode
Browse files Browse the repository at this point in the history
Bugfix testperiode #3
  • Loading branch information
jonolehagemo authored Nov 20, 2023
2 parents b198a12 + fbd63d2 commit 15dc89f
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Familievern52aMain(arguments: KotlinArguments) : PositionedFileValidator(a
override val fieldDefinitions = Familievern52aFieldDefinitions

override val preValidationRules: List<AbstractRule<List<String>>> = listOf(
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to),
Rule002FileDescription(fieldDefinitions.fieldDefinitions)
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to)
)

override val validationRules = listOf(
Rule002FileDescription(fieldDefinitions.fieldDefinitions),
Rule003Regionsnummer(kontorFylkeRegionMappingList),
Rule004Kontornummer(kontorFylkeRegionMappingList),
Rule005RegionsnummerKontornummer(kontorFylkeRegionMappingList),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class Familievern52bMain(arguments: KotlinArguments) : PositionedFileValidator(a
override val fieldDefinitions = Familievern52bFieldDefinitions

override val preValidationRules: List<AbstractRule<List<String>>> = listOf(
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to),
Rule002FileDescription(fieldDefinitions.fieldDefinitions)
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to)

)

override val validationRules = listOf(
Rule002FileDescription(fieldDefinitions.fieldDefinitions),
Rule003Regionsnummer(kontorFylkeRegionMappingList),
Rule004Kontornummer(kontorFylkeRegionMappingList),
Rule005RegionsnummerKontornummer(kontorFylkeRegionMappingList),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Familievern53Main(arguments: KotlinArguments) : PositionedFileValidator(ar
override val fieldDefinitions = Familievern53FieldDefinitions

override val preValidationRules: List<AbstractRule<List<String>>> = listOf(
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to),
Rule002FileDescription(fieldDefinitions.fieldDefinitions)
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to)
)

override val validationRules = listOf(
Rule002FileDescription(fieldDefinitions.fieldDefinitions),
Rule003Fylkesnummer(FamilievernConstants.kontorFylkeRegionMappingList),
Rule004Kontornummer(FamilievernConstants.kontorFylkeRegionMappingList),
Rule005FylkesnummerKontornummer(FamilievernConstants.kontorFylkeRegionMappingList),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Familievern55Main(arguments: KotlinArguments) : PositionedFileValidator(ar
override val fieldDefinitions = Familievern55FieldDefinitions

override val preValidationRules: List<AbstractRule<List<String>>> = listOf(
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to),
Rule002FileDescription(fieldDefinitions.fieldDefinitions)
Rule001RecordLength(fieldDefinitions.fieldDefinitions.last().to)
)

override val validationRules = listOf(
Rule002FileDescription(fieldDefinitions.fieldDefinitions),
Rule003Fylkesnummer(FamilievernConstants.kontorFylkeRegionMappingList),
Rule005AvsluttedeMeklingerEtterTidsbruk(),
Rule006AvsluttedeMeklingerEtterDeltakere(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@ import no.ssb.kostra.program.DataType.INTEGER_TYPE
import no.ssb.kostra.program.FieldDefinition
import no.ssb.kostra.program.KostraRecord
import no.ssb.kostra.program.extension.codeIsMissing
import no.ssb.kostra.program.extension.toKostraRecord
import no.ssb.kostra.validation.report.Severity
import no.ssb.kostra.validation.report.ValidationReportEntry


class Rule002FileDescription(
val fieldDefinitions: List<FieldDefinition>
) : AbstractNoArgsRule<List<String>>("Kontroll 002 : Filbeskrivelse", Severity.ERROR) {
override fun validate(context: List<String>) = context
.withIndex()
.map { (index, recordString) ->
recordString.toKostraRecord(
index = index + 1,
fieldDefinitions = fieldDefinitions
)
}.flatMap records@{ kostraRecord ->
) : AbstractNoArgsRule<List<KostraRecord>>("Kontroll 002 : Filbeskrivelse", Severity.ERROR) {
override fun validate(context: List<KostraRecord>) = context
.flatMap records@{ kostraRecord ->
fieldDefinitions
.map { fieldDefinition ->
kostraRecord to fieldDefinition
}
}.mapNotNull { (kostraRecord, fieldDefinition) ->
}
.mapNotNull { (kostraRecord, fieldDefinition) ->
validateValue(kostraRecord, fieldDefinition)
}.ifEmpty { null }
}
.ifEmpty { null }

private fun validateValue(
kostraRecord: KostraRecord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ enum class IndividRuleId(val title: String) {
TILTAK_07("Tiltak Kontroll 7: Kontroll av manglende presisering for tiltakskategori"),
TILTAK_08("Tiltak Kontroll 8: Kontroll av kode og presisering for opphevelse"),
TILTAK_09("Tiltak Kontroll 9: Flere plasseringstiltak i samme periode"),
TILTAK_24("Tiltak Kontroll 24: Lovhjemmel refererer til feil barnevernlov"),

LOVHJEMMEL_02("Lovhjemmel Kontroll 2: Omsorgstiltak med sluttdato krever årsak til opphevelse"),
LOVHJEMMEL_03("Lovhjemmel Kontroll 3: Individet er over 18 år og har omsorgstiltak"),
LOVHJEMMEL_04("Lovhjemmel Kontroll 4: Lovhjemmel");
LOVHJEMMEL_04("Lovhjemmel Kontroll 4: Lovhjemmel"),

FLYTTING_02C("Flytting Kontroll 2c: Sluttdato mot individets sluttdato"),
FLYTTING_02F("Flytting kontroll 2f: Sluttdato mot individets startdato"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ object IndividRules {
Undersokelse07(),
Undersokelse08(),

Vedtak02()
Vedtak02(),

Flytting02c(),
Flytting02f()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package no.ssb.kostra.validation.rule.barnevern.individrule

import no.ssb.kostra.barnevern.xsd.KostraIndividType
import no.ssb.kostra.program.KotlinArguments
import no.ssb.kostra.validation.report.Severity
import no.ssb.kostra.validation.rule.AbstractRule
import no.ssb.kostra.validation.rule.barnevern.IndividRuleId

class Flytting02c : AbstractRule<KostraIndividType>(
ruleName = IndividRuleId.FLYTTING_02C.title,
severity = Severity.ERROR
) {
override fun validate(context: KostraIndividType, arguments: KotlinArguments) = context
.takeIf { it.sluttDato != null }
?.let { innerContext ->
innerContext.flytting
.filter { it.sluttDato.isAfter(context.sluttDato) }
.map { flytting ->
createValidationReportEntry(
contextId = flytting.id,
messageText = "Flytting (${flytting.id}). Sluttdato (${flytting.sluttDato}) er " +
"etter individets sluttdato (${context.sluttDato})"
)
}
.ifEmpty { null }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.ssb.kostra.validation.rule.barnevern.individrule

import no.ssb.kostra.barnevern.xsd.KostraIndividType
import no.ssb.kostra.program.KotlinArguments
import no.ssb.kostra.validation.report.Severity
import no.ssb.kostra.validation.rule.AbstractRule
import no.ssb.kostra.validation.rule.barnevern.IndividRuleId

class Flytting02f : AbstractRule<KostraIndividType>(
ruleName = IndividRuleId.FLYTTING_02F.title,
severity = Severity.ERROR
) {
override fun validate(context: KostraIndividType, arguments: KotlinArguments) = context.flytting
.filter { it.sluttDato.isBefore(context.startDato) }
.map { flytting ->
createValidationReportEntry(
contextId = flytting.id,
messageText = "Flytting (${flytting.id}). Sluttdato (${flytting.sluttDato}) er " +
"før individets startdato (${context.startDato})"
)
}
.ifEmpty { null }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package no.ssb.kostra.validation.rule.barnevern.individrule

import no.ssb.kostra.barnevern.xsd.KostraIndividType
import no.ssb.kostra.program.KotlinArguments
import no.ssb.kostra.validation.report.Severity
import no.ssb.kostra.validation.rule.AbstractRule
import no.ssb.kostra.validation.rule.barnevern.IndividRuleId
import no.ssb.kostra.validation.rule.barnevern.SharedValidationConstants.BVL1992
import no.ssb.kostra.validation.rule.barnevern.SharedValidationConstants.BVL2021
import java.time.LocalDate

class Tiltak24 : AbstractRule<KostraIndividType>(
ruleName = IndividRuleId.TILTAK_24.title,
severity = Severity.ERROR
) {
override fun validate(context: KostraIndividType, arguments: KotlinArguments) = context.tiltak
.mapNotNull { tiltak ->
val bvlThresholdDate: LocalDate = LocalDate.of(2022, 12, 31)

when {
tiltak.startDato.isBefore(bvlThresholdDate.plusDays(1))
&& (tiltak.lovhjemmel.lov != BVL1992 || tiltak.jmfrLovhjemmel.any { it.lov != BVL1992 }) ->
createValidationReportEntry(
contextId = tiltak.id,
messageText = "Tiltak (${tiltak.id}). " +
"Tiltak opprettet før 01.01.2023 krever lov = '$BVL1992'"
)

tiltak.startDato.isAfter(bvlThresholdDate)
&& (
tiltak.lovhjemmel.lov !in listOf(BVL1992, BVL2021)
|| tiltak.jmfrLovhjemmel.all { it.lov !in listOf(BVL1992, BVL2021) }
) ->
createValidationReportEntry(
contextId = tiltak.id,
messageText = "Tiltak (${tiltak.id}). " +
"Tiltak opprettet 01.01.2023 eller etter, krever lov = '$BVL1992' eller '$BVL2021'"

)

else -> null
}
}
.ifEmpty { null }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ class Rule021DatoForsteBehandlingssamtaleEtterHenvendelse : AbstractNoArgsRule<L
Familievern52aRuleId.FAMILIEVERN52A_RULE021.title,
Severity.WARNING
) {
override fun validate(context: List<KostraRecord>) = context.filterNot {
it.fieldAs<LocalDate?>(HENV_DATO_A_COL_NAME) != null
&& it.fieldAs<LocalDate?>(FORSTE_SAMT_A_COL_NAME) != null
&& it.fieldAs<LocalDate>(HENV_DATO_A_COL_NAME) < it.fieldAs<LocalDate>(FORSTE_SAMT_A_COL_NAME)
}.map {
createValidationReportEntry(
messageText = "Dato for første behandlingssamtale '${it[FORSTE_SAMT_A_COL_NAME]}' er før dato for " +
"primærklientens henvendelse '${it[HENV_DATO_A_COL_NAME]}' til familievernkontoret.",
lineNumbers = listOf(it.lineNumber)
).copy(
caseworker = it[KONTOR_NR_A_COL_NAME],
journalId = it[JOURNAL_NR_A_COL_NAME]
)
}.ifEmpty { null }
override fun validate(context: List<KostraRecord>) = context
.filter {
it[HENV_DATO_A_COL_NAME].isNotBlank()
&& it[FORSTE_SAMT_A_COL_NAME].isNotBlank()
}
.filterNot {
it.fieldAs<LocalDate?>(HENV_DATO_A_COL_NAME) != null
&& it.fieldAs<LocalDate?>(FORSTE_SAMT_A_COL_NAME) != null
&& it.fieldAs<LocalDate>(HENV_DATO_A_COL_NAME) <= it.fieldAs<LocalDate>(FORSTE_SAMT_A_COL_NAME)
}
.map {
createValidationReportEntry(
messageText = "Dato for første behandlingssamtale '${it[FORSTE_SAMT_A_COL_NAME]}' er før dato for " +
"primærklientens henvendelse '${it[HENV_DATO_A_COL_NAME]}' til familievernkontoret.",
lineNumbers = listOf(it.lineNumber)
).copy(
caseworker = it[KONTOR_NR_A_COL_NAME],
journalId = it[JOURNAL_NR_A_COL_NAME]
)
}
.ifEmpty { null }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ class Rule036AvslutningsdatoForForsteSamtale : AbstractNoArgsRule<List<KostraRec
Familievern52aRuleId.FAMILIEVERN52A_RULE036.title,
Severity.WARNING
) {
override fun validate(context: List<KostraRecord>) = context.filterNot {
it.fieldAs<LocalDate?>(FORSTE_SAMT_A_COL_NAME) != null
&& it.fieldAs<LocalDate?>(DATO_AVSL_A_COL_NAME) != null
&& it.fieldAs<LocalDate>(FORSTE_SAMT_A_COL_NAME) < it.fieldAs<LocalDate>(DATO_AVSL_A_COL_NAME)
}.map {
createValidationReportEntry(
messageText = "Dato for avslutting av saken '${it[DATO_AVSL_A_COL_NAME]}' kommer " +
"før dato for første behandlingssamtale '${it[FORSTE_SAMT_A_COL_NAME]}'.",
lineNumbers = listOf(it.lineNumber)
).copy(
caseworker = it[KONTOR_NR_A_COL_NAME],
journalId = it[JOURNAL_NR_A_COL_NAME]
)
}.ifEmpty { null }
override fun validate(context: List<KostraRecord>) = context
.filter {
it[FORSTE_SAMT_A_COL_NAME].isNotBlank()
&& it[DATO_AVSL_A_COL_NAME].isNotBlank()
}
.filterNot {
it.fieldAs<LocalDate?>(FORSTE_SAMT_A_COL_NAME) != null
&& it.fieldAs<LocalDate?>(DATO_AVSL_A_COL_NAME) != null
&& it.fieldAs<LocalDate>(FORSTE_SAMT_A_COL_NAME) <= it.fieldAs<LocalDate>(DATO_AVSL_A_COL_NAME)
}
.map {
createValidationReportEntry(
messageText = "Dato for avslutting av saken '${it[DATO_AVSL_A_COL_NAME]}' kommer " +
"før dato for første behandlingssamtale '${it[FORSTE_SAMT_A_COL_NAME]}'.",
lineNumbers = listOf(it.lineNumber)
).copy(
caseworker = it[KONTOR_NR_A_COL_NAME],
journalId = it[JOURNAL_NR_A_COL_NAME]
)
}
.ifEmpty { null }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Familievern52aMainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern52aFieldDefinitions.fieldLength + 10)
),
2,
1,
1
),
row(
Expand All @@ -34,8 +34,8 @@ class Familievern52aMainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern52aFieldDefinitions.fieldLength)
),
2,
18
36,
42
),
row(
"validating a valid record string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Familievern52bMainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern52bFieldDefinitions.fieldLength + 10)
),
2,
1,
1
),
row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Familievern53MainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern53FieldDefinitions.fieldLength + 10)
),
2,
1,
1
),
row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Familievern55MainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern55FieldDefinitions.fieldLength + 10)
),
2,
1,
1
),
row(
Expand All @@ -33,8 +33,8 @@ class Familievern55MainTest : BehaviorSpec({
region = REGION,
inputFileContent = " ".repeat(Familievern55FieldDefinitions.fieldLength)
),
2,
12
15,
13
),
row(
"validating a valid record string",
Expand Down
Loading

0 comments on commit 15dc89f

Please sign in to comment.