# 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 (
    Annotation,
    CodeableConcept,
    Identifier,
    Period,
    Quantity,
    Range,
    Ratio,
    Reference,
    Timing,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

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

    as_needed_boolean: bool | None = Field(
        None, alias="asNeededBoolean", serialization_alias="asNeededBoolean"
    )
    as_needed_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="asNeededCodeableConcept",
        serialization_alias="asNeededCodeableConcept",
    )
    authored_on: str | None = Field(
        None, alias="authoredOn", serialization_alias="authoredOn"
    )
    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    body_site: PyList[CodeableConcept] | None = Field(
        None, alias="bodySite", serialization_alias="bodySite"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    do_not_perform: bool | None = Field(
        None, alias="doNotPerform", serialization_alias="doNotPerform"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    instantiates_canonical: PyList[str] | None = Field(
        None, alias="instantiatesCanonical", serialization_alias="instantiatesCanonical"
    )
    instantiates_uri: PyList[str] | None = Field(
        None, alias="instantiatesUri", serialization_alias="instantiatesUri"
    )
    insurance: PyList[Reference] | None = Field(
        None, alias="insurance", serialization_alias="insurance"
    )
    intent: Literal[
        "proposal",
        "plan",
        "directive",
        "order",
        "option",
        "original-order",
        "reflex-order",
        "filler-order",
        "instance-order",
    ] = Field(alias="intent", serialization_alias="intent")
    location_code: PyList[CodeableConcept] | None = Field(
        None, alias="locationCode", serialization_alias="locationCode"
    )
    location_reference: PyList[Reference] | None = Field(
        None, alias="locationReference", serialization_alias="locationReference"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    occurrence_timing: Timing | None = Field(
        None, alias="occurrenceTiming", serialization_alias="occurrenceTiming"
    )
    order_detail: PyList[CodeableConcept] | None = Field(
        None, alias="orderDetail", serialization_alias="orderDetail"
    )
    patient_instruction: str | None = Field(
        None, alias="patientInstruction", serialization_alias="patientInstruction"
    )
    performer: PyList[Reference] | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    performer_type: CodeableConcept | None = Field(
        None, alias="performerType", serialization_alias="performerType"
    )
    priority: Literal["routine", "urgent", "asap", "stat"] | None = Field(
        None, alias="priority", serialization_alias="priority"
    )
    quantity_quantity: Quantity | None = Field(
        None, alias="quantityQuantity", serialization_alias="quantityQuantity"
    )
    quantity_range: Range | None = Field(
        None, alias="quantityRange", serialization_alias="quantityRange"
    )
    quantity_ratio: Ratio | None = Field(
        None, alias="quantityRatio", serialization_alias="quantityRatio"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    relevant_history: PyList[Reference] | None = Field(
        None, alias="relevantHistory", serialization_alias="relevantHistory"
    )
    replaces: PyList[Reference] | None = Field(
        None, alias="replaces", serialization_alias="replaces"
    )
    requester: Reference | None = Field(
        None, alias="requester", serialization_alias="requester"
    )
    requisition: Identifier | None = Field(
        None, alias="requisition", serialization_alias="requisition"
    )
    specimen: PyList[Reference] | None = Field(
        None, alias="specimen", serialization_alias="specimen"
    )
    status: Literal[
        "draft",
        "active",
        "on-hold",
        "revoked",
        "completed",
        "entered-in-error",
        "unknown",
    ] = Field(alias="status", serialization_alias="status")
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    supporting_info: PyList[Reference] | None = Field(
        None, alias="supportingInfo", serialization_alias="supportingInfo"
    )

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