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

// Auto-generated from StructureDefinition for Composition.
// A set of resources composed into a single coherent clinical statement with
// clinical attestation. See http://hl7.org/fhir/StructureDefinition/Composition
message Composition {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/Composition";

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

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

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

  // Version-independent identifier for the Composition
  Identifier identifier = 10;

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

    CompositionStatusCode.Value value = 1;

    String id = 2;

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

  // Kind of composition (LOINC if possible)
  CodeableConcept type = 12
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Categorization of Composition
  repeated CodeableConcept category = 13;

  // Who and/or what the composition is about
  Reference subject = 14
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

  // Context of the Composition
  Reference encounter = 15
      [(.google.fhir.proto.valid_reference_type) = "Encounter"];

  // Composition editing time
  DateTime date = 16
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Who and/or what authored the composition
  repeated Reference author = 17 [
    (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Device",
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
    (.google.fhir.proto.valid_reference_type) = "Organization"
  ];

  // Human Readable name/title
  String title = 18
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // As defined by affinity domain
  message ConfidentialityCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://terminology.hl7.org/ValueSet/v3-ConfidentialityClassification";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    V3ConfidentialityClassificationValueSet.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  ConfidentialityCode confidentiality = 19;

  // Attests to accuracy of composition
  message Attester {
    // 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;

    // personal | professional | legal | official
    message ModeCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/composition-attestation-mode";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      CompositionAttestationModeCode.Value value = 1;

      String id = 2;

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

    // When the composition was attested
    DateTime time = 5;

    // Who attested the composition
    Reference party = 6 [
      (.google.fhir.proto.valid_reference_type) = "Patient",
      (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "Organization"
    ];
  }
  repeated Attester attester = 20;

  // Organization which maintains the composition
  Reference custodian = 21
      [(.google.fhir.proto.valid_reference_type) = "Organization"];

  // Relationships to other compositions/documents
  message RelatesTo {
    // 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;

    // replaces | transforms | signs | appends
    message CodeType {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/document-relationship-type";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      DocumentRelationshipTypeCode.Value value = 1;

      String id = 2;

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

    // Target of the relationship
    message TargetX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Identifier identifier = 1;
        Reference reference = 2
            [(.google.fhir.proto.valid_reference_type) = "Composition"];
      }
    }
    TargetX target = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated RelatesTo relates_to = 22;

  // The clinical service(s) being documented
  message Event {
    // 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;

    // Code(s) that apply to the event being documented
    repeated CodeableConcept code = 4;

    // The period covered by the documentation
    Period period = 5;

    // The event(s) being documented
    repeated Reference detail = 6
        [(.google.fhir.proto.valid_reference_type) = "Resource"];
  }
  repeated Event event = 23;

  // Composition is broken into sections
  message Section {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "text.exists() or entry.exists() or section.exists()";
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "emptyReason.empty() or entry.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;

    // Label for section (e.g. for ToC)
    String title = 4;

    // Classification of section (recommended)
    CodeableConcept code = 5;

    // Who and/or what authored the section
    repeated Reference author = 6 [
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "Device",
      (.google.fhir.proto.valid_reference_type) = "Patient",
      (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
      (.google.fhir.proto.valid_reference_type) = "Organization"
    ];

    // Who/what the section is about, when it is not about the subject of
    // composition
    Reference focus = 7
        [(.google.fhir.proto.valid_reference_type) = "Resource"];

    // Text summary of the section, for human interpretation
    Narrative text = 8;

    // working | snapshot | changes
    message ModeCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/list-mode";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      ListModeCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    ModeCode mode = 9;

    // Order of section entries
    CodeableConcept ordered_by = 10;

    // A reference to data that supports this section
    repeated Reference entry = 11
        [(.google.fhir.proto.valid_reference_type) = "Resource"];

    // Why the section is empty
    CodeableConcept empty_reason = 12;

    // Nested Section
    repeated Section section = 13;
  }
  repeated Section section = 24;
}
