Skip to content

Commit be69d7d

Browse files
committed
Read out form snapshot from database JSON to object
Some renaming and refactoring: - Rename formFillout to formSnapshot - Rename motebehovSvar fields that are not in DTOs to formValues - Move some mapping functions in MotebehovService to PMotebehov
1 parent d9c8302 commit be69d7d

21 files changed

+418
-425
lines changed

src/main/kotlin/no/nav/syfo/metric/Metric.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package no.nav.syfo.metric
22

33
import io.micrometer.core.instrument.MeterRegistry
44
import io.micrometer.core.instrument.Tags
5-
import no.nav.syfo.motebehov.MotebehovSvar
5+
import no.nav.syfo.motebehov.MotebehovFormValues
66
import no.nav.syfo.motebehov.motebehovstatus.MotebehovSkjemaType
77
import no.nav.syfo.oppfolgingstilfelle.database.PersonOppfolgingstilfelle
88
import org.springframework.stereotype.Controller
@@ -150,28 +150,31 @@ class Metric @Inject constructor(
150150
fun tellBesvarMotebehov(
151151
activeOppfolgingstilfelle: PersonOppfolgingstilfelle,
152152
motebehovSkjemaType: MotebehovSkjemaType?,
153-
motebehovSvar: MotebehovSvar,
153+
motebehovFormValues: MotebehovFormValues,
154154
erInnloggetBrukerArbeidstaker: Boolean
155155
) {
156-
val harForklaring = motebehovSvar.forklaring?.isNotBlank() ?: false
156+
val harForklaring = motebehovFormValues.forklaring?.isNotBlank() ?: false
157157

158158
tellMotebehovBesvart(
159159
activeOppfolgingstilfelle,
160160
motebehovSkjemaType,
161-
motebehovSvar.harMotebehov,
161+
motebehovFormValues.harMotebehov,
162162
erInnloggetBrukerArbeidstaker
163163
)
164164
countDayInOppfolgingstilfelleMotebehovCreated(
165165
activeOppfolgingstilfelle,
166166
motebehovSkjemaType,
167-
motebehovSvar.harMotebehov,
167+
motebehovFormValues.harMotebehov,
168168
harForklaring,
169169
erInnloggetBrukerArbeidstaker
170170
)
171-
if (!motebehovSvar.harMotebehov) {
172-
tellMotebehovBesvartNeiAntallTegn(motebehovSvar.forklaring!!.length, erInnloggetBrukerArbeidstaker)
171+
if (!motebehovFormValues.harMotebehov) {
172+
tellMotebehovBesvartNeiAntallTegn(motebehovFormValues.forklaring!!.length, erInnloggetBrukerArbeidstaker)
173173
} else if (harForklaring) {
174-
tellMotebehovBesvartJaMedForklaringTegn(motebehovSvar.forklaring!!.length, erInnloggetBrukerArbeidstaker)
174+
tellMotebehovBesvartJaMedForklaringTegn(
175+
motebehovFormValues.forklaring!!.length,
176+
erInnloggetBrukerArbeidstaker
177+
)
175178
tellMotebehovBesvartJaMedForklaringAntall(erInnloggetBrukerArbeidstaker)
176179
}
177180
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package no.nav.syfo.motebehov
22

3-
import no.nav.syfo.motebehov.formFillout.*
3+
import no.nav.syfo.motebehov.formSnapshot.*
44
import no.nav.syfo.motebehov.motebehovstatus.MotebehovSkjemaType
55
import org.springframework.stereotype.Component
66

@@ -10,7 +10,7 @@ enum class MotebehovInnmelderType {
1010
}
1111

1212
@Component
13-
class ConvertLegacyMotebehovSvarFieldsHelper {
13+
class CreateFormSnapshotFromLegacyMotebehovHelper {
1414
private val formIdentifierArbeidsgiverSvarBehov = "motebehov-arbeidsgiver-svar"
1515
private val formIdentifierArbeidsgiverMeldBehov = "motebehov-arbeidsgiver-meld"
1616
private val formIdentifierArbeidsgiverUnknownSvarMeldBehov = "motebehov-arbeidsgiver-unknown"
@@ -20,7 +20,7 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
2020

2121
private val legacyFormsSemanticVersion = "0.1.0"
2222

23-
enum class MotebehovLegacyLabel(val label: String) {
23+
enum class MotebehovLegacyFormLabel(val label: String) {
2424
SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD("Har dere behov for et møte med NAV?"),
2525
SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD("Har du behov for et møte med NAV og arbeidsgiveren din?"),
2626
SVAR_HAR_BEHOV_RADIO_OPTION_YES("Ja, jeg mener det er behov for et møte"),
@@ -36,7 +36,7 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
3636
BEGRUNNELSE_TEXT_FIELD("Begrunnelse")
3737
}
3838

39-
private val formFilloutOptionIds = mapOf(
39+
private val formSnapshotOptionIds = mapOf(
4040
"svarHarBehovRadioOptionYes" to "ja",
4141
"svarHarBehovRadioOptionNo" to "nei"
4242
)
@@ -46,49 +46,112 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
4646
val onskerSykmelderDeltar: Boolean
4747
)
4848

49+
/**
50+
* Converts a "legacy motebehovSvar" with fields harMotebehov and forklaring to a FormSnapshot.
51+
* The returned FormSnapshot matches what the forms look like in production at the time of writing, which is before
52+
* an update to the frontend that will make the forms contain more fields, and that will make the frontend submit
53+
* a FormSnapshot instead of individual hard-coded field values.
54+
*/
55+
fun createFormSnapshotFromLegacyMotebehov(
56+
harMotebehov: Boolean,
57+
forklaring: String?,
58+
skjemaType: MotebehovSkjemaType?,
59+
motebehovInnmelderType: MotebehovInnmelderType
60+
): FormSnapshot {
61+
val fieldSnapshots = mutableListOf<FieldSnapshot>()
62+
63+
if (skjemaType == MotebehovSkjemaType.SVAR_BEHOV) {
64+
fieldSnapshots.add(
65+
createLegacySvarBehovRadioGroupField(
66+
harMotebehov,
67+
motebehovInnmelderType
68+
)
69+
)
70+
} else if (skjemaType == MotebehovSkjemaType.MELD_BEHOV) {
71+
fieldSnapshots.add(
72+
createLegacyMeldOnskerMoteCheckboxField(
73+
motebehovInnmelderType
74+
)
75+
)
76+
}
77+
78+
val (actualBegrunnelse, onskerAtSykmelderDeltar) =
79+
extractActualUserBegrunnelseAndOnskerSykmelderDeltarFromLegacyForklaring(forklaring)
80+
81+
// It was only the MELD_BEHOV form that had the "onskerSykmelderDeltar" checkbox.
82+
if (skjemaType == MotebehovSkjemaType.MELD_BEHOV || onskerAtSykmelderDeltar) {
83+
fieldSnapshots.add(
84+
createLegacyOnskerSykmelderDeltarCheckboxField(
85+
onskerAtSykmelderDeltar,
86+
motebehovInnmelderType
87+
)
88+
)
89+
}
90+
91+
fieldSnapshots.add(createLegacyBegrunnelseTextField(actualBegrunnelse, harMotebehov, skjemaType))
92+
93+
val formIdentifier = when (motebehovInnmelderType) {
94+
MotebehovInnmelderType.ARBEIDSGIVER ->
95+
when (skjemaType) {
96+
MotebehovSkjemaType.SVAR_BEHOV -> formIdentifierArbeidsgiverSvarBehov
97+
MotebehovSkjemaType.MELD_BEHOV -> formIdentifierArbeidsgiverMeldBehov
98+
else -> formIdentifierArbeidsgiverUnknownSvarMeldBehov
99+
}
100+
101+
MotebehovInnmelderType.ARBEIDSTAKER ->
102+
when (skjemaType) {
103+
MotebehovSkjemaType.SVAR_BEHOV -> formIdentifierArbeidstakerSvarBehov
104+
MotebehovSkjemaType.MELD_BEHOV -> formIdentifierArbeidstakerMeldBehov
105+
else -> formIdentifierArbeidstakerUnknownSvarMeldBehov
106+
}
107+
}
108+
109+
return FormSnapshot(formIdentifier, legacyFormsSemanticVersion, fieldSnapshots)
110+
}
111+
49112
fun createLegacyBegrunnelseTextField(
50113
begrunnelseTextValue: String,
51114
harMotebehov: Boolean,
52115
skjemaType: MotebehovSkjemaType?,
53-
): FilloutTextField = FilloutTextField(
116+
): TextFieldSnapshot = TextFieldSnapshot(
54117
fieldID = BEGRUNNELSE_TEXT_FIELD_ID,
55-
fieldLabel = MotebehovLegacyLabel.BEGRUNNELSE_TEXT_FIELD.label,
118+
fieldLabel = MotebehovLegacyFormLabel.BEGRUNNELSE_TEXT_FIELD.label,
56119
textValue = begrunnelseTextValue,
57120
wasOptional = skjemaType == MotebehovSkjemaType.MELD_BEHOV || harMotebehov
58121
)
59122

60123
fun createLegacySvarBehovRadioGroupField(
61124
harMotebehov: Boolean,
62125
motebehovInnmelderType: MotebehovInnmelderType
63-
): FilloutRadioGroupField {
64-
val optionIdYes = formFilloutOptionIds["svarHarBehovRadioOptionYes"]!!
65-
val optionIdNo = formFilloutOptionIds["svarHarBehovRadioOptionNo"]!!
126+
): RadioGroupFieldSnapshot {
127+
val optionIdYes = formSnapshotOptionIds["svarHarBehovRadioOptionYes"]!!
128+
val optionIdNo = formSnapshotOptionIds["svarHarBehovRadioOptionNo"]!!
66129

67-
val optionLabelYes = MotebehovLegacyLabel.SVAR_HAR_BEHOV_RADIO_OPTION_YES.label
68-
val optionLabelNo = MotebehovLegacyLabel.SVAR_HAR_BEHOV_RADIO_OPTION_NO.label
130+
val optionLabelYes = MotebehovLegacyFormLabel.SVAR_HAR_BEHOV_RADIO_OPTION_YES.label
131+
val optionLabelNo = MotebehovLegacyFormLabel.SVAR_HAR_BEHOV_RADIO_OPTION_NO.label
69132

70133
val selectedOptionId = if (harMotebehov) optionIdYes else optionIdNo
71134
val selectedOptionLabel = if (harMotebehov) optionLabelYes else optionLabelNo
72135

73-
return FilloutRadioGroupField(
136+
return RadioGroupFieldSnapshot(
74137
fieldID = SVAR_HAR_BEHOV_RADIO_GROUP_FIELD_ID,
75138
fieldLabel = motebehovInnmelderType.let {
76139
when (it) {
77140
MotebehovInnmelderType.ARBEIDSGIVER ->
78-
MotebehovLegacyLabel.SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD.label
141+
MotebehovLegacyFormLabel.SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD.label
79142
MotebehovInnmelderType.ARBEIDSTAKER ->
80-
MotebehovLegacyLabel.SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD.label
143+
MotebehovLegacyFormLabel.SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD.label
81144
}
82145
},
83146
selectedOptionId,
84147
selectedOptionLabel,
85148
options = listOf(
86-
FormFilloutFieldOption(
149+
FormSnapshotFieldOption(
87150
optionId = optionIdYes,
88151
optionLabel = optionLabelYes,
89152
wasSelected = harMotebehov
90153
),
91-
FormFilloutFieldOption(
154+
FormSnapshotFieldOption(
92155
optionId = optionIdNo,
93156
optionLabel = optionLabelNo,
94157
wasSelected = !harMotebehov
@@ -99,14 +162,14 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
99162

100163
fun createLegacyMeldOnskerMoteCheckboxField(
101164
motebehovInnmelderType: MotebehovInnmelderType
102-
): FilloutCheckboxField = FilloutCheckboxField(
165+
): SingleCheckboxFieldSnapshot = SingleCheckboxFieldSnapshot(
103166
fieldID = MELD_HAR_BEHOV_LEGACY_CHECKBOX_FIELD_ID,
104167
fieldLabel = motebehovInnmelderType.let {
105168
when (it) {
106169
MotebehovInnmelderType.ARBEIDSGIVER ->
107-
MotebehovLegacyLabel.MELD_ARBEIDSGIVER_ONSKER_MOTE_CHECKBOX.label
170+
MotebehovLegacyFormLabel.MELD_ARBEIDSGIVER_ONSKER_MOTE_CHECKBOX.label
108171
MotebehovInnmelderType.ARBEIDSTAKER ->
109-
MotebehovLegacyLabel.MELD_ARBEIDSTAKER_ONSKER_MOTE_CHECKBOX.label
172+
MotebehovLegacyFormLabel.MELD_ARBEIDSTAKER_ONSKER_MOTE_CHECKBOX.label
110173
}
111174
},
112175
wasChecked = true,
@@ -115,15 +178,15 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
115178
fun createLegacyOnskerSykmelderDeltarCheckboxField(
116179
onskerSykmelderDeltar: Boolean,
117180
motebehovInnmelderType: MotebehovInnmelderType,
118-
): FilloutCheckboxField = FilloutCheckboxField(
181+
): SingleCheckboxFieldSnapshot = SingleCheckboxFieldSnapshot(
119182
fieldID = ONSKER_SYKMELDER_DELTAR_CHECKBOX_FIELD_ID,
120183
fieldLabel = motebehovInnmelderType.let {
121184
when (it) {
122185
MotebehovInnmelderType.ARBEIDSGIVER ->
123-
MotebehovLegacyLabel.MELD_ARBEIDSGIVER_ONSKER_SYKMELDER_DELTAR_CHECKBOX.label
186+
MotebehovLegacyFormLabel.MELD_ARBEIDSGIVER_ONSKER_SYKMELDER_DELTAR_CHECKBOX.label
124187

125188
MotebehovInnmelderType.ARBEIDSTAKER ->
126-
MotebehovLegacyLabel.MELD_ARBEIDSTAKER_ONSKER_SYKMELDER_DELTAR_CHECKBOX.label
189+
MotebehovLegacyFormLabel.MELD_ARBEIDSTAKER_ONSKER_SYKMELDER_DELTAR_CHECKBOX.label
127190
}
128191
},
129192
wasChecked = onskerSykmelderDeltar,
@@ -164,67 +227,4 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
164227

165228
return ExtractedFromLegacyForklaring(actualBegrunnelse, onskerSykmelderDeltar)
166229
}
167-
168-
/**
169-
* Converts a "legacy motebehovSvar" with fields harMotebehov and forklaring to a FormFillout.
170-
* The returned FormFillout matches what the forms look like in production at the time of writing, which is before
171-
* an update to the frontend that will make the forms contain more fields, and that will make the frontend submit
172-
* a FormFillout instead of individual hard-coded field values.
173-
*/
174-
fun convertLegacyMotebehovSvarToFormFillout(
175-
harMotebehov: Boolean,
176-
forklaring: String?,
177-
skjemaType: MotebehovSkjemaType?,
178-
motebehovInnmelderType: MotebehovInnmelderType
179-
): FormFillout {
180-
val formFilloutFields = mutableListOf<FilloutField>()
181-
182-
if (skjemaType == MotebehovSkjemaType.SVAR_BEHOV) {
183-
formFilloutFields.add(
184-
createLegacySvarBehovRadioGroupField(
185-
harMotebehov,
186-
motebehovInnmelderType
187-
)
188-
)
189-
} else if (skjemaType == MotebehovSkjemaType.MELD_BEHOV) {
190-
formFilloutFields.add(
191-
createLegacyMeldOnskerMoteCheckboxField(
192-
motebehovInnmelderType
193-
)
194-
)
195-
}
196-
197-
val (actualBegrunnelse, onskerAtSykmelderDeltar) =
198-
extractActualUserBegrunnelseAndOnskerSykmelderDeltarFromLegacyForklaring(forklaring)
199-
200-
// It was only the MELD_BEHOV form that had the "onskerSykmelderDeltar" checkbox.
201-
if (skjemaType == MotebehovSkjemaType.MELD_BEHOV || onskerAtSykmelderDeltar) {
202-
formFilloutFields.add(
203-
createLegacyOnskerSykmelderDeltarCheckboxField(
204-
onskerAtSykmelderDeltar,
205-
motebehovInnmelderType
206-
)
207-
)
208-
}
209-
210-
formFilloutFields.add(createLegacyBegrunnelseTextField(actualBegrunnelse, harMotebehov, skjemaType))
211-
212-
val formIdentifier = when (motebehovInnmelderType) {
213-
MotebehovInnmelderType.ARBEIDSGIVER ->
214-
when (skjemaType) {
215-
MotebehovSkjemaType.SVAR_BEHOV -> formIdentifierArbeidsgiverSvarBehov
216-
MotebehovSkjemaType.MELD_BEHOV -> formIdentifierArbeidsgiverMeldBehov
217-
else -> formIdentifierArbeidsgiverUnknownSvarMeldBehov
218-
}
219-
220-
MotebehovInnmelderType.ARBEIDSTAKER ->
221-
when (skjemaType) {
222-
MotebehovSkjemaType.SVAR_BEHOV -> formIdentifierArbeidstakerSvarBehov
223-
MotebehovSkjemaType.MELD_BEHOV -> formIdentifierArbeidstakerMeldBehov
224-
else -> formIdentifierArbeidstakerUnknownSvarMeldBehov
225-
}
226-
}
227-
228-
return FormFillout(formIdentifier, legacyFormsSemanticVersion, formFilloutFields)
229-
}
230230
}

src/main/kotlin/no/nav/syfo/motebehov/Motebehov.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class Motebehov(
1717
val opprettetAvFnr: String,
1818
val arbeidstakerFnr: String,
1919
val virksomhetsnummer: String,
20-
val motebehovSvar: MotebehovSvar,
20+
val formValues: MotebehovFormValues,
2121
val tildeltEnhet: String? = null,
2222
val behandletTidspunkt: LocalDateTime? = null,
2323
val behandletVeilederIdent: String? = null,
@@ -32,7 +32,7 @@ data class MotebehovOutputDTO(
3232
val opprettetAvFnr: String,
3333
val arbeidstakerFnr: String,
3434
val virksomhetsnummer: String,
35-
val motebehovSvar: MotebehovSvarOutputDTO,
35+
val motebehovSvar: MotebehovFormValuesOutputDTO,
3636
val tildeltEnhet: String? = null,
3737
val behandletTidspunkt: LocalDateTime? = null,
3838
val behandletVeilederIdent: String? = null,
@@ -51,15 +51,15 @@ fun Motebehov.toMotebehovVeilederDTO(): MotebehovVeilederDTO {
5151
opprettetAvNavn = null,
5252
arbeidstakerFnr = this.arbeidstakerFnr,
5353
virksomhetsnummer = this.virksomhetsnummer,
54-
motebehovSvar = this.motebehovSvar.toMotebehovSvarOutputDTO(),
54+
motebehovSvar = this.formValues.toMotebehovFormValuesOutputDTO(),
5555
tildeltEnhet = this.tildeltEnhet,
5656
behandletTidspunkt = this.behandletTidspunkt,
5757
behandletVeilederIdent = this.behandletVeilederIdent, skjemaType = this.skjemaType,
5858
)
5959
}
6060

6161
fun Motebehov.isUbehandlet(): Boolean {
62-
return this.motebehovSvar.harMotebehov && this.behandletVeilederIdent.isNullOrEmpty()
62+
return this.formValues.harMotebehov && this.behandletVeilederIdent.isNullOrEmpty()
6363
}
6464

6565
fun Motebehov.isCreatedInOppfolgingstilfelle(oppfolgingstilfelle: PersonOppfolgingstilfelle): Boolean {
@@ -76,19 +76,18 @@ fun Motebehov.isSvarBehovForOppfolgingstilfelle(oppfolgingstilfelle: PersonOppfo
7676
createdDate.isBefore(lastDateSvarBehovAvailability.plusDays(1))
7777
}
7878

79-
fun Motebehov.toMotebehovOutputDTO(): MotebehovOutputDTO {
80-
return MotebehovOutputDTO(
79+
fun Motebehov.toMotebehovOutputDTO(): MotebehovOutputDTO =
80+
MotebehovOutputDTO(
8181
id = this.id,
8282
opprettetDato = this.opprettetDato,
8383
aktorId = this.aktorId,
8484
opprettetAv = this.opprettetAv,
8585
opprettetAvFnr = this.opprettetAvFnr,
8686
arbeidstakerFnr = this.arbeidstakerFnr,
8787
virksomhetsnummer = this.virksomhetsnummer,
88-
motebehovSvar = this.motebehovSvar.toMotebehovSvarOutputDTO(),
88+
motebehovSvar = this.formValues.toMotebehovFormValuesOutputDTO(),
8989
tildeltEnhet = this.tildeltEnhet,
9090
behandletTidspunkt = this.behandletTidspunkt,
9191
behandletVeilederIdent = this.behandletVeilederIdent,
9292
skjemaType = this.skjemaType,
9393
)
94-
}

0 commit comments

Comments
 (0)