Skip to content

Commit dba7d98

Browse files
Create draft before setting stuff.
Get pdf based on db data. Co-authored-by: Øyvind N. Wedøe <[email protected]>
1 parent 29d4071 commit dba7d98

File tree

5 files changed

+188
-45
lines changed

5 files changed

+188
-45
lines changed

src/main/kotlin/no/nav/klage/oppgave/api/controller/ForlengetBehandlingstidDraftController.kt

+44-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import no.nav.klage.oppgave.util.TokenUtil
77
import no.nav.klage.oppgave.util.getLogger
88
import no.nav.klage.oppgave.util.logMethodDetails
99
import no.nav.security.token.support.core.api.ProtectedWithClaims
10+
import org.springframework.http.HttpHeaders
11+
import org.springframework.http.HttpStatus
12+
import org.springframework.http.MediaType
13+
import org.springframework.http.ResponseEntity
1014
import org.springframework.web.bind.annotation.*
1115
import java.util.*
1216

@@ -22,14 +26,37 @@ class ForlengetBehandlingstidDraftController(
2226
private val logger = getLogger(javaClass.enclosingClass)
2327
}
2428

25-
@GetMapping
26-
fun getForlengetBehandlingstidDraft(@PathVariable behandlingId: UUID): ForlengetBehandlingstidDraftView {
29+
@PostMapping
30+
fun getOrCreateForlengetBehandlingstidDraft(@PathVariable behandlingId: UUID): ForlengetBehandlingstidDraftView {
2731
logMethodDetails(
28-
methodName = ::getForlengetBehandlingstidDraft.name,
32+
methodName = ::getOrCreateForlengetBehandlingstidDraft.name,
2933
innloggetIdent = tokenUtil.getIdent(),
3034
logger = logger,
3135
)
32-
return forlengetBehandlingstidDraftService.getForlengetBehandlingstidDraft(behandlingId = behandlingId)
36+
return forlengetBehandlingstidDraftService.getOrCreateForlengetBehandlingstidDraft(behandlingId = behandlingId)
37+
}
38+
39+
@ResponseBody
40+
@GetMapping("/pdf")
41+
fun getPdf(@PathVariable behandlingId: UUID): ResponseEntity<ByteArray> {
42+
logMethodDetails(
43+
methodName = ::getPdf.name,
44+
innloggetIdent = tokenUtil.getIdent(),
45+
logger = logger,
46+
)
47+
48+
forlengetBehandlingstidDraftService.getPdf(
49+
behandlingId = behandlingId
50+
).let {
51+
val responseHeaders = HttpHeaders()
52+
responseHeaders.contentType = MediaType.APPLICATION_PDF
53+
responseHeaders.add("Content-Disposition", "inline; filename=forlenget-behandlingstid-preview.pdf")
54+
return ResponseEntity(
55+
it,
56+
responseHeaders,
57+
HttpStatus.OK
58+
)
59+
}
3360
}
3461

3562
@PutMapping("/title")
@@ -124,6 +151,19 @@ class ForlengetBehandlingstidDraftController(
124151
return forlengetBehandlingstidDraftService.setBehandlingstidDate(behandlingId = behandlingId, input = input)
125152
}
126153

154+
@PutMapping("/previous-behandlingstid-info")
155+
fun setPreviousBehandlingstidInfo(
156+
@PathVariable behandlingId: UUID,
157+
@RequestBody input: ForlengetBehandlingstidPreviousBehandlingstidInfoInput
158+
): ForlengetBehandlingstidDraftView {
159+
logMethodDetails(
160+
methodName = ::setPreviousBehandlingstidInfo.name,
161+
innloggetIdent = tokenUtil.getIdent(),
162+
logger = logger,
163+
)
164+
return forlengetBehandlingstidDraftService.setPreviousBehandlingstidInfo(behandlingId = behandlingId, input = input)
165+
}
166+
127167
@PutMapping("/receivers")
128168
fun setReceivers(
129169
@PathVariable behandlingId: UUID,

src/main/kotlin/no/nav/klage/oppgave/api/view/ForlengetBehandlingstid.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ data class ForlengetBehandlingstidTitleInput(val title: String)
77

88
data class ForlengetBehandlingstidFullmektigFritekstInput(val fullmektigFritekst: String?)
99

10-
data class ForlengetBehandlingstidCustomTextInput(val customText: String)
10+
data class ForlengetBehandlingstidCustomTextInput(val customText: String?)
1111

12-
data class ForlengetBehandlingstidReasonInput(val reason: String)
12+
data class ForlengetBehandlingstidReasonInput(val reason: String?)
13+
14+
data class ForlengetBehandlingstidPreviousBehandlingstidInfoInput(val previousBehandlingstidInfo: String?)
1315

1416
data class ForlengetBehandlingstidVarsletBehandlingstidUnitsInput(val varsletBehandlingstidUnits: Int)
1517

@@ -41,6 +43,7 @@ data class ForlengetBehandlingstidDraftView(
4143
val fullmektigFritekst: String?,
4244
val customText: String?,
4345
val reason: String?,
46+
val previousBehandlingstidInfo: String?,
4447
val behandlingstid: ForlengetBehandlingstidVarsletBehandlingstidView,
4548
// val receivers: List<ForlengetBehandlingstidReceiverView>,
4649
)

src/main/kotlin/no/nav/klage/oppgave/domain/klage/ForlengetBehandlingstidDraft.kt

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ForlengetBehandlingstidDraft(
2222
var customText: String? = null,
2323
@Column(name = "reason")
2424
var reason: String? = null,
25+
@Column(name = "previous_behandlingstid_info")
26+
var previousBehandlingstidInfo: String? = null,
2527
@Embedded
2628
@AttributeOverrides(
2729
value = [

src/main/kotlin/no/nav/klage/oppgave/service/ForlengetBehandlingstidDraftService.kt

+116-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package no.nav.klage.oppgave.service
22

3+
import no.nav.klage.dokument.service.KabalJsonToPdfService
4+
import no.nav.klage.kodeverk.Enhet
35
import no.nav.klage.kodeverk.TimeUnitType
46
import no.nav.klage.oppgave.api.view.*
57
import no.nav.klage.oppgave.domain.klage.BehandlingWithVarsletBehandlingstid
@@ -14,19 +16,39 @@ import java.util.*
1416
@Transactional
1517
class ForlengetBehandlingstidDraftService(
1618
private val behandlingService: BehandlingService,
19+
private val partSearchService: PartSearchService,
20+
private val kabalJsonToPdfService: KabalJsonToPdfService,
1721
) {
1822

19-
fun getForlengetBehandlingstidDraft(behandlingId: UUID): ForlengetBehandlingstidDraftView {
23+
fun getOrCreateForlengetBehandlingstidDraft(behandlingId: UUID): ForlengetBehandlingstidDraftView {
2024
val behandling = behandlingService.getBehandlingForUpdate(behandlingId = behandlingId)
25+
2126
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())
2630
}
2731
} else {
2832
error("Behandling har ikke varslet behandlingstid")
2933
}
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()
3052
}
3153

3254
fun setTitle(behandlingId: UUID, input: ForlengetBehandlingstidTitleInput): ForlengetBehandlingstidDraftView {
@@ -35,13 +57,19 @@ class ForlengetBehandlingstidDraftService(
3557
return behandling.forlengetBehandlingstidDraft!!.toView()
3658
}
3759

38-
fun setFullmektigFritekst(behandlingId: UUID, input: ForlengetBehandlingstidFullmektigFritekstInput): ForlengetBehandlingstidDraftView {
60+
fun setFullmektigFritekst(
61+
behandlingId: UUID,
62+
input: ForlengetBehandlingstidFullmektigFritekstInput
63+
): ForlengetBehandlingstidDraftView {
3964
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
4065
behandling.forlengetBehandlingstidDraft!!.fullmektigFritekst = input.fullmektigFritekst
4166
return behandling.forlengetBehandlingstidDraft!!.toView()
4267
}
4368

44-
fun setCustomText(behandlingId: UUID, input: ForlengetBehandlingstidCustomTextInput): ForlengetBehandlingstidDraftView {
69+
fun setCustomText(
70+
behandlingId: UUID,
71+
input: ForlengetBehandlingstidCustomTextInput
72+
): ForlengetBehandlingstidDraftView {
4573
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
4674
behandling.forlengetBehandlingstidDraft!!.customText = input.customText
4775
return behandling.forlengetBehandlingstidDraft!!.toView()
@@ -53,9 +81,13 @@ class ForlengetBehandlingstidDraftService(
5381
return behandling.forlengetBehandlingstidDraft!!.toView()
5482
}
5583

56-
fun setBehandlingstidUnits(behandlingId: UUID, input: ForlengetBehandlingstidVarsletBehandlingstidUnitsInput): ForlengetBehandlingstidDraftView {
84+
fun setBehandlingstidUnits(
85+
behandlingId: UUID,
86+
input: ForlengetBehandlingstidVarsletBehandlingstidUnitsInput
87+
): ForlengetBehandlingstidDraftView {
5788
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
58-
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnits = input.varsletBehandlingstidUnits
89+
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnits =
90+
input.varsletBehandlingstidUnits
5991
setVarsletFristBasedOnUnits(behandling.varsletBehandlingstid!!)
6092
return behandling.forlengetBehandlingstidDraft!!.toView()
6193
}
@@ -65,42 +97,61 @@ class ForlengetBehandlingstidDraftService(
6597
input: ForlengetBehandlingstidVarsletBehandlingstidUnitTypeIdInput
6698
): ForlengetBehandlingstidDraftView {
6799
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
68-
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnitType = TimeUnitType.of(input.varsletBehandlingstidUnitTypeId)
100+
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnitType =
101+
TimeUnitType.of(input.varsletBehandlingstidUnitTypeId)
69102
setVarsletFristBasedOnUnits(behandling.varsletBehandlingstid!!)
70103
return behandling.forlengetBehandlingstidDraft!!.toView()
71104
}
72105

73-
fun setBehandlingstidDate(behandlingId: UUID, input: ForlengetBehandlingstidBehandlingstidDateInput): ForlengetBehandlingstidDraftView {
106+
fun setBehandlingstidDate(
107+
behandlingId: UUID,
108+
input: ForlengetBehandlingstidBehandlingstidDateInput
109+
): ForlengetBehandlingstidDraftView {
74110
val behandling = getBehandlingWithForlengetBehandlingstidDraft(behandlingId = behandlingId)
75111
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletFrist = input.behandlingstidDate
76112
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnits = null
77113
behandling.forlengetBehandlingstidDraft!!.behandlingstid!!.varsletBehandlingstidUnitType = null
78114
return behandling.forlengetBehandlingstidDraft!!.toView()
79115
}
80116

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 {
82130
TODO("Not yet implemented")
83131
}
84132

85133
private fun setVarsletFristBasedOnUnits(varsletBehandlingstid: VarsletBehandlingstid) {
86134
if (varsletBehandlingstid.varsletBehandlingstidUnits != null && varsletBehandlingstid.varsletBehandlingstidUnitType != null) {
87135
//Her velger vi å ta utgangspunkt i dagens dato. Ta det opp med funksjonell når vi har en demo.
88136
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())
91142
}
92143
}
93144
}
94145

95146
private fun getBehandlingWithForlengetBehandlingstidDraft(behandlingId: UUID): BehandlingWithVarsletBehandlingstid {
96147
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) {
102149
error("Behandling har ikke varslet behandlingstid")
103150
}
151+
152+
if (behandling.forlengetBehandlingstidDraft == null) {
153+
error("Forlenget behandlingstidutkast mangler")
154+
}
104155
return behandling
105156
}
106157

@@ -110,6 +161,7 @@ class ForlengetBehandlingstidDraftService(
110161
fullmektigFritekst = fullmektigFritekst,
111162
customText = customText,
112163
reason = reason,
164+
previousBehandlingstidInfo = previousBehandlingstidInfo,
113165
behandlingstid = behandlingstid!!.toView(),
114166
)
115167
}
@@ -121,4 +173,49 @@ class ForlengetBehandlingstidDraftService(
121173
varsletFrist = varsletFrist,
122174
)
123175
}
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+
}
124221
}

src/main/resources/db/migration/V197__forlenget_behandlingstid.sql

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
CREATE TABLE klage.forlenget_behandlingstid_draft
22
(
3-
id UUID PRIMARY KEY NOT NULL,
4-
created TIMESTAMP NOT NULL,
5-
title TEXT,
6-
fullmektig_fritekst TEXT,
7-
custom_text TEXT,
8-
reason TEXT,
9-
behandlingstid_units INT,
10-
behandlingstid_unit_type_id TEXT,
11-
behandlingstid_date DATE
3+
id UUID PRIMARY KEY NOT NULL,
4+
created TIMESTAMP NOT NULL,
5+
title TEXT,
6+
fullmektig_fritekst TEXT,
7+
custom_text TEXT,
8+
reason TEXT,
9+
previous_behandlingstid_info TEXT,
10+
behandlingstid_units INT,
11+
behandlingstid_unit_type_id TEXT,
12+
behandlingstid_date DATE
1213
);
1314

1415
CREATE TABLE klage.forlenget_behandlingstid_draft_receiver
1516
(
16-
id UUID PRIMARY KEY NOT NULL,
17-
identifikator TEXT NOT NULL,
17+
id UUID PRIMARY KEY NOT NULL,
18+
identifikator TEXT NOT NULL,
1819
forlenget_behandlingstid_draft_id UUID NOT NULL
1920
CONSTRAINT fk_fbd_receiver
2021
REFERENCES klage.forlenget_behandlingstid_draft,
21-
local_print BOOLEAN DEFAULT FALSE,
22-
force_central_print BOOLEAN DEFAULT FALSE,
23-
address_adresselinje_1 TEXT,
24-
address_adresselinje_2 TEXT,
25-
address_adresselinje_3 TEXT,
26-
address_postnummer TEXT,
27-
address_poststed TEXT,
28-
address_landkode TEXT,
29-
navn TEXT
22+
local_print BOOLEAN DEFAULT FALSE,
23+
force_central_print BOOLEAN DEFAULT FALSE,
24+
address_adresselinje_1 TEXT,
25+
address_adresselinje_2 TEXT,
26+
address_adresselinje_3 TEXT,
27+
address_postnummer TEXT,
28+
address_poststed TEXT,
29+
address_landkode TEXT,
30+
navn TEXT
3031
);
3132

3233
ALTER TABLE klage.behandling

0 commit comments

Comments
 (0)