A 25-year-old woman presents with a 6-week history of persistent dry cough, night sweats, and unintentional weight loss of 4kg. She recently emigrated from a country with a high prevalence of tuberculosis (TB). Chest X-ray reveals patchy consolidation in the right upper lobe with possible cavitation. What is the most appropriate next investigation to confirm the diagnosis?