starting BatchcodeCompletion
This commit is contained in:
11
src/BatchcodeCompletion.py
Normal file
11
src/BatchcodeCompletion.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from SmartRegexpFactory import SmartRegexpFactory
|
||||
|
||||
class BatchcodeCompletion:
|
||||
|
||||
def __init__(self, ADR_by_Batchcode):
|
||||
self.ADR_by_Batchcode = ADR_by_Batchcode.sort_values(by = 'Adverse Reaction Reports', ascending = False)
|
||||
|
||||
def completeBatchcode(self, partialBatchcode):
|
||||
smartRegexp = SmartRegexpFactory().createSmartRegexp(partialBatchcode)
|
||||
filteredBbatchCodeTable = self.ADR_by_Batchcode[self.ADR_by_Batchcode.index.str.contains(smartRegexp, na=False, regex=True)]
|
||||
return filteredBbatchCodeTable.index[0] if not filteredBbatchCodeTable.empty else None
|
||||
50
src/BatchcodeCompletionTest.py
Normal file
50
src/BatchcodeCompletionTest.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import unittest
|
||||
from TestHelper import TestHelper
|
||||
from BatchcodeCompletion import BatchcodeCompletion
|
||||
import pandas as pd
|
||||
|
||||
class BatchcodeCompletionTest(unittest.TestCase):
|
||||
|
||||
def test_completeBatchcode(self):
|
||||
# Given
|
||||
ADR_by_Batchcode = TestHelper.createDataFrame(
|
||||
columns = ['Adverse Reaction Reports'],
|
||||
data = [ [1],
|
||||
[200],
|
||||
[149]],
|
||||
index = pd.Index(
|
||||
[
|
||||
'LOT000057A',
|
||||
'030L20B',
|
||||
'000057A'
|
||||
],
|
||||
name = 'VAX_LOT'))
|
||||
batchcodeCompletion = BatchcodeCompletion(ADR_by_Batchcode)
|
||||
|
||||
# When
|
||||
completedBatchcode = batchcodeCompletion.completeBatchcode('000057')
|
||||
|
||||
# Then
|
||||
self.assertEqual(completedBatchcode, '000057A')
|
||||
|
||||
def test_completeBatchcode_no_completion(self):
|
||||
# Given
|
||||
ADR_by_Batchcode = TestHelper.createDataFrame(
|
||||
columns = ['Adverse Reaction Reports'],
|
||||
data = [ [1],
|
||||
[200],
|
||||
[149]],
|
||||
index = pd.Index(
|
||||
[
|
||||
'LOT000057A',
|
||||
'030L20B',
|
||||
'000057A'
|
||||
],
|
||||
name = 'VAX_LOT'))
|
||||
batchcodeCompletion = BatchcodeCompletion(ADR_by_Batchcode)
|
||||
|
||||
# When
|
||||
completedBatchcode = batchcodeCompletion.completeBatchcode('non existing batch code')
|
||||
|
||||
# Then
|
||||
self.assertIsNone(completedBatchcode)
|
||||
Reference in New Issue
Block a user