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

// Auto-generated from StructureDefinition for MeasureReport.
// Results of a measure evaluation.
// See http://hl7.org/fhir/StructureDefinition/MeasureReport
message MeasureReport {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/MeasureReport";
  option (.google.fhir.proto.fhir_path_message_constraint) =
      "(type != 'data-collection') or group.exists().not()";
  option (.google.fhir.proto.fhir_path_message_constraint) =
      "group.stratifier.stratum.all(value.exists() xor component.exists())";

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

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

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

  // Additional identifier for the MeasureReport
  repeated Identifier identifier = 10;

  // complete | pending | 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/measure-report-status";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    MeasureReportStatusCode.Value value = 1;

    String id = 2;

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

  // individual | subject-list | summary | data-collection
  message TypeCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/measure-report-type";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    MeasureReportTypeCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  TypeCode type = 12
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // What measure was calculated
  Canonical measure = 13
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // What individual(s) the report is for
  Reference subject = 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) = "Location",
    (.google.fhir.proto.valid_reference_type) = "Device",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
    (.google.fhir.proto.valid_reference_type) = "Group"
  ];

  // When the report was generated
  DateTime date = 15;

  // Who is reporting the data
  Reference reporter = 16 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Location",
    (.google.fhir.proto.valid_reference_type) = "Organization"
  ];

  // What period the report covers
  Period period = 17
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // increase | decrease
  CodeableConcept improvement_notation = 18;

  // Measure results for each group
  message Group {
    // 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;

    // Meaning of the group
    CodeableConcept code = 4;

    // The populations in the group
    message Population {
      // 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;

      // initial-population | numerator | numerator-exclusion | denominator |
      // denominator-exclusion | denominator-exception | measure-population |
      // measure-population-exclusion | measure-observation
      CodeableConcept code = 4;

      // Size of the population
      Integer count = 5;

      // For subject-list reports, the subject results in this population
      Reference subject_results = 6
          [(.google.fhir.proto.valid_reference_type) = "List"];
    }
    repeated Population population = 5;

    // What score this group achieved
    Quantity measure_score = 6;

    // Stratification results
    message Stratifier {
      // 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 stratifier of the group
      repeated CodeableConcept code = 4;

      // Stratum results, one for each unique value, or set of values, in the
      // stratifier, or stratifier components
      message StratifierGroup {
        // 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 stratum value, e.g. male
        CodeableConcept value = 4;

        // Stratifier component values
        message Component {
          // 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 stratifier component of the group
          CodeableConcept code = 4
              [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

          // The stratum component value, e.g. male
          CodeableConcept value = 5
              [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
        }
        repeated Component component = 5;

        // Population results in this stratum
        message StratifierGroupPopulation {
          // 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;

          // initial-population | numerator | numerator-exclusion | denominator
          // | denominator-exclusion | denominator-exception |
          // measure-population | measure-population-exclusion |
          // measure-observation
          CodeableConcept code = 4;

          // Size of the population
          Integer count = 5;

          // For subject-list reports, the subject results in this population
          Reference subject_results = 6
              [(.google.fhir.proto.valid_reference_type) = "List"];
        }
        repeated StratifierGroupPopulation population = 6;

        // What score this stratum achieved
        Quantity measure_score = 7;
      }
      repeated StratifierGroup stratum = 5;
    }
    repeated Stratifier stratifier = 7;
  }
  repeated Group group = 19;

  // What data was used to calculate the measure score
  repeated Reference evaluated_resource = 20
      [(.google.fhir.proto.valid_reference_type) = "Resource"];
}
