コード例 #1
0
    def run(self):
        ''' 
        Make a key-value map of certain attributes in the Open FDA dataset
        '''
        print('Acquiring Records')
        for record in self.source.acquire_labels():
            if 'openfda' in record and 'product_ndc' in record['openfda']:
                for entry in record['openfda']['product_ndc']:
                    ndc = ProductNdc.parse(entry)
                    id = ndc.format()
                    for op in self.features:
                        op['feature'].accumulate(id, record)
        
        print('Writing Features')
        for op in self.features:
            feature = op['feature']
            baseName = '-'.join(feature.fields)
            fileName = io.relativeToAbsolute('../../data/'+baseName+'.txt')

            with open(fileName, 'w', encoding='utf-8') as f:
                print('product_ndc', op['column'], sep='\t', file=f)
                for pair in sorted(feature.data, key=itemgetter(0, 1)):
                    value = pair[1]
                    for fn in op['transform']:
                        value = fn(value)
                    print(pair[0],value,sep='\t',file=f)
コード例 #2
0
    def run(self):
        ''' 
        Make a key-value map of certain attributes in the Open FDA dataset
        '''
        print('Acquiring Records')
        for record in self.source.acquire_labels():
            if 'openfda' in record and 'product_ndc' in record['openfda']:
                for entry in record['openfda']['product_ndc']:
                    ndc = ProductNdc.parse(entry)
                    id = ndc.format()
                    for op in self.features:
                        op['feature'].accumulate(id, record)

        print('Writing Features')
        for op in self.features:
            feature = op['feature']
            baseName = '-'.join(feature.fields)
            fileName = io.relativeToAbsolute('../../data/' + baseName + '.txt')

            with open(fileName, 'w', encoding='utf-8') as f:
                print('product_ndc', op['column'], sep='\t', file=f)
                for pair in sorted(feature.data, key=itemgetter(0, 1)):
                    value = pair[1]
                    for fn in op['transform']:
                        value = fn(value)
                    print(pair[0], value, sep='\t', file=f)
コード例 #3
0
 def map_fda(self, x):
     ''' Project an element from the FDA product list
     '''
     ndc = ProductNdc.parse(x['PRODUCTNDC'])
     return {'product_ndc': ndc.format(),
             'proprietary_name': self.title(x['PROPRIETARYNAME']),
             'nonproprietary_name': self.title(x['NONPROPRIETARYNAME']),
             'dea_schedule': x['DEASCHEDULE']
             }
コード例 #4
0
 def map_fda(self, x):
     ''' Project an element from the FDA product list
     '''
     ndc = ProductNdc.parse(x['PRODUCTNDC'])
     return {
         'product_ndc': ndc.format(),
         'proprietary_name': self.title(x['PROPRIETARYNAME']),
         'nonproprietary_name': self.title(x['NONPROPRIETARYNAME']),
         'dea_schedule': x['DEASCHEDULE']
     }
コード例 #5
0
    def test_fda(self):
        self.suite[4]['formatted'] = '99999-009'
        self.suite[9]['formatted'] = '99999-099'
        self.suite[14]['formatted'] = '99999-999'

        for s in self.suite:
            actual = ProductNdc.parse(s['formatted'])
            self.assertEqual(s['l'], actual.labeler)
            self.assertEqual(s['prc'], actual.productCode)
            self.assertEqual(s['formatted'], actual.format_fda())
コード例 #6
0
    def test_fda(self):
        self.suite[4]['formatted'] = '99999-009'
        self.suite[9]['formatted'] = '99999-099'
        self.suite[14]['formatted'] = '99999-999'

        for s in self.suite:
            actual = ProductNdc.parse(s['formatted'])
            self.assertEqual(s['l'], actual.labeler)
            self.assertEqual(s['prc'], actual.productCode)
            self.assertEqual(s['formatted'], actual.format_fda())
コード例 #7
0
 def _map(self, label):
     ''' A generator function that produces multiple elements from each 
     OpenFDA record
     '''
     if ('openfda' in label and 'product_ndc' in label['openfda'] and
         'brand_name' in label['openfda']):
         asString = json.dumps(label)
         for x in label['openfda']['brand_name']:
             brand = self.sourceNames.title(x)
             for y in label['openfda']['product_ndc']:
                 ndc = ProductNdc.parse(y).format()
                 yield {'proprietary_name': brand, 
                        'ndc':ndc, 
                        'size':len(asString)}
コード例 #8
0
    def _map(self, x):
        ''' Extend the manufacturer record to include the labeler value from 
        the product NDC and the partition key to use
        '''
        ndc = ProductNdc.parse(x['product_ndc'])
        partition = x['name']
        for fn in [self._stripThe, self._fixEDotFO, self._defaultPartition]:
            partition = fn(partition)

        return {'name': x['name'],
                'labeler': ndc.labeler,
                'product_ndc': x['product_ndc'],
                'partition' : partition
                }
コード例 #9
0
    def _map(self, x):
        ''' Extend the manufacturer record to include the labeler value from 
        the product NDC and the partition key to use
        '''
        ndc = ProductNdc.parse(x['product_ndc'])
        partition = x['name']
        for fn in [self._stripThe, self._fixEDotFO, self._defaultPartition]:
            partition = fn(partition)

        return {
            'name': x['name'],
            'labeler': ndc.labeler,
            'product_ndc': x['product_ndc'],
            'partition': partition
        }
コード例 #10
0
 def test_nutricel(self):
     actual = ProductNdc.parse('53157-AS3')
     self.assertEqual(53157, actual.labeler)
     self.assertEqual(120, actual.productCode)
     self.assertEqual('53157-0120', actual.format())
コード例 #11
0
 def test_canon(self):
     for s in self.suite:
         actual = ProductNdc.parse(s['formatted'])
         self.assertEqual(s['l'], actual.labeler)
         self.assertEqual(s['prc'], actual.productCode)
         self.assertEqual(s['formatted'], actual.format())
コード例 #12
0
 def test_nutricel(self):
     actual = ProductNdc.parse('53157-AS3')
     self.assertEqual(53157, actual.labeler)
     self.assertEqual(120, actual.productCode)
     self.assertEqual('53157-0120', actual.format())
コード例 #13
0
 def test_canon(self):
     for s in self.suite:
         actual = ProductNdc.parse(s['formatted'])
         self.assertEqual(s['l'], actual.labeler)
         self.assertEqual(s['prc'], actual.productCode)
         self.assertEqual(s['formatted'], actual.format())