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

// Auto-generated from StructureDefinition for AdverseEvent.
// Medical care, research study or other healthcare event causing physical
// injury. See http://hl7.org/fhir/StructureDefinition/AdverseEvent
message AdverseEvent {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/AdverseEvent";

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

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

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

  // Business identifier for the event
  Identifier identifier = 10;

  // actual | potential
  message ActualityCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/adverse-event-actuality";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    AdverseEventActualityCode.Value value = 1;

    String id = 2;

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

  // product-problem | product-quality | product-use-error | wrong-dose |
  // incorrect-prescribing-information | wrong-technique |
  // wrong-route-of-administration | wrong-rate | wrong-duration | wrong-time |
  // expired-drug | medical-device-use-error | problem-different-manufacturer |
  // unsafe-physical-environment
  repeated CodeableConcept category = 12;

  // Type of the event itself in relation to the subject
  CodeableConcept event = 13;

  // Subject impacted by event
  Reference subject = 14 [
    (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "Group",
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson"
  ];

  // Encounter created as part of
  Reference encounter = 15
      [(.google.fhir.proto.valid_reference_type) = "Encounter"];

  // When the event occurred
  DateTime date = 16;

  // When the event was detected
  DateTime detected = 17;

  // When the event was recorded
  DateTime recorded_date = 18;

  // Effect on the subject due to this event
  repeated Reference resulting_condition = 19
      [(.google.fhir.proto.valid_reference_type) = "Condition"];

  // Location where adverse event occurred
  Reference location = 20
      [(.google.fhir.proto.valid_reference_type) = "Location"];

  // Seriousness of the event
  CodeableConcept seriousness = 21;

  // mild | moderate | severe
  CodeableConcept severity = 22;

  // resolved | recovering | ongoing | resolvedWithSequelae | fatal | unknown
  CodeableConcept outcome = 23;

  // Who recorded the adverse event
  Reference recorder = 24 [
    (.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) = "RelatedPerson"
  ];

  // Who  was involved in the adverse event or the potential adverse event
  repeated Reference contributor = 25 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Device"
  ];

  // The suspected agent causing the adverse event
  message SuspectEntity {
    // 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;

    // Refers to the specific entity that caused the adverse event
    Reference instance = 4 [
      (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
      (.google.fhir.proto.valid_reference_type) = "Immunization",
      (.google.fhir.proto.valid_reference_type) = "Procedure",
      (.google.fhir.proto.valid_reference_type) = "Substance",
      (.google.fhir.proto.valid_reference_type) = "Medication",
      (.google.fhir.proto.valid_reference_type) = "MedicationAdministration",
      (.google.fhir.proto.valid_reference_type) = "MedicationStatement",
      (.google.fhir.proto.valid_reference_type) = "Device"
    ];

    // Information on the possible cause of the event
    message Causality {
      // 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;

      // Assessment of if the entity caused the event
      CodeableConcept assessment = 4;

      // AdverseEvent.suspectEntity.causalityProductRelatedness
      String product_relatedness = 5;

      // AdverseEvent.suspectEntity.causalityAuthor
      Reference author = 6 [
        (.google.fhir.proto.valid_reference_type) = "Practitioner",
        (.google.fhir.proto.valid_reference_type) = "PractitionerRole"
      ];

      // ProbabilityScale | Bayesian | Checklist
      CodeableConcept method = 7;
    }
    repeated Causality causality = 5;
  }
  repeated SuspectEntity suspect_entity = 26;

  // AdverseEvent.subjectMedicalHistory
  repeated Reference subject_medical_history = 27 [
    (.google.fhir.proto.valid_reference_type) = "Condition",
    (.google.fhir.proto.valid_reference_type) = "Observation",
    (.google.fhir.proto.valid_reference_type) = "AllergyIntolerance",
    (.google.fhir.proto.valid_reference_type) = "FamilyMemberHistory",
    (.google.fhir.proto.valid_reference_type) = "Immunization",
    (.google.fhir.proto.valid_reference_type) = "Procedure",
    (.google.fhir.proto.valid_reference_type) = "Media",
    (.google.fhir.proto.valid_reference_type) = "DocumentReference"
  ];

  // AdverseEvent.referenceDocument
  repeated Reference reference_document = 28
      [(.google.fhir.proto.valid_reference_type) = "DocumentReference"];

  // AdverseEvent.study
  repeated Reference study = 29
      [(.google.fhir.proto.valid_reference_type) = "ResearchStudy"];
}
