<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_instruments_vocabulary(self, analysis_brain):
 """Returns a vocabulary with the valid and active instruments available for the analysis passed in. If the option "Allow instrument entry of results" for the Analysis is disabled, the function returns an empty vocabulary. If the analysis passed in is a Reference Analysis (Blank or Control), the vocabulary, the invalid instruments will be included in the vocabulary too. The vocabulary is a list of dictionaries. Each dictionary has the following structure: {'ResultValue': <instrument_UID>, 'ResultText': <instrument_Title>} :param analysis_brain: A single Analysis or ReferenceAnalysis :type analysis_brain: Analysis or.ReferenceAnalysis :return: A vocabulary with the instruments for the analysis :rtype: A list of dicts: [{'ResultValue':UID, 'ResultText':Title}] """

        if not analysis_brain.getInstrumentEntryOfResults:
            # Instrument entry of results for this analysis is not allowed
            return list()

        # If the analysis is a QC analysis, display all instruments, including
        # those uncalibrated or for which the last QC test failed.
        meta_type = analysis_brain.meta_type
        uncalibrated = meta_type == 'ReferenceAnalysis'
        if meta_type == 'DuplicateAnalysis':
            base_analysis_type = analysis_brain.getAnalysisPortalType
            uncalibrated = base_analysis_type == 'ReferenceAnalysis'

        uids = analysis_brain.getAllowedInstrumentUIDs
        query = {'portal_type': 'Instrument',
                 'is_active': True,
                 'UID': uids}
        brains = api.search(query, 'bika_setup_catalog')
        vocab = [{'ResultValue': '', 'ResultText': _('None')}]
        for brain in brains:
            instrument = self.get_object(brain)
            if uncalibrated and not instrument.isOutOfDate():
                # Is a QC analysis, include instrument also if is not valid
                vocab.append({'ResultValue': instrument.UID(),
                              'ResultText': instrument.Title()})
            if instrument.isValid():
                # Only add the 'valid' instruments: certificate
                # on-date and valid internal calibration tests
                vocab.append({'ResultValue': instrument.UID(),
                              'ResultText': instrument.Title()})
        return vocab