© Published by the BMJ Publishing Group Limited. For permission to use (where not already granted under a licence) please go to http://www.bmj.com/company/products-services/rights-And-licensing/. Objective To estimate the prevalence of HIV testing among patients diagnosed with an indicator condition (IC) for HIV, seen in primary care (PC) in Catalonia, and to estimate the prevalence of HIV infection among those patients. Design Cross-sectional and population-based study in patients aged between 16 and 65 diagnosed with an IC within PC in Catalonia. Methods Data used in this study were extracted from a large population-based public health database in Spain, the Information System for the Development of Research in Primary Care (SIDIAP). All participants registered in SIDIAP from 1 January 2010 to 31 August 2012 and with a diagnosis of an IC were screened to identify those with an HIV test within the following 4 €..months. Results 99 €..426 patients were diagnosed with an IC during the study period. In these patients, there were 102 €..647 episodes in which at least one IC was diagnosed. An HIV test was performed within 4 months in only 18 €..515 of the episodes in which an IC was diagnosed (18.5%). The prevalence of HIV infection was 1.46%. Women (OR 1.35, 95% CI 1.30 to 1.39), people aged 50 or over (OR 2.85, 95% CI 2.69 to 3.00) and patients having a single IC (OR 3.59. 95% CI 3.20 to 4.03) had the greatest odds of not having an HIV test. Conclusions The study highlights the persistence of missed opportunities for HIV testing within PC in Catalonia. Urgent engagement with PC professionals is required in order to increase HIV testing and prevent late HIV diagnoses.