text: from typing import Union, List, Optional
  
  from pyspark.sql.types import (
      StructType,
      StructField,
      StringType,
      ArrayType,
      DataType,
      TimestampType,
  )
  
  
  # This file is auto-generated by generate_schema so do not edit it manually
  # noinspection PyPep8Naming
  class SupplyDeliverySchema:
      """
      Record of delivery of what is supplied.
      """
  
      # noinspection PyDefaultArgument
      @staticmethod
      def get_schema(
          max_nesting_depth: Optional[int] = 6,
          nesting_depth: int = 0,
          nesting_list: List[str] = [],
          max_recursion_limit: Optional[int] = 2,
          include_extension: Optional[bool] = False,
          extension_fields: Optional[List[str]] = None,
          extension_depth: int = 0,
          max_extension_depth: Optional[int] = 2,
          include_modifierExtension: Optional[bool] = False,
          use_date_for: Optional[List[str]] = None,
          parent_path: Optional[str] = "",
      ) -> Union[StructType, DataType]:
          """
          Record of delivery of what is supplied.
  
  
          resourceType: This is a SupplyDelivery resource
  
          id: The logical id of the resource, as used in the URL for the resource. Once
              assigned, this value never changes.
  
          meta: The metadata about the resource. This is content that is maintained by the
              infrastructure. Changes to the content might not always be associated with
              version changes to the resource.
  
          implicitRules: A reference to a set of rules that were followed when the resource was
              constructed, and which must be understood when processing the content. Often,
              this is a reference to an implementation guide that defines the special rules
              along with other profiles etc.
  
          language: The base language in which the resource is written.
  
          text: A human-readable narrative that contains a summary of the resource and can be
              used to represent the content of the resource to a human. The narrative need
              not encode all the structured data, but is required to contain sufficient
              detail to make it "clinically safe" for a human to just read the narrative.
              Resource definitions may define what content should be represented in the
              narrative to ensure clinical safety.
  
          contained: These resources do not have an independent existence apart from the resource
              that contains them - they cannot be identified independently, and nor can they
              have their own independent transaction scope.
  
          extension: May be used to represent additional information that is not part of the basic
              definition of the resource. To make the use of extensions safe and manageable,
              there is a strict set of governance  applied to the definition and use of
              extensions. Though any implementer can define an extension, there is a set of
              requirements that SHALL be met as part of the definition of the extension.
  
          modifierExtension: May be used to represent additional information that is not part of the basic
              definition of the resource and that modifies the understanding of the element
              that contains it and/or the understanding of the containing element's
              descendants. Usually modifier elements provide negation or qualification. To
              make the use of extensions safe and manageable, there is a strict set of
              governance applied to the definition and use of extensions. Though any
              implementer is allowed to define an extension, there is a set of requirements
              that SHALL be met as part of the definition of the extension. Applications
              processing a resource are required to check for modifier extensions.
  
              Modifier extensions SHALL NOT change the meaning of any elements on Resource
              or DomainResource (including cannot change the meaning of modifierExtension
              itself).
  
          identifier: Identifier for the supply delivery event that is used to identify it across
              multiple disparate systems.
  
          basedOn: A plan, proposal or order that is fulfilled in whole or in part by this event.
  
          partOf: A larger event of which this particular event is a component or step.
  
          status: A code specifying the state of the dispense event.
  
          patient: A link to a resource representing the person whom the delivered item is for.
  
          type: Indicates the type of dispensing event that is performed. Examples include:
              Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.
  
          suppliedItem: The item that is being delivered or has been supplied.
  
          occurrenceDateTime: The date or time(s) the activity occurred.
  
          occurrencePeriod: The date or time(s) the activity occurred.
  
          occurrenceTiming: The date or time(s) the activity occurred.
  
          supplier: The individual responsible for dispensing the medication, supplier or device.
  
          destination: Identification of the facility/location where the Supply was shipped to, as
              part of the dispense event.
  
          receiver: Identifies the person who picked up the Supply.
  
          """
          if extension_fields is None:
              extension_fields = [
                  "valueBoolean",
                  "valueCode",
                  "valueDate",
                  "valueDateTime",
                  "valueDecimal",
                  "valueId",
                  "valueInteger",
                  "valuePositiveInt",
                  "valueString",
                  "valueTime",
                  "valueUnsignedInt",
                  "valueUri",
                  "valueUrl",
                  "valueReference",
                  "valueCodeableConcept",
                  "valueAddress",
              ]
          from spark_fhir_schemas.r4.simple_types.id import idSchema
          from spark_fhir_schemas.r4.complex_types.meta import MetaSchema
          from spark_fhir_schemas.r4.simple_types.uri import uriSchema
          from spark_fhir_schemas.r4.simple_types.code import codeSchema
          from spark_fhir_schemas.r4.complex_types.narrative import NarrativeSchema
          from spark_fhir_schemas.r4.complex_types.resourcelist import ResourceListSchema
          from spark_fhir_schemas.r4.complex_types.extension import ExtensionSchema
          from spark_fhir_schemas.r4.complex_types.identifier import IdentifierSchema
          from spark_fhir_schemas.r4.complex_types.reference import ReferenceSchema
          from spark_fhir_schemas.r4.complex_types.codeableconcept import (
              CodeableConceptSchema,
          )
          from spark_fhir_schemas.r4.complex_types.supplydelivery_supplieditem import (
              SupplyDelivery_SuppliedItemSchema,
          )
          from spark_fhir_schemas.r4.complex_types.period import PeriodSchema
          from spark_fhir_schemas.r4.complex_types.timing import TimingSchema
  
          if (
              max_recursion_limit
              and nesting_list.count("SupplyDelivery") >= max_recursion_limit
          ) or (max_nesting_depth and nesting_depth >= max_nesting_depth):
              return StructType([StructField("id", StringType(), True)])
          # add my name to recursion list for later
          my_nesting_list: List[str] = nesting_list + ["SupplyDelivery"]
          my_parent_path = (
              parent_path + ".supplydelivery" if parent_path else "supplydelivery"
          )
          schema = StructType(
              [
                  # This is a SupplyDelivery resource
                  StructField("resourceType", StringType(), True),
                  # The logical id of the resource, as used in the URL for the resource. Once
                  # assigned, this value never changes.
                  StructField(
                      "id",
                      idSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path + ".id",
                      ),
                      True,
                  ),
                  # The metadata about the resource. This is content that is maintained by the
                  # infrastructure. Changes to the content might not always be associated with
                  # version changes to the resource.
                  StructField(
                      "meta",
                      MetaSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # A reference to a set of rules that were followed when the resource was
                  # constructed, and which must be understood when processing the content. Often,
                  # this is a reference to an implementation guide that defines the special rules
                  # along with other profiles etc.
                  StructField(
                      "implicitRules",
                      uriSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path + ".implicitrules",
                      ),
                      True,
                  ),
                  # The base language in which the resource is written.
                  StructField(
                      "language",
                      codeSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path + ".language",
                      ),
                      True,
                  ),
                  # A human-readable narrative that contains a summary of the resource and can be
                  # used to represent the content of the resource to a human. The narrative need
                  # not encode all the structured data, but is required to contain sufficient
                  # detail to make it "clinically safe" for a human to just read the narrative.
                  # Resource definitions may define what content should be represented in the
                  # narrative to ensure clinical safety.
                  StructField(
                      "text",
                      NarrativeSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # These resources do not have an independent existence apart from the resource
                  # that contains them - they cannot be identified independently, and nor can they
                  # have their own independent transaction scope.
                  StructField(
                      "contained",
                      ArrayType(
                          ResourceListSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # May be used to represent additional information that is not part of the basic
                  # definition of the resource. To make the use of extensions safe and manageable,
                  # there is a strict set of governance  applied to the definition and use of
                  # extensions. Though any implementer can define an extension, there is a set of
                  # requirements that SHALL be met as part of the definition of the extension.
                  StructField(
                      "extension",
                      ArrayType(
                          ExtensionSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # May be used to represent additional information that is not part of the basic
                  # definition of the resource and that modifies the understanding of the element
                  # that contains it and/or the understanding of the containing element's
                  # descendants. Usually modifier elements provide negation or qualification. To
                  # make the use of extensions safe and manageable, there is a strict set of
                  # governance applied to the definition and use of extensions. Though any
                  # implementer is allowed to define an extension, there is a set of requirements
                  # that SHALL be met as part of the definition of the extension. Applications
                  # processing a resource are required to check for modifier extensions.
                  #
                  # Modifier extensions SHALL NOT change the meaning of any elements on Resource
                  # or DomainResource (including cannot change the meaning of modifierExtension
                  # itself).
                  StructField(
                      "modifierExtension",
                      ArrayType(
                          ExtensionSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # Identifier for the supply delivery event that is used to identify it across
                  # multiple disparate systems.
                  StructField(
                      "identifier",
                      ArrayType(
                          IdentifierSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # A plan, proposal or order that is fulfilled in whole or in part by this event.
                  StructField(
                      "basedOn",
                      ArrayType(
                          ReferenceSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # A larger event of which this particular event is a component or step.
                  StructField(
                      "partOf",
                      ArrayType(
                          ReferenceSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # A code specifying the state of the dispense event.
                  StructField("status", StringType(), True),
                  # A link to a resource representing the person whom the delivered item is for.
                  StructField(
                      "patient",
                      ReferenceSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # Indicates the type of dispensing event that is performed. Examples include:
                  # Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.
                  StructField(
                      "type",
                      CodeableConceptSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # The item that is being delivered or has been supplied.
                  StructField(
                      "suppliedItem",
                      SupplyDelivery_SuppliedItemSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # The date or time(s) the activity occurred.
                  StructField("occurrenceDateTime", TimestampType(), True),
                  # The date or time(s) the activity occurred.
                  StructField(
                      "occurrencePeriod",
                      PeriodSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # The date or time(s) the activity occurred.
                  StructField(
                      "occurrenceTiming",
                      TimingSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # The individual responsible for dispensing the medication, supplier or device.
                  StructField(
                      "supplier",
                      ReferenceSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # Identification of the facility/location where the Supply was shipped to, as
                  # part of the dispense event.
                  StructField(
                      "destination",
                      ReferenceSchema.get_schema(
                          max_nesting_depth=max_nesting_depth,
                          nesting_depth=nesting_depth + 1,
                          nesting_list=my_nesting_list,
                          max_recursion_limit=max_recursion_limit,
                          include_extension=include_extension,
                          extension_fields=extension_fields,
                          extension_depth=extension_depth + 1,
                          max_extension_depth=max_extension_depth,
                          include_modifierExtension=include_modifierExtension,
                          use_date_for=use_date_for,
                          parent_path=my_parent_path,
                      ),
                      True,
                  ),
                  # Identifies the person who picked up the Supply.
                  StructField(
                      "receiver",
                      ArrayType(
                          ReferenceSchema.get_schema(
                              max_nesting_depth=max_nesting_depth,
                              nesting_depth=nesting_depth + 1,
                              nesting_list=my_nesting_list,
                              max_recursion_limit=max_recursion_limit,
                              include_extension=include_extension,
                              extension_fields=extension_fields,
                              extension_depth=extension_depth,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
              ]
          )
          if not include_extension:
              schema.fields = [
                  c
                  if c.name != "extension"
                  else StructField("extension", StringType(), True)
                  for c in schema.fields
              ]
  
          if not include_modifierExtension:
              schema.fields = [
                  c
                  if c.name != "modifierExtension"
                  else StructField("modifierExtension", StringType(), True)
                  for c in schema.fields
              ]
  
          return schema
  