text: from typing import Union, List, Optional
  
  from pyspark.sql.types import (
      StructType,
      StructField,
      StringType,
      ArrayType,
      BooleanType,
      DataType,
      TimestampType,
  )
  
  
  # This file is auto-generated by generate_schema so do not edit it manually
  # noinspection PyPep8Naming
  class Contract_ActionSchema:
      """
      Legally enforceable, formally recorded unilateral or bilateral directive i.e.,
      a policy or agreement.
      """
  
      # 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]:
          """
          Legally enforceable, formally recorded unilateral or bilateral directive i.e.,
          a policy or agreement.
  
  
          id: Unique id for the element within a resource (for internal references). This
              may be any string value that does not contain spaces.
  
          extension: May be used to represent additional information that is not part of the basic
              definition of the element. 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 element and that modifies the understanding of the element
              in which it is contained 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 can 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).
  
          doNotPerform: True if the term prohibits the  action.
  
          type: Activity or service obligation to be done or not done, performed or not
              performed, effectuated or not by this Contract term.
  
          subject: Entity of the action.
  
          intent: Reason or purpose for the action stipulated by this Contract Provision.
  
          linkId: Id [identifier??] of the clause or question text related to this action in the
              referenced form or QuestionnaireResponse.
  
          status: Current state of the term action.
  
          context: Encounter or Episode with primary association to specified term activity.
  
          contextLinkId: Id [identifier??] of the clause or question text related to the requester of
              this action in the referenced form or QuestionnaireResponse.
  
          occurrenceDateTime: When action happens.
  
          occurrencePeriod: When action happens.
  
          occurrenceTiming: When action happens.
  
          requester: Who or what initiated the action and has responsibility for its activation.
  
          requesterLinkId: Id [identifier??] of the clause or question text related to the requester of
              this action in the referenced form or QuestionnaireResponse.
  
          performerType: The type of individual that is desired or required to perform or not perform
              the action.
  
          performerRole: The type of role or competency of an individual desired or required to perform
              or not perform the action.
  
          performer: Indicates who or what is being asked to perform (or not perform) the ction.
  
          performerLinkId: Id [identifier??] of the clause or question text related to the reason type or
              reference of this  action in the referenced form or QuestionnaireResponse.
  
          reasonCode: Rationale for the action to be performed or not performed. Describes why the
              action is permitted or prohibited.
  
          reasonReference: Indicates another resource whose existence justifies permitting or not
              permitting this action.
  
          reason: Describes why the action is to be performed or not performed in textual form.
  
          reasonLinkId: Id [identifier??] of the clause or question text related to the reason type or
              reference of this  action in the referenced form or QuestionnaireResponse.
  
          note: Comments made about the term action made by the requester, performer, subject
              or other participants.
  
          securityLabelNumber: Security labels that protects the action.
  
          """
          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.complex_types.extension import ExtensionSchema
          from spark_fhir_schemas.r4.complex_types.codeableconcept import (
              CodeableConceptSchema,
          )
          from spark_fhir_schemas.r4.complex_types.contract_subject import (
              Contract_SubjectSchema,
          )
          from spark_fhir_schemas.r4.complex_types.reference import ReferenceSchema
          from spark_fhir_schemas.r4.complex_types.period import PeriodSchema
          from spark_fhir_schemas.r4.complex_types.timing import TimingSchema
          from spark_fhir_schemas.r4.complex_types.annotation import AnnotationSchema
          from spark_fhir_schemas.r4.simple_types.unsignedint import unsignedIntSchema
  
          if (
              max_recursion_limit
              and nesting_list.count("Contract_Action") >= 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 + ["Contract_Action"]
          my_parent_path = (
              parent_path + ".contract_action" if parent_path else "contract_action"
          )
          schema = StructType(
              [
                  # Unique id for the element within a resource (for internal references). This
                  # may be any string value that does not contain spaces.
                  StructField("id", StringType(), True),
                  # May be used to represent additional information that is not part of the basic
                  # definition of the element. 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 element and that modifies the understanding of the element
                  # in which it is contained 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 can 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,
                  ),
                  # True if the term prohibits the  action.
                  StructField("doNotPerform", BooleanType(), True),
                  # Activity or service obligation to be done or not done, performed or not
                  # performed, effectuated or not by this Contract term.
                  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,
                  ),
                  # Entity of the action.
                  StructField(
                      "subject",
                      ArrayType(
                          Contract_SubjectSchema.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,
                  ),
                  # Reason or purpose for the action stipulated by this Contract Provision.
                  StructField(
                      "intent",
                      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,
                  ),
                  # Id [identifier??] of the clause or question text related to this action in the
                  # referenced form or QuestionnaireResponse.
                  StructField("linkId", ArrayType(StringType()), True),
                  # Current state of the term action.
                  StructField(
                      "status",
                      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,
                  ),
                  # Encounter or Episode with primary association to specified term activity.
                  StructField(
                      "context",
                      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,
                  ),
                  # Id [identifier??] of the clause or question text related to the requester of
                  # this action in the referenced form or QuestionnaireResponse.
                  StructField("contextLinkId", ArrayType(StringType()), True),
                  # When action happens.
                  StructField("occurrenceDateTime", TimestampType(), True),
                  # When action happens.
                  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,
                  ),
                  # When action happens.
                  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,
                  ),
                  # Who or what initiated the action and has responsibility for its activation.
                  StructField(
                      "requester",
                      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,
                  ),
                  # Id [identifier??] of the clause or question text related to the requester of
                  # this action in the referenced form or QuestionnaireResponse.
                  StructField("requesterLinkId", ArrayType(StringType()), True),
                  # The type of individual that is desired or required to perform or not perform
                  # the action.
                  StructField(
                      "performerType",
                      ArrayType(
                          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,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # The type of role or competency of an individual desired or required to perform
                  # or not perform the action.
                  StructField(
                      "performerRole",
                      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,
                  ),
                  # Indicates who or what is being asked to perform (or not perform) the ction.
                  StructField(
                      "performer",
                      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,
                  ),
                  # Id [identifier??] of the clause or question text related to the reason type or
                  # reference of this  action in the referenced form or QuestionnaireResponse.
                  StructField("performerLinkId", ArrayType(StringType()), True),
                  # Rationale for the action to be performed or not performed. Describes why the
                  # action is permitted or prohibited.
                  StructField(
                      "reasonCode",
                      ArrayType(
                          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,
                              max_extension_depth=max_extension_depth,
                              include_modifierExtension=include_modifierExtension,
                              use_date_for=use_date_for,
                              parent_path=my_parent_path,
                          )
                      ),
                      True,
                  ),
                  # Indicates another resource whose existence justifies permitting or not
                  # permitting this action.
                  StructField(
                      "reasonReference",
                      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,
                  ),
                  # Describes why the action is to be performed or not performed in textual form.
                  StructField("reason", ArrayType(StringType()), True),
                  # Id [identifier??] of the clause or question text related to the reason type or
                  # reference of this  action in the referenced form or QuestionnaireResponse.
                  StructField("reasonLinkId", ArrayType(StringType()), True),
                  # Comments made about the term action made by the requester, performer, subject
                  # or other participants.
                  StructField(
                      "note",
                      ArrayType(
                          AnnotationSchema.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,
                  ),
                  # Security labels that protects the action.
                  StructField(
                      "securityLabelNumber",
                      ArrayType(
                          unsignedIntSchema.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
  