def run(self):
        ''' Perform an inner join between the Medicare and FDA spreadsheets
        '''
        print('Load the FDA info as a dictionary')
        fda_info = {x['product_ndc']: x for x in self.acquire_fda_ndc() }

        print('Join to the Medicare spreadsheet and save')
        io.saveAsTabbedText(self.join(fda_info), '../../data/product_ndc.txt')
Exemple #2
0
    def run(self):
        ''' Perform an inner join between the Medicare and FDA spreadsheets
        '''
        print('Load the FDA info as a dictionary')
        fda_info = {x['product_ndc']: x for x in self.acquire_fda_ndc()}

        print('Join to the Medicare spreadsheet and save')
        io.saveAsTabbedText(self.join(fda_info), '../../data/product_ndc.txt')
Exemple #3
0
    def run(self):
        ''' Use the size of a record in the FDA data set to determine which 
        package or product NDC is considered _the_ representitive for the same
        proprietary name
        '''
        print('Loading White List')
        whiteListFileName = io.relativeToAbsolute('../../data/product_ndc.txt')
        records = []
        with open(whiteListFileName) as f:
            for row in csv.DictReader(f, dialect=csv.excel_tab):
                # for some reason a weird 'None' column appears
                records.append({k:v for k,v in row.items() if k})

        partitions = {x['proprietary_name']: [] for x in records}
        products = {x['product_ndc'] for x in records if x['proprietary_name']}

        print('Mapping Labels')
        for node in self._mapLabels():
            nameKey = node['proprietary_name']
            prodKey = node['ndc']
            if nameKey in partitions and prodKey in products:
                partitions[nameKey].append(node)

        print('Reducing to Canon')
        outFileName = io.relativeToAbsolute('../../data/canon_drugs.txt')
        canon = {x for x in self._reduceToCanon(partitions)}

        print('Updating NDC Whitelist')
        for row in records:
            tuple = (row['proprietary_name'], row['product_ndc'])
            if tuple in canon:
                # consume because multiple package codes map to this key
                canon.remove(tuple) 
                row['is_canon'] = 'true'
            else:
                row['is_canon'] = 'false'

        print('Saving')
        tempName = io.relativeToAbsolute('../../data/product_ndc_canon.txt')
        io.saveAsTabbedText(records, '../../data/product_ndc_canon.txt')

        # no errors, rename
        os.remove(whiteListFileName)
        os.rename(tempName, whiteListFileName)