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

// Auto-generated from StructureDefinition for AuditEvent.
// Event record kept for security purposes.
// See http://hl7.org/fhir/StructureDefinition/AuditEvent
message AuditEvent {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/AuditEvent";

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

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

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

  // Type/identifier of event
  Coding type = 10
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // More specific type/id for the event
  repeated Coding subtype = 11;

  // Type of action performed during the event
  message ActionCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/audit-event-action";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    AuditEventActionCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  ActionCode action = 12;

  // When the activity occurred
  Period period = 13;

  // Time when the event was recorded
  Instant recorded = 14
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Whether the event succeeded or failed
  message OutcomeCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/audit-event-outcome";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    AuditEventOutcomeCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  OutcomeCode outcome = 15;

  // Description of the event outcome
  String outcome_desc = 16;

  // The purposeOfUse of the event
  repeated CodeableConcept purpose_of_event = 17;

  // Actor involved in the event
  message Agent {
    // 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;

    // How agent participated
    CodeableConcept type = 4;

    // Agent role in the event
    repeated CodeableConcept role = 5;

    // Identifier of who
    Reference who = 6 [
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "Organization",
      (.google.fhir.proto.valid_reference_type) = "Device",
      (.google.fhir.proto.valid_reference_type) = "Patient",
      (.google.fhir.proto.valid_reference_type) = "RelatedPerson"
    ];

    // Alternative User identity
    String alt_id = 7;

    // Human friendly name for the agent
    String name = 8;

    // Whether user is initiator
    Boolean requestor = 9
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Where
    Reference location = 10
        [(.google.fhir.proto.valid_reference_type) = "Location"];

    // Policy that authorized event
    repeated Uri policy = 11;

    // Type of media
    Coding media = 12;

    // Logical network location for application activity
    message Network {
      // 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;

      // Identifier for the network access point of the user device
      String address = 4;

      // The type of network access point
      message TypeCode {
        option (.google.fhir.proto.structure_definition_kind) =
            KIND_PRIMITIVE_TYPE;
        option (.google.fhir.proto.fhir_valueset_url) =
            "http://hl7.org/fhir/ValueSet/network-type";
        option (.google.fhir.proto.fhir_profile_base) =
            "http://hl7.org/fhir/StructureDefinition/code";

        AuditEventAgentNetworkTypeCode.Value value = 1;

        String id = 2;

        repeated Extension extension = 3;
      }
      TypeCode type = 5;
    }
    Network network = 13;

    // Reason given for this user
    repeated CodeableConcept purpose_of_use = 14;
  }
  repeated Agent agent = 18
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Audit Event Reporter
  message Source {
    // 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;

    // Logical source location within the enterprise
    String site = 4;

    // The identity of source detecting the event
    Reference observer = 5 [
      (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "Organization",
      (.google.fhir.proto.valid_reference_type) = "Device",
      (.google.fhir.proto.valid_reference_type) = "Patient",
      (.google.fhir.proto.valid_reference_type) = "RelatedPerson"
    ];

    // The type of source where event originated
    repeated Coding type = 6;
  }
  Source source = 19
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Data or objects used
  message Entity {
    option (.google.fhir.proto.fhir_path_message_constraint) =
        "name.empty() or query.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;

    // Specific instance of resource
    Reference what = 4 [(.google.fhir.proto.valid_reference_type) = "Resource"];

    // Type of entity involved
    Coding type = 5;

    // What role the entity played
    Coding role = 6;

    // Life-cycle stage for the entity
    Coding lifecycle = 7;

    // Security labels on the entity
    repeated Coding security_label = 8;

    // Descriptor for entity
    String name = 9;

    // Descriptive text
    String description = 10;

    // Query parameters
    Base64Binary query = 11;

    // Additional Information about the entity
    message Detail {
      // 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;

      // Name of the property
      String type = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Property value
      message ValueX {
        option (.google.fhir.proto.is_choice_type) = true;

        oneof choice {
          String string_value = 1 [json_name = "string"];
          Base64Binary base64_binary = 2;
        }
      }
      ValueX value = 5
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];
    }
    repeated Detail detail = 12;
  }
  repeated Entity entity = 20;
}
