from childmonitoring.models import (
    SunChild, DayHospital,  Case, Region, School, Leisure,
    SurgicalMedicalHistory, FamilyMedicalHistory, Outpatient,
    IdentifiedAllergy, IdentifiedPathology, BaseMedicalHistory, Speciality, SpecialistReport
)


def details_sunchild(pk):
    try:
        sun_child = SunChild.objects.get(pk=pk)
        medical_histories = sun_child.medical_histories.select_related().all()
        specialist_reports = sun_child.specialist_report.select_related().all()
        context = {
            'sun_child': sun_child,
            'medical_histories': medical_histories,
            'specialist_reports': specialist_reports,
        }
        return context
    except SunChild.DoesNotExist:
        return ('error',)


def details_day_hospital(pk):
    try:
        day_hospital = DayHospital.objects.get(pk=pk)
        context = {
            'day_hospital': day_hospital,
        }
        return context
    except DayHospital.DoesNotExist:
        return ('error',)


def details_school(pk):
    try:
        school = School.objects.get(pk=pk)
        context = {
            'school': school
        }
        return context
    except School.DoesNotExist:
        return ('error',)


def details_case(pk):
    try:
        case = Case.objects.get(pk=pk)
        context = {
            'case': case
        }
        return context
    except Case.DoesNotExist:
        return ('error',)


def details_region(pk):
    try:
        region = Region.objects.get(pk=pk)
        context = {
            'region': region
        }
        return context
    except Region.DoesNotExist:
        return ('error',)


def details_leisure(pk):
    try:
        leisure = Leisure.objects.get(pk=pk)
        context = {
            'leisure': leisure
        }
        return context
    except Leisure.DoesNotExist:
        return ('error',)


def details_identified_allergy(pk):
    try:
        identified_allergy = IdentifiedAllergy.objects.get(pk=pk)
        context = {
            'identified_allergy': identified_allergy
        }
        return context
    except IdentifiedAllergy.DoesNotExist:
        return ('error',)


def details_identified_pathology(pk):
    try:
        identified_pathology = IdentifiedPathology.objects.get(pk=pk)
        context = {
            'identified_pathology': identified_pathology
        }
        return context
    except IdentifiedPathology.DoesNotExist:
        return ('error',)


def details_surgical_medical_history(pk):
    try:
        surgical_medical_history = SurgicalMedicalHistory.objects.get(pk=pk)
        context = {
            'surgical_medical_history': surgical_medical_history
        }
        return context
    except SurgicalMedicalHistory.DoesNotExist:
        return ('error',)


def details_family_medical_history(pk):
    try:
        family_medical_history = FamilyMedicalHistory.objects.get(pk=pk)
        context = {
            'family_medical_history': family_medical_history
        }
        return context
    except FamilyMedicalHistory.DoesNotExist:
        return ('error',)


def details_base_medical_history(pk):
    try:
        base_medical_history = BaseMedicalHistory.objects.get(pk=pk)
        context = {
            'base_medical_history': base_medical_history
        }
        return context
    except BaseMedicalHistory.DoesNotExist:
        return ('error',)


def details_speciality(pk):
    try:
        speciality = Speciality.objects.get(pk=pk)
        context = {
            'speciality': speciality
        }
        return context
    except Speciality.DoesNotExist:
        return ('error',)


def details_specialist_report(pk):
    try:
        specialist_report = SpecialistReport.objects.get(pk=pk)
        context = {
            'specialist_report': specialist_report
        }
        return context
    except SpecialistReport.DoesNotExist:
        return ('error',)


def details_outpatient(pk):
    try:
        outpatients = Outpatient.objects.get(pk=pk)
        context = {
            'outpatients': outpatients
        }
        return context
    except Outpatient.DoesNotExist:
        return ('error',)
