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

// Auto-generated from StructureDefinition for Claim.
// Claim, Pre-determination or Pre-authorization.
// See http://hl7.org/fhir/StructureDefinition/Claim
message Claim {
  option (.google.fhir.proto.structure_definition_kind) = KIND_RESOURCE;
  option (.google.fhir.proto.fhir_structure_definition_url) =
      "http://hl7.org/fhir/StructureDefinition/Claim";

  // 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:
  // Claim.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 claim
  repeated Identifier identifier = 10;

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

    FinancialResourceStatusCode.Value value = 1;

    String id = 2;

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

  // Category or discipline
  CodeableConcept type = 12
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // More granular claim type
  CodeableConcept sub_type = 13;

  // claim | preauthorization | predetermination
  message UseCode {
    option (.google.fhir.proto.structure_definition_kind) = KIND_PRIMITIVE_TYPE;
    option (.google.fhir.proto.fhir_valueset_url) =
        "http://hl7.org/fhir/ValueSet/claim-use";
    option (.google.fhir.proto.fhir_profile_base) =
        "http://hl7.org/fhir/StructureDefinition/code";

    .google.fhir.r4.core.UseCode.Value value = 1;

    String id = 2;

    repeated Extension extension = 3;
  }
  UseCode use = 14
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // The recipient of the products and services
  Reference patient = 15 [
    (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
    (.google.fhir.proto.valid_reference_type) = "Patient"
  ];

  // Relevant time frame for the claim
  Period billable_period = 16;

  // Resource creation date
  DateTime created = 17
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Author of the claim
  Reference enterer = 18 [
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole"
  ];

  // Target
  Reference insurer = 19
      [(.google.fhir.proto.valid_reference_type) = "Organization"];

  // Party responsible for the claim
  Reference provider = 20 [
    (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
    (.google.fhir.proto.valid_reference_type) = "Practitioner",
    (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
    (.google.fhir.proto.valid_reference_type) = "Organization"
  ];

  // Desired processing ugency
  CodeableConcept priority = 21
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // For whom to reserve funds
  CodeableConcept funds_reserve = 22;

  // Prior or corollary claims
  message RelatedClaim {
    // 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;

    // Reference to the related claim
    Reference claim = 4 [(.google.fhir.proto.valid_reference_type) = "Claim"];

    // How the reference claim is related
    CodeableConcept relationship = 5;

    // File or case reference
    Identifier reference = 6;
  }
  repeated RelatedClaim related = 23;

  // Prescription authorizing services and products
  Reference prescription = 24 [
    (.google.fhir.proto.valid_reference_type) = "DeviceRequest",
    (.google.fhir.proto.valid_reference_type) = "MedicationRequest",
    (.google.fhir.proto.valid_reference_type) = "VisionPrescription"
  ];

  // Original prescription if superseded by fulfiller
  Reference original_prescription = 25 [
    (.google.fhir.proto.valid_reference_type) = "DeviceRequest",
    (.google.fhir.proto.valid_reference_type) = "MedicationRequest",
    (.google.fhir.proto.valid_reference_type) = "VisionPrescription"
  ];

  // Recipient of benefits payable
  message Payee {
    // 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;

    // Category of recipient
    CodeableConcept type = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Recipient reference
    Reference party = 5 [
      (.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"
    ];
  }
  Payee payee = 26;

  // Treatment referral
  Reference referral = 27
      [(.google.fhir.proto.valid_reference_type) = "ServiceRequest"];

  // Servicing facility
  Reference facility = 28
      [(.google.fhir.proto.valid_reference_type) = "Location"];

  // Members of the care team
  message CareTeam {
    // 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;

    // Order of care team
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Practitioner or organization
    Reference provider = 5 [
      (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
      (.google.fhir.proto.valid_reference_type) = "Practitioner",
      (.google.fhir.proto.valid_reference_type) = "PractitionerRole",
      (.google.fhir.proto.valid_reference_type) = "Organization"
    ];

    // Indicator of the lead practitioner
    Boolean responsible = 6;

    // Function within the team
    CodeableConcept role = 7;

    // Practitioner credential or specialization
    CodeableConcept qualification = 8;
  }
  repeated CareTeam care_team = 29;

  // Supporting information
  message SupportingInformation {
    // 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;

    // Information instance identifier
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Classification of the supplied information
    CodeableConcept category = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Type of information
    CodeableConcept code = 6;

    // When it occurred
    message TimingX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Date date = 1;
        Period period = 2;
      }
    }
    TimingX timing = 7;

    // Data to be provided
    message ValueX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Boolean boolean = 1;
        String string_value = 2 [json_name = "string"];
        Quantity quantity = 3;
        Attachment attachment = 4;
        Reference reference = 5
            [(.google.fhir.proto.valid_reference_type) = "Resource"];
      }
    }
    ValueX value = 8;

    // Explanation for the information
    CodeableConcept reason = 9;
  }
  repeated SupportingInformation supporting_info = 30;

  // Pertinent diagnosis information
  message Diagnosis {
    // 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;

    // Diagnosis instance identifier
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Nature of illness or problem
    message DiagnosisX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        CodeableConcept codeable_concept = 1;
        Reference reference = 2
            [(.google.fhir.proto.valid_reference_type) = "Condition"];
      }
    }
    DiagnosisX diagnosis = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Timing or nature of the diagnosis
    repeated CodeableConcept type = 6;

    // Present on admission
    CodeableConcept on_admission = 7;

    // Package billing code
    CodeableConcept package_code = 8;
  }
  repeated Diagnosis diagnosis = 31;

  // Clinical procedures performed
  message Procedure {
    // 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;

    // Procedure instance identifier
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Category of Procedure
    repeated CodeableConcept type = 5;

    // When the procedure was performed
    DateTime date = 6;

    // Specific clinical procedure
    message ProcedureX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        CodeableConcept codeable_concept = 1;
        Reference reference = 2
            [(.google.fhir.proto.valid_reference_type) = "Procedure"];
      }
    }
    ProcedureX procedure = 7
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Unique device identifier
    repeated Reference udi = 8
        [(.google.fhir.proto.valid_reference_type) = "Device"];
  }
  repeated Procedure procedure = 32;

  // Patient insurance information
  message Insurance {
    // 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;

    // Insurance instance identifier
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Coverage to be used for adjudication
    Boolean focal = 5
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Pre-assigned Claim number
    Identifier identifier = 6;

    // Insurance information
    Reference coverage = 7 [
      (.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR,
      (.google.fhir.proto.valid_reference_type) = "Coverage"
    ];

    // Additional provider contract number
    String business_arrangement = 8;

    // Prior authorization reference number
    repeated String pre_auth_ref = 9;

    // Adjudication results
    Reference claim_response = 10
        [(.google.fhir.proto.valid_reference_type) = "ClaimResponse"];
  }
  repeated Insurance insurance = 33
      [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

  // Details of the event
  message Accident {
    // 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;

    // When the incident occurred
    Date date = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // The nature of the accident
    CodeableConcept type = 5;

    // Where the event occurred
    message LocationX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Address address = 1;
        Reference reference = 2
            [(.google.fhir.proto.valid_reference_type) = "Location"];
      }
    }
    LocationX location = 6;
  }
  Accident accident = 34;

  // Product or service provided
  message Item {
    // 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;

    // Item instance identifier
    PositiveInt sequence = 4
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Applicable careTeam members
    repeated PositiveInt care_team_sequence = 5;

    // Applicable diagnoses
    repeated PositiveInt diagnosis_sequence = 6;

    // Applicable procedures
    repeated PositiveInt procedure_sequence = 7;

    // Applicable exception and supporting information
    repeated PositiveInt information_sequence = 8;

    // Revenue or cost center code
    CodeableConcept revenue = 9;

    // Benefit classification
    CodeableConcept category = 10;

    // Billing, service, product, or drug code
    CodeableConcept product_or_service = 11
        [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

    // Product or service billing modifiers
    repeated CodeableConcept modifier = 12;

    // Program the product or service is provided under
    repeated CodeableConcept program_code = 13;

    // Date or dates of service or product delivery
    message ServicedX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        Date date = 1;
        Period period = 2;
      }
    }
    ServicedX serviced = 14;

    // Place of service or where product was supplied
    message LocationX {
      option (.google.fhir.proto.is_choice_type) = true;

      oneof choice {
        CodeableConcept codeable_concept = 1;
        Address address = 2;
        Reference reference = 3
            [(.google.fhir.proto.valid_reference_type) = "Location"];
      }
    }
    LocationX location = 15;

    // Count of products or services
    SimpleQuantity quantity = 16;

    // Fee, charge or cost per item
    Money unit_price = 17;

    // Price scaling factor
    Decimal factor = 18;

    // Total item cost
    Money net = 19;

    // Unique device identifier
    repeated Reference udi = 20
        [(.google.fhir.proto.valid_reference_type) = "Device"];

    // Anatomical location
    CodeableConcept body_site = 21;

    // Anatomical sub-location
    repeated CodeableConcept sub_site = 22;

    // Encounters related to this billed item
    repeated Reference encounter = 23
        [(.google.fhir.proto.valid_reference_type) = "Encounter"];

    // Product or service provided
    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;

      // Item instance identifier
      PositiveInt sequence = 4
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Revenue or cost center code
      CodeableConcept revenue = 5;

      // Benefit classification
      CodeableConcept category = 6;

      // Billing, service, product, or drug code
      CodeableConcept product_or_service = 7
          [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

      // Service/Product billing modifiers
      repeated CodeableConcept modifier = 8;

      // Program the product or service is provided under
      repeated CodeableConcept program_code = 9;

      // Count of products or services
      SimpleQuantity quantity = 10;

      // Fee, charge or cost per item
      Money unit_price = 11;

      // Price scaling factor
      Decimal factor = 12;

      // Total item cost
      Money net = 13;

      // Unique device identifier
      repeated Reference udi = 14
          [(.google.fhir.proto.valid_reference_type) = "Device"];

      // Product or service provided
      message SubDetail {
        // 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;

        // Item instance identifier
        PositiveInt sequence = 4
            [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

        // Revenue or cost center code
        CodeableConcept revenue = 5;

        // Benefit classification
        CodeableConcept category = 6;

        // Billing, service, product, or drug code
        CodeableConcept product_or_service = 7
            [(.google.fhir.proto.validation_requirement) = REQUIRED_BY_FHIR];

        // Service/Product billing modifiers
        repeated CodeableConcept modifier = 8;

        // Program the product or service is provided under
        repeated CodeableConcept program_code = 9;

        // Count of products or services
        SimpleQuantity quantity = 10;

        // Fee, charge or cost per item
        Money unit_price = 11;

        // Price scaling factor
        Decimal factor = 12;

        // Total item cost
        Money net = 13;

        // Unique device identifier
        repeated Reference udi = 14
            [(.google.fhir.proto.valid_reference_type) = "Device"];
      }
      repeated SubDetail sub_detail = 15;
    }
    repeated Detail detail = 24;
  }
  repeated Item item = 35;

  // Total claim cost
  Money total = 36;
}
