# DataCardControllerMock.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.api.datacard

    import dk.nsp.api.util.extensions.asyncIO
    import dk.nsp.models.*
    import dk.nsp.shared.ResultWrapper
    import dk.nsp.shared.Success
    import kotlinx.coroutines.CoroutineScope
    import kotlinx.coroutines.Deferred
    import java.time.LocalDateTime
    import java.time.temporal.ChronoUnit

    class DataCardControllerMock : IDataCardController {

        private val firstDayOfLastPeriod = LocalDateTime.of(2020, 11, 12, 12, 0)
        private val expectedDateOfDeliveryFromUltraSound = LocalDateTime.of(2020, 8, 14, 12, 0)

        private fun calcTrimester(): Int {
            return when (ChronoUnit.WEEKS.between(firstDayOfLastPeriod, LocalDateTime.now()).toInt()) {
                in (27..50) -> 3
                in (12..27) -> 2
                in (0..12) -> 1
                else -> 0
            }
        }

        private val trimester = calcTrimester()
        private val monthsIntoPregnancy =
            ChronoUnit.MONTHS.between(firstDayOfLastPeriod, LocalDateTime.now()).toDouble()
        private val pregnancyWeek = 36
        private val gestationAge = "${pregnancyWeek - 1}+4"

        private val author = HealthCareOrganization("Org", "sordId")

        override fun getMaternityDataCard(scope: CoroutineScope): Deferred<ResultWrapper<List<DataCard>>> =
            scope.asyncIO {
                Success(
                    listOf(
                        DataCard(
                            modifiedTime = LocalDateTime.now(),
                            author = author,
                            recordTarget = CprIdentifiedPerson(
                                PersonName(
                                    prefixName = null,
                                    firstNames = listOf(
                                        "Maja",
                                        "Ingrid"
                                    ),
                                    middleNames = listOf("Middle", "Name"),
                                    lastName = "Petersen",
                                ),
                                "0101010102"
                            ),
                            childPartnerSection = ChildPartnerSection(
                                modifiedTime = LocalDateTime.now(),
                                author = author,
                                name = PersonName(null, listOf("Jens"), null, "Petersen"),
                                identifier = "0101010101"
                            ),
                            languageSection = null,
                            bodyMeasuresSection = null,
                            socialHistorySection = null,
                            previousBirthsSection = null,
                            previousAbortionsSection = null,
                            expectedDateOfDeliverySection = ExpectedDateOfDeliverySection(
                                modifiedTime = LocalDateTime.now(),
                                author = author,
                                trimester = trimester,
                                monthsIntoPregnancy = monthsIntoPregnancy,
                                dirty = false,
                                expectedDateOfDeliveryFromLastPeriod = ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriod(
                                    LocalDateTime.now().minusMonths(1),
                                    ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriodMenstrualCycle(
                                        IntegerValueWithUnitEnum(20, UnitEnum.D)
                                    ),
                                    LocalDateTime.now().plusMonths(8),
                                    ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriod.Certainty.Certain
                                ),
                                gestationAge = gestationAge,
                                week = pregnancyWeek,
                                remarks = "No remarks..."
                            ),
                            ultrasoundSection = UltrasoundSection(
                                modifiedTime = LocalDateTime.now(),
                                author = author,
                                dirty = false,
                                expectedDateOfDeliveryFromPrenatalUltrasoundScan = expectedDateOfDeliveryFromUltraSound
                            ),
                            workEnvironmentImpactSection = null,
                            allergiesSection = AllergiesSection(
                                LocalDateTime.now(),
                                HealthCareOrganization("Org", "sorId"),
                                false,
                                "Nødder, morfin, skaldyr",
                                AllergiesSection.AllergicPredispositionOfChild.DoublePredisposition
                            ),
                            screeningsSection = null,
                            chronicDiseasesSection = null,
                            medicineSection = null,
                            mmrVaccinationSection = null,
                            historyOfPreviousTreatmentWithImpactOnPregnancySection = null,
                            tobaccoUseAndExposureSection = null,
                            alcoholDrinkingBehaviorSection = null,
                            assistedFertilizationSection = null,
                            substanceUseSection = null,
                            dietaryAndExerciseSection = null,
                            healthInsuranceSection = null,
                            desiredBirthPlaceSection = null,
                            midwifeClinicSection = MidwifeClinicSection(
                                modifiedTime = LocalDateTime.now(),
                                author = author,
                                dirty = false,
                                assignedMidwifeClinic = HealthCareOrganization(
                                    "Jordemoder navn",
                                    "SorID"
                                ),
                                parentalCraftClassDesired = MidwifeClinicSectionAllOfParentalCraftClassDesired(
                                    YesNoEnum.True,
                                    MidwifeClinicSectionAllOfParentalCraftClassDesired.ConsultationForm.Group
                                )
                            ),
                            midwifeConsultationSection = MidwifeConsultationSection(
                                modifiedTime = LocalDateTime.now(),
                                author = author,
                                dirty = false,
                                midwifeConsultationWishes = MidwifeConsultationSectionAllOfMidwifeConsultationWishes(
                                    location = "Ønsker denne lokation",
                                    midwife = "Ønsker denne jordemoder",
                                    weekday = MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Monday
                                )
                            ),
                            overallAssessmentSection = OverallAssessmentSection(
                                LocalDateTime.now(),
                                author,
                                false,
                                OverallAssessmentSectionAllOfPrenatalCareAssessment(
                                    "I sidste graviditet præeklampsi, men kontrolleret bagefter og har normal BT. Dårlig fødselsoplevelse efter akut sectio sidst. Overvejer sectio denne fødsel. Faderen arbejder delvist i udlandet så er meget alene, men har godt netværk.",
                                    "Here are countless ways you can turn your grilling not only into. Without a doubt there is something very.",
                                    OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel.Basic
                                ),
                                ObstetricAssessment(YesNoEnum.True, "Det er der bare behov for"),
                                SocialServicesPerinatalCareAssessment(
                                    YesNoEnum.True,
                                )
                            ),
                            personalDataSection = PersonalDataSection(
                                PersonName(
                                    null,
                                    listOf(
                                        "Maja",
                                        "Ingrid"
                                    ),
                                    listOf("Middle", "Name"),
                                    "Petersen",
                                ),
                                "0101010101",
                                Address("Møllegangen 3", "Risskov", "8240"),
                                null,
                                Telecoms("12345678", null, null),
                                PersonalDataSectionGeneralPractitioner(
                                    "En læges navn",
                                    null,
                                    "12345678"
                                ),
                                listOf(
                                    PersonalDataSectionNextOfKin(
                                        PersonName(
                                            prefixName = null,
                                            firstNames = listOf("Sarah"),
                                            middleNames = null,
                                            lastName = "Hansen"
                                        ),
                                        PersonalDataSectionNextOfKin.Relation.SSkende,
                                        Telecoms("87654321", null, null),
                                        "Ingen ekstra information :)"
                                    )
                                )
                            ),
                            healthcareSection = null,
                            episodeOfCareIdentifier = "episodeOfCareIdentifier",
                            version = "Identifier",
                            dirty = null,
                            documentUniqueId = null,
                            documentStatus = DataCard.DocumentStatus.ACTIVE
                        ),
                    )
                )
            }
    }