//    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";

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/request_group_go_proto";

// Auto-generated from StructureDefinition for RequestGroup.
// A group of related requests.
// See http://hl7.org/fhir/StructureDefinition/RequestGroup
message RequestGroup {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/RequestGroup";

  // 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:
  // RequestGroup.contained
  reserved 7;

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

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

  // Business identifier
  repeated Identifier identifier = 10;

  // Instantiates FHIR protocol or definition
  repeated Canonical instantiates_canonical = 11;

  // Instantiates external protocol or definition
  repeated Uri instantiates_uri = 12;

  // Fulfills plan, proposal, or order
  repeated Reference based_on = 13
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

  // Request(s) replaced by this request
  repeated Reference replaces = 14
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

  // Composite request this is part of
  Identifier group_identifier = 15;

  // draft | active | on-hold | revoked | completed | entered-in-error | 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/request-status";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    RequestStatusCode.Value value = 1;

    String id = 2;

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

  // proposal | plan | directive | order | original-order | reflex-order |
  // filler-order | instance-order | option
  message IntentCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/request-intent";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    RequestIntentCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  IntentCode intent = 17
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // routine | urgent | asap | stat
  message PriorityCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/request-priority";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    RequestPriorityCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  PriorityCode priority = 18;

  // What's being requested/ordered
  CodeableConcept code = 19;

  // Who the request group is about
  Reference subject = 20 [
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "Group"
  ];

  // Created as part of
  Reference encounter = 21
      [(.google.fhir.proto.valid_reference_type) = "Encounter"];

  // When the request group was authored
  DateTime authored_on = 22;

  // Device or practitioner that authored the request group
  Reference author = 23 [
    (.google.fhir.proto.valid_reference_type) = "Device",
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole"
  ];

  // Why the request group is needed
  repeated CodeableConcept reason_code = 24;

  // Why the request group is needed
  repeated Reference reason_reference = 25 [
    (.google.fhir.proto.valid_reference_type) = "Condition",
    (.google.fhir.proto.valid_reference_type) = "Observation",
    (.google.fhir.proto.valid_reference_type) = "DiagnosticReport",
    (.google.fhir.proto.valid_reference_type) = "DocumentReference"
  ];

  // Additional notes about the response
  repeated Annotation note = 26;

  // Proposed actions, if any
  message Action {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "resource.exists() != action.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;

    // User-visible prefix for the action (e.g. 1. or A.)
    String prefix = 4;

    // User-visible title
    String title = 5;

    // Short description of the action
    String description = 6;

    // Static text equivalent of the action, used if the dynamic aspects cannot
    // be interpreted by the receiving system
    String text_equivalent = 7;

    // routine | urgent | asap | stat
    message PriorityCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/request-priority";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      RequestPriorityCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    PriorityCode priority = 8;

    // Code representing the meaning of the action or sub-actions
    repeated CodeableConcept code = 9;

    // Supporting documentation for the intended performer of the action
    repeated RelatedArtifact documentation = 10;

    // Whether or not the action is applicable
    message Condition {
      // 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;

      // applicability | start | stop
      message KindCode {
        option (.google.fhir.proto.structure_definition_kind) =
            KIND_PRIMITIVE_TYPE;
        option (.google.fhir.proto.fhir_valueset_url) =
            "http://hl7.org/fhir/ValueSet/action-condition-kind";
        option (.google.fhir.proto.fhir_profile_base) =
            "http://hl7.org/fhir/StructureDefinition/code";

        ActionConditionKindCode.Value value = 1;

        String id = 2;

        repeated Extension extension = 3;
      }
      KindCode kind = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Boolean-valued expression
      Expression expression = 5;
    }
    repeated Condition condition = 11;

    // Relationship to another action
    message RelatedAction {
      // 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;

      // What action this is related to
      Id action_id = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // before-start | before | before-end | concurrent-with-start | concurrent
      // | concurrent-with-end | after-start | after | after-end
      message RelationshipCode {
        option (.google.fhir.proto.structure_definition_kind) =
            KIND_PRIMITIVE_TYPE;
        option (.google.fhir.proto.fhir_valueset_url) =
            "http://hl7.org/fhir/ValueSet/action-relationship-type";
        option (.google.fhir.proto.fhir_profile_base) =
            "http://hl7.org/fhir/StructureDefinition/code";

        ActionRelationshipTypeCode.Value value = 1;

        String id = 2;

        repeated Extension extension = 3;
      }
      RelationshipCode relationship = 5
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Time offset for the relationship
      message OffsetX {
        option (.google.fhir.proto.is_choice_type) = true;

        oneof choice {
          Duration duration = 1;
          Range range = 2;
        }
      }
      OffsetX offset = 6;
    }
    repeated RelatedAction related_action = 12;

    // When the action should take place
    message TimingX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        DateTime date_time = 1;
        Age age = 2;
        Period period = 3;
        Duration duration = 4;
        Range range = 5;
        Timing timing = 6;
      }
    }
    TimingX timing = 13;

    // Who should perform the action
    repeated Reference participant = 14 [
      (.google.fhir.proto.valid_reference_type) = "Patient",
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
      (.google.fhir.proto.valid_reference_type) = "Device"
    ];

    // create | update | remove | fire-event
    CodeableConcept type = 15;

    // visual-group | logical-group | sentence-group
    message GroupingBehaviorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/action-grouping-behavior";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ActionGroupingBehaviorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    GroupingBehaviorCode grouping_behavior = 16;

    // any | all | all-or-none | exactly-one | at-most-one | one-or-more
    message SelectionBehaviorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/action-selection-behavior";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ActionSelectionBehaviorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    SelectionBehaviorCode selection_behavior = 17;

    // must | could | must-unless-documented
    message RequiredBehaviorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/action-required-behavior";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ActionRequiredBehaviorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    RequiredBehaviorCode required_behavior = 18;

    // yes | no
    message PrecheckBehaviorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/action-precheck-behavior";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ActionPrecheckBehaviorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    PrecheckBehaviorCode precheck_behavior = 19;

    // single | multiple
    message CardinalityBehaviorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/action-cardinality-behavior";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ActionCardinalityBehaviorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    CardinalityBehaviorCode cardinality_behavior = 20;

    // The target of the action
    Reference resource = 21
        [(.google.fhir.proto.valid_reference_type) = "Resource"];

    // Sub action
    repeated Action action = 22;
  }
  repeated Action action = 27;
}
