starting BatchcodeCompletion

This commit is contained in:
frankknoll
2023-03-24 17:53:44 +01:00
parent 951ef62200
commit 0d4006ea92
2 changed files with 61 additions and 0 deletions

View 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

View 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)