# WARNING: This file is autogenerated by FHIR Schema Codegen.
# https://github.com/fhir-schema/fhir-schema-codegen
# Any manual changes made to this file may be overwritten.

from __future__ import annotations
from pydantic import ConfigDict, Field
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Attachment,
    BackboneElement,
    CodeableConcept,
    Coding,
    ContactDetail,
    Identifier,
    Period,
    Quantity,
    Reference,
    UsageContext,
)
from fhirschemapy.R4B.domain_resource import DomainResource


class QuestionnaireItem(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    answer_option: PyList[QuestionnaireItemAnswerOption] | None = Field(
        None, alias="answerOption", serialization_alias="answerOption"
    )
    answer_value_set: str | None = Field(
        None, alias="answerValueSet", serialization_alias="answerValueSet"
    )
    code: PyList[Coding] | None = Field(None, alias="code", serialization_alias="code")
    definition: str | None = Field(
        None, alias="definition", serialization_alias="definition"
    )
    enable_behavior: Literal["all", "any"] | None = Field(
        None, alias="enableBehavior", serialization_alias="enableBehavior"
    )
    enable_when: PyList[QuestionnaireItemEnableWhen] | None = Field(
        None, alias="enableWhen", serialization_alias="enableWhen"
    )
    initial: PyList[QuestionnaireItemInitial] | None = Field(
        None, alias="initial", serialization_alias="initial"
    )
    item: PyList[QuestionnaireItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    link_id: str = Field(alias="linkId", serialization_alias="linkId")
    max_length: int | None = Field(
        None, alias="maxLength", serialization_alias="maxLength"
    )
    prefix: str | None = Field(None, alias="prefix", serialization_alias="prefix")
    read_only: bool | None = Field(
        None, alias="readOnly", serialization_alias="readOnly"
    )
    repeats: bool | None = Field(None, alias="repeats", serialization_alias="repeats")
    required: bool | None = Field(
        None, alias="required", serialization_alias="required"
    )
    text: str | None = Field(None, alias="text", serialization_alias="text")
    type: Literal[
        "group",
        "display",
        "question",
        "boolean",
        "decimal",
        "integer",
        "date",
        "dateTime",
        "time",
        "string",
        "text",
        "url",
        "choice",
        "open-choice",
        "attachment",
        "reference",
        "quantity",
    ] = Field(alias="type", serialization_alias="type")


class QuestionnaireItemAnswerOption(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    initial_selected: bool | None = Field(
        None, alias="initialSelected", serialization_alias="initialSelected"
    )
    value_coding: Coding | None = Field(
        None, alias="valueCoding", serialization_alias="valueCoding"
    )
    value_date: str | None = Field(
        None, alias="valueDate", serialization_alias="valueDate"
    )
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_reference: Reference | None = Field(
        None, alias="valueReference", serialization_alias="valueReference"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )
    value_time: str | None = Field(
        None, alias="valueTime", serialization_alias="valueTime"
    )


class QuestionnaireItemEnableWhen(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    answer_boolean: bool | None = Field(
        None, alias="answerBoolean", serialization_alias="answerBoolean"
    )
    answer_coding: Coding | None = Field(
        None, alias="answerCoding", serialization_alias="answerCoding"
    )
    answer_date: str | None = Field(
        None, alias="answerDate", serialization_alias="answerDate"
    )
    answer_date_time: str | None = Field(
        None, alias="answerDateTime", serialization_alias="answerDateTime"
    )
    answer_decimal: float | None = Field(
        None, alias="answerDecimal", serialization_alias="answerDecimal"
    )
    answer_integer: int | None = Field(
        None, alias="answerInteger", serialization_alias="answerInteger"
    )
    answer_quantity: Quantity | None = Field(
        None, alias="answerQuantity", serialization_alias="answerQuantity"
    )
    answer_reference: Reference | None = Field(
        None, alias="answerReference", serialization_alias="answerReference"
    )
    answer_string: str | None = Field(
        None, alias="answerString", serialization_alias="answerString"
    )
    answer_time: str | None = Field(
        None, alias="answerTime", serialization_alias="answerTime"
    )
    operator: Literal["exists", "=", "!=", ">", "<", ">=", "<="] = Field(
        alias="operator", serialization_alias="operator"
    )
    question: str = Field(alias="question", serialization_alias="question")


class QuestionnaireItemInitial(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    value_attachment: Attachment | None = Field(
        None, alias="valueAttachment", serialization_alias="valueAttachment"
    )
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_coding: Coding | None = Field(
        None, alias="valueCoding", serialization_alias="valueCoding"
    )
    value_date: str | None = Field(
        None, alias="valueDate", serialization_alias="valueDate"
    )
    value_date_time: str | None = Field(
        None, alias="valueDateTime", serialization_alias="valueDateTime"
    )
    value_decimal: float | None = Field(
        None, alias="valueDecimal", serialization_alias="valueDecimal"
    )
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_reference: Reference | None = Field(
        None, alias="valueReference", serialization_alias="valueReference"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )
    value_time: str | None = Field(
        None, alias="valueTime", serialization_alias="valueTime"
    )
    value_uri: str | None = Field(
        None, alias="valueUri", serialization_alias="valueUri"
    )


class Questionnaire(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    resource_type: str = Field(
        default="Questionnaire",
        alias="resourceType",
        serialization_alias="resourceType",
        frozen=True,
        pattern="Questionnaire",
    )

    approval_date: str | None = Field(
        None, alias="approvalDate", serialization_alias="approvalDate"
    )
    code: PyList[Coding] | None = Field(None, alias="code", serialization_alias="code")
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    derived_from: PyList[str] | None = Field(
        None, alias="derivedFrom", serialization_alias="derivedFrom"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    effective_period: Period | None = Field(
        None, alias="effectivePeriod", serialization_alias="effectivePeriod"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    item: PyList[QuestionnaireItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    last_review_date: str | None = Field(
        None, alias="lastReviewDate", serialization_alias="lastReviewDate"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    publisher: str | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    purpose: str | None = Field(None, alias="purpose", serialization_alias="purpose")
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    subject_type: (
        PyList[
            Literal[
                "Account",
                "ActivityDefinition",
                "AdverseEvent",
                "AllergyIntolerance",
                "Appointment",
                "AppointmentResponse",
                "AuditEvent",
                "Basic",
                "Binary",
                "BiologicallyDerivedProduct",
                "BodyStructure",
                "Bundle",
                "CapabilityStatement",
                "CarePlan",
                "CareTeam",
                "CatalogEntry",
                "ChargeItem",
                "ChargeItemDefinition",
                "Claim",
                "ClaimResponse",
                "ClinicalImpression",
                "CodeSystem",
                "Communication",
                "CommunicationRequest",
                "CompartmentDefinition",
                "Composition",
                "ConceptMap",
                "Condition",
                "Consent",
                "Contract",
                "Coverage",
                "CoverageEligibilityRequest",
                "CoverageEligibilityResponse",
                "DetectedIssue",
                "Device",
                "DeviceDefinition",
                "DeviceMetric",
                "DeviceRequest",
                "DeviceUseStatement",
                "DiagnosticReport",
                "DocumentManifest",
                "DocumentReference",
                "DomainResource",
                "EffectEvidenceSynthesis",
                "Encounter",
                "Endpoint",
                "EnrollmentRequest",
                "EnrollmentResponse",
                "EpisodeOfCare",
                "EventDefinition",
                "Evidence",
                "EvidenceVariable",
                "ExampleScenario",
                "ExplanationOfBenefit",
                "FamilyMemberHistory",
                "Flag",
                "Goal",
                "GraphDefinition",
                "Group",
                "GuidanceResponse",
                "HealthcareService",
                "ImagingStudy",
                "Immunization",
                "ImmunizationEvaluation",
                "ImmunizationRecommendation",
                "ImplementationGuide",
                "InsurancePlan",
                "Invoice",
                "Library",
                "Linkage",
                "List",
                "Location",
                "Measure",
                "MeasureReport",
                "Media",
                "Medication",
                "MedicationAdministration",
                "MedicationDispense",
                "MedicationKnowledge",
                "MedicationRequest",
                "MedicationStatement",
                "MedicinalProduct",
                "MedicinalProductAuthorization",
                "MedicinalProductContraindication",
                "MedicinalProductIndication",
                "MedicinalProductIngredient",
                "MedicinalProductInteraction",
                "MedicinalProductManufactured",
                "MedicinalProductPackaged",
                "MedicinalProductPharmaceutical",
                "MedicinalProductUndesirableEffect",
                "MessageDefinition",
                "MessageHeader",
                "MolecularSequence",
                "NamingSystem",
                "NutritionOrder",
                "Observation",
                "ObservationDefinition",
                "OperationDefinition",
                "OperationOutcome",
                "Organization",
                "OrganizationAffiliation",
                "Parameters",
                "Patient",
                "PaymentNotice",
                "PaymentReconciliation",
                "Person",
                "PlanDefinition",
                "Practitioner",
                "PractitionerRole",
                "Procedure",
                "Provenance",
                "Questionnaire",
                "QuestionnaireResponse",
                "RelatedPerson",
                "RequestGroup",
                "ResearchDefinition",
                "ResearchElementDefinition",
                "ResearchStudy",
                "ResearchSubject",
                "Resource",
                "RiskAssessment",
                "RiskEvidenceSynthesis",
                "Schedule",
                "SearchParameter",
                "ServiceRequest",
                "Slot",
                "Specimen",
                "SpecimenDefinition",
                "StructureDefinition",
                "StructureMap",
                "Subscription",
                "Substance",
                "SubstanceNucleicAcid",
                "SubstancePolymer",
                "SubstanceProtein",
                "SubstanceReferenceInformation",
                "SubstanceSourceMaterial",
                "SubstanceSpecification",
                "SupplyDelivery",
                "SupplyRequest",
                "Task",
                "TerminologyCapabilities",
                "TestReport",
                "TestScript",
                "ValueSet",
                "VerificationResult",
                "VisionPrescription",
            ]
        ]
        | None
    ) = Field(None, alias="subjectType", serialization_alias="subjectType")
    title: str | None = Field(None, alias="title", serialization_alias="title")
    url: str | None = Field(None, alias="url", serialization_alias="url")
    use_context: PyList[UsageContext] | None = Field(
        None, alias="useContext", serialization_alias="useContext"
    )
    version: str | None = Field(None, alias="version", serialization_alias="version")

    def to_json(self, indent: int | None = None) -> str:
        return self.model_dump_json(
            exclude_unset=True, exclude_none=True, indent=indent
        )

    @classmethod
    def from_json(cls, json: str) -> Questionnaire:
        return cls.model_validate_json(json)
