1
1
package no.nav.syfo.motebehov
2
2
3
- import no.nav.syfo.motebehov.formFillout .*
3
+ import no.nav.syfo.motebehov.formSnapshot .*
4
4
import no.nav.syfo.motebehov.motebehovstatus.MotebehovSkjemaType
5
5
import org.springframework.stereotype.Component
6
6
@@ -10,7 +10,7 @@ enum class MotebehovInnmelderType {
10
10
}
11
11
12
12
@Component
13
- class ConvertLegacyMotebehovSvarFieldsHelper {
13
+ class CreateFormSnapshotFromLegacyMotebehovHelper {
14
14
private val formIdentifierArbeidsgiverSvarBehov = " motebehov-arbeidsgiver-svar"
15
15
private val formIdentifierArbeidsgiverMeldBehov = " motebehov-arbeidsgiver-meld"
16
16
private val formIdentifierArbeidsgiverUnknownSvarMeldBehov = " motebehov-arbeidsgiver-unknown"
@@ -20,7 +20,7 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
20
20
21
21
private val legacyFormsSemanticVersion = " 0.1.0"
22
22
23
- enum class MotebehovLegacyLabel (val label : String ) {
23
+ enum class MotebehovLegacyFormLabel (val label : String ) {
24
24
SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD (" Har dere behov for et møte med NAV?" ),
25
25
SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD (" Har du behov for et møte med NAV og arbeidsgiveren din?" ),
26
26
SVAR_HAR_BEHOV_RADIO_OPTION_YES (" Ja, jeg mener det er behov for et møte" ),
@@ -36,7 +36,7 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
36
36
BEGRUNNELSE_TEXT_FIELD (" Begrunnelse" )
37
37
}
38
38
39
- private val formFilloutOptionIds = mapOf (
39
+ private val formSnapshotOptionIds = mapOf (
40
40
" svarHarBehovRadioOptionYes" to " ja" ,
41
41
" svarHarBehovRadioOptionNo" to " nei"
42
42
)
@@ -46,49 +46,112 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
46
46
val onskerSykmelderDeltar : Boolean
47
47
)
48
48
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
+
49
112
fun createLegacyBegrunnelseTextField (
50
113
begrunnelseTextValue : String ,
51
114
harMotebehov : Boolean ,
52
115
skjemaType : MotebehovSkjemaType ? ,
53
- ): FilloutTextField = FilloutTextField (
116
+ ): TextFieldSnapshot = TextFieldSnapshot (
54
117
fieldID = BEGRUNNELSE_TEXT_FIELD_ID ,
55
- fieldLabel = MotebehovLegacyLabel .BEGRUNNELSE_TEXT_FIELD .label,
118
+ fieldLabel = MotebehovLegacyFormLabel .BEGRUNNELSE_TEXT_FIELD .label,
56
119
textValue = begrunnelseTextValue,
57
120
wasOptional = skjemaType == MotebehovSkjemaType .MELD_BEHOV || harMotebehov
58
121
)
59
122
60
123
fun createLegacySvarBehovRadioGroupField (
61
124
harMotebehov : Boolean ,
62
125
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" ]!!
66
129
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
69
132
70
133
val selectedOptionId = if (harMotebehov) optionIdYes else optionIdNo
71
134
val selectedOptionLabel = if (harMotebehov) optionLabelYes else optionLabelNo
72
135
73
- return FilloutRadioGroupField (
136
+ return RadioGroupFieldSnapshot (
74
137
fieldID = SVAR_HAR_BEHOV_RADIO_GROUP_FIELD_ID ,
75
138
fieldLabel = motebehovInnmelderType.let {
76
139
when (it) {
77
140
MotebehovInnmelderType .ARBEIDSGIVER ->
78
- MotebehovLegacyLabel .SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD .label
141
+ MotebehovLegacyFormLabel .SVAR_ARBEIDSGIVER_HAR_BEHOV_FIELD .label
79
142
MotebehovInnmelderType .ARBEIDSTAKER ->
80
- MotebehovLegacyLabel .SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD .label
143
+ MotebehovLegacyFormLabel .SVAR_ARBEIDSTAKER_HAR_BEHOV_FIELD .label
81
144
}
82
145
},
83
146
selectedOptionId,
84
147
selectedOptionLabel,
85
148
options = listOf (
86
- FormFilloutFieldOption (
149
+ FormSnapshotFieldOption (
87
150
optionId = optionIdYes,
88
151
optionLabel = optionLabelYes,
89
152
wasSelected = harMotebehov
90
153
),
91
- FormFilloutFieldOption (
154
+ FormSnapshotFieldOption (
92
155
optionId = optionIdNo,
93
156
optionLabel = optionLabelNo,
94
157
wasSelected = ! harMotebehov
@@ -99,14 +162,14 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
99
162
100
163
fun createLegacyMeldOnskerMoteCheckboxField (
101
164
motebehovInnmelderType : MotebehovInnmelderType
102
- ): FilloutCheckboxField = FilloutCheckboxField (
165
+ ): SingleCheckboxFieldSnapshot = SingleCheckboxFieldSnapshot (
103
166
fieldID = MELD_HAR_BEHOV_LEGACY_CHECKBOX_FIELD_ID ,
104
167
fieldLabel = motebehovInnmelderType.let {
105
168
when (it) {
106
169
MotebehovInnmelderType .ARBEIDSGIVER ->
107
- MotebehovLegacyLabel .MELD_ARBEIDSGIVER_ONSKER_MOTE_CHECKBOX .label
170
+ MotebehovLegacyFormLabel .MELD_ARBEIDSGIVER_ONSKER_MOTE_CHECKBOX .label
108
171
MotebehovInnmelderType .ARBEIDSTAKER ->
109
- MotebehovLegacyLabel .MELD_ARBEIDSTAKER_ONSKER_MOTE_CHECKBOX .label
172
+ MotebehovLegacyFormLabel .MELD_ARBEIDSTAKER_ONSKER_MOTE_CHECKBOX .label
110
173
}
111
174
},
112
175
wasChecked = true ,
@@ -115,15 +178,15 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
115
178
fun createLegacyOnskerSykmelderDeltarCheckboxField (
116
179
onskerSykmelderDeltar : Boolean ,
117
180
motebehovInnmelderType : MotebehovInnmelderType ,
118
- ): FilloutCheckboxField = FilloutCheckboxField (
181
+ ): SingleCheckboxFieldSnapshot = SingleCheckboxFieldSnapshot (
119
182
fieldID = ONSKER_SYKMELDER_DELTAR_CHECKBOX_FIELD_ID ,
120
183
fieldLabel = motebehovInnmelderType.let {
121
184
when (it) {
122
185
MotebehovInnmelderType .ARBEIDSGIVER ->
123
- MotebehovLegacyLabel .MELD_ARBEIDSGIVER_ONSKER_SYKMELDER_DELTAR_CHECKBOX .label
186
+ MotebehovLegacyFormLabel .MELD_ARBEIDSGIVER_ONSKER_SYKMELDER_DELTAR_CHECKBOX .label
124
187
125
188
MotebehovInnmelderType .ARBEIDSTAKER ->
126
- MotebehovLegacyLabel .MELD_ARBEIDSTAKER_ONSKER_SYKMELDER_DELTAR_CHECKBOX .label
189
+ MotebehovLegacyFormLabel .MELD_ARBEIDSTAKER_ONSKER_SYKMELDER_DELTAR_CHECKBOX .label
127
190
}
128
191
},
129
192
wasChecked = onskerSykmelderDeltar,
@@ -164,67 +227,4 @@ class ConvertLegacyMotebehovSvarFieldsHelper {
164
227
165
228
return ExtractedFromLegacyForklaring (actualBegrunnelse, onskerSykmelderDeltar)
166
229
}
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
- }
230
230
}
0 commit comments