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

// Auto-generated from StructureDefinition for SubstanceSpecification.
// The detailed description of a substance, typically at a level beyond what is
// used for prescribing. See
// http://hl7.org/fhir/StructureDefinition/SubstanceSpecification
message SubstanceSpecification {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/SubstanceSpecification";

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

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

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

  // Identifier by which this substance is known
  Identifier identifier = 10;

  // High level categorization, e.g. polymer or nucleic acid
  CodeableConcept type = 11;

  // Status of substance within the catalogue e.g. approved
  CodeableConcept status = 12;

  // If the substance applies to only human or veterinary use
  CodeableConcept domain = 13;

  // Textual description of the substance
  String description = 14;

  // Supporting literature
  repeated Reference source = 15
      [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];

  // Textual comment about this record of a substance
  String comment = 16;

  // Moiety, for structural modifications
  message Moiety {
    // 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;

    // Role that the moiety is playing
    CodeableConcept role = 4;

    // Identifier by which this moiety substance is known
    Identifier identifier = 5;

    // Textual name for this moiety substance
    String name = 6;

    // Stereochemistry type
    CodeableConcept stereochemistry = 7;

    // Optical activity type
    CodeableConcept optical_activity = 8;

    // Molecular formula
    String molecular_formula = 9;

    // Quantitative value for this moiety
    message AmountX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Quantity quantity = 1;
        String string_value = 2 [json_name = "string"];
      }
    }
    AmountX amount = 10;
  }
  repeated Moiety moiety = 17;

  // General specifications for this substance, including how it is related to
  // other substances
  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;

    // A category for this property, e.g. Physical, Chemical, Enzymatic
    CodeableConcept category = 4;

    // Property type e.g. viscosity, pH, isoelectric point
    CodeableConcept code = 5;

    // Parameters that were used in the measurement of a property (e.g. for
    // viscosity: measured at 20C with a pH of 7.1)
    String parameters = 6;

    // A substance upon which a defining property depends (e.g. for solubility:
    // in water, in alcohol)
    message DefiningSubstanceX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Reference reference = 1 [
          (.google.fhir.proto.valid_reference_type) = "SubstanceSpecification",
          (.google.fhir.proto.valid_reference_type) = "Substance"
        ];
        CodeableConcept codeable_concept = 2;
      }
    }
    DefiningSubstanceX defining_substance = 7;

    // Quantitative value for this property
    message AmountX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Quantity quantity = 1;
        String string_value = 2 [json_name = "string"];
      }
    }
    AmountX amount = 8;
  }
  repeated Property property = 18;

  // General information detailing this substance
  Reference reference_information = 19
      [(.google.fhir.proto.valid_reference_type) =
           "SubstanceReferenceInformation"];

  // Structural information
  message Structure {
    // 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;

    // Stereochemistry type
    CodeableConcept stereochemistry = 4;

    // Optical activity type
    CodeableConcept optical_activity = 5;

    // Molecular formula
    String molecular_formula = 6;

    // Specified per moiety according to the Hill system, i.e. first C, then H,
    // then alphabetical, each moiety separated by a dot
    String molecular_formula_by_moiety = 7;

    // Applicable for single substances that contain a radionuclide or a
    // non-natural isotopic ratio
    message Isotope {
      // 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;

      // Substance identifier for each non-natural or radioisotope
      Identifier identifier = 4;

      // Substance name for each non-natural or radioisotope
      CodeableConcept name = 5;

      // The type of isotopic substitution present in a single substance
      CodeableConcept substitution = 6;

      // Half life - for a non-natural nuclide
      Quantity half_life = 7;

      // The molecular weight or weight range (for proteins, polymers or nucleic
      // acids)
      message MolecularWeight {
        // 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 method by which the molecular weight was determined
        CodeableConcept method = 4;

        // Type of molecular weight such as exact, average (also known as.
        // number average), weight average
        CodeableConcept type = 5;

        // Used to capture quantitative values for a variety of elements. If
        // only limits are given, the arithmetic mean would be the average. If
        // only a single definite value for a given element is given, it would
        // be captured in this field
        Quantity amount = 6;
      }
      MolecularWeight molecular_weight = 8;
    }
    repeated Isotope isotope = 8;

    // The molecular weight or weight range (for proteins, polymers or nucleic
    // acids)
    Isotope.MolecularWeight molecular_weight = 9;

    // Supporting literature
    repeated Reference source = 10
        [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];

    // Molecular structural representation
    message Representation {
      // 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 type of structure (e.g. Full, Partial, Representative)
      CodeableConcept type = 4;

      // The structural representation as text string in a format e.g. InChI,
      // SMILES, MOLFILE, CDX
      String representation = 5;

      // An attached file with the structural representation
      Attachment attachment = 6;
    }
    repeated Representation representation = 11;
  }
  Structure structure = 20;

  // Codes associated with the substance
  message CodeType {
    // 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 specific code
    CodeableConcept code = 4;

    // Status of the code assignment
    CodeableConcept status = 5;

    // The date at which the code status is changed as part of the terminology
    // maintenance
    DateTime status_date = 6;

    // Any comment can be provided in this field, if necessary
    String comment = 7;

    // Supporting literature
    repeated Reference source = 8
        [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];
  }
  repeated CodeType code = 21;

  // Names applicable to this substance
  message Name {
    // 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 actual name
    String name = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Name type
    CodeableConcept type = 5;

    // The status of the name
    CodeableConcept status = 6;

    // If this is the preferred name for this substance
    Boolean preferred = 7;

    // Language of the name
    repeated CodeableConcept language = 8;

    // The use context of this name for example if there is a different name a
    // drug active ingredient as opposed to a food colour additive
    repeated CodeableConcept domain = 9;

    // The jurisdiction where this name applies
    repeated CodeableConcept jurisdiction = 10;

    // A synonym of this name
    repeated Name synonym = 11;

    // A translation for this name
    repeated Name translation = 12;

    // Details of the official nature of this name
    message Official {
      // 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;

      // Which authority uses this official name
      CodeableConcept authority = 4;

      // The status of the official name
      CodeableConcept status = 5;

      // Date of official name change
      DateTime date = 6;
    }
    repeated Official official = 13;

    // Supporting literature
    repeated Reference source = 14
        [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];
  }
  repeated Name name = 22;

  // The molecular weight or weight range (for proteins, polymers or nucleic
  // acids)
  repeated Structure.Isotope.MolecularWeight molecular_weight = 23;

  // A link between this substance and another, with details of the relationship
  message Relationship {
    // 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 pointer to another substance, as a resource or just a representational
    // code
    message SubstanceX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Reference reference = 1 [(.google.fhir.proto.valid_reference_type) =
                                     "SubstanceSpecification"];
        CodeableConcept codeable_concept = 2;
      }
    }
    SubstanceX substance = 4;

    // For example "salt to parent", "active moiety", "starting material"
    CodeableConcept relationship = 5;

    // For example where an enzyme strongly bonds with a particular substance,
    // this is a defining relationship for that enzyme, out of several possible
    // substance relationships
    Boolean is_defining = 6;

    // A numeric factor for the relationship, for instance to express that the
    // salt of a substance has some percentage of the active substance in
    // relation to some other
    message AmountX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Quantity quantity = 1;
        Range range = 2;
        Ratio ratio = 3;
        String string_value = 4 [json_name = "string"];
      }
    }
    AmountX amount = 7;

    // For use when the numeric
    Ratio amount_ratio_low_limit = 8;

    // An operator for the amount, for example "average", "approximately", "less
    // than"
    CodeableConcept amount_type = 9;

    // Supporting literature
    repeated Reference source = 10
        [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];
  }
  repeated Relationship relationship = 24;

  // Data items specific to nucleic acids
  Reference nucleic_acid = 25
      [(.google.fhir.proto.valid_reference_type) = "SubstanceNucleicAcid"];

  // Data items specific to polymers
  Reference polymer = 26
      [(.google.fhir.proto.valid_reference_type) = "SubstancePolymer"];

  // Data items specific to proteins
  Reference protein = 27
      [(.google.fhir.proto.valid_reference_type) = "SubstanceProtein"];

  // Material or taxonomic/anatomical source for the substance
  Reference source_material = 28
      [(.google.fhir.proto.valid_reference_type) = "SubstanceSourceMaterial"];
}
