//    Copyright 2019 Google Inc.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        https://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

syntax = "proto3";

package google.fhir.r4.core;

import "google/protobuf/any.proto";
import "google/fhir/core/proto/annotations.proto";
import "google/fhir/r4/proto/core/codes.proto";
import "google/fhir/r4/proto/core/datatypes.proto";
import "google/fhir/r4/proto/core/valuesets.proto";

option java_multiple_files = true;
option java_package = "com.google.fhir.r4.core";
option (.google.fhir.proto.fhir_version) = R4;
option go_package = "github.com/google/fhir/go/google/fhir/r4/proto/core/resources/test_script_go_proto";

// Auto-generated from StructureDefinition for TestScript.
// Describes a set of tests.
// See http://hl7.org/fhir/StructureDefinition/TestScript
message TestScript {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/TestScript";
  option (.google.fhir.proto.fhir_path_message_warning_constraint) =
      "name.matches('[A-Z]([A-Za-z0-9_]){0,254}')";

  // Logical id of this artifact
  Id id = 1;

  // Metadata about the resource
  Meta meta = 2;

  // A set of rules under which this content was created
  Uri implicit_rules = 3;

  // Language of the resource content
  Code language = 4;

  // Text summary of the resource, for human interpretation
  Narrative text = 5;

  // Contained, inline Resources
  repeated protobuf.Any contained = 6;

  // Field 7 reserved for strongly-typed ContainedResource for id:
  // TestScript.contained
  reserved 7;

  // Additional content defined by implementations
  repeated Extension extension = 8;

  // Extensions that cannot be ignored
  repeated Extension modifier_extension = 9;

  // Canonical identifier for this test script, represented as a URI (globally
  // unique)
  Uri url = 10 [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Additional identifier for the test script
  Identifier identifier = 11;

  // Business version of the test script
  String version = 12;

  // Name for this test script (computer friendly)
  String name = 13
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Name for this test script (human friendly)
  String title = 14;

  // draft | active | retired | unknown
  message StatusCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/publication-status";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    PublicationStatusCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  StatusCode status = 15
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // For testing purposes, not real usage
  Boolean experimental = 16;

  // Date last changed
  DateTime date = 17;

  // Name of the publisher (organization or individual)
  String publisher = 18;

  // Contact details for the publisher
  repeated ContactDetail contact = 19;

  // Natural language description of the test script
  Markdown description = 20;

  // The context that the content is intended to support
  repeated UsageContext use_context = 21;

  // Intended jurisdiction for test script (if applicable)
  repeated CodeableConcept jurisdiction = 22;

  // Why this test script is defined
  Markdown purpose = 23;

  // Use and/or publishing restrictions
  Markdown copyright = 24;

  // An abstract server representing a client or sender in a message exchange
  message Origin {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // The index of the abstract origin server starting at 1
    Integer index = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // FHIR-Client | FHIR-SDC-FormFiller
    Coding profile = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated Origin origin = 25;

  // An abstract server representing a destination or receiver in a message
  // exchange
  message Destination {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // The index of the abstract destination server starting at 1
    Integer index = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // FHIR-Server | FHIR-SDC-FormManager | FHIR-SDC-FormReceiver |
    // FHIR-SDC-FormProcessor
    Coding profile = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated Destination destination = 26;

  // Required capability that is assumed to function correctly on the FHIR
  // server being tested
  message Metadata {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "capability.required.exists() or capability.validated.exists()";

    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // Links to the FHIR specification
    message Link {
      // Unique id for inter-element referencing
      String id = 1;

      // Additional content defined by implementations
      repeated Extension extension = 2;

      // Extensions that cannot be ignored even if unrecognized
      repeated Extension modifier_extension = 3;

      // URL to the specification
      Uri url = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Short description
      String description = 5;
    }
    repeated Link link = 4;

    // Capabilities  that are assumed to function correctly on the FHIR server
    // being tested
    message Capability {
      // Unique id for inter-element referencing
      String id = 1;

      // Additional content defined by implementations
      repeated Extension extension = 2;

      // Extensions that cannot be ignored even if unrecognized
      repeated Extension modifier_extension = 3;

      // Are the capabilities required?
      Boolean required = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Are the capabilities validated?
      Boolean validated = 5
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // The expected capabilities of the server
      String description = 6;

      // Which origin server these requirements apply to
      repeated Integer origin = 7;

      // Which server these requirements apply to
      Integer destination = 8;

      // Links to the FHIR specification
      repeated Uri link = 9;

      // Required Capability Statement
      Canonical capabilities = 10
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
    }
    repeated Capability capability = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  Metadata metadata = 27;

  // Fixture in the test script - by reference (uri)
  message Fixture {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // Whether or not to implicitly create the fixture during setup
    Boolean autocreate = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Whether or not to implicitly delete the fixture during teardown
    Boolean autodelete = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Reference of the resource
    Reference resource = 6
        [(.google.fhir.proto.valid_reference_type) = "Resource"];
  }
  repeated Fixture fixture = 28;

  // Reference of the validation profile
  repeated Reference profile = 29
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

  // Placeholder for evaluated elements
  message Variable {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "expression.empty() or headerField.empty() or path.empty()";

    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // Descriptive name for this variable
    String name = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Default, hard-coded, or user-defined value for this variable
    String default_value = 5;

    // Natural language description of the variable
    String description = 6;

    // The FHIRPath expression against the fixture body
    String expression = 7;

    // HTTP header field name for source
    String header_field = 8;

    // Hint help text for default value to enter
    String hint = 9;

    // XPath or JSONPath against the fixture body
    String path = 10;

    // Fixture Id of source expression or headerField within this variable
    Id source_id = 11;
  }
  repeated Variable variable = 30;

  // A series of required setup operations before tests are executed
  message Setup {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // A setup operation or assert to perform
    message SetupAction {
      option (.google.fhir.proto.fhir_path_message_constraint) =
          "operation.exists() xor assert.exists()";

      // Unique id for inter-element referencing
      String id = 1;

      // Additional content defined by implementations
      repeated Extension extension = 2;

      // Extensions that cannot be ignored even if unrecognized
      repeated Extension modifier_extension = 3;

      // The setup operation to perform
      message Operation {
        option (.google.fhir.proto.fhir_path_message_constraint) =
            "sourceId.exists() or (targetId.count() + url.count() + params.count() = 1) or (type.code in ('capabilities' |'search' | 'transaction' | 'history'))";

        // Unique id for inter-element referencing
        String id = 1;

        // Additional content defined by implementations
        repeated Extension extension = 2;

        // Extensions that cannot be ignored even if unrecognized
        repeated Extension modifier_extension = 3;

        // The operation code type that will be executed
        Coding type = 4;

        // Resource type
        message ResourceCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/defined-types";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          FHIRDefinedTypeValueSet.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        ResourceCode resource = 5;

        // Tracking/logging operation label
        String label = 6;

        // Tracking/reporting operation description
        String description = 7;

        // Mime type to accept in the payload of the response, with charset etc.
        message AcceptCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/mimetypes";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          // Field 1 reserved to allow enumeration in the future.
          reserved 1;

          String id = 2;

          repeated Extension extension = 3;

          // This valueset is not enumerable, and so is represented as a string.
          string value = 4;
        }
        AcceptCode accept = 8;

        // Mime type of the request payload contents, with charset etc.
        message ContentTypeCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/mimetypes";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          // Field 1 reserved to allow enumeration in the future.
          reserved 1;

          String id = 2;

          repeated Extension extension = 3;

          // This valueset is not enumerable, and so is represented as a string.
          string value = 4;
        }
        ContentTypeCode content_type = 9;

        // Server responding to the request
        Integer destination = 10;

        // Whether or not to send the request url in encoded format
        Boolean encode_request_url = 11
            [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

        // delete | get | options | patch | post | put | head
        message MethodCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/http-operations";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          TestScriptRequestMethodCode.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        MethodCode method = 12;

        // Server initiating the request
        Integer origin = 13;

        // Explicitly defined path parameters
        String params = 14;

        // Each operation can have one or more header elements
        message RequestHeader {
          // Unique id for inter-element referencing
          String id = 1;

          // Additional content defined by implementations
          repeated Extension extension = 2;

          // Extensions that cannot be ignored even if unrecognized
          repeated Extension modifier_extension = 3;

          // HTTP header field name
          String field = 4
              [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

          // HTTP headerfield value
          String value = 5
              [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
        }
        repeated RequestHeader request_header = 15;

        // Fixture Id of mapped request
        Id request_id = 16;

        // Fixture Id of mapped response
        Id response_id = 17;

        // Fixture Id of body for PUT and POST requests
        Id source_id = 18;

        // Id of fixture used for extracting the [id],  [type], and [vid] for
        // GET requests
        Id target_id = 19;

        // Request URL
        String url = 20;
      }
      Operation operation = 4;

      // The assertion to perform
      message Assert {
        option (.google.fhir.proto.fhir_path_message_constraint) =
            "extension.exists() or (contentType.count() + expression.count() + headerField.count() + minimumId.count() + navigationLinks.count() + path.count() + requestMethod.count() + resource.count() + responseCode.count() + response.count()  + validateProfileId.count() <=1)";
        option (.google.fhir.proto.fhir_path_message_constraint) =
            "compareToSourceId.empty() xor (compareToSourceExpression.exists() or compareToSourcePath.exists())";
        option (.google.fhir.proto.fhir_path_message_constraint) =
            "(response.empty() and responseCode.empty() and direction = 'request') or direction.empty() or direction = 'response'";

        // Unique id for inter-element referencing
        String id = 1;

        // Additional content defined by implementations
        repeated Extension extension = 2;

        // Extensions that cannot be ignored even if unrecognized
        repeated Extension modifier_extension = 3;

        // Tracking/logging assertion label
        String label = 4;

        // Tracking/reporting assertion description
        String description = 5;

        // response | request
        message DirectionCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/assert-direction-codes";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          AssertionDirectionTypeCode.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        DirectionCode direction = 6;

        // Id of the source fixture to be evaluated
        String compare_to_source_id = 7;

        // The FHIRPath expression to evaluate against the source fixture
        String compare_to_source_expression = 8;

        // XPath or JSONPath expression to evaluate against the source fixture
        String compare_to_source_path = 9;

        // Mime type to compare against the 'Content-Type' header
        message ContentTypeCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/mimetypes";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          // Field 1 reserved to allow enumeration in the future.
          reserved 1;

          String id = 2;

          repeated Extension extension = 3;

          // This valueset is not enumerable, and so is represented as a string.
          string value = 4;
        }
        ContentTypeCode content_type = 10;

        // The FHIRPath expression to be evaluated
        String expression = 11;

        // HTTP header field name
        String header_field = 12;

        // Fixture Id of minimum content resource
        String minimum_id = 13;

        // Perform validation on navigation links?
        Boolean navigation_links = 14;

        // equals | notEquals | in | notIn | greaterThan | lessThan | empty |
        // notEmpty | contains | notContains | eval
        message OperatorCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/assert-operator-codes";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          AssertionOperatorTypeCode.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        OperatorCode operator = 15;

        // XPath or JSONPath expression
        String path = 16;

        // delete | get | options | patch | post | put | head
        message RequestMethodCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/http-operations";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          TestScriptRequestMethodCode.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        RequestMethodCode request_method = 17;

        // Request URL comparison value
        String request_url = 18 [json_name = "requestURL"];

        // Resource type
        message ResourceCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/defined-types";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          FHIRDefinedTypeValueSet.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        ResourceCode resource = 19;

        // okay | created | noContent | notModified | bad | forbidden | notFound
        // | methodNotAllowed | conflict | gone | preconditionFailed |
        // unprocessable
        message ResponseCode {
          option (.google.fhir.proto.structure_definition_kind) =
              KIND_PRIMITIVE_TYPE;
          option (.google.fhir.proto.fhir_valueset_url) =
              "http://hl7.org/fhir/ValueSet/assert-response-code-types";
          option (.google.fhir.proto.fhir_profile_base) =
              "http://hl7.org/fhir/StructureDefinition/code";

          AssertionResponseTypesCode.Value value = 1;

          String id = 2;

          repeated Extension extension = 3;
        }
        ResponseCode response = 20;

        // HTTP response code to test
        String response_code = 21;

        // Fixture Id of source expression or headerField
        Id source_id = 22;

        // Profile Id of validation profile reference
        Id validate_profile_id = 23;

        // The value to compare to
        String value = 24;

        // Will this assert produce a warning only on error?
        Boolean warning_only = 25
            [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
      }
      Assert assert_value = 5 [json_name = "assert"];
    }
    repeated SetupAction action = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  Setup setup = 31;

  // A test in this script
  message Test {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // Tracking/logging name of this test
    String name = 4;

    // Tracking/reporting short description of the test
    String description = 5;

    // A test operation or assert to perform
    message TestAction {
      option (.google.fhir.proto.fhir_path_message_constraint) =
          "operation.exists() xor assert.exists()";

      // Unique id for inter-element referencing
      String id = 1;

      // Additional content defined by implementations
      repeated Extension extension = 2;

      // Extensions that cannot be ignored even if unrecognized
      repeated Extension modifier_extension = 3;

      // The setup operation to perform
      Setup.SetupAction.Operation operation = 4 [
        (.google.fhir.proto.fhir_path_constraint) =
            "sourceId.exists() or (targetId.count() + url.count() + params.count() = 1) or (type.code in ('capabilities' | 'search' | 'transaction' | 'history'))"
      ];

      // The setup assertion to perform
      Setup.SetupAction.Assert assert_value = 5 [
        json_name = "assert",
        (.google.fhir.proto.fhir_path_constraint) =
            "extension.exists() or (contentType.count() + expression.count() + headerField.count() + minimumId.count() + navigationLinks.count() + path.count() + requestMethod.count() + resource.count() + responseCode.count() + response.count() + validateProfileId.count() <=1)",
        (.google.fhir.proto.fhir_path_constraint) =
            "compareToSourceId.empty() xor (compareToSourceExpression.exists() or compareToSourcePath.exists())",
        (.google.fhir.proto.fhir_path_constraint) =
            "(response.empty() and responseCode.empty() and direction = 'request') or direction.empty() or direction = 'response'"
      ];
    }
    repeated TestAction action = 6
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated Test test = 32;

  // A series of required clean up steps
  message Teardown {
    // Unique id for inter-element referencing
    String id = 1;

    // Additional content defined by implementations
    repeated Extension extension = 2;

    // Extensions that cannot be ignored even if unrecognized
    repeated Extension modifier_extension = 3;

    // One or more teardown operations to perform
    message TeardownAction {
      // Unique id for inter-element referencing
      String id = 1;

      // Additional content defined by implementations
      repeated Extension extension = 2;

      // Extensions that cannot be ignored even if unrecognized
      repeated Extension modifier_extension = 3;

      // The teardown operation to perform
      Setup.SetupAction.Operation operation = 4 [
        (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
        (.google.fhir.proto.fhir_path_constraint) =
            "sourceId.exists() or (targetId.count() + url.count() + params.count() = 1) or (type.code in ('capabilities' | 'search' | 'transaction' | 'history'))"
      ];
    }
    repeated TeardownAction action = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  Teardown teardown = 33;
}
