# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_08_14_203449) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "appointments", force: :cascade do |t|
    t.datetime "start"
    t.datetime "end"
    t.boolean "active", default: true, null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.bigint "ubs_id"
    t.integer "patient_id"
    t.datetime "check_in"
    t.datetime "check_out"
    t.string "suspend_reason"
    t.index ["patient_id"], name: "index_appointments_on_patient_id"
    t.index ["start"], name: "index_appointments_on_start"
    t.index ["ubs_id"], name: "index_appointments_on_ubs_id"
  end

  create_table "conditions", force: :cascade do |t|
    t.string "name"
    t.datetime "start_at", null: false
    t.datetime "end_at", null: false
    t.integer "min_age"
    t.integer "max_age"
    t.boolean "can_register", default: false, null: false
    t.boolean "can_schedule", default: false, null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["end_at"], name: "index_conditions_on_end_at"
    t.index ["start_at"], name: "index_conditions_on_start_at"
  end

  create_table "conditions_groups", force: :cascade do |t|
    t.bigint "group_id", null: false
    t.bigint "condition_id", null: false
    t.index ["condition_id", "group_id"], name: "index_conditions_groups_on_scg_id"
    t.index ["condition_id"], name: "index_conditions_groups_on_condition_id"
    t.index ["group_id", "condition_id"], name: "index_conditions_groups_on_gsc_id"
    t.index ["group_id"], name: "index_conditions_groups_on_group_id"
  end

  create_table "conditions_ubs", force: :cascade do |t|
    t.bigint "ubs_id", null: false
    t.bigint "condition_id", null: false
    t.index ["condition_id", "ubs_id"], name: "index_conditions_ubs_on_cgu_id"
    t.index ["condition_id"], name: "index_conditions_ubs_on_condition_id"
    t.index ["ubs_id", "condition_id"], name: "index_conditions_ubs_on_usc_id"
    t.index ["ubs_id"], name: "index_conditions_ubs_on_ubs_id"
  end

  create_table "doses", force: :cascade do |t|
    t.bigint "patient_id", null: false
    t.bigint "appointment_id", null: false
    t.bigint "vaccine_id", null: false
    t.integer "sequence_number", default: 1, null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.bigint "follow_up_appointment_id"
    t.index ["appointment_id"], name: "index_doses_on_appointment_id"
    t.index ["follow_up_appointment_id"], name: "index_doses_on_follow_up_appointment_id"
    t.index ["patient_id"], name: "index_doses_on_patient_id"
    t.index ["vaccine_id"], name: "index_doses_on_vaccine_id"
  end

  create_table "groups", force: :cascade do |t|
    t.string "name"
    t.bigint "parent_group_id"
    t.integer "context", default: 0, null: false
    t.integer "position", default: 0, null: false
    t.boolean "active", default: true, null: false
    t.index ["active"], name: "index_groups_on_active"
    t.index ["context"], name: "index_groups_on_context"
    t.index ["parent_group_id"], name: "index_groups_on_parent_group_id"
    t.index ["position"], name: "index_groups_on_position"
  end

  create_table "groups_patients", id: false, force: :cascade do |t|
    t.bigint "patient_id", null: false
    t.bigint "group_id", null: false
    t.index ["group_id", "patient_id"], name: "index_groups_patients_on_group_id_and_patient_id"
    t.index ["patient_id", "group_id"], name: "index_groups_patients_on_patient_id_and_group_id", unique: true
  end

  create_table "inquiry_answers", force: :cascade do |t|
    t.string "text", null: false
    t.bigint "inquiry_question_id", null: false
    t.integer "position", default: 0, null: false
    t.boolean "active", default: true, null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["active"], name: "index_inquiry_answers_on_active"
    t.index ["inquiry_question_id"], name: "index_inquiry_answers_on_inquiry_question_id"
    t.index ["position"], name: "index_inquiry_answers_on_position"
  end

  create_table "inquiry_questions", force: :cascade do |t|
    t.string "text", null: false
    t.integer "form_type", default: 0, null: false
    t.integer "position", default: 0, null: false
    t.boolean "active", default: true, null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["active"], name: "index_inquiry_questions_on_active"
    t.index ["position"], name: "index_inquiry_questions_on_position"
  end

  create_table "neighborhoods", force: :cascade do |t|
    t.string "name"
    t.index ["name"], name: "index_neighborhoods_on_name", unique: true
  end

  create_table "neighborhoods_ubs", id: false, force: :cascade do |t|
    t.bigint "ubs_id", null: false
    t.bigint "neighborhood_id", null: false
    t.index ["neighborhood_id", "ubs_id"], name: "index_neighborhoods_ubs_on_neighborhood_id_and_ubs_id"
    t.index ["ubs_id", "neighborhood_id"], name: "index_neighborhoods_ubs_on_ubs_id_and_neighborhood_id"
  end

  create_table "pages", force: :cascade do |t|
    t.string "path", null: false
    t.string "title", null: false
    t.text "body", null: false
    t.integer "context", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["context"], name: "index_pages_on_context"
    t.index ["path"], name: "index_pages_on_path", unique: true
  end

  create_table "patients", force: :cascade do |t|
    t.string "email", default: ""
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "name", default: "", null: false
    t.string "cpf", default: "", null: false
    t.string "mother_name", default: "", null: false
    t.string "phone"
    t.string "other_phone"
    t.string "sus"
    t.string "fake_mothers", default: [], array: true
    t.integer "login_attempts", default: 0
    t.string "public_place"
    t.string "place_number"
    t.bigint "neighborhood_id"
    t.string "street_2"
    t.string "internal_note"
    t.datetime "user_updated_at"
    t.date "birthday", null: false
    t.index ["birthday"], name: "index_patients_on_birthday"
    t.index ["cpf"], name: "index_patients_on_cpf", unique: true
  end

  create_table "patients_inquiry_answers", force: :cascade do |t|
    t.bigint "patient_id", null: false
    t.bigint "inquiry_answer_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["inquiry_answer_id"], name: "index_patients_inquiry_answers_on_inquiry_answer_id"
    t.index ["patient_id"], name: "index_patients_inquiry_answers_on_patient_id"
  end

  create_table "ubs", force: :cascade do |t|
    t.string "name"
    t.string "shift_start"
    t.string "shift_end"
    t.string "break_start"
    t.string "break_end"
    t.integer "slot_interval_minutes"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "phone"
    t.string "address", default: ""
    t.string "cnes"
    t.boolean "active", default: false
    t.string "saturday_shift_start"
    t.string "saturday_break_start"
    t.string "saturday_break_end"
    t.string "saturday_shift_end"
    t.integer "appointments_per_time_slot", default: 1
    t.string "sunday_shift_start"
    t.string "sunday_break_start"
    t.string "sunday_break_end"
    t.string "sunday_shift_end"
    t.bigint "neighborhood_id"
    t.boolean "enabled_for_reschedule", default: false, null: false
    t.index ["cnes"], name: "index_ubs_on_cnes", unique: true
  end

  create_table "ubs_users", force: :cascade do |t|
    t.bigint "ubs_id", null: false
    t.bigint "user_id", null: false
    t.index ["ubs_id", "user_id"], name: "index_ubs_users_on_ubs_id_and_user_id", unique: true
    t.index ["ubs_id"], name: "index_ubs_users_on_ubs_id"
    t.index ["user_id"], name: "index_ubs_users_on_user_id"
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: ""
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "name", default: "", null: false
    t.boolean "administrator", default: false, null: false
    t.index ["name"], name: "index_users_on_name", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

  create_table "vaccines", force: :cascade do |t|
    t.string "name"
    t.string "formal_name"
    t.integer "second_dose_after_in_days"
    t.integer "third_dose_after_in_days"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["name"], name: "index_vaccines_on_name"
  end

  add_foreign_key "appointments", "ubs"
  add_foreign_key "conditions_groups", "conditions"
  add_foreign_key "conditions_groups", "groups"
  add_foreign_key "conditions_ubs", "conditions"
  add_foreign_key "conditions_ubs", "ubs"
  add_foreign_key "doses", "appointments"
  add_foreign_key "doses", "appointments", column: "follow_up_appointment_id"
  add_foreign_key "doses", "patients"
  add_foreign_key "doses", "vaccines"
  add_foreign_key "ubs_users", "ubs"
  add_foreign_key "ubs_users", "users"
end
