Skip to content

Commit

Permalink
Noen punkter for statistikk
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieHillRoa committed Feb 10, 2025
1 parent f6d58f5 commit c3d4018
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum class BehandlingType {
enum class BehandlingStatus {
UNDER_BEHANDLING,
SENDT_TIL_KVALITETSSIKRING,
SENDT_TIL_VEILEDER,// ???
FATTET,
AVBRUTT
}
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 All @@ -132,6 +138,7 @@ public void setGodkjentAvBeslutter(long vedtakId) {
vedtakStatusEndringService.godkjentAvBeslutter(utkast);
meldingRepository.opprettSystemMelding(utkast.getId(), SystemMeldingType.BESLUTTER_HAR_GODKJENT, innloggetVeilederIdent);
metricsService.rapporterTidMellomUtkastOpprettetTilGodkjent(utkast);
//TODO her bør det nok også være en rad eller?
}

public void oppdaterBeslutterProsessStatus(long vedtakId) {
Expand All @@ -154,7 +161,7 @@ public void oppdaterBeslutterProsessStatus(long vedtakId) {
}

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

// TODO her må vi gjøre noe med tanke på rad i sakstatistikk
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 @@ -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 @@ -106,6 +107,127 @@ class SakStatistikkService @Autowired constructor(
}
}

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 statistikkRad = SakStatistikk(
behandlingStatus = BehandlingStatus.UNDER_BEHANDLING,
behandlingMetode = BehandlingMetode.MANUELL,
)

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

val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy(
ansvarligBeslutter = null,
behandlingResultat = null,
hovedmal = null,
innsatsgruppe = null,
)

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

fun sendTilbakeSomVeileder(vedtak: Vedtak, innloggetVeileder: String) {
//Skal noe skje her? (vi ha ene klar for veilederknapp dersom man øsnker det
}

fun godkjentKvalitetssiikring(vedtak: Vedtak, innloggetVeileder: String) {
//Skal noe skje her? egenglig ingenting å oppdatere her?
// kunne vært en behandlingsstatus, burde vi kjøre på med en til? eller skal vi bare la vær å ha det som en rad?
}

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 statistikkRad = SakStatistikk(
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,
)

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

val ferdigpopulertStatistikkRad = populertMedOppfolgingsperiodeData.copy(
saksbehandler = innloggetVeilederIdent
)

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


private fun populerSakstatistikkMedStatiskeData(sakStatistikk: SakStatistikk): SakStatistikk {
return sakStatistikk.copy(
endretTid = Instant.now(),
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 c3d4018

Please sign in to comment.