# AroundThePregnancyHelper.kt

    /*
     * The MIT License
     *
     * Original work sponsored and donated by The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     * Copyright (C) 2020 The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy of
     * this software and associated documentation files (the "Software"), to deal in
     * the Software without restriction, including without limitation the rights to
     * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     * of the Software, and to permit persons to whom the Software is furnished to do
     * so, subject to the following conditions:
     *
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */

    package dk.nsp.mingraviditet.ui.main.journal.sections.sectiondetails.aroundthepregnancy

    import dk.nsp.domain.dictionary.DictionaryEntry
    import dk.nsp.domain.journal.observations.JournalSectionRow
    import dk.nsp.domain.repository.DataCardRepository
    import dk.nsp.domain.repository.DictionaryRepository
    import dk.nsp.mingraviditet.R
    import dk.nsp.mingraviditet.ui.adapterviews.KeyValueData
    import dk.nsp.mingraviditet.ui.adapterviews.KeyValueRow
    import dk.nsp.mingraviditet.ui.adapterviews.KeyValueSectionHeader
    import dk.nsp.mingraviditet.ui.main.journal.extensions.toCommaSeparatedTextModel
    import dk.nsp.mingraviditet.ui.main.journal.extensions.toTextModel
    import dk.nsp.mingraviditet.util.android.recycler.RecyclerAdapterView
    import dk.nsp.mingraviditet.util.extensions.toTextModelOrDefault
    import dk.nsp.mingraviditet.util.extensions.toYesNoTextModelOrDefault
    import dk.nsp.shared.util.extensions.toMediumFormat
    import dk.nsp.util.textmodel.TextModel
    import kotlinx.coroutines.CoroutineScope

    class AroundThePregnancyHelper(
        private val dataCardRepository: DataCardRepository,
        private val dictionaryRepository: DictionaryRepository
    ) {

        private fun getDictionaryEntryFor(
            scope: CoroutineScope,
            key: TextModel
        ): DictionaryEntry? {
            return dictionaryRepository.getDictionaryEntryFor(scope, key)
        }

        fun getExpectedDateOfBirthSection(scope: CoroutineScope): List<JournalSectionRow> {
            val dataCard = dataCardRepository.currentDataCard.value
            val expectedDateOfDeliverySection =
                dataCard?.expectedDateOfDeliverySection

            val expectedDateOfDeliveryFromUltrasoundScanKey =
                TextModel.from(R.string.journal_section_scans_expected_date_of_delivery_from_prenatal_ultrasound_scan)
            val lastFirstDayOfMenstrualCycleKey =
                TextModel.from(R.string.journal_section_expected_date_of_birth_last_first_day_of_menstrual_cycle)
            val daysInMenstrualCycleKey =
                TextModel.from(R.string.journal_section_expected_date_of_birth_days_in_cycle)
            val calculatedDateOfBirthKey =
                TextModel.from(R.string.journal_section_expected_date_of_birth_calculated_date_of_birth)
            val cycleCertaintyKey =
                TextModel.from(R.string.journal_section_expected_date_of_birth_cycle_certainty)
            val remarksKey =
                TextModel.from(R.string.journal_section_expected_date_of_birth_remarks)

            return listOf(
                JournalSectionRow(
                    expectedDateOfDeliveryFromUltrasoundScanKey,
                    dataCard?.ultrasoundSection?.expectedDateOfDeliveryFromPrenatalUltrasoundScan.toMediumFormat()
                        .toTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(
                        scope,
                        expectedDateOfDeliveryFromUltrasoundScanKey
                    )
                ),
                JournalSectionRow(
                    lastFirstDayOfMenstrualCycleKey,
                    expectedDateOfDeliverySection?.expectedDateOfDeliveryFromLastPeriod.lastFirstDayOfCycleToTextModel(),
                    null,
                    getDictionaryEntryFor(scope, lastFirstDayOfMenstrualCycleKey)
                ),
                JournalSectionRow(
                    daysInMenstrualCycleKey,
                    expectedDateOfDeliverySection?.expectedDateOfDeliveryFromLastPeriod?.menstrualCycle.toTextModel(),
                    null,
                    getDictionaryEntryFor(scope, daysInMenstrualCycleKey)
                ),
                JournalSectionRow(
                    calculatedDateOfBirthKey,
                    expectedDateOfDeliverySection?.expectedDateOfDeliveryFromLastPeriod.getCalculatedExpectedDeliveryDate(),
                    null,
                    getDictionaryEntryFor(scope, calculatedDateOfBirthKey)
                ),
                JournalSectionRow(
                    cycleCertaintyKey,
                    expectedDateOfDeliverySection?.expectedDateOfDeliveryFromLastPeriod?.certainty.toTextModel(),
                    null,
                    getDictionaryEntryFor(scope, cycleCertaintyKey)
                ),
                JournalSectionRow(
                    remarksKey,
                    expectedDateOfDeliverySection?.remarks.toTextModelOrDefault(),
                    null,
                    null
                )
            )
        }

        fun getAssistedFertilitySection(scope: CoroutineScope): List<JournalSectionRow> {
            val dataCard = dataCardRepository.currentDataCard.value
            val assistedFertilizationSection =
                dataCard?.assistedFertilizationSection
            val treatmentTypeKey =
                TextModel.from(R.string.journal_section_assisted_fertilization_type)
            val remarksKey =
                TextModel.from(R.string.journal_section_assisted_fertilization_remarks)

            return listOf(
                JournalSectionRow(
                    treatmentTypeKey,
                    assistedFertilizationSection?.type.toTextModel(),
                    null,
                    getDictionaryEntryFor(scope, treatmentTypeKey)
                ),
                JournalSectionRow(
                    remarksKey,
                    assistedFertilizationSection?.remarks.toTextModelOrDefault(),
                    null,
                    null
                )
            )
        }

        fun getRiskAssessmentSection(scope: CoroutineScope): List<JournalSectionRow> {
            val dataCard = dataCardRepository.currentDataCard.value
            val prenatalRiskAssessmentSection =
                dataCard?.prenatalRiskAssessmentSection
            val familyHistoryKey =
                TextModel.from(R.string.journal_section_risk_assessment_family_history)
            val consanguinityKey =
                TextModel.from(R.string.journal_section_risk_assessment_consanguinity)
            val firstTrimesterScanRequestedKey =
                TextModel.from(R.string.journal_section_risk_assessment_requested_scan_first_trimester)
            val secondTrimesterScanRequestedKey =
                TextModel.from(R.string.journal_section_risk_assessment_requested_scan_second_trimester)
            val wantsRiskAssessmentKey =
                TextModel.from(R.string.journal_section_risk_assessment_wants_risk_assessment)

            return listOf(
                JournalSectionRow(
                    familyHistoryKey,
                    prenatalRiskAssessmentSection?.riskAssessment1?.familyHistory.toTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(scope, familyHistoryKey)
                ),
                JournalSectionRow(
                    consanguinityKey,
                    prenatalRiskAssessmentSection?.riskAssessment1?.consanguinity.toYesNoTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(scope, consanguinityKey)
                ),
                JournalSectionRow(
                    firstTrimesterScanRequestedKey,
                    prenatalRiskAssessmentSection?.riskAssessment1?.firstTrimesterUltrasoundScanOfFetusRequested.toYesNoTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(scope, firstTrimesterScanRequestedKey)
                ),
                JournalSectionRow(
                    secondTrimesterScanRequestedKey,
                    prenatalRiskAssessmentSection?.riskAssessment1?.secondTrimesterUltrasoundScanOfFetusRequested.toYesNoTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(scope, secondTrimesterScanRequestedKey)
                ),
                JournalSectionRow(
                    wantsRiskAssessmentKey,
                    prenatalRiskAssessmentSection?.riskAssessment1?.prenatalRiskAssessmentRequested.toYesNoTextModelOrDefault(),
                    null,
                    getDictionaryEntryFor(scope, wantsRiskAssessmentKey)
                )
            )
        }

        fun getHealthSection(
            scope: CoroutineScope,
            onDictionaryCallback: (DictionaryEntry) -> Unit
        ): List<RecyclerAdapterView<*>> {
            val dataCard = dataCardRepository.currentDataCard.value
            val allergiesSection = dataCard?.allergiesSection
            val chronicDiseasesSection = dataCard?.chronicDiseasesSection
            val medicineSection = dataCard?.medicineSection
            val vaccinationSection = dataCard?.mmrVaccinationSection

            val maternalAllergiesKey =
                TextModel.Companion.from(R.string.journal_section_health_maternal_allergies)
            val allergyPredispositionOfChild =
                TextModel.Companion.from(R.string.journal_section_health_child_predisposition)

            val allergyDictionaryEntry =
                getDictionaryEntryFor(scope, maternalAllergiesKey)
            val allergyPredispositionOfChildDictEntry =
                getDictionaryEntryFor(scope, allergyPredispositionOfChild)

            val allergyRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_health_allergies_title)),
                KeyValueRow(KeyValueData(
                    maternalAllergiesKey,
                    allergiesSection?.allergiesOfMother.toTextModelOrDefault(),
                    null,
                    allergyDictionaryEntry?.let { { onDictionaryCallback(it) } }
                )),
                KeyValueRow(
                    KeyValueData(
                        allergyPredispositionOfChild,
                        allergiesSection?.allergicPredispositionOfChild.toTextModel(),
                        null,
                        allergyPredispositionOfChildDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                )
            )

            val chronicConditionsKey =
                TextModel.from(R.string.journal_section_health_chronic_diseases_relevant_to_pregnancy)
            val chronicDiseasesCommentKey =
                TextModel.from(R.string.journal_section_health_chronic_diseases_remarks)
            val chronicConditionsDictEntry =
                getDictionaryEntryFor(scope, chronicConditionsKey)

            val chronicConditionsRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_health_chronic_diseases_title)),
                KeyValueRow(KeyValueData(
                    chronicConditionsKey,
                    chronicDiseasesSection?.conditions.toTextModel(),
                    null,
                    chronicConditionsDictEntry?.let { { onDictionaryCallback(it) } }
                )),
                KeyValueRow(
                    KeyValueData(
                        chronicDiseasesCommentKey,
                        chronicDiseasesSection?.comment.toTextModelOrDefault(),
                        null,
                        null
                    )
                )
            )

            val realMedicineKey =
                TextModel.from(R.string.journal_section_health_information_about_medicine)
            val natureMedicineKey =
                TextModel.from(R.string.journal_section_health_information_about_nature_medicine)

            val realMedicineDictEntry =
                getDictionaryEntryFor(scope, realMedicineKey)
            val natureMedicineDictEntry =
                getDictionaryEntryFor(scope, natureMedicineKey)
            val medicineRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_health_medicine_title)),
                KeyValueRow(KeyValueData(
                    realMedicineKey,
                    medicineSection?.realMedicine.toTextModelOrDefault(),
                    null,
                    realMedicineDictEntry?.let { { onDictionaryCallback(it) } }
                )),
                KeyValueRow(
                    KeyValueData(
                        natureMedicineKey,
                        medicineSection?.natureMedicine.toTextModelOrDefault(),
                        null,
                        natureMedicineDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                )
            )

            val mmrVaccinationKey =
                TextModel.from(R.string.journal_section_health_mfr_vaccination)
            val mmrVaccinationDictEntry =
                getDictionaryEntryFor(scope, mmrVaccinationKey)

            val vaccinationRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_health_vaccination_title)),
                KeyValueRow(
                    KeyValueData(
                        mmrVaccinationKey,
                        vaccinationSection?.status.toTextModel(),
                        null,
                        mmrVaccinationDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                )
            )

            val previousTreatmentWithImpactOnPregnancyKey =
                TextModel.from(R.string.journal_section_health_previous_treatment_with_impact_on_pregnancy)
            val previousTreatmentWithImpactOnPregnancyDictEntry =
                getDictionaryEntryFor(
                    scope,
                    previousTreatmentWithImpactOnPregnancyKey
                )

            val previousTreatmentWithImpactOnPregnancyRows = listOf(
                KeyValueSectionHeader(TextModel.Companion.from(R.string.journal_section_health_previous_treatment_with_impact_on_pregnancy_title)),
                KeyValueRow(KeyValueData(
                    previousTreatmentWithImpactOnPregnancyKey,
                    dataCard?.historyOfPreviousTreatmentWithImpactOnPregnancySection?.history.toTextModelOrDefault(),
                    null,
                    previousTreatmentWithImpactOnPregnancyDictEntry?.let {
                        {
                            onDictionaryCallback(
                                it
                            )
                        }
                    }
                ))
            )

            val finalList = mutableListOf<RecyclerAdapterView<*>>()
            with(finalList) {
                addAll(allergyRows)
                addAll(chronicConditionsRows)
                addAll(medicineRows)
                addAll(vaccinationRows)
                addAll(previousTreatmentWithImpactOnPregnancyRows)
            }

            return finalList
        }

        fun getLifestyleSection(
            scope: CoroutineScope,
            onDictionaryCallback: (DictionaryEntry) -> Unit
        ): List<RecyclerAdapterView<*>> {
            val dataCard = dataCardRepository.currentDataCard.value
            val tobaccoUseAndExposureSection =
                dataCard?.tobaccoUseAndExposureSection
            val alcoholDrinkingBehaviorSection =
                dataCard?.alcoholDrinkingBehaviorSection
            val substanceUseSection = dataCard?.substanceUseSection
            val dietaryAndExerciseSection = dataCard?.dietaryAndExerciseSection

            val tobaccoUsageBeforePregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_tobacco_before_pregnancy)
            val tobaccoEndDateKey =
                TextModel.from(R.string.journal_section_lifestyle_tobacco_end_date)
            val tobaccoSmokingDuringPregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_tobacco_smoking_during_pregnancy)
            val tobacooSmokeStopReferredKey =
                TextModel.from(R.string.journal_section_lifestyle_tobacco_smoking_stop_referred)
            val tobaccoEnvironmentalExposureKey =
                TextModel.from(R.string.journal_section_lifestyle_tobacco_exposure_to_environmental_smoke)

            val tobaccoUsageBeforePregnancyDictEntry =
                getDictionaryEntryFor(scope, tobaccoUsageBeforePregnancyKey)
            val tobaccoEndDateDictEntry =
                getDictionaryEntryFor(scope, tobaccoEndDateKey)
            val tobaccoSmokingDuringPregnancyDictEntry =
                getDictionaryEntryFor(scope, tobaccoSmokingDuringPregnancyKey)
            val tobaccoEnvironmentalExposureDictEntry =
                getDictionaryEntryFor(scope, tobaccoEnvironmentalExposureKey)

            val tobaccoRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_lifestyle_tobacco_title)),
                KeyValueRow(
                    KeyValueData(
                        tobaccoUsageBeforePregnancyKey,
                        tobaccoUseAndExposureSection?.tobaccoUser.toTextModel(),
                        null,
                        tobaccoUsageBeforePregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        tobaccoEndDateKey,
                        tobaccoUseAndExposureSection?.endDate?.toMediumFormat()
                            .toTextModelOrDefault(),
                        null,
                        tobaccoEndDateDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        tobaccoSmokingDuringPregnancyKey,
                        tobaccoUseAndExposureSection?.smokeDuringPregnancy.toTextModel(),
                        null,
                        tobaccoSmokingDuringPregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )),
                KeyValueRow(
                    KeyValueData(
                        tobacooSmokeStopReferredKey,
                        tobaccoUseAndExposureSection?.referredToTobaccoCessationEducation.toTextModel(),
                        null,
                        tobaccoSmokingDuringPregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )),
                KeyValueRow(
                    KeyValueData(
                        tobaccoEnvironmentalExposureKey,
                        tobaccoUseAndExposureSection?.exposureToEnvironmentalTobaccoSmoke.toTextModel(),
                        null,
                        tobaccoEnvironmentalExposureDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ))

            val usageBeforePregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_before_usage)
            val averageConsumptionBeforePregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_before_average_consumption)
            val usageDuringPregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_during_usage)
            val averageConsumptionDuringPregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_during_average_consumption)
            val excessiveDrinkingKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_during_excessive_drinking)
            val excessiveDrinkingWeeksKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_during_excessive_drinking_weeks)
            val tweakPointsKey =
                TextModel.from(R.string.journal_section_lifestyle_alcohol_tweak_points)

            val usageBeforePregnancyDictEntry =
                getDictionaryEntryFor(scope, usageBeforePregnancyKey)
            val averageConsumptionBeforePregnancyDictEntry =
                getDictionaryEntryFor(scope, averageConsumptionBeforePregnancyKey)
            val usageDuringPregnancyDictEntry =
                getDictionaryEntryFor(scope, usageDuringPregnancyKey)
            val averageConsumptionDuringPregnancyDictEntry =
                getDictionaryEntryFor(scope, averageConsumptionDuringPregnancyKey)
            val excessiveDrinkingDictEntry =
                getDictionaryEntryFor(scope, excessiveDrinkingKey)
            val excessiveDrinkingWeeksDictEntry =
                getDictionaryEntryFor(scope, excessiveDrinkingWeeksKey)
            val tweakPointsDictEntry = getDictionaryEntryFor(scope, tweakPointsKey)

            val alcoholDrinkingBehaviorRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_lifestyle_alcohol_title)),
                KeyValueRow(
                    KeyValueData(
                        usageBeforePregnancyKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionBeforePregnancy?.consumesAlcohol.toTextModel(),
                        null,
                        usageBeforePregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(KeyValueData(
                    averageConsumptionBeforePregnancyKey,
                    alcoholDrinkingBehaviorSection?.weeklyConsumptionBeforePregnancy.getConsumption(),
                    null,
                    averageConsumptionBeforePregnancyDictEntry?.let {
                        {
                            onDictionaryCallback(
                                it
                            )
                        }
                    }
                )),
                KeyValueRow(
                    KeyValueData(
                        usageDuringPregnancyKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionDuringPregnancy?.consumesAlcohol.toTextModel(),
                        null,
                        usageDuringPregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        averageConsumptionDuringPregnancyKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionDuringPregnancy.getAverageConsumption(),
                        null,
                        averageConsumptionDuringPregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        excessiveDrinkingKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionDuringPregnancy.getExcessiveDrinkingCount(),
                        null,
                        excessiveDrinkingDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        excessiveDrinkingWeeksKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionDuringPregnancy.getExcessiveDrinkingWeeks(),
                        null,
                        excessiveDrinkingWeeksDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        tweakPointsKey,
                        alcoholDrinkingBehaviorSection?.weeklyConsumptionDuringPregnancy.getTweakPoints(),
                        null,
                        tweakPointsDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                )
            )

            val substanceUseBeforePregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_substance_use_before_pregnancy)
            val substanceUseBeforePregnancyTextKey =
                TextModel.from(R.string.journal_section_lifestyle_substance_use_before_pregnancy_text)
            val substanceUseDuringPregnancyKey =
                TextModel.from(R.string.journal_section_lifestyle_substance_use_during_pregnancy)
            val substanceUseDuringPregnancyTextKey =
                TextModel.from(R.string.journal_section_lifestyle_substance_use_during_pregnancy_text)

            val substanceUseBeforePregnancyDictEntry =
                getDictionaryEntryFor(scope, substanceUseBeforePregnancyKey)
            val substanceUseDuringPregnancyDictEntry =
                getDictionaryEntryFor(scope, substanceUseDuringPregnancyKey)

            val substanceUseRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_lifestyle_substance_use_title)),
                KeyValueRow(KeyValueData(
                    substanceUseBeforePregnancyKey,
                    substanceUseSection?.substanceUseBeforePregnancy?.substanceUse.toTextModel(),
                    null,
                    substanceUseBeforePregnancyDictEntry?.let {
                        {
                            onDictionaryCallback(
                                it
                            )
                        }
                    }
                )),
                KeyValueRow(
                    KeyValueData(
                        substanceUseBeforePregnancyTextKey,
                        substanceUseSection?.substanceUseBeforePregnancy?.text.toTextModelOrDefault(),
                        null,
                        null
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        substanceUseDuringPregnancyKey,
                        substanceUseSection?.substanceUseDuringPregnancy?.substanceUse.toTextModel(),
                        null,
                        substanceUseDuringPregnancyDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        substanceUseDuringPregnancyTextKey,
                        substanceUseSection?.substanceUseDuringPregnancy?.text.toTextModelOrDefault(),
                        null,
                        null
                    )
                )
            )

            val dietaryAndExerciseTextKey =
                TextModel.from(R.string.journal_section_lifestyle_dietary_and_exercise_text)
            val dietaryAndExerciseTextDictEntry =
                getDictionaryEntryFor(scope, dietaryAndExerciseTextKey)
            val dietaryAndExerciseRows = listOf(
                KeyValueSectionHeader(TextModel.from(R.string.journal_section_lifestyle_dietary_and_exercise_title)),
                KeyValueRow(KeyValueData(
                    dietaryAndExerciseTextKey,
                    dietaryAndExerciseSection?.text.toTextModelOrDefault(),
                    null,
                    dietaryAndExerciseTextDictEntry?.let {
                        {
                            onDictionaryCallback(
                                it
                            )
                        }
                    }
                ))
            )

            return mutableListOf<RecyclerAdapterView<*>>().apply {
                addAll(tobaccoRows)
                addAll(alcoholDrinkingBehaviorRows)
                addAll(substanceUseRows)
                addAll(dietaryAndExerciseRows)
            }
        }

        fun getWorkEnvironmentSection(
            scope: CoroutineScope,
            onDictionaryCallback: (DictionaryEntry) -> Unit
        ): List<KeyValueRow> {
            val dataCard = dataCardRepository.currentDataCard.value
            val workEnvironmentImpactSection =
                dataCard?.workEnvironmentImpactSection

            val mothersJobKey =
                TextModel.from(R.string.journal_section_work_environment_mothers_job)
            val mothersWorkingHoursKey =
                TextModel.from(R.string.journal_section_work_environment_mothers_work_hours_per_week)
            val exposureToRiskKey =
                TextModel.from(R.string.journal_section_work_environment_exposure_to_risk)
            val typeOfExposureKey =
                TextModel.from(R.string.journal_section_work_environment_type_of_exposure)
            val durationOfExposureKey =
                TextModel.from(R.string.journal_section_work_environment_duration_of_exposure)
            val referredToOccupationalHealthDepartmentKey =
                TextModel.from(R.string.journal_section_work_environment_referred_to_occupational_health_department)
            val sickLeaveKey =
                TextModel.from(R.string.journal_section_work_environment_sick_leave)
            val partnersJobKey =
                TextModel.from(R.string.journal_section_work_environment_partners_job)

            val mothersJobDictEntry = getDictionaryEntryFor(scope, mothersJobKey)
            val mothersWorkingHoursDictEntry =
                getDictionaryEntryFor(scope, mothersWorkingHoursKey)
            val exposureToRiskDictEntry =
                getDictionaryEntryFor(scope, exposureToRiskKey)
            val typeOfExposureDictEntry =
                getDictionaryEntryFor(scope, typeOfExposureKey)
            val durationOfExposureDictEntry =
                getDictionaryEntryFor(scope, durationOfExposureKey)
            val referredToOccupationalHealthDepartmentDictEntry =
                getDictionaryEntryFor(
                    scope,
                    referredToOccupationalHealthDepartmentKey
                )
            val sickLeaveDictEntry = getDictionaryEntryFor(scope, sickLeaveKey)
            val partnersJobDictEntry = getDictionaryEntryFor(scope, partnersJobKey)

            return listOf(
                KeyValueRow(
                    KeyValueData(
                        mothersJobKey,
                        workEnvironmentImpactSection?.mother?.jobType.toTextModelOrDefault(),
                        null,
                        mothersJobDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        mothersWorkingHoursKey,
                        workEnvironmentImpactSection?.mother?.hoursOfWorkPerWeek.toTextModelOrDefault(),
                        null,
                        mothersWorkingHoursDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        exposureToRiskKey,
                        workEnvironmentImpactSection?.mother?.exposureToWorkEnvironmentRisk?.types.toCommaSeparatedTextModel(),
                        null,
                        exposureToRiskDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        typeOfExposureKey,
                        workEnvironmentImpactSection?.mother?.exposureToWorkEnvironmentRisk?.remarks.toTextModelOrDefault(),
                        null,
                        typeOfExposureDictEntry?.let { { onDictionaryCallback(it) } }
                    )),
                KeyValueRow(
                    KeyValueData(
                        durationOfExposureKey,
                        workEnvironmentImpactSection?.mother?.exposureToWorkEnvironmentRisk.getExposureDuration(),
                        null,
                        durationOfExposureDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        referredToOccupationalHealthDepartmentKey,
                        workEnvironmentImpactSection?.mother?.referredToOccupationalHealthDepartmentForRiskAssessment.toYesNoTextModelOrDefault(),
                        null,
                        referredToOccupationalHealthDepartmentDictEntry?.let {
                            {
                                onDictionaryCallback(
                                    it
                                )
                            }
                        }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        sickLeaveKey,
                        workEnvironmentImpactSection?.mother?.prenatalSickLeave.toTextModel(),
                        null,
                        sickLeaveDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                ),
                KeyValueRow(
                    KeyValueData(
                        partnersJobKey,
                        workEnvironmentImpactSection?.partner?.jobType.toTextModelOrDefault(),
                        null,
                        partnersJobDictEntry?.let { { onDictionaryCallback(it) } }
                    )
                )
            )
        }
    }