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

// Auto-generated from StructureDefinition for MedicationRequest.
// Ordering of medication for patient or group.
// See http://hl7.org/fhir/StructureDefinition/MedicationRequest
message MedicationRequest {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/MedicationRequest";

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

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

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

  // External ids for this request
  repeated Identifier identifier = 10;

  // active | on-hold | cancelled | completed | entered-in-error | stopped |
  // draft | 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/medicationrequest-status";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    MedicationrequestStatusCode.Value value = 1;

    String id = 2;

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

  // Reason for current status
  CodeableConcept status_reason = 12;

  // proposal | plan | order | original-order | reflex-order | filler-order |
  // instance-order | option
  message IntentCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/medicationrequest-intent";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    MedicationRequestIntentCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  IntentCode intent = 13
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Type of medication usage
  repeated CodeableConcept category = 14;

  // routine | urgent | asap | stat
  message PriorityCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/request-priority";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    RequestPriorityCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  PriorityCode priority = 15;

  // True if request is prohibiting action
  Boolean do_not_perform = 16;

  // Reported rather than primary record
  message ReportedX {
    option (.google.fhir.proto.is_choice_type) = true;

    oneof choice {
      Boolean boolean = 1;
      Reference reference = 2 [
        (.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",
        (.google.fhir.proto.valid_reference_type) = "Organization"
      ];
    }
  }
  ReportedX reported = 17;

  // Medication to be taken
  message MedicationX {
    option (.google.fhir.proto.is_choice_type) = true;

    oneof choice {
      CodeableConcept codeable_concept = 1;
      Reference reference = 2
          [(.google.fhir.proto.valid_reference_type) = "Medication"];
    }
  }
  MedicationX medication = 18
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Who or group medication request is for
  Reference subject = 19 [
    (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "Group"
  ];

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

  // Information to support ordering of the medication
  repeated Reference supporting_information = 21
      [(.google.fhir.proto.valid_reference_type) = "Resource"];

  // When request was initially authored
  DateTime authored_on = 22;

  // Who/What requested the Request
  Reference requester = 23 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Organization",
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
    (.google.fhir.proto.valid_reference_type) = "Device"
  ];

  // Intended performer of administration
  Reference performer = 24 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Organization",
    (.google.fhir.proto.valid_reference_type) = "Patient",
    (.google.fhir.proto.valid_reference_type) = "Device",
    (.google.fhir.proto.valid_reference_type) = "RelatedPerson",
    (.google.fhir.proto.valid_reference_type) = "CareTeam"
  ];

  // Desired kind of performer of the medication administration
  CodeableConcept performer_type = 25;

  // Person who entered the request
  Reference recorder = 26 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole"
  ];

  // Reason or indication for ordering or not ordering the medication
  repeated CodeableConcept reason_code = 27;

  // Condition or observation that supports why the prescription is being
  // written
  repeated Reference reason_reference = 28 [
    (.google.fhir.proto.valid_reference_type) = "Condition",
    (.google.fhir.proto.valid_reference_type) = "Observation"
  ];

  // Instantiates FHIR protocol or definition
  repeated Canonical instantiates_canonical = 29;

  // Instantiates external protocol or definition
  repeated Uri instantiates_uri = 30;

  // What request fulfills
  repeated Reference based_on = 31 [
    (.google.fhir.proto.valid_reference_type) = "CarePlan",
    (.google.fhir.proto.valid_reference_type) = "MedicationRequest",
    (.google.fhir.proto.valid_reference_type) = "ServiceRequest",
    (.google.fhir.proto.valid_reference_type) = "ImmunizationRecommendation"
  ];

  // Composite request this is part of
  Identifier group_identifier = 32;

  // Overall pattern of medication administration
  CodeableConcept course_of_therapy_type = 33;

  // Associated insurance coverage
  repeated Reference insurance = 34 [
    (.google.fhir.proto.valid_reference_type) = "Coverage",
    (.google.fhir.proto.valid_reference_type) = "ClaimResponse"
  ];

  // Information about the prescription
  repeated Annotation note = 35;

  // How the medication should be taken
  repeated Dosage dosage_instruction = 36;

  // Medication supply authorization
  message DispenseRequest {
    // 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;

    // First fill details
    message InitialFill {
      // 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;

      // First fill quantity
      SimpleQuantity quantity = 4;

      // First fill duration
      Duration duration = 5;
    }
    InitialFill initial_fill = 4;

    // Minimum period of time between dispenses
    Duration dispense_interval = 5;

    // Time period supply is authorized for
    Period validity_period = 6;

    // Number of refills authorized
    UnsignedInt number_of_repeats_allowed = 7;

    // Amount of medication to supply per dispense
    SimpleQuantity quantity = 8;

    // Number of days supply per dispense
    Duration expected_supply_duration = 9;

    // Intended dispenser
    Reference performer = 10
        [(.google.fhir.proto.valid_reference_type) = "Organization"];
  }
  DispenseRequest dispense_request = 37;

  // Any restrictions on medication substitution
  message Substitution {
    // 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;

    // Whether substitution is allowed or not
    message AllowedX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Boolean boolean = 1;
        CodeableConcept codeable_concept = 2;
      }
    }
    AllowedX allowed = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Why should (not) substitution be made
    CodeableConcept reason = 5;
  }
  Substitution substitution = 38;

  // An order/prescription that is being replaced
  Reference prior_prescription = 39
      [(.google.fhir.proto.valid_reference_type) = "MedicationRequest"];

  // Clinical Issue with action
  repeated Reference detected_issue = 40
      [(.google.fhir.proto.valid_reference_type) = "DetectedIssue"];

  // A list of events of interest in the lifecycle
  repeated Reference event_history = 41
      [(.google.fhir.proto.valid_reference_type) = "Provenance"];
}
