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

// Auto-generated from StructureDefinition for QuestionnaireResponse.
// A structured set of questions and their answers.
// See http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse
message QuestionnaireResponse {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse";

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

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

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

  // Unique id for this set of answers
  Identifier identifier = 10;

  // Request fulfilled by this QuestionnaireResponse
  repeated Reference based_on = 11 [
    (.google.fhir.proto.valid_reference_type) = "CarePlan",
    (.google.fhir.proto.valid_reference_type) = "ServiceRequest"
  ];

  // Part of this action
  repeated Reference part_of = 12 [
    (.google.fhir.proto.valid_reference_type) = "Observation",
    (.google.fhir.proto.valid_reference_type) = "Procedure"
  ];

  // Form being answered
  Canonical questionnaire = 13;

  // in-progress | completed | amended | entered-in-error | stopped
  message StatusCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/questionnaire-answers-status";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    QuestionnaireResponseStatusCode.Value value = 1;

    String id = 2;

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

  // The subject of the questions
  Reference subject = 15
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

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

  // Date the answers were gathered
  DateTime authored = 17;

  // Person who received and recorded the answers
  Reference author = 18 [
    (.google.fhir.proto.valid_reference_type) = "Device",
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
    (.google.fhir.proto.valid_reference_type) = "Organization"
  ];

  // The person who answered the questions
  Reference source = 19 [
    (.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"
  ];

  // Groups and questions
  message Item {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "(answer.exists() and item.exists()).not()";

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

    // Pointer to specific item from Questionnaire
    String link_id = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // ElementDefinition - details for the item
    Uri definition = 5;

    // Name for group or question text
    String text = 6;

    // The response(s) to the question
    message Answer {
      // 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;

      // Single-valued answer to the question
      message ValueX {
        option (.google.fhir.proto.is_choice_type) = true;

        oneof choice {
          Boolean boolean = 1;
          Decimal decimal = 2;
          Integer integer = 3;
          Date date = 4;
          DateTime date_time = 5;
          Time time = 6;
          String string_value = 7 [json_name = "string"];
          Uri uri = 8;
          Attachment attachment = 9;
          Coding coding = 10;
          Quantity quantity = 11;
          Reference reference = 12
              [(.google.fhir.proto.valid_reference_type) = "Resource"];
        }
      }
      ValueX value = 4;

      // Nested groups and questions
      repeated Item item = 5;
    }
    repeated Answer answer = 7;

    // Nested questionnaire response items
    repeated Item item = 8;
  }
  repeated Item item = 20;
}
