1
1
package no.nav.klage.oppgave.service
2
2
3
+ import no.nav.klage.dokument.service.KabalJsonToPdfService
4
+ import no.nav.klage.kodeverk.Enhet
3
5
import no.nav.klage.kodeverk.TimeUnitType
4
6
import no.nav.klage.oppgave.api.view.*
5
7
import no.nav.klage.oppgave.domain.klage.BehandlingWithVarsletBehandlingstid
@@ -14,19 +16,39 @@ import java.util.*
14
16
@Transactional
15
17
class ForlengetBehandlingstidDraftService (
16
18
private val behandlingService : BehandlingService ,
19
+ private val partSearchService : PartSearchService ,
20
+ private val kabalJsonToPdfService : KabalJsonToPdfService ,
17
21
) {
18
22
19
- fun getForlengetBehandlingstidDraft (behandlingId : UUID ): ForlengetBehandlingstidDraftView {
23
+ fun getOrCreateForlengetBehandlingstidDraft (behandlingId : UUID ): ForlengetBehandlingstidDraftView {
20
24
val behandling = behandlingService.getBehandlingForUpdate(behandlingId = behandlingId)
25
+
21
26
if (behandling is BehandlingWithVarsletBehandlingstid ) {
22
- return if (behandling.forlengetBehandlingstidDraft == null ) {
23
- ForlengetBehandlingstidDraft (behandlingstid = VarsletBehandlingstid ()).toView()
24
- } else {
25
- behandling.forlengetBehandlingstidDraft!! .toView()
27
+ if (behandling.forlengetBehandlingstidDraft == null ) {
28
+ behandling.forlengetBehandlingstidDraft =
29
+ ForlengetBehandlingstidDraft (behandlingstid = VarsletBehandlingstid ())
26
30
}
27
31
} else {
28
32
error(" Behandling har ikke varslet behandlingstid" )
29
33
}
34
+
35
+ behandling.forlengetBehandlingstidDraft!! .title = " Nav klageinstans orienterer om forlenget behandlingstid"
36
+
37
+ if (behandling.varsletBehandlingstid != null ) {
38
+ val lastVarsletBehandlingstid = behandling.varsletBehandlingstidHistorikk.maxByOrNull { it.tidspunkt }
39
+
40
+ if (lastVarsletBehandlingstid?.varsletBehandlingstid != null &&
41
+ lastVarsletBehandlingstid.varsletBehandlingstid!! .varsletBehandlingstidUnits != null &&
42
+ lastVarsletBehandlingstid.varsletBehandlingstid!! .varsletBehandlingstidUnitType != null
43
+ ) {
44
+ // TODO format
45
+ // "I brev fra Nav sendt 16. januar 2025 fikk du informasjon om at forventet behandlingstid var 6 uker."
46
+ behandling.forlengetBehandlingstidDraft!! .previousBehandlingstidInfo =
47
+ " I brev fra Nav sendt ${lastVarsletBehandlingstid.tidspunkt} fikk du informasjon om at forventet behandlingstid var ${lastVarsletBehandlingstid.varsletBehandlingstid!! .varsletBehandlingstidUnits} ${lastVarsletBehandlingstid.varsletBehandlingstid!! .varsletBehandlingstidUnitType} "
48
+ }
49
+ }
50
+
51
+ return behandling.forlengetBehandlingstidDraft!! .toView()
30
52
}
31
53
32
54
fun setTitle (behandlingId : UUID , input : ForlengetBehandlingstidTitleInput ): ForlengetBehandlingstidDraftView {
@@ -35,13 +57,19 @@ class ForlengetBehandlingstidDraftService(
35
57
return behandling.forlengetBehandlingstidDraft!! .toView()
36
58
}
37
59
38
- fun setFullmektigFritekst (behandlingId : UUID , input : ForlengetBehandlingstidFullmektigFritekstInput ): ForlengetBehandlingstidDraftView {
60
+ fun setFullmektigFritekst (
61
+ behandlingId : UUID ,
62
+ input : ForlengetBehandlingstidFullmektigFritekstInput
63
+ ): ForlengetBehandlingstidDraftView {
39
64
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
40
65
behandling.forlengetBehandlingstidDraft!! .fullmektigFritekst = input.fullmektigFritekst
41
66
return behandling.forlengetBehandlingstidDraft!! .toView()
42
67
}
43
68
44
- fun setCustomText (behandlingId : UUID , input : ForlengetBehandlingstidCustomTextInput ): ForlengetBehandlingstidDraftView {
69
+ fun setCustomText (
70
+ behandlingId : UUID ,
71
+ input : ForlengetBehandlingstidCustomTextInput
72
+ ): ForlengetBehandlingstidDraftView {
45
73
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
46
74
behandling.forlengetBehandlingstidDraft!! .customText = input.customText
47
75
return behandling.forlengetBehandlingstidDraft!! .toView()
@@ -53,9 +81,13 @@ class ForlengetBehandlingstidDraftService(
53
81
return behandling.forlengetBehandlingstidDraft!! .toView()
54
82
}
55
83
56
- fun setBehandlingstidUnits (behandlingId : UUID , input : ForlengetBehandlingstidVarsletBehandlingstidUnitsInput ): ForlengetBehandlingstidDraftView {
84
+ fun setBehandlingstidUnits (
85
+ behandlingId : UUID ,
86
+ input : ForlengetBehandlingstidVarsletBehandlingstidUnitsInput
87
+ ): ForlengetBehandlingstidDraftView {
57
88
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
58
- behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnits = input.varsletBehandlingstidUnits
89
+ behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnits =
90
+ input.varsletBehandlingstidUnits
59
91
setVarsletFristBasedOnUnits(behandling.varsletBehandlingstid!! )
60
92
return behandling.forlengetBehandlingstidDraft!! .toView()
61
93
}
@@ -65,42 +97,61 @@ class ForlengetBehandlingstidDraftService(
65
97
input : ForlengetBehandlingstidVarsletBehandlingstidUnitTypeIdInput
66
98
): ForlengetBehandlingstidDraftView {
67
99
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
68
- behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnitType = TimeUnitType .of(input.varsletBehandlingstidUnitTypeId)
100
+ behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnitType =
101
+ TimeUnitType .of(input.varsletBehandlingstidUnitTypeId)
69
102
setVarsletFristBasedOnUnits(behandling.varsletBehandlingstid!! )
70
103
return behandling.forlengetBehandlingstidDraft!! .toView()
71
104
}
72
105
73
- fun setBehandlingstidDate (behandlingId : UUID , input : ForlengetBehandlingstidBehandlingstidDateInput ): ForlengetBehandlingstidDraftView {
106
+ fun setBehandlingstidDate (
107
+ behandlingId : UUID ,
108
+ input : ForlengetBehandlingstidBehandlingstidDateInput
109
+ ): ForlengetBehandlingstidDraftView {
74
110
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
75
111
behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletFrist = input.behandlingstidDate
76
112
behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnits = null
77
113
behandling.forlengetBehandlingstidDraft!! .behandlingstid!! .varsletBehandlingstidUnitType = null
78
114
return behandling.forlengetBehandlingstidDraft!! .toView()
79
115
}
80
116
81
- fun setReceivers (behandlingId : UUID , input : ForlengetBehandlingstidReceiversInput ): ForlengetBehandlingstidDraftView {
117
+ fun setPreviousBehandlingstidInfo (
118
+ behandlingId : UUID ,
119
+ input : ForlengetBehandlingstidPreviousBehandlingstidInfoInput
120
+ ): ForlengetBehandlingstidDraftView {
121
+ val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
122
+ behandling.forlengetBehandlingstidDraft!! .previousBehandlingstidInfo = input.previousBehandlingstidInfo
123
+ return behandling.forlengetBehandlingstidDraft!! .toView()
124
+ }
125
+
126
+ fun setReceivers (
127
+ behandlingId : UUID ,
128
+ input : ForlengetBehandlingstidReceiversInput
129
+ ): ForlengetBehandlingstidDraftView {
82
130
TODO (" Not yet implemented" )
83
131
}
84
132
85
133
private fun setVarsletFristBasedOnUnits (varsletBehandlingstid : VarsletBehandlingstid ) {
86
134
if (varsletBehandlingstid.varsletBehandlingstidUnits != null && varsletBehandlingstid.varsletBehandlingstidUnitType != null ) {
87
135
// Her velger vi å ta utgangspunkt i dagens dato. Ta det opp med funksjonell når vi har en demo.
88
136
varsletBehandlingstid.varsletFrist = when (varsletBehandlingstid.varsletBehandlingstidUnitType!! ) {
89
- TimeUnitType .WEEKS -> LocalDate .now().plusWeeks(varsletBehandlingstid.varsletBehandlingstidUnits!! .toLong())
90
- TimeUnitType .MONTHS -> LocalDate .now().plusMonths(varsletBehandlingstid.varsletBehandlingstidUnits!! .toLong())
137
+ TimeUnitType .WEEKS -> LocalDate .now()
138
+ .plusWeeks(varsletBehandlingstid.varsletBehandlingstidUnits!! .toLong())
139
+
140
+ TimeUnitType .MONTHS -> LocalDate .now()
141
+ .plusMonths(varsletBehandlingstid.varsletBehandlingstidUnits!! .toLong())
91
142
}
92
143
}
93
144
}
94
145
95
146
private fun getBehandlingWithForlengetBehandlingstidDraft (behandlingId : UUID ): BehandlingWithVarsletBehandlingstid {
96
147
val behandling = behandlingService.getBehandlingForUpdate(behandlingId = behandlingId)
97
- if (behandling is BehandlingWithVarsletBehandlingstid ) {
98
- if (behandling.forlengetBehandlingstidDraft == null ) {
99
- behandling.forlengetBehandlingstidDraft = ForlengetBehandlingstidDraft (behandlingstid = VarsletBehandlingstid ())
100
- }
101
- } else {
148
+ if (behandling !is BehandlingWithVarsletBehandlingstid ) {
102
149
error(" Behandling har ikke varslet behandlingstid" )
103
150
}
151
+
152
+ if (behandling.forlengetBehandlingstidDraft == null ) {
153
+ error(" Forlenget behandlingstidutkast mangler" )
154
+ }
104
155
return behandling
105
156
}
106
157
@@ -110,6 +161,7 @@ class ForlengetBehandlingstidDraftService(
110
161
fullmektigFritekst = fullmektigFritekst,
111
162
customText = customText,
112
163
reason = reason,
164
+ previousBehandlingstidInfo = previousBehandlingstidInfo,
113
165
behandlingstid = behandlingstid!! .toView(),
114
166
)
115
167
}
@@ -121,4 +173,49 @@ class ForlengetBehandlingstidDraftService(
121
173
varsletFrist = varsletFrist,
122
174
)
123
175
}
176
+
177
+ fun getPdf (behandlingId : UUID ): ByteArray {
178
+ val behandling = behandlingService.getBehandlingForUpdate(behandlingId = behandlingId)
179
+
180
+ if (behandling !is BehandlingWithVarsletBehandlingstid ) {
181
+ error(" Behandling har ikke varslet behandlingstid" )
182
+ }
183
+
184
+ if (behandling.forlengetBehandlingstidDraft == null ) {
185
+ error(" Forlenget behandlingstidutkast mangler" )
186
+ }
187
+
188
+ val sakenGjelderName = partSearchService.searchPart(
189
+ identifikator = behandling.sakenGjelder.partId.value,
190
+ skipAccessControl = true
191
+ ).name
192
+
193
+ val forlengetBehandlingstidDraft = behandling.forlengetBehandlingstidDraft
194
+
195
+ return kabalJsonToPdfService.getForlengetBehandlingstidPDF(
196
+ title = forlengetBehandlingstidDraft?.title!! ,
197
+ sakenGjelderName = sakenGjelderName,
198
+ sakenGjelderIdentifikator = behandling.sakenGjelder.partId.value,
199
+ klagerIdentifikator = behandling.klager.partId.value,
200
+ klagerName = if (behandling.klager.partId.value != behandling.sakenGjelder.partId.value) {
201
+ partSearchService.searchPart(
202
+ identifikator = behandling.klager.partId.value,
203
+ skipAccessControl = true
204
+ ).name
205
+ } else {
206
+ sakenGjelderName
207
+ },
208
+ ytelse = behandling.ytelse,
209
+ fullmektigFritekst = forlengetBehandlingstidDraft.fullmektigFritekst,
210
+ behandlingstidUnits = forlengetBehandlingstidDraft.behandlingstid!! .varsletBehandlingstidUnits,
211
+ behandlingstidUnitType = forlengetBehandlingstidDraft.behandlingstid!! .varsletBehandlingstidUnitType,
212
+ behandlingstidDate = forlengetBehandlingstidDraft.behandlingstid!! .varsletFrist.toString(),
213
+ avsenderEnhetId = Enhet .E4291 .navn,
214
+ type = behandling.type,
215
+ mottattKlageinstans = behandling.mottattKlageinstans.toLocalDate(),
216
+ previousBehandlingstidInfo = forlengetBehandlingstidDraft.previousBehandlingstidInfo,
217
+ reason = forlengetBehandlingstidDraft.reason,
218
+ customText = forlengetBehandlingstidDraft.customText,
219
+ )
220
+ }
124
221
}
0 commit comments