# 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 (
    BackboneElement,
    CodeableConcept,
    Dosage,
    Duration,
    Money,
    Quantity,
    Ratio,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    dosage: PyList[MedicationKnowledgeAdministrationGuidelinesDosage] | None = Field(
        None, alias="dosage", serialization_alias="dosage"
    )
    indication_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="indicationCodeableConcept",
        serialization_alias="indicationCodeableConcept",
    )
    indication_reference: Reference | None = Field(
        None, alias="indicationReference", serialization_alias="indicationReference"
    )
    patient_characteristics: (
        PyList[MedicationKnowledgeAdministrationGuidelinesPatientCharacteristics] | None
    ) = Field(
        None,
        alias="patientCharacteristics",
        serialization_alias="patientCharacteristics",
    )


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

    dosage: PyList[Dosage] = Field(alias="dosage", serialization_alias="dosage")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    characteristic_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="characteristicCodeableConcept",
        serialization_alias="characteristicCodeableConcept",
    )
    characteristic_quantity: Quantity | None = Field(
        None,
        alias="characteristicQuantity",
        serialization_alias="characteristicQuantity",
    )
    value: PyList[str] | None = Field(None, alias="value", serialization_alias="value")


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

    cost: Money = Field(alias="cost", serialization_alias="cost")
    source: str | None = Field(None, alias="source", serialization_alias="source")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    value_base64binary: str | None = Field(
        None, alias="valueBase64Binary", serialization_alias="valueBase64Binary"
    )
    value_codeable_concept: CodeableConcept | None = Field(
        None, alias="valueCodeableConcept", serialization_alias="valueCodeableConcept"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )


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

    is_active: bool | None = Field(
        None, alias="isActive", serialization_alias="isActive"
    )
    item_codeable_concept: CodeableConcept | None = Field(
        None, alias="itemCodeableConcept", serialization_alias="itemCodeableConcept"
    )
    item_reference: Reference | None = Field(
        None, alias="itemReference", serialization_alias="itemReference"
    )
    strength: Ratio | None = Field(
        None, alias="strength", serialization_alias="strength"
    )


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

    area_under_curve: PyList[Quantity] | None = Field(
        None, alias="areaUnderCurve", serialization_alias="areaUnderCurve"
    )
    half_life_period: Duration | None = Field(
        None, alias="halfLifePeriod", serialization_alias="halfLifePeriod"
    )
    lethal_dose50: PyList[Quantity] | None = Field(
        None, alias="lethalDose50", serialization_alias="lethalDose50"
    )


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

    classification: PyList[CodeableConcept] | None = Field(
        None, alias="classification", serialization_alias="classification"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    name: str | None = Field(None, alias="name", serialization_alias="name")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    source: Reference | None = Field(None, alias="source", serialization_alias="source")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    max_dispense: MedicationKnowledgeRegulatoryMaxDispense | None = Field(
        None, alias="maxDispense", serialization_alias="maxDispense"
    )
    regulatory_authority: Reference = Field(
        alias="regulatoryAuthority", serialization_alias="regulatoryAuthority"
    )
    schedule: PyList[MedicationKnowledgeRegulatorySchedule] | None = Field(
        None, alias="schedule", serialization_alias="schedule"
    )
    substitution: PyList[MedicationKnowledgeRegulatorySubstitution] | None = Field(
        None, alias="substitution", serialization_alias="substitution"
    )


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

    period: Duration | None = Field(None, alias="period", serialization_alias="period")
    quantity: Quantity = Field(alias="quantity", serialization_alias="quantity")


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

    schedule: CodeableConcept = Field(alias="schedule", serialization_alias="schedule")


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

    allowed: bool = Field(alias="allowed", serialization_alias="allowed")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    reference: PyList[Reference] = Field(
        alias="reference", serialization_alias="reference"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

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

    administration_guidelines: (
        PyList[MedicationKnowledgeAdministrationGuidelines] | None
    ) = Field(
        None,
        alias="administrationGuidelines",
        serialization_alias="administrationGuidelines",
    )
    amount: Quantity | None = Field(None, alias="amount", serialization_alias="amount")
    associated_medication: PyList[Reference] | None = Field(
        None, alias="associatedMedication", serialization_alias="associatedMedication"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    contraindication: PyList[Reference] | None = Field(
        None, alias="contraindication", serialization_alias="contraindication"
    )
    cost: PyList[MedicationKnowledgeCost] | None = Field(
        None, alias="cost", serialization_alias="cost"
    )
    dose_form: CodeableConcept | None = Field(
        None, alias="doseForm", serialization_alias="doseForm"
    )
    drug_characteristic: PyList[MedicationKnowledgeDrugCharacteristic] | None = Field(
        None, alias="drugCharacteristic", serialization_alias="drugCharacteristic"
    )
    ingredient: PyList[MedicationKnowledgeIngredient] | None = Field(
        None, alias="ingredient", serialization_alias="ingredient"
    )
    intended_route: PyList[CodeableConcept] | None = Field(
        None, alias="intendedRoute", serialization_alias="intendedRoute"
    )
    kinetics: PyList[MedicationKnowledgeKinetics] | None = Field(
        None, alias="kinetics", serialization_alias="kinetics"
    )
    manufacturer: Reference | None = Field(
        None, alias="manufacturer", serialization_alias="manufacturer"
    )
    medicine_classification: (
        PyList[MedicationKnowledgeMedicineClassification] | None
    ) = Field(
        None,
        alias="medicineClassification",
        serialization_alias="medicineClassification",
    )
    monitoring_program: PyList[MedicationKnowledgeMonitoringProgram] | None = Field(
        None, alias="monitoringProgram", serialization_alias="monitoringProgram"
    )
    monograph: PyList[MedicationKnowledgeMonograph] | None = Field(
        None, alias="monograph", serialization_alias="monograph"
    )
    packaging: MedicationKnowledgePackaging | None = Field(
        None, alias="packaging", serialization_alias="packaging"
    )
    preparation_instruction: str | None = Field(
        None,
        alias="preparationInstruction",
        serialization_alias="preparationInstruction",
    )
    product_type: PyList[CodeableConcept] | None = Field(
        None, alias="productType", serialization_alias="productType"
    )
    regulatory: PyList[MedicationKnowledgeRegulatory] | None = Field(
        None, alias="regulatory", serialization_alias="regulatory"
    )
    related_medication_knowledge: (
        PyList[MedicationKnowledgeRelatedMedicationKnowledge] | None
    ) = Field(
        None,
        alias="relatedMedicationKnowledge",
        serialization_alias="relatedMedicationKnowledge",
    )
    status: Literal["active", "inactive", "entered-in-error"] | None = Field(
        None, alias="status", serialization_alias="status"
    )
    synonym: PyList[str] | None = Field(
        None, alias="synonym", serialization_alias="synonym"
    )

    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) -> MedicationKnowledge:
        return cls.model_validate_json(json)
