Skip to content

Commit

Permalink
Sakstatistikkrader for kvaltitetssikring på BigQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieHillRoa committed Feb 11, 2025
1 parent f6d58f5 commit 0c4d990
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ data class SakStatistikk(
val tekniskTid: Instant? = null,
val sakYtelse: String? = null,
val behandlingType: BehandlingType? = null,
val behandlingStatus: BehandlingStatus,
val behandlingStatus: BehandlingStatus? = null,
val behandlingResultat: BehandlingResultat? = null,
val behandlingMetode: BehandlingMetode,
val behandlingMetode: BehandlingMetode? = null,
val opprettetAv: String? = null,
val saksbehandler: String? = null,
val ansvarligBeslutter: String? = null,
Expand Down Expand Up @@ -122,9 +122,6 @@ fun SakStatistikk.validate() {
if (ansvarligEnhet == null) {
throw IllegalStateException("ansvarligEnhet kan ikke være null")
}
if (avsender == null) {
throw IllegalStateException("avsender kan ikke være null")
}
if (versjon == null) {
throw IllegalStateException("versjon kan ikke være null")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class SakStatistikkRepository(val jdbcTemplate: JdbcTemplate) {
TimeUtils.toTimestampOrNull(sakStatistikkRad.tekniskTid),
sakStatistikkRad.sakYtelse,
sakStatistikkRad.behandlingType?.name,
sakStatistikkRad.behandlingStatus.name,
sakStatistikkRad.behandlingStatus?.name,
sakStatistikkRad.behandlingResultat?.name,
sakStatistikkRad.behandlingMetode.name,
sakStatistikkRad.behandlingMetode?.name,
sakStatistikkRad.innsatsgruppe?.name,
sakStatistikkRad.hovedmal?.name,
sakStatistikkRad.opprettetAv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class BeslutterService {

private final MetricsService metricsService;

private final SakStatistikkService sakStatistikkService;

public void startBeslutterProsess(long vedtakId) {
Vedtak utkast = vedtaksstotteRepository.hentUtkastEllerFeil(vedtakId);
authService.sjekkTilgangTilBrukerOgEnhet(AktorId.of(utkast.getAktorId()));
Expand All @@ -63,6 +65,7 @@ public void startBeslutterProsess(long vedtakId) {
vedtaksstotteRepository.setBeslutterProsessStatus(utkast.getId(), BeslutterProsessStatus.KLAR_TIL_BESLUTTER);
vedtakStatusEndringService.beslutterProsessStartet(utkast);
meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.BESLUTTER_PROSESS_STARTET, utkast.getVeilederIdent());
sakStatistikkService.startetKvalitetssikring(utkast);
}

public void avbrytBeslutterProsess(long vedtakId) {
Expand All @@ -80,6 +83,7 @@ public void avbrytBeslutterProsess(long vedtakId) {
vedtaksstotteRepository.setBeslutter(utkast.getId(), null);
vedtakStatusEndringService.beslutterProsessAvbrutt(utkast);
meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.BESLUTTER_PROSESS_AVBRUTT, utkast.getVeilederIdent());
sakStatistikkService.avbrytKvalitetssikringsprosess(utkast);
});
}

Expand Down Expand Up @@ -111,6 +115,8 @@ public void bliBeslutter(long vedtakId) {
vedtakStatusEndringService.tattOverForBeslutter(utkast, innloggetVeilederIdent);
meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.TATT_OVER_SOM_BESLUTTER, innloggetVeilederIdent);
}

sakStatistikkService.bliEllerTaOverSomKvalitetssikrer(utkast, innloggetVeilederIdent);
}

public void setGodkjentAvBeslutter(long vedtakId) {
Expand Down Expand Up @@ -154,7 +160,6 @@ public void oppdaterBeslutterProsessStatus(long vedtakId) {
}

vedtaksstotteRepository.setBeslutterProsessStatus(utkast.getId(), nyStatus);

if (nyStatus == BeslutterProsessStatus.KLAR_TIL_BESLUTTER) {
beslutteroversiktRepository.oppdaterStatus(utkast.getId(), BeslutteroversiktStatus.KLAR_TIL_BESLUTTER);
meldingRepository.opprettSystemMelding(vedtakId, SystemMeldingType.SENDT_TIL_BESLUTTER, innloggetVeilederIdent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class BigQueryService(@Value("\${gcp.projectId}") val projectId: String,
"teknisk_tid" to sakStatistikk.tekniskTid.toString(),
"sak_ytelse" to sakStatistikk.sakYtelse,
"behandling_type" to sakStatistikk.behandlingType?.name,
"behandling_status" to sakStatistikk.behandlingStatus.name,
"behandling_status" to sakStatistikk.behandlingStatus?.name,
"behandling_resultat" to sakStatistikk.behandlingResultat?.name,
"behandling_metode" to sakStatistikk.behandlingMetode.name,
"behandling_metode" to sakStatistikk.behandlingMetode?.name,
"innsatsgruppe" to sakStatistikk.innsatsgruppe?.name,
"hovedmal" to sakStatistikk.hovedmal?.name,
"opprettet_av" to sakStatistikk.opprettetAv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SakStatistikkService @Autowired constructor(
val statistikkRad = SakStatistikk(
ferdigbehandletTid = Instant.now(),
behandlingStatus = BehandlingStatus.FATTET,
behandlingMetode = BehandlingMetode.MANUELL,
behandlingMetode = if(vedtak.beslutterIdent != null) BehandlingMetode.TOTRINNS else BehandlingMetode.MANUELL,
ansvarligBeslutter = vedtak.beslutterIdent
)

val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad)
Expand Down Expand Up @@ -81,27 +82,129 @@ class SakStatistikkService @Autowired constructor(
val aktorId = AktorId(vedtak.aktorId)
val fnr = aktorOppslagClient.hentFnr(aktorId)

val statistikkRad = SakStatistikk(
val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk())
val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak)
val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr)

val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy(
innsatsgruppe = null,
hovedmal = null,
behandlingResultat = null,
behandlingStatus = BehandlingStatus.AVBRUTT,
behandlingMetode = BehandlingMetode.MANUELL,
)

try {
ferdigpopulertStatistikkRad.validate()
sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad)
bigQueryService.logEvent(ferdigpopulertStatistikkRad)
} catch (e: Exception) {
secureLog.error("Kunne ikke lagre slettetutkast - sakstatistikk", e)
}
}
}

fun startetKvalitetssikring (vedtak: Vedtak) {
val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA)
if (statistikkPaa) {
val aktorId = AktorId(vedtak.aktorId)
val fnr = aktorOppslagClient.hentFnr(aktorId)

val statistikkRad = SakStatistikk(
behandlingStatus = BehandlingStatus.SENDT_TIL_KVALITETSSIKRING,
behandlingMetode = BehandlingMetode.TOTRINNS,
)
val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad)
val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak)
val ferdigpopulertStatistikkRad = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr)

try {
ferdigpopulertStatistikkRad.validate()
sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad)
bigQueryService.logEvent(ferdigpopulertStatistikkRad)
} catch (e: Exception) {
secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e)
}
}
}

fun bliEllerTaOverSomKvalitetssikrer(vedtak: Vedtak, innloggetVeileder: String) {
val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA)
if (statistikkPaa) {
val aktorId = AktorId(vedtak.aktorId)
val fnr = aktorOppslagClient.hentFnr(aktorId)

val statistikkRad = SakStatistikk(
behandlingStatus = BehandlingStatus.SENDT_TIL_KVALITETSSIKRING,
behandlingMetode = BehandlingMetode.TOTRINNS,
ansvarligBeslutter = innloggetVeileder,
)
val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(statistikkRad)
val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak)
val ferdigpopulertStatistikkRad = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr)

try {
ferdigpopulertStatistikkRad.validate()
sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad)
bigQueryService.logEvent(ferdigpopulertStatistikkRad)
} catch (e: Exception) {
secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e)
}
}
}

fun avbrytKvalitetssikringsprosess(vedtak: Vedtak) {
val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA)
if (statistikkPaa) {
val aktorId = AktorId(vedtak.aktorId)
val fnr = aktorOppslagClient.hentFnr(aktorId)

val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk())
val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak)
val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr)

val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy(
innsatsgruppe = null,
ansvarligBeslutter = null,
behandlingResultat = null,
hovedmal = null,
behandlingResultat = null
innsatsgruppe = null,
behandlingStatus = BehandlingStatus.UNDER_BEHANDLING,
behandlingMetode = BehandlingMetode.MANUELL,
)

try {
ferdigpopulertStatistikkRad.validate()
sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad)
bigQueryService.logEvent(ferdigpopulertStatistikkRad)
} catch (e: Exception) {
secureLog.error("Kunne ikke lagre slettetutkast - sakstatistikk", e)
secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e)
}
}
}

fun overtattUtkast(vedtak: Vedtak, innloggetVeilederIdent: String, erAlleredeBeslutter: Boolean) {
val statistikkPaa = unleashClient.isEnabled(SAK_STATISTIKK_PAA)
if (statistikkPaa) {
val aktorId = AktorId(vedtak.aktorId)
val fnr = aktorOppslagClient.hentFnr(aktorId)

val populertMedStatiskeData = populerSakstatistikkMedStatiskeData(SakStatistikk())
val populertMedVedtaksdata = populerSakstatistikkMedVedtakData(populertMedStatiskeData, vedtak)
val populertMedOppfolgingsperiodeData = populerSakStatistikkMedOppfolgingsperiodeData(populertMedVedtaksdata, fnr)

val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy(
ansvarligBeslutter = if (erAlleredeBeslutter) innloggetVeilederIdent else vedtak.beslutterIdent,
behandlingStatus = if (vedtak.beslutterProsessStatus != null) BehandlingStatus.SENDT_TIL_KVALITETSSIKRING else BehandlingStatus.UNDER_BEHANDLING,
behandlingMetode = if (vedtak.beslutterProsessStatus != null) BehandlingMetode.TOTRINNS else BehandlingMetode.MANUELL,
saksbehandler = innloggetVeilederIdent
)

try {
ferdigpopulertStatistikkRad.validate()
sakStatistikkRepository.insertSakStatistikkRad(ferdigpopulertStatistikkRad)
bigQueryService.logEvent(ferdigpopulertStatistikkRad)
} catch (e: Exception) {
secureLog.error("Kunne ikke lagre startetKvalitetssikring - sakstatistikk", e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public void taOverUtkast(long vedtakId) {
vedtaksstotteRepository.oppdaterUtkastVeileder(utkast.getId(), innloggetVeilederIdent);
beslutteroversiktRepository.oppdaterVeileder(utkast.getId(), veileder.getNavn());
meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.TATT_OVER_SOM_VEILEDER, innloggetVeilederIdent);
sakStatistikkService.overtattUtkast(utkast, innloggetVeilederIdent, erAlleredeBeslutter);
});

vedtakStatusEndringService.tattOverForVeileder(utkast, innloggetVeilederIdent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ public class BeslutterServiceTest {

private final AuthService authService = mock(AuthService.class);

private final SakStatistikkService sakStatistikkService = mock(SakStatistikkService.class);

private final JdbcTemplate db = SingletonPostgresContainer.init().createJdbcTemplate();

private TransactionTemplate transactor = new TransactionTemplate(new DataSourceTransactionManager(db.getDataSource()));

private BeslutterService beslutterService = new BeslutterService(
authService, vedtaksstotteRepository, vedtakStatusEndringService, beslutteroversiktRepository,
meldingRepository, veilederService, veilarbpersonClient, transactor, metricsService
meldingRepository, veilederService, veilarbpersonClient, transactor, metricsService, sakStatistikkService
);


Expand Down

0 comments on commit 0c4d990

Please sign in to comment.