class Admin::Admissions::Families::Current::MedicalsController < Admin::Admissions::Controller
  include Admin::Admissions::FamilyScoped

  def show
    render_success :ok, json: medical_props
  end

  def update
    if medical.update(medical_params)
      render_success :ok, object: :medical_fields, json: medical_props
    else
      render_error :unprocessable_entity, errors: :medical
    end
  end

  private
    def medical
      @medical ||= family.find_or_build_family_medical
    end

    def medical_params
      params.permit(Admission::MedicalRevision::MEDICAL_ATTRIBUTES)
    end

    def medical_props
      {
        physician: medical.physician,
        physician_phone: medical.physician_phone,
        physician_address: medical.physician_address,
        physician_address_ext: medical.physician_address_ext,
        physician_city: medical.physician_city,
        physician_state: medical.physician_state,
        physician_zip: medical.physician_zip,
        physician_country_id: medical.physician_country_id,
        dentist: medical.dentist,
        dentist_phone: medical.dentist_phone,
        dentist_address: medical.dentist_address,
        dentist_address_ext: medical.dentist_address_ext,
        dentist_city: medical.dentist_city,
        dentist_state: medical.dentist_state,
        dentist_zip: medical.dentist_zip,
        dentist_country_id: medical.dentist_country_id,
        insurance_company: medical.insurance_company,
        insurance_plan: medical.insurance_plan,
        insurance_group: medical.insurance_group,
        hospital: medical.hospital,
        comments: medical.comments
      }
    end
end
