refactoring
This commit is contained in:
@@ -5,23 +5,24 @@ class SymptomsByBatchcodesTableFactory:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createSymptomsByBatchcodesTable(VAERSVAX, VAERSSYMPTOMS):
|
def createSymptomsByBatchcodesTable(VAERSVAX, VAERSSYMPTOMS):
|
||||||
|
index_columns = ['VAX_LOT1', 'VAX_LOT2']
|
||||||
return pd.merge(
|
return pd.merge(
|
||||||
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX),
|
SymptomsByBatchcodesTableFactory._get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns),
|
||||||
SymptomsByBatchcodesTableFactory._getSymptomsTable(VAERSSYMPTOMS),
|
SymptomsByBatchcodesTableFactory._getSymptomsTable(VAERSSYMPTOMS),
|
||||||
on = 'VAERS_ID').set_index(['VAX_LOT1', 'VAX_LOT2'])[['SYMPTOMS']]
|
on = 'VAERS_ID').set_index(index_columns)[['SYMPTOMS']]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX):
|
def _get_VAERSVAX_WITH_VAX_LOTS(VAERSVAX, index_columns):
|
||||||
return pd.concat(
|
return pd.concat(
|
||||||
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX)],
|
[VAERSVAX, SymptomsByBatchcodesTableFactory._getVaxLotsTable(VAERSVAX, index_columns)],
|
||||||
axis='columns').reset_index().drop_duplicates(subset=['VAERS_ID', 'VAX_LOT1', 'VAX_LOT2'])
|
axis='columns').reset_index().drop_duplicates(subset = ['VAERS_ID'] + index_columns)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _getVaxLotsTable(VAERSVAX):
|
def _getVaxLotsTable(VAERSVAX, index_columns):
|
||||||
VAX_LOT_LIST_Table = VAERSVAX.groupby("VAERS_ID").agg(VAX_LOT_LIST = pd.NamedAgg(column = 'VAX_LOT', aggfunc = list))
|
VAX_LOT_LIST_Table = VAERSVAX.groupby("VAERS_ID").agg(VAX_LOT_LIST = pd.NamedAgg(column = 'VAX_LOT', aggfunc = list))
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
[fill(VAX_LOTS, 2, str(np.nan)) for VAX_LOTS in VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist()],
|
[fill(VAX_LOTS, 2, str(np.nan)) for VAX_LOTS in VAX_LOT_LIST_Table['VAX_LOT_LIST'].tolist()],
|
||||||
columns = ['VAX_LOT1', 'VAX_LOT2'],
|
columns = index_columns,
|
||||||
index = VAX_LOT_LIST_Table.index)
|
index = VAX_LOT_LIST_Table.index)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ class SymptomsByBatchcodesTableFactoryTest(unittest.TestCase):
|
|||||||
def test_createSymptomsByBatchcodesTable_two_patients_same_symptoms(self):
|
def test_createSymptomsByBatchcodesTable_two_patients_same_symptoms(self):
|
||||||
# Given
|
# Given
|
||||||
VAERSVAX = TestHelper.createDataFrame(
|
VAERSVAX = TestHelper.createDataFrame(
|
||||||
columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],
|
columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],
|
||||||
data = [ ['COVID19', 'JANSSEN', 'EW0175', '1'],
|
data = [ ['COVID19', 'JANSSEN', 'EW0175', '1'],
|
||||||
['COVID19', 'JANSSEN', 'EW0175', '1']],
|
['COVID19', 'JANSSEN', 'EW0175', '1']],
|
||||||
index = pd.Index(
|
index = pd.Index(
|
||||||
name = 'VAERS_ID',
|
name = 'VAERS_ID',
|
||||||
data=[
|
data=[
|
||||||
|
|||||||
Reference in New Issue
Block a user