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

// Auto-generated from StructureDefinition for CodeSystem.
// Declares the existence of and describes a code system or code system
// supplement. See http://hl7.org/fhir/StructureDefinition/CodeSystem
message CodeSystem {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/CodeSystem";
  option (.google.fhir.proto.fhir_path_message_constraint) =
      "concept.code.combine($this.descendants().concept.code).isDistinct()";
  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:
  // CodeSystem.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 code system, represented as a URI (globally
  // unique) (Coding.system)
  Uri url = 10;

  // Additional identifier for the code system (business identifier)
  repeated Identifier identifier = 11;

  // Business version of the code system (Coding.version)
  String version = 12;

  // Name for this code system (computer friendly)
  String name = 13;

  // Name for this code system (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 code system
  Markdown description = 20;

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

  // Intended jurisdiction for code system (if applicable)
  repeated CodeableConcept jurisdiction = 22;

  // Why this code system is defined
  Markdown purpose = 23;

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

  // If code comparison is case sensitive
  Boolean case_sensitive = 25;

  // Canonical reference to the value set with entire code system
  Canonical value_set = 26;

  // grouped-by | is-a | part-of | classified-with
  message HierarchyMeaningCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/codesystem-hierarchy-meaning";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    CodeSystemHierarchyMeaningCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  HierarchyMeaningCode hierarchy_meaning = 27;

  // If code system defines a compositional grammar
  Boolean compositional = 28;

  // If definitions are not stable
  Boolean version_needed = 29;

  // not-present | example | fragment | complete | supplement
  message ContentCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/codesystem-content-mode";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    CodeSystemContentModeCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  ContentCode content = 30
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Canonical URL of Code System this adds designations and properties to
  Canonical supplements = 31;

  // Total concepts in the code system
  UnsignedInt count = 32;

  // Filter that can be used in a value set
  message Filter {
    // 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 that identifies the filter
    Code code = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // How or why the filter is used
    String description = 5;

    // = | is-a | descendent-of | is-not-a | regex | in | not-in | generalizes |
    // exists
    message OperatorCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/filter-operator";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      FilterOperatorCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    repeated OperatorCode operator = 6
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // What to use for the value
    String value = 7
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated Filter filter = 33;

  // Additional information supplied about each concept
  message Property {
    // 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;

    // Identifies the property on the concepts, and when referred to in
    // operations
    Code code = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Formal identifier for the property
    Uri uri = 5;

    // Why the property is defined, and/or what it conveys
    String description = 6;

    // code | Coding | string | integer | boolean | dateTime | decimal
    message TypeCode {
      option (.google.fhir.proto.structure_definition_kind) =
          KIND_PRIMITIVE_TYPE;
      option (.google.fhir.proto.fhir_valueset_url) =
          "http://hl7.org/fhir/ValueSet/concept-property-type";
      option (.google.fhir.proto.fhir_profile_base) =
          "http://hl7.org/fhir/StructureDefinition/code";

      PropertyTypeCode.Value value = 1;

      String id = 2;

      repeated Extension extension = 3;
    }
    TypeCode type = 7
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
  }
  repeated Property property = 34;

  // Concepts in the code system
  message ConceptDefinition {
    // 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 that identifies concept
    Code code = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Text to display to the user
    String display = 5;

    // Formal definition
    String definition = 6;

    // Additional representations for the concept
    message Designation {
      // 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;

      // Human language of the designation
      Code language = 4;

      // Details how this designation would be used
      Coding use = 5;

      // The text value for this designation
      String value = 6
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
    }
    repeated Designation designation = 7;

    // Property value for the concept
    message ConceptProperty {
      // 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;

      // Reference to CodeSystem.property.code
      Code code = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Value of the property for this concept
      message ValueX {
        option (.google.fhir.proto.is_choice_type) = true;

        oneof choice {
          Code code = 1;
          Coding coding = 2;
          String string_value = 3 [json_name = "string"];
          Integer integer = 4;
          Boolean boolean = 5;
          DateTime date_time = 6;
          Decimal decimal = 7;
        }
      }
      ValueX value = 5
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
    }
    repeated ConceptProperty property = 8;

    // Child Concepts (is-a/contains/categorizes)
    repeated ConceptDefinition concept = 9;
  }
  repeated ConceptDefinition concept = 35;
}
